diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-12 18:15:58 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-12 18:15:58 -0800 |
commit | 062518cbe64d096186c5b48e1de0717bc02486f9 (patch) | |
tree | 207d82eade6591b4e0946ab5cf77da547e64e045 | |
parent | d429bbcc5d9aa402b8902274dce5b9a71653676f (diff) | |
download | binaryen-062518cbe64d096186c5b48e1de0717bc02486f9.tar.gz binaryen-062518cbe64d096186c5b48e1de0717bc02486f9.tar.bz2 binaryen-062518cbe64d096186c5b48e1de0717bc02486f9.zip |
scan function result types in s2wasm
-rwxr-xr-x | auto_update_tests.py | 2 | ||||
-rwxr-xr-x | check.py | 2 | ||||
-rw-r--r-- | src/s2wasm.h | 35 |
3 files changed, 34 insertions, 5 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py index 789e1e1be..b00023c65 100755 --- a/auto_update_tests.py +++ b/auto_update_tests.py @@ -32,7 +32,7 @@ for t in sorted(os.listdir('test')): open(t, 'w').write(actual) -for s in ['minimal.s', 'basics.s', 'call.s', 'conv.s', 'fast-isel.s', 'i64.s', 'load.s', 'phi.s', 'select.s', 'unreachable.s', 'cfg-stackify.s', 'cpus.s', 'frem.s', 'immediates.s', 'load-store-i1.s', 'reg-stackify.s', 'unused-argument.s', 'comparisons_f32.s', 'dead-vreg.s', 'func.s', 'import.s', 'memory-addr32.s', 'store-results.s', 'varargs.s', 'comparisons_f64.s', 'exit.s', 'global.s', 'memory-addr64.s', 'returned.s', 'store.s', 'comparisons_i32.s', 'f32.s', 'globl.s', 'legalize.s', 'offset-folding.s', 'return-int32.s', 'store-trunc.s', 'comparisons_i64.s', 'f64.s', 'i32.s', 'load-ext.s', 'permute.s', 'return-void.s']: # TODO: 'signext-zeroext.s', 'relocation.s', 'inline-asm.s', 'switch.s' +for s in ['minimal.s', 'basics.s', 'call.s', 'conv.s', 'fast-isel.s', 'i64.s', 'load.s', 'phi.s', 'select.s', 'unreachable.s', 'cfg-stackify.s', 'cpus.s', 'frem.s', 'immediates.s', 'load-store-i1.s', 'reg-stackify.s', 'unused-argument.s', 'comparisons_f32.s', 'dead-vreg.s', 'func.s', 'import.s', 'memory-addr32.s', 'store-results.s', 'varargs.s', 'comparisons_f64.s', 'exit.s', 'global.s', 'memory-addr64.s', 'returned.s', 'store.s', 'comparisons_i32.s', 'f32.s', 'globl.s', 'legalize.s', 'offset-folding.s', 'return-int32.s', 'store-trunc.s', 'comparisons_i64.s', 'f64.s', 'i32.s', 'load-ext.s', 'permute.s', 'return-void.s', 'signext-zeroext.s']: # TODO: 'relocation.s', 'inline-asm.s', 'switch.s' print '..', s wasm = s.replace('.s', '.wast') full = os.path.join('test', 'dot_s', s) @@ -214,7 +214,7 @@ for t in spec_tests: print '\n[ checking .s testcases... ]\n' -for s in ['minimal.s', 'basics.s', 'call.s', 'conv.s', 'fast-isel.s', 'i64.s', 'load.s', 'phi.s', 'select.s', 'unreachable.s', 'cfg-stackify.s', 'cpus.s', 'frem.s', 'immediates.s', 'load-store-i1.s', 'reg-stackify.s', 'unused-argument.s', 'comparisons_f32.s', 'dead-vreg.s', 'func.s', 'import.s', 'memory-addr32.s', 'store-results.s', 'varargs.s', 'comparisons_f64.s', 'exit.s', 'global.s', 'memory-addr64.s', 'returned.s', 'store.s', 'comparisons_i32.s', 'f32.s', 'globl.s', 'legalize.s', 'offset-folding.s', 'return-int32.s', 'store-trunc.s', 'comparisons_i64.s', 'f64.s', 'i32.s', 'load-ext.s', 'permute.s', 'return-void.s']: # TODO: 'signext-zeroext.s', 'relocation.s', 'inline-asm.s', 'switch.s' +for s in ['minimal.s', 'basics.s', 'call.s', 'conv.s', 'fast-isel.s', 'i64.s', 'load.s', 'phi.s', 'select.s', 'unreachable.s', 'cfg-stackify.s', 'cpus.s', 'frem.s', 'immediates.s', 'load-store-i1.s', 'reg-stackify.s', 'unused-argument.s', 'comparisons_f32.s', 'dead-vreg.s', 'func.s', 'import.s', 'memory-addr32.s', 'store-results.s', 'varargs.s', 'comparisons_f64.s', 'exit.s', 'global.s', 'memory-addr64.s', 'returned.s', 'store.s', 'comparisons_i32.s', 'f32.s', 'globl.s', 'legalize.s', 'offset-folding.s', 'return-int32.s', 'store-trunc.s', 'comparisons_i64.s', 'f64.s', 'i32.s', 'load-ext.s', 'permute.s', 'return-void.s', 'signext-zeroext.s']: # TODO: 'relocation.s', 'inline-asm.s', 'switch.s' print '..', s wasm = s.replace('.s', '.wast') full = os.path.join('test', 'dot_s', s) diff --git a/src/s2wasm.h b/src/s2wasm.h index 85d9f6c9e..a1b5a7ef9 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -21,7 +21,10 @@ class S2WasmBuilder { char *s; public: - S2WasmBuilder(AllocatingModule& wasm, char *s) : wasm(wasm), allocator(wasm.allocator), s(s) { + S2WasmBuilder(AllocatingModule& wasm, char *input) : wasm(wasm), allocator(wasm.allocator) { + s = input; + scan(); + s = input; process(); fix(); } @@ -34,6 +37,8 @@ private: typedef std::pair<Const*, Name> Addressing; std::vector<Addressing> addressings; // we fix these up + std::map<Name, WasmType> functionResults; // function name => result type. we scan this early, then use it during processing. + // utilities void skipWhitespace() { @@ -219,6 +224,27 @@ 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(":"); + while (1) { + skipWhitespace(); + if (match(".param")) s = strchr(s, '\n'); + else if (match(".result")) { + functionResults[name] = getType(); + break; + } else break; + } + } + } + void process() { while (*s) { skipWhitespace(); @@ -590,11 +616,14 @@ private: } Name assign = getAssign(); if (curr->is<Call>()) { - curr->dyn_cast<Call>()->target = getCommaSeparated(); + Name name = curr->dyn_cast<Call>()->target = getCommaSeparated(); + curr->type = functionResults[name]; } else if (curr->is<CallImport>()) { - curr->dyn_cast<CallImport>()->target = getCommaSeparated(); + 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 } while (1) { if (!skipComma()) break; |