Skip to content

Commit ca09203

Browse files
authored
Update call_indirect text syntax to match spec update (#1281)
Function type gets its own element rather than being a part of the call_indirect (see WebAssembly/spec#599)
1 parent 20b8b02 commit ca09203

77 files changed

Lines changed: 359 additions & 357 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/passes/Print.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
264264
printCallBody(curr);
265265
}
266266
void visitCallIndirect(CallIndirect *curr) {
267-
printOpening(o, "call_indirect ") << curr->fullType;
267+
printOpening(o, "call_indirect (type ") << curr->fullType << ')';
268268
incIndent();
269269
for (auto operand : curr->operands) {
270270
printFullLine(operand);

src/wasm/wasm-s-parser.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,9 @@ Expression* SExpressionWasmBuilder::makeCallImport(Element& s) {
13871387
Expression* SExpressionWasmBuilder::makeCallIndirect(Element& s) {
13881388
if (!wasm.table.exists) throw ParseException("no table");
13891389
auto ret = allocator.alloc<CallIndirect>();
1390-
IString type = s[1]->str();
1390+
Element& typeElement = *s[1];
1391+
if (typeElement[0]->str() != "type") throw ParseException("expected 'type' in call_indirect", s.line, s.col);
1392+
IString type = typeElement[1]->str();
13911393
auto* fullType = wasm.getFunctionTypeOrNull(type);
13921394
if (!fullType) throw ParseException("invalid call_indirect type", s.line, s.col);
13931395
ret->fullType = fullType->name;

test/ctor-eval/bad-indirect-call.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(elem (i32.const 0) $call-indirect)
77
(export "test1" $test1)
88
(func $test1
9-
(call_indirect $v (i32.const 1)) ;; unsafe to call, out of range
9+
(call_indirect (type $v) (i32.const 1)) ;; unsafe to call, out of range
1010
(i32.store8 (i32.const 20) (i32.const 120))
1111
)
1212
(func $call-indirect

test/ctor-eval/bad-indirect-call.wast.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(data (i32.const 10) "waka waka waka waka waka")
77
(export "test1" (func $test1))
88
(func $test1 (; 0 ;) (type $v)
9-
(call_indirect $v
9+
(call_indirect (type $v)
1010
(i32.const 1)
1111
)
1212
(i32.store8

test/ctor-eval/bad-indirect-call2.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
(elem (i32.const 0) $_abort $call-indirect)
88
(export "test1" $test1)
99
(func $test1
10-
(call_indirect $v (i32.const 0)) ;; unsafe to call, imported
10+
(call_indirect (type $v) (i32.const 0)) ;; unsafe to call, imported
1111
(i32.store8 (i32.const 20) (i32.const 120))
1212
)
1313
(func $call-indirect

test/ctor-eval/bad-indirect-call2.wast.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(data (i32.const 10) "waka waka waka waka waka")
99
(export "test1" (func $test1))
1010
(func $test1 (; 1 ;) (type $v)
11-
(call_indirect $v
11+
(call_indirect (type $v)
1212
(i32.const 0)
1313
)
1414
(i32.store8

test/ctor-eval/basics-flatten.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(func $test1
1414
(drop (i32.const 0)) ;; no work at all, really
1515
(call $safe-to-call) ;; safe to call
16-
(call_indirect $v (i32.const 0)) ;; safe to call
16+
(call_indirect (type $v) (i32.const 0)) ;; safe to call
1717
)
1818
(func $test2
1919
(drop (i32.load (i32.const 12))) ;; a safe load

test/ctor-eval/basics.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
(func $test1
1111
(drop (i32.const 0)) ;; no work at all, really
1212
(call $safe-to-call) ;; safe to call
13-
(call_indirect $v (i32.const 0)) ;; safe to call
13+
(call_indirect (type $v) (i32.const 0)) ;; safe to call
1414
)
1515
(func $test2
1616
(drop (i32.load (i32.const 12))) ;; a safe load

test/ctor-eval/indirect-call3.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(elem (get_global $tableBase) $_abort $call-indirect)
99
(export "test1" $test1)
1010
(func $test1
11-
(call_indirect $v (i32.const 1)) ;; safe to call
11+
(call_indirect (type $v) (i32.const 1)) ;; safe to call
1212
(i32.store8 (i32.const 20) (i32.const 120))
1313
)
1414
(func $call-indirect

test/dot_s/alias.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
(unreachable)
6363
)
6464
(func $dynCall_v (; 6 ;) (param $fptr i32)
65-
(call_indirect $FUNCSIG$v
65+
(call_indirect (type $FUNCSIG$v)
6666
(get_local $fptr)
6767
)
6868
)

0 commit comments

Comments
 (0)