summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/s2wasm.h47
-rw-r--r--test/dot_s/basics.wast2
-rw-r--r--test/dot_s/call.wast23
-rw-r--r--test/dot_s/cfg-stackify.wast14
-rw-r--r--test/dot_s/exit.wast2
-rw-r--r--test/dot_s/f32.wast2
-rw-r--r--test/dot_s/f64.wast2
-rw-r--r--test/dot_s/frem.wast4
-rw-r--r--test/dot_s/global.wast2
-rw-r--r--test/dot_s/import.wast12
-rw-r--r--test/dot_s/returned.wast6
-rw-r--r--test/dot_s/switch.wast24
-rw-r--r--test/dot_s/unreachable.wast2
-rw-r--r--test/dot_s/unused-argument.wast2
-rw-r--r--test/dot_s/varargs.wast2
15 files changed, 81 insertions, 65 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 45f12fdb7..1c3568aff 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -41,6 +41,8 @@ private:
typedef std::pair<std::vector<char>*, Name> Relocation; // the data, and the name whose address we should place there
std::vector<Relocation> relocations;
+ std::set<Name> implementedFunctions;
+
// utilities
void skipWhitespace() {
@@ -227,6 +229,17 @@ private:
// processors
void scan() {
+ while (*s) {
+ s = strstr(s, "\n .type ");
+ if (!s) break;
+ mustMatch("\n .type ");
+ Name name = getCommaSeparated();
+ skipComma();
+ if (!match("@function")) continue;
+ mustMatch(name.str);
+ mustMatch(":");
+ implementedFunctions.insert(name);
+ }
}
void process() {
@@ -434,24 +447,26 @@ private:
};
auto makeCall = [&](WasmType type) {
CallBase* curr;
- if (match("_import")) {
- curr = allocator.alloc<CallImport>();
- } else if (match("_indirect")) {
- curr = allocator.alloc<CallIndirect>();
+ Name assign;
+ if (match("_indirect")) {
+ auto indirect = allocator.alloc<CallIndirect>();
+ assign = getAssign();
+ indirect->target = getInput();
+ curr = indirect;
} else {
- curr = allocator.alloc<Call>();
- }
- Name assign = getAssign();
- if (curr->is<Call>()) {
- Name name = curr->dyn_cast<Call>()->target = getCommaSeparated();
- curr->type = type;
- } else if (curr->is<CallImport>()) {
- Name name = curr->dyn_cast<CallImport>()->target = getCommaSeparated();
- // XXX import definitions would help here, but still undecided in .s format
- } else {
- curr->dyn_cast<CallIndirect>()->target = getInput();
- // XXX no way to know return type, https://github.com/WebAssembly/experimental/issues/53
+ assign = getAssign();
+ Name target = getCommaSeparated();
+ if (implementedFunctions.count(target) > 0) {
+ auto plain = allocator.alloc<Call>();
+ plain->target = target;
+ curr = plain;
+ } else {
+ auto import = allocator.alloc<CallImport>();
+ import->target = target;
+ curr = import;
+ }
}
+ curr->type = type;
while (1) {
if (!skipComma()) break;
curr->operands.push_back(getInput());
diff --git a/test/dot_s/basics.wast b/test/dot_s/basics.wast
index 2dce3b877..3c5836bb1 100644
--- a/test/dot_s/basics.wast
+++ b/test/dot_s/basics.wast
@@ -4,7 +4,7 @@
(func $main (param $$0 i32) (param $$1 i32) (result i32)
(block $fake_return_waka123
(block
- (call $puts
+ (call_import $puts
(i32.const 16)
)
(block $BB0_5
diff --git a/test/dot_s/call.wast b/test/dot_s/call.wast
index 5c1bad327..5462e8fd5 100644
--- a/test/dot_s/call.wast
+++ b/test/dot_s/call.wast
@@ -1,6 +1,7 @@
(module
(memory 0 4294967295)
(type $FUNCSIG_v (func))
+ (type $FUNCSIG_i (func))
(export "call_i32_nullary" $call_i32_nullary)
(export "call_i64_nullary" $call_i64_nullary)
(export "call_float_nullary" $call_float_nullary)
@@ -17,7 +18,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call $i32_nullary)
+ (call_import $i32_nullary)
)
)
)
@@ -26,7 +27,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call $i64_nullary)
+ (call_import $i64_nullary)
)
)
)
@@ -35,7 +36,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call $float_nullary)
+ (call_import $float_nullary)
)
)
)
@@ -44,7 +45,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call $double_nullary)
+ (call_import $double_nullary)
)
)
)
@@ -52,7 +53,7 @@
(func $call_void_nullary
(block $fake_return_waka123
(block
- (call $void_nullary)
+ (call_import $void_nullary)
(br $fake_return_waka123)
)
)
@@ -61,7 +62,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call $i32_unary
+ (call_import $i32_unary
(get_local $$0)
)
)
@@ -72,7 +73,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call $i32_binary
+ (call_import $i32_binary
(get_local $$1)
(get_local $$0)
)
@@ -94,7 +95,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call_indirect $FUNCSIG_v
+ (call_indirect $FUNCSIG_i
(get_local $$0)
)
)
@@ -104,7 +105,7 @@
(func $tail_call_void_nullary
(block $fake_return_waka123
(block
- (call $void_nullary)
+ (call_import $void_nullary)
(br $fake_return_waka123)
)
)
@@ -112,7 +113,7 @@
(func $fastcc_tail_call_void_nullary
(block $fake_return_waka123
(block
- (call $void_nullary)
+ (call_import $void_nullary)
(br $fake_return_waka123)
)
)
@@ -120,7 +121,7 @@
(func $coldcc_tail_call_void_nullary
(block $fake_return_waka123
(block
- (call $void_nullary)
+ (call_import $void_nullary)
(br $fake_return_waka123)
)
)
diff --git a/test/dot_s/cfg-stackify.wast b/test/dot_s/cfg-stackify.wast
index 2d70401ee..8a5f3e720 100644
--- a/test/dot_s/cfg-stackify.wast
+++ b/test/dot_s/cfg-stackify.wast
@@ -44,7 +44,7 @@
)
$BB0_3
)
- (call $something)
+ (call_import $something)
(br $BB0_1)
)
)
@@ -74,7 +74,7 @@
)
$BB1_3
)
- (call $something)
+ (call_import $something)
(br $BB1_1)
)
)
@@ -473,7 +473,7 @@
)
)
)
- (call $bar)
+ (call_import $bar)
(br $BB12_1)
)
)
@@ -797,7 +797,7 @@
(i32.eq
(i32.and
(get_local $$1)
- (call $a)
+ (call_import $a)
)
(i32.const 0)
)
@@ -814,7 +814,7 @@
(i32.eq
(i32.and
(get_local $$1)
- (call $a)
+ (call_import $a)
)
(i32.const 0)
)
@@ -827,7 +827,7 @@
(br_if
(i32.and
(get_local $$1)
- (call $a)
+ (call_import $a)
)
$BB18_2
)
@@ -840,7 +840,7 @@
(br_if
(i32.and
(get_local $$1)
- (call $a)
+ (call_import $a)
)
$BB18_2
)
diff --git a/test/dot_s/exit.wast b/test/dot_s/exit.wast
index 328b8e47e..6c646cd7c 100644
--- a/test/dot_s/exit.wast
+++ b/test/dot_s/exit.wast
@@ -4,7 +4,7 @@
(func $main (result i32)
(local $$0 i32)
(block
- (call $exit
+ (call_import $exit
(i32.const 0)
)
)
diff --git a/test/dot_s/f32.wast b/test/dot_s/f32.wast
index 316dd263e..7a83b3211 100644
--- a/test/dot_s/f32.wast
+++ b/test/dot_s/f32.wast
@@ -192,7 +192,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call $fmaf
+ (call_import $fmaf
(get_local $$2)
(get_local $$1)
(get_local $$0)
diff --git a/test/dot_s/f64.wast b/test/dot_s/f64.wast
index 5d2549fb0..bfc267fb2 100644
--- a/test/dot_s/f64.wast
+++ b/test/dot_s/f64.wast
@@ -192,7 +192,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call $fma
+ (call_import $fma
(get_local $$2)
(get_local $$1)
(get_local $$0)
diff --git a/test/dot_s/frem.wast b/test/dot_s/frem.wast
index 3d169ff6d..07a9d417c 100644
--- a/test/dot_s/frem.wast
+++ b/test/dot_s/frem.wast
@@ -6,7 +6,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call $fmodf
+ (call_import $fmodf
(get_local $$1)
(get_local $$0)
)
@@ -18,7 +18,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call $fmod
+ (call_import $fmod
(get_local $$1)
(get_local $$0)
)
diff --git a/test/dot_s/global.wast b/test/dot_s/global.wast
index 9c6cea15b..8fe08b1b0 100644
--- a/test/dot_s/global.wast
+++ b/test/dot_s/global.wast
@@ -16,7 +16,7 @@
(func $call_memcpy (param $$0 i32) (param $$1 i32) (param $$2 i32) (result i32)
(block $fake_return_waka123
(block
- (call $memcpy
+ (call_import $memcpy
(get_local $$2)
(get_local $$1)
(get_local $$0)
diff --git a/test/dot_s/import.wast b/test/dot_s/import.wast
index 691b6913e..004d05dc1 100644
--- a/test/dot_s/import.wast
+++ b/test/dot_s/import.wast
@@ -4,21 +4,21 @@
(func $f (param $$0 i32) (param $$1 f32) (param $$2 i64) (param $$3 i64) (param $$4 i32)
(block $fake_return_waka123
(block
- (call $printi
+ (call_import $printi
(get_local $$0)
)
- (call $printf
+ (call_import $printf
(get_local $$1)
)
- (call $printv)
- (call $split_arg
+ (call_import $printv)
+ (call_import $split_arg
(get_local $$3)
(get_local $$2)
)
- (call $expanded_arg
+ (call_import $expanded_arg
(get_local $$4)
)
- (call $lowered_result)
+ (call_import $lowered_result)
(br $fake_return_waka123)
)
)
diff --git a/test/dot_s/returned.wast b/test/dot_s/returned.wast
index 8f28594a6..8426e8ea3 100644
--- a/test/dot_s/returned.wast
+++ b/test/dot_s/returned.wast
@@ -6,8 +6,8 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call $_ZN5AppleC1Ev
- (call $_Znwm
+ (call_import $_ZN5AppleC1Ev
+ (call_import $_Znwm
(i32.const 1)
)
)
@@ -19,7 +19,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (call $memcpy
+ (call_import $memcpy
(get_local $$2)
(get_local $$1)
(get_local $$0)
diff --git a/test/dot_s/switch.wast b/test/dot_s/switch.wast
index 7d97fbe57..6d7be38bb 100644
--- a/test/dot_s/switch.wast
+++ b/test/dot_s/switch.wast
@@ -24,22 +24,22 @@
(table (case $BB0_2) (case $BB0_2) (case $BB0_2) (case $BB0_2) (case $BB0_2) (case $BB0_2) (case $BB0_2) (case $BB0_3) (case $BB0_3) (case $BB0_3) (case $BB0_3) (case $BB0_3) (case $BB0_3) (case $BB0_3) (case $BB0_3) (case $BB0_4) (case $BB0_4) (case $BB0_4) (case $BB0_4) (case $BB0_4) (case $BB0_4) (case $BB0_5) (case $BB0_6) (case $BB0_7)) (case $BB0_2)
)
)
- (call $foo0)
+ (call_import $foo0)
(br $BB0_8)
)
- (call $foo1)
+ (call_import $foo1)
(br $BB0_8)
)
- (call $foo2)
+ (call_import $foo2)
(br $BB0_8)
)
- (call $foo3)
+ (call_import $foo3)
(br $BB0_8)
)
- (call $foo4)
+ (call_import $foo4)
(br $BB0_8)
)
- (call $foo5)
+ (call_import $foo5)
)
(br $fake_return_waka123)
)
@@ -69,22 +69,22 @@
(table (case $BB1_2) (case $BB1_2) (case $BB1_2) (case $BB1_2) (case $BB1_2) (case $BB1_2) (case $BB1_2) (case $BB1_3) (case $BB1_3) (case $BB1_3) (case $BB1_3) (case $BB1_3) (case $BB1_3) (case $BB1_3) (case $BB1_3) (case $BB1_4) (case $BB1_4) (case $BB1_4) (case $BB1_4) (case $BB1_4) (case $BB1_4) (case $BB1_5) (case $BB1_6) (case $BB1_7)) (case $BB1_2)
)
)
- (call $foo0)
+ (call_import $foo0)
(br $BB1_8)
)
- (call $foo1)
+ (call_import $foo1)
(br $BB1_8)
)
- (call $foo2)
+ (call_import $foo2)
(br $BB1_8)
)
- (call $foo3)
+ (call_import $foo3)
(br $BB1_8)
)
- (call $foo4)
+ (call_import $foo4)
(br $BB1_8)
)
- (call $foo5)
+ (call_import $foo5)
)
(br $fake_return_waka123)
)
diff --git a/test/dot_s/unreachable.wast b/test/dot_s/unreachable.wast
index 9a9387805..3dfa0c091 100644
--- a/test/dot_s/unreachable.wast
+++ b/test/dot_s/unreachable.wast
@@ -5,7 +5,7 @@
(export "f3" $f3)
(func $f1 (result i32)
(block
- (call $abort)
+ (call_import $abort)
(unreachable)
)
)
diff --git a/test/dot_s/unused-argument.wast b/test/dot_s/unused-argument.wast
index 7316528c4..8a71571f7 100644
--- a/test/dot_s/unused-argument.wast
+++ b/test/dot_s/unused-argument.wast
@@ -24,7 +24,7 @@
(func $call_something
(block $fake_return_waka123
(block
- (call $return_something)
+ (call_import $return_something)
(br $fake_return_waka123)
)
)
diff --git a/test/dot_s/varargs.wast b/test/dot_s/varargs.wast
index 56374051d..8e252997c 100644
--- a/test/dot_s/varargs.wast
+++ b/test/dot_s/varargs.wast
@@ -142,7 +142,7 @@
(func $caller_none
(block $fake_return_waka123
(block
- (call $callee)
+ (call_import $callee)
(br $fake_return_waka123)
)
)