From 444d7f66182c091b2e207a7bc842309f0925e228 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 16 Sep 2016 11:18:04 -0700 Subject: call_import changes: no more call_import, shared index space with functions --- src/passes/Print.cpp | 2 +- src/wasm-binary.h | 121 +++++++++++++++++++++++++++++---------------------- src/wasm-s-parser.h | 12 ++++- 3 files changed, 81 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 43ddc954c..e0fab9901 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -224,7 +224,7 @@ struct PrintSExpression : public Visitor { printCallBody(curr); } void visitCallImport(CallImport *curr) { - printOpening(o, "call_import "); + printOpening(o, "call "); printCallBody(curr); } void visitCallIndirect(CallIndirect *curr) { diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 561a310b0..9b8451b98 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -411,7 +411,6 @@ enum ASTNodes { SetLocal = 0x15, CallFunction = 0x16, CallIndirect = 0x17, - CallImport = 0x18, TeeLocal = 0x19, GetGlobal = 0x1a, SetGlobal = 0x1b, @@ -727,27 +726,21 @@ public: } finishSection(start); } - - std::map mappedImports; // name of the Import => index - uint32_t getImportIndex(Name name) { - if (!mappedImports.size()) { - // Create name => index mapping. - for (size_t i = 0; i < wasm->imports.size(); i++) { - assert(mappedImports.count(wasm->imports[i]->name) == 0); - mappedImports[wasm->imports[i]->name] = i; - } - } - assert(mappedImports.count(name)); - return mappedImports[name]; - } - std::map mappedFunctions; // name of the Function => index + std::map mappedFunctions; // name of the Function => index. first imports, then internals uint32_t getFunctionIndex(Name name) { if (!mappedFunctions.size()) { // Create name => index mapping. + for (auto& import : wasm->imports) { + if (import->kind != Import::Function) continue; + assert(mappedFunctions.count(import->name) == 0); + auto index = mappedFunctions.size(); + mappedFunctions[import->name] = index; + } for (size_t i = 0; i < wasm->functions.size(); i++) { assert(mappedFunctions.count(wasm->functions[i]->name) == 0); - mappedFunctions[wasm->functions[i]->name] = i; + auto index = mappedFunctions.size(); + mappedFunctions[wasm->functions[i]->name] = index; } } assert(mappedFunctions.count(name)); @@ -957,7 +950,7 @@ public: for (auto* operand : curr->operands) { recurse(operand); } - o << int8_t(BinaryConsts::CallImport) << U32LEB(curr->operands.size()) << U32LEB(getImportIndex(curr->target)); + o << int8_t(BinaryConsts::CallFunction) << U32LEB(curr->operands.size()) << U32LEB(getFunctionIndex(curr->target)); } void visitCallIndirect(CallIndirect *curr) { if (debug) std::cerr << "zz node: CallIndirect" << std::endl; @@ -1501,6 +1494,20 @@ public: } } + std::vector functionImportIndexes; // index in function index space => name of function import + + // gets a name in the combined function import+defined function space + Name getFunctionIndexName(Index i) { + if (i < functionImportIndexes.size()) { + auto* import = wasm.getImport(functionImportIndexes[i]); + assert(import->kind == Import::Function); + return import->name; + } else { + i -= functionImportIndexes.size(); + return wasm.functions.at(i)->name; + } + } + void readImports() { if (debug) std::cerr << "== readImports" << std::endl; size_t num = getU32LEB(); @@ -1511,16 +1518,17 @@ public: curr->name = Name(std::string("import$") + std::to_string(i)); curr->kind = (Import::Kind)getU32LEB(); switch (curr->kind) { - case Export::Function: { + case Import::Function: { auto index = getU32LEB(); assert(index < wasm.functionTypes.size()); curr->functionType = wasm.getFunctionType(index); assert(curr->functionType->name.is()); + functionImportIndexes.push_back(curr->name); break; } - case Export::Table: break; - case Export::Memory: break; - case Export::Global: curr->globalType = getWasmType(); break; + case Import::Table: break; + case Import::Memory: break; + case Import::Global: curr->globalType = getWasmType(); break; default: WASM_UNREACHABLE(); } curr->module = getInlineString(); @@ -1529,7 +1537,7 @@ public: } } - std::vector functionTypes; + std::vector functionTypes; // types of defined functions void readFunctionSignatures() { if (debug) std::cerr << "== readFunctionSignatures" << std::endl; @@ -1551,7 +1559,7 @@ public: // We read functions before we know their names, so we need to backpatch the names later std::vector functions; // we store functions here before wasm.addFunction after we know their names - std::map> functionCalls; // at index i we have all calls to i + std::map> functionCalls; // at index i we have all calls to the defined function i Function* currFunction = nullptr; size_t endOfFunction; @@ -1611,7 +1619,7 @@ public: } } - std::map exportIndexes; + std::map exportIndexes; void readExports() { if (debug) std::cerr << "== readExports" << std::endl; @@ -1705,7 +1713,10 @@ public: for (auto& iter : exportIndexes) { Export* curr = iter.first; switch (curr->kind) { - case Export::Function: curr->value = wasm.functions[iter.second]->name; break; + case Export::Function: { + curr->value = getFunctionIndexName(iter.second); + break; + } case Export::Table: curr->value = Name::fromInt(0); break; case Export::Memory: curr->value = Name::fromInt(0); break; case Export::Global: curr->value = getGlobalName(iter.second); break; @@ -1726,7 +1737,7 @@ public: auto i = pair.first; auto& indexes = pair.second; for (auto j : indexes) { - wasm.table.segments[i].data.push_back(wasm.functions[j]->name); + wasm.table.segments[i].data.push_back(getFunctionIndexName(j)); } } } @@ -1795,8 +1806,7 @@ public: case BinaryConsts::Br: case BinaryConsts::BrIf: visitBreak((curr = allocator.alloc())->cast(), code); break; // code distinguishes br from br_if case BinaryConsts::TableSwitch: visitSwitch((curr = allocator.alloc())->cast()); break; - case BinaryConsts::CallFunction: visitCall((curr = allocator.alloc())->cast()); break; - case BinaryConsts::CallImport: visitCallImport((curr = allocator.alloc())->cast()); break; + case BinaryConsts::CallFunction: curr = visitCall(); break; // we don't know if it's a call or call_import yet case BinaryConsts::CallIndirect: visitCallIndirect((curr = allocator.alloc())->cast()); break; case BinaryConsts::GetLocal: visitGetLocal((curr = allocator.alloc())->cast()); break; case BinaryConsts::TeeLocal: @@ -1938,38 +1948,45 @@ public: } curr->default_ = getBreakName(getInt32()); } - void visitCall(Call *curr) { - if (debug) std::cerr << "zz node: Call" << std::endl; - auto arity = getU32LEB(); - WASM_UNUSED(arity); - auto index = getU32LEB(); - assert(index < functionTypes.size()); - auto type = functionTypes[index]; + + template + void fillCall(T* call, FunctionType* type, Index arity) { + assert(type); auto num = type->params.size(); assert(num == arity); - curr->operands.resize(num); + call->operands.resize(num); for (size_t i = 0; i < num; i++) { - curr->operands[num - i - 1] = popExpression(); + call->operands[num - i - 1] = popExpression(); } - curr->type = type->result; - functionCalls[index].push_back(curr); + call->type = type->result; } - void visitCallImport(CallImport *curr) { - if (debug) std::cerr << "zz node: CallImport" << std::endl; + + Expression* visitCall() { + if (debug) std::cerr << "zz node: Call" << std::endl; auto arity = getU32LEB(); WASM_UNUSED(arity); - auto import = wasm.getImport(getU32LEB()); - curr->target = import->name; - auto type = import->functionType; - assert(type); - auto num = type->params.size(); - assert(num == arity); - if (debug) std::cerr << "zz node: CallImport " << curr->target << " with type " << type->name << " and " << num << " params\n"; - curr->operands.resize(num); - for (size_t i = 0; i < num; i++) { - curr->operands[num - i - 1] = popExpression(); + auto index = getU32LEB(); + FunctionType* type; + Expression* ret; + if (index < functionImportIndexes.size()) { + // this is a call of an imported function + auto* call = allocator.alloc(); + auto* import = wasm.getImport(functionImportIndexes[index]); + call->target = import->name; + type = import->functionType; + fillCall(call, type, arity); + ret = call; + } else { + // this is a call of a defined function + auto* call = allocator.alloc(); + auto adjustedIndex = index - functionImportIndexes.size(); + assert(adjustedIndex < functionTypes.size()); + type = functionTypes[adjustedIndex]; + fillCall(call, type, arity); + functionCalls[adjustedIndex].push_back(call); // we don't know function names yet + ret = call; } - curr->type = type->result; + return ret; } void visitCallIndirect(CallIndirect *curr) { if (debug) std::cerr << "zz node: CallIndirect" << std::endl; diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 9abdea744..1a9e71bd4 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1207,8 +1207,18 @@ private: } Expression* makeCall(Element& s) { + auto target = s[1]->str(); + auto* import = wasm.checkImport(target); + if (import && import->kind == Import::Function) { + auto ret = allocator.alloc(); + ret->target = target; + Import* import = wasm.getImport(ret->target); + ret->type = import->functionType->result; + parseCallOperands(s, 2, s.size(), ret); + return ret; + } auto ret = allocator.alloc(); - ret->target = s[1]->str(); + ret->target = target; ret->type = functionTypes[ret->target]; parseCallOperands(s, 2, s.size(), ret); return ret; -- cgit v1.2.3 From 5126ebef968cd27ae3cb8f61357c95626c25ad25 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 16 Sep 2016 16:45:37 -0700 Subject: s-expression modules can have names --- src/wasm-s-parser.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 1a9e71bd4..3f80f6f9e 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -272,12 +272,18 @@ class SExpressionWasmBuilder { public: // Assumes control of and modifies the input. - SExpressionWasmBuilder(Module& wasm, Element& module) : wasm(wasm), allocator(wasm.allocator), importCounter(0), globalCounter(0) { + SExpressionWasmBuilder(Module& wasm, Element& module, Name* moduleName = nullptr) : wasm(wasm), allocator(wasm.allocator), importCounter(0), globalCounter(0) { assert(module[0]->str() == MODULE); - if (module.size() > 1 && module[1]->isStr()) { + Index i = 1; + if (module[i]->dollared()) { + if (moduleName) { + *moduleName = module[i]->str(); + } + i++; + } + if (i < module.size() && module[i]->isStr()) { // these s-expressions contain a binary module, actually std::vector data; - size_t i = 1; while (i < module.size()) { auto str = module[i++]->c_str(); if (auto size = strlen(str)) { @@ -289,13 +295,13 @@ public: return; } functionCounter = 0; - for (unsigned i = 1; i < module.size(); i++) { - preParseFunctionType(*module[i]); - preParseImports(*module[i]); + for (unsigned j = i; j < module.size(); j++) { + preParseFunctionType(*module[j]); + preParseImports(*module[j]); } functionCounter = 0; - for (unsigned i = 1; i < module.size(); i++) { - parseModuleElement(*module[i]); + for (unsigned j = i; j < module.size(); j++) { + parseModuleElement(*module[j]); } } -- cgit v1.2.3 From 8ff678788ada565d15273ca6ca872946f14584d6 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 16 Sep 2016 16:48:20 -0700 Subject: support assert_malformed in shell test runner --- src/shared-constants.h | 3 --- src/tools/wasm-shell.cpp | 7 ++++++- src/wasm.cpp | 3 --- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/shared-constants.h b/src/shared-constants.h index f0148cb67..e37879088 100644 --- a/src/shared-constants.h +++ b/src/shared-constants.h @@ -47,9 +47,6 @@ extern Name GROW_WASM_MEMORY, BR, ANYFUNC, FAKE_RETURN, - ASSERT_RETURN, - ASSERT_TRAP, - ASSERT_INVALID, SPECTEST, PRINT, INVOKE, diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp index a95ced87f..ddb2f8a85 100644 --- a/src/tools/wasm-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -34,6 +34,11 @@ using namespace cashew; using namespace wasm; +Name ASSERT_RETURN("assert_return"), + ASSERT_TRAP("assert_trap"), + ASSERT_INVALID("assert_invalid"), + ASSERT_MALFORMED("assert_malformed"); + // // An invocation into a module // @@ -109,7 +114,7 @@ static void run_asserts(size_t* i, bool* checked, Module* wasm, Colors::green(std::cerr); std::cerr << " [line: " << curr.line << "]\n"; Colors::normal(std::cerr); - if (id == ASSERT_INVALID) { + if (id == ASSERT_INVALID || id == ASSERT_MALFORMED) { // a module invalidity test Module wasm; bool invalid = false; diff --git a/src/wasm.cpp b/src/wasm.cpp index f6486eb50..144cabd16 100644 --- a/src/wasm.cpp +++ b/src/wasm.cpp @@ -72,9 +72,6 @@ Name GROW_WASM_MEMORY("__growWasmMemory"), BR("br"), ANYFUNC("anyfunc"), FAKE_RETURN("fake_return_waka123"), - ASSERT_RETURN("assert_return"), - ASSERT_TRAP("assert_trap"), - ASSERT_INVALID("assert_invalid"), SPECTEST("spectest"), PRINT("print"), INVOKE("invoke"), -- cgit v1.2.3 From f0546a0c8322a4e2f1777c8a749207a70cdca681 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 16 Sep 2016 17:10:06 -0700 Subject: block signatures --- src/passes/Print.cpp | 3 + src/wasm-s-parser.h | 31 ++-- test/emcc_O2_hello_world.fromasm | 60 ++++---- test/emcc_O2_hello_world.fromasm.imprecise | 60 ++++---- test/emcc_O2_hello_world.fromasm.imprecise.no-opts | 34 ++--- test/emcc_O2_hello_world.fromasm.no-opts | 34 ++--- test/emcc_hello_world.fromasm | 158 ++++++++++----------- test/emcc_hello_world.fromasm.imprecise | 158 ++++++++++----------- test/emcc_hello_world.fromasm.imprecise.no-opts | 12 +- test/emcc_hello_world.fromasm.no-opts | 12 +- test/example/c-api-kitchen-sink.txt | 8 +- test/example/c-api-kitchen-sink.txt.txt | 4 +- test/kitchen_sink.wast | 2 +- test/kitchen_sink.wast.fromBinary | 2 +- test/memorygrowth.fromasm | 54 +++---- test/memorygrowth.fromasm.imprecise | 54 +++---- test/min.fromasm.imprecise.no-opts | 2 +- test/min.fromasm.no-opts | 2 +- test/min.wast | 6 +- test/min.wast.fromBinary | 6 +- test/passes/duplicate-function-elimination.txt | 4 +- test/passes/remove-unused-brs.txt | 38 ++--- test/passes/remove-unused-names_merge-blocks.txt | 46 +++--- test/passes/simplify-locals.txt | 30 ++-- test/passes/vacuum.txt | 8 +- test/unit.fromasm | 6 +- test/unit.fromasm.imprecise | 6 +- test/unit.fromasm.imprecise.no-opts | 40 +++--- test/unit.fromasm.no-opts | 40 +++--- test/unit.wast | 14 +- test/unit.wast.fromBinary | 16 +-- 31 files changed, 484 insertions(+), 466 deletions(-) (limited to 'src') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index e0fab9901..4cb363e66 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -109,6 +109,9 @@ struct PrintSExpression : public Visitor { o << ' '; printName(curr->name); } + if (isConcreteWasmType(curr->type)) { + o << ' ' << printWasmType(curr->type); + } incIndent(); if (curr->list.size() > 0 && curr->list[0]->is()) { // recurse into the first element diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 3f80f6f9e..a39eb59dc 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -991,13 +991,23 @@ private: auto& s = *sp; size_t i = 1; if (i < s.size() && s[i]->isStr()) { - curr->name = s[i]->str(); - i++; + // could be a name or a type + if (s[i]->dollared() || stringToWasmType(s[i]->str(), true /* allowError */) == none) { + curr->name = s[i]->str(); + i++; + } else { + curr->name = getPrefixedName("block"); + } } else { curr->name = getPrefixedName("block"); } labelStack.push_back(curr->name); - if (i >= s.size()) break; // labeled empty block + if (i >= s.size()) break; // empty block + if (s[i]->isStr()) { + // block signature + i++; // TODO: parse the signature + if (i >= s.size()) break; // empty block + } auto& first = *s[i]; if (first[0]->str() == BLOCK) { // recurse @@ -1014,7 +1024,7 @@ private: auto& s = *sp; size_t i = 1; if (i < s.size()) { - if (s[i]->isStr()) { + while (i < s.size() && s[i]->isStr()) { i++; } if (t < int(stack.size()) - 1) { @@ -1132,7 +1142,12 @@ private: Expression* makeIf(Element& s) { auto ret = allocator.alloc(); - ret->condition = parseExpression(s[1]); + Index i = 1; + if (s[i]->isStr()) { + // if type + i++; + } + ret->condition = parseExpression(s[i++]); // ifTrue and ifFalse may get implicit blocks auto handle = [&](const char* title, Element& s) { @@ -1162,9 +1177,9 @@ private: return ret; }; - ret->ifTrue = handle("if-true", *s[2]); - if (s.size() == 4) { - ret->ifFalse = handle("if-else", *s[3]); + ret->ifTrue = handle("if-true", *s[i++]); + if (i < s.size()) { + ret->ifFalse = handle("if-else", *s[i++]); ret->finalize(); } return ret; diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm index 3d968f754..b8e25baa5 100644 --- a/test/emcc_O2_hello_world.fromasm +++ b/test/emcc_O2_hello_world.fromasm @@ -1721,7 +1721,7 @@ (get_local $30) ) ) - (block + (block i32 (if (i32.eqz (tee_local $3 @@ -3163,7 +3163,7 @@ (i32.const 0) (i32.eq (tee_local $6 - (block $label$break$L257 + (block $label$break$L257 i32 (if (i32.and (i32.load @@ -3172,7 +3172,7 @@ (i32.const 4) ) (i32.const 190) - (block + (block i32 (block $label$break$L259 (if (tee_local $3 @@ -3817,7 +3817,7 @@ ) ) ) - (block + (block i32 (i32.store (i32.const 192) (get_local $20) @@ -4036,7 +4036,7 @@ ) (i32.const 1) ) - (block + (block i32 (set_local $13 (i32.and (get_local $0) @@ -4665,7 +4665,7 @@ (i32.const 480) (i32.shl (tee_local $3 - (block $do-once$67 + (block $do-once$67 i32 (if (tee_local $2 (i32.shr_u @@ -4673,7 +4673,7 @@ (i32.const 8) ) ) - (block + (block i32 (br_if $do-once$67 (i32.const 31) (i32.gt_u @@ -7904,7 +7904,7 @@ (i32.load (i32.const 8) ) - (block + (block i32 (call $_pthread_cleanup_push (i32.const 4) (get_local $0) @@ -7936,7 +7936,7 @@ ) (get_local $9) ) - (block + (block i32 (i32.store (get_local $11) (i32.load @@ -8006,7 +8006,7 @@ (get_local $4) (i32.const 2) ) - (block + (block i32 (i32.store (get_local $8) (i32.add @@ -8024,14 +8024,14 @@ ) (get_local $14) ) - (block + (block i32 (set_local $3 (get_local $5) ) (get_local $14) ) ) - (block + (block i32 (i32.store (get_local $8) (tee_local $3 @@ -8270,7 +8270,7 @@ ) ) (set_local $1 - (block $label$break$L10 + (block $label$break$L10 i32 (if (i32.gt_s (i32.load8_s offset=75 @@ -8278,7 +8278,7 @@ ) (i32.const -1) ) - (block + (block i32 (set_local $3 (get_local $1) ) @@ -8363,7 +8363,7 @@ (get_local $3) ) ) - (block + (block i32 (set_local $2 (i32.const 0) ) @@ -8402,10 +8402,10 @@ (func $_fflush (param $0 i32) (result i32) (local $1 i32) (local $2 i32) - (block $do-once$0 + (block $do-once$0 i32 (if (get_local $0) - (block + (block i32 (if (i32.le_s (i32.load offset=76 @@ -8434,7 +8434,7 @@ (if (get_local $1) (get_local $2) - (block + (block i32 (call $___unlockfile (get_local $0) ) @@ -8442,7 +8442,7 @@ ) ) ) - (block + (block i32 (set_local $0 (if (i32.load @@ -8866,7 +8866,7 @@ ) ) ) - (block + (block i32 (drop (call_indirect $FUNCSIG$iiii (get_local $0) @@ -8892,7 +8892,7 @@ (i32.const 0) ) (i32.const -1) - (block + (block i32 (if (i32.lt_u (tee_local $4 @@ -9274,7 +9274,7 @@ ) ) (set_local $0 - (block $do-once$0 + (block $do-once$0 i32 (if (i32.lt_s (call $_fputs @@ -9284,7 +9284,7 @@ (i32.const 0) ) (i32.const 1) - (block + (block i32 (if (if (i32.ne @@ -9404,7 +9404,7 @@ ) (i32.const 0) ) - (block + (block i32 (i32.store (get_local $0) (i32.const -1) @@ -9453,7 +9453,7 @@ ) (i32.const 8) ) - (block + (block i32 (i32.store (get_local $0) (i32.or @@ -9463,7 +9463,7 @@ ) (i32.const -1) ) - (block + (block i32 (i32.store offset=8 (get_local $0) (i32.const 0) @@ -9516,7 +9516,7 @@ ) (i32.const -1) ) - (block + (block i32 (set_local $5 (i32.eqz (call $___lockfile @@ -9534,7 +9534,7 @@ (if (get_local $5) (get_local $0) - (block + (block i32 (call $___unlockfile (get_local $3) ) @@ -9586,7 +9586,7 @@ (i32.const 64) ) (i32.const 0) - (block + (block i32 (i32.store (get_local $3) (i32.load offset=60 @@ -9745,7 +9745,7 @@ (get_local $0) (i32.const -4096) ) - (block + (block i32 (i32.store (call $___errno_location) (i32.sub diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise index 50ba812c3..f2b2c401c 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise +++ b/test/emcc_O2_hello_world.fromasm.imprecise @@ -1719,7 +1719,7 @@ (get_local $30) ) ) - (block + (block i32 (if (i32.eqz (tee_local $3 @@ -3161,7 +3161,7 @@ (i32.const 0) (i32.eq (tee_local $6 - (block $label$break$L257 + (block $label$break$L257 i32 (if (i32.and (i32.load @@ -3170,7 +3170,7 @@ (i32.const 4) ) (i32.const 190) - (block + (block i32 (block $label$break$L259 (if (tee_local $3 @@ -3815,7 +3815,7 @@ ) ) ) - (block + (block i32 (i32.store (i32.const 192) (get_local $20) @@ -4034,7 +4034,7 @@ ) (i32.const 1) ) - (block + (block i32 (set_local $13 (i32.and (get_local $0) @@ -4663,7 +4663,7 @@ (i32.const 480) (i32.shl (tee_local $3 - (block $do-once$67 + (block $do-once$67 i32 (if (tee_local $2 (i32.shr_u @@ -4671,7 +4671,7 @@ (i32.const 8) ) ) - (block + (block i32 (br_if $do-once$67 (i32.const 31) (i32.gt_u @@ -7902,7 +7902,7 @@ (i32.load (i32.const 8) ) - (block + (block i32 (call $_pthread_cleanup_push (i32.const 4) (get_local $0) @@ -7934,7 +7934,7 @@ ) (get_local $9) ) - (block + (block i32 (i32.store (get_local $11) (i32.load @@ -8004,7 +8004,7 @@ (get_local $4) (i32.const 2) ) - (block + (block i32 (i32.store (get_local $8) (i32.add @@ -8022,14 +8022,14 @@ ) (get_local $14) ) - (block + (block i32 (set_local $3 (get_local $5) ) (get_local $14) ) ) - (block + (block i32 (i32.store (get_local $8) (tee_local $3 @@ -8268,7 +8268,7 @@ ) ) (set_local $1 - (block $label$break$L10 + (block $label$break$L10 i32 (if (i32.gt_s (i32.load8_s offset=75 @@ -8276,7 +8276,7 @@ ) (i32.const -1) ) - (block + (block i32 (set_local $3 (get_local $1) ) @@ -8361,7 +8361,7 @@ (get_local $3) ) ) - (block + (block i32 (set_local $2 (i32.const 0) ) @@ -8400,10 +8400,10 @@ (func $_fflush (param $0 i32) (result i32) (local $1 i32) (local $2 i32) - (block $do-once$0 + (block $do-once$0 i32 (if (get_local $0) - (block + (block i32 (if (i32.le_s (i32.load offset=76 @@ -8432,7 +8432,7 @@ (if (get_local $1) (get_local $2) - (block + (block i32 (call $___unlockfile (get_local $0) ) @@ -8440,7 +8440,7 @@ ) ) ) - (block + (block i32 (set_local $0 (if (i32.load @@ -8864,7 +8864,7 @@ ) ) ) - (block + (block i32 (drop (call_indirect $FUNCSIG$iiii (get_local $0) @@ -8890,7 +8890,7 @@ (i32.const 0) ) (i32.const -1) - (block + (block i32 (if (i32.lt_u (tee_local $4 @@ -9272,7 +9272,7 @@ ) ) (set_local $0 - (block $do-once$0 + (block $do-once$0 i32 (if (i32.lt_s (call $_fputs @@ -9282,7 +9282,7 @@ (i32.const 0) ) (i32.const 1) - (block + (block i32 (if (if (i32.ne @@ -9402,7 +9402,7 @@ ) (i32.const 0) ) - (block + (block i32 (i32.store (get_local $0) (i32.const -1) @@ -9451,7 +9451,7 @@ ) (i32.const 8) ) - (block + (block i32 (i32.store (get_local $0) (i32.or @@ -9461,7 +9461,7 @@ ) (i32.const -1) ) - (block + (block i32 (i32.store offset=8 (get_local $0) (i32.const 0) @@ -9514,7 +9514,7 @@ ) (i32.const -1) ) - (block + (block i32 (set_local $5 (i32.eqz (call $___lockfile @@ -9532,7 +9532,7 @@ (if (get_local $5) (get_local $0) - (block + (block i32 (call $___unlockfile (get_local $3) ) @@ -9584,7 +9584,7 @@ (i32.const 64) ) (i32.const 0) - (block + (block i32 (i32.store (get_local $3) (i32.load offset=60 @@ -9743,7 +9743,7 @@ (get_local $0) (i32.const -4096) ) - (block + (block i32 (i32.store (call $___errno_location) (i32.sub diff --git a/test/emcc_O2_hello_world.fromasm.imprecise.no-opts b/test/emcc_O2_hello_world.fromasm.imprecise.no-opts index 3b8fb4922..8db740bfc 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise.no-opts +++ b/test/emcc_O2_hello_world.fromasm.imprecise.no-opts @@ -3722,13 +3722,13 @@ (get_local $i52) (i32.const 0) ) - (block + (block i32 (set_local $i51 (i32.load (i32.const 608) ) ) - (block + (block i32 (set_local $i50 (i32.add (get_local $i51) @@ -3794,7 +3794,7 @@ (get_local $i51) (get_local $i52) ) - (block + (block i32 (set_local $i45 (i32.add (get_local $i50) @@ -3924,7 +3924,7 @@ (get_local $i36) (i32.const 173) ) - (block + (block i32 (set_local $i52 (call $_sbrk (i32.const 0) @@ -4100,13 +4100,13 @@ ) ) ) - (block + (block i32 (set_local $i52 (i32.load (i32.const 656) ) ) - (block + (block i32 (set_local $i5 (i32.and (i32.add @@ -4213,13 +4213,13 @@ ) (i32.const 0) ) - (block + (block i32 (set_local $i63 (call $_sbrk (get_local $i43) ) ) - (block + (block i32 (set_local $i43 (call $_sbrk (i32.const 0) @@ -4245,7 +4245,7 @@ ) (i32.const 0) ) - (block + (block i32 (set_local $i60 (i32.sub (get_local $i43) @@ -5995,7 +5995,7 @@ (get_local $i63) (get_local $i60) ) - (block + (block i32 (set_local $i53 (i32.add (get_local $i63) @@ -10465,7 +10465,7 @@ (get_local $i6) (get_local $i8) ) - (block + (block i32 (set_local $i11 (i32.and (get_local $i2) @@ -10572,7 +10572,7 @@ (get_local $i3) ) ) - (block + (block i32 (drop (call_indirect $FUNCSIG$iiii (get_local $i1) @@ -11068,14 +11068,14 @@ ) (i32.const 10) ) - (block + (block i32 (set_local $i5 (i32.add (get_local $i2) (i32.const 20) ) ) - (block + (block i32 (set_local $i6 (i32.load (get_local $i5) @@ -11455,7 +11455,7 @@ ) (i32.const 0) ) - (block + (block i32 (i32.store (get_local $i5) (i32.load @@ -11465,7 +11465,7 @@ ) ) ) - (block + (block i32 (i32.store (i32.add (get_local $i5) @@ -11473,7 +11473,7 @@ ) (i32.const 21505) ) - (block + (block i32 (i32.store (i32.add (get_local $i5) diff --git a/test/emcc_O2_hello_world.fromasm.no-opts b/test/emcc_O2_hello_world.fromasm.no-opts index 80dbde975..bdc00ad43 100644 --- a/test/emcc_O2_hello_world.fromasm.no-opts +++ b/test/emcc_O2_hello_world.fromasm.no-opts @@ -3723,13 +3723,13 @@ (get_local $i52) (i32.const 0) ) - (block + (block i32 (set_local $i51 (i32.load (i32.const 608) ) ) - (block + (block i32 (set_local $i50 (i32.add (get_local $i51) @@ -3795,7 +3795,7 @@ (get_local $i51) (get_local $i52) ) - (block + (block i32 (set_local $i45 (i32.add (get_local $i50) @@ -3925,7 +3925,7 @@ (get_local $i36) (i32.const 173) ) - (block + (block i32 (set_local $i52 (call $_sbrk (i32.const 0) @@ -4101,13 +4101,13 @@ ) ) ) - (block + (block i32 (set_local $i52 (i32.load (i32.const 656) ) ) - (block + (block i32 (set_local $i5 (i32.and (i32.add @@ -4214,13 +4214,13 @@ ) (i32.const 0) ) - (block + (block i32 (set_local $i63 (call $_sbrk (get_local $i43) ) ) - (block + (block i32 (set_local $i43 (call $_sbrk (i32.const 0) @@ -4246,7 +4246,7 @@ ) (i32.const 0) ) - (block + (block i32 (set_local $i60 (i32.sub (get_local $i43) @@ -5996,7 +5996,7 @@ (get_local $i63) (get_local $i60) ) - (block + (block i32 (set_local $i53 (i32.add (get_local $i63) @@ -10466,7 +10466,7 @@ (get_local $i6) (get_local $i8) ) - (block + (block i32 (set_local $i11 (i32.and (get_local $i2) @@ -10573,7 +10573,7 @@ (get_local $i3) ) ) - (block + (block i32 (drop (call_indirect $FUNCSIG$iiii (get_local $i1) @@ -11069,14 +11069,14 @@ ) (i32.const 10) ) - (block + (block i32 (set_local $i5 (i32.add (get_local $i2) (i32.const 20) ) ) - (block + (block i32 (set_local $i6 (i32.load (get_local $i5) @@ -11456,7 +11456,7 @@ ) (i32.const 0) ) - (block + (block i32 (i32.store (get_local $i5) (i32.load @@ -11466,7 +11466,7 @@ ) ) ) - (block + (block i32 (i32.store (i32.add (get_local $i5) @@ -11474,7 +11474,7 @@ ) (i32.const 21505) ) - (block + (block i32 (i32.store (i32.add (get_local $i5) diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index 516fe6b30..24f6d4f75 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -288,7 +288,7 @@ (i32.const 52) ) ) - (block $switch$0 + (block $switch$0 f64 (block $switch-default$3 (block $switch-case$2 (block $switch-case$1 @@ -311,7 +311,7 @@ (get_local $0) (f64.const 0) ) - (block + (block i32 (set_local $0 (call $_frexp (f64.mul @@ -674,7 +674,7 @@ ) (i32.const 0) ) - (block + (block i32 (i32.store (get_local $0) (i32.const -1) @@ -694,10 +694,10 @@ (func $_fflush (param $0 i32) (result i32) (local $1 i32) (local $2 i32) - (block $do-once$0 + (block $do-once$0 i32 (if (get_local $0) - (block + (block i32 (if (i32.le_s (i32.load offset=76 @@ -726,7 +726,7 @@ (if (get_local $2) (get_local $1) - (block + (block i32 (call $___unlockfile (get_local $0) ) @@ -734,7 +734,7 @@ ) ) ) - (block + (block i32 (set_local $0 (if (i32.load @@ -964,7 +964,7 @@ ) ) (set_local $0 - (block $jumpthreading$outer$1 + (block $jumpthreading$outer$1 i32 (block $jumpthreading$inner$1 (block $jumpthreading$inner$0 (loop $while-in$1 @@ -976,7 +976,7 @@ (i32.load (i32.const 16) ) - (block + (block i32 (call $_pthread_cleanup_push (i32.const 5) (get_local $0) @@ -1008,7 +1008,7 @@ ) (get_local $3) ) - (block + (block i32 (i32.store (get_local $8) (i32.load @@ -1057,7 +1057,7 @@ ) ) ) - (block + (block i32 (i32.store (get_local $6) (tee_local $3 @@ -1097,7 +1097,7 @@ (get_local $4) (i32.const 2) ) - (block + (block i32 (i32.store (get_local $6) (i32.add @@ -1115,7 +1115,7 @@ ) (get_local $12) ) - (block + (block i32 (set_local $3 (get_local $1) ) @@ -1308,7 +1308,7 @@ (i32.const 0) ) (i32.const -1) - (block + (block i32 (set_local $12 (if (i32.gt_s @@ -1367,7 +1367,7 @@ (get_local $8) (get_local $9) ) - (block + (block i32 (set_local $2 (i32.load (tee_local $7 @@ -1427,7 +1427,7 @@ ) (if (get_local $2) - (block + (block i32 (drop (call_indirect $FUNCSIG$iiii (get_local $0) @@ -1590,7 +1590,7 @@ ) (drop (call $_memcpy - (block $label$break$L10 + (block $label$break$L10 i32 (if (i32.gt_s (i32.load8_s offset=75 @@ -1598,7 +1598,7 @@ ) (i32.const -1) ) - (block + (block i32 (set_local $3 (get_local $1) ) @@ -1677,7 +1677,7 @@ (get_local $5) ) ) - (block + (block i32 (set_local $2 (i32.const 0) ) @@ -1742,7 +1742,7 @@ ) (i32.const 8) ) - (block + (block i32 (i32.store (get_local $0) (i32.or @@ -1752,7 +1752,7 @@ ) (i32.const -1) ) - (block + (block i32 (i32.store offset=8 (get_local $0) (i32.const 0) @@ -1787,10 +1787,10 @@ ) ) (func $_wcrtomb (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (block $do-once$0 + (block $do-once$0 i32 (if (get_local $0) - (block + (block i32 (if (i32.lt_u (get_local $1) @@ -1916,7 +1916,7 @@ ) (i32.const 1048576) ) - (block + (block i32 (i32.store8 (get_local $0) (i32.and @@ -1977,7 +1977,7 @@ ) (i32.const 4) ) - (block + (block i32 (i32.store (call $___errno_location) (i32.const 84) @@ -2254,7 +2254,7 @@ (get_local $0) (i32.const -4096) ) - (block + (block i32 (i32.store (call $___errno_location) (i32.sub @@ -2274,7 +2274,7 @@ (local $4 i32) (local $5 i32) (local $6 i32) - (block $jumpthreading$outer$0 + (block $jumpthreading$outer$0 i32 (block $jumpthreading$inner$0 (br_if $jumpthreading$inner$0 (i32.le_u @@ -2614,7 +2614,7 @@ (get_local $15) ) ) - (block + (block i32 (i32.store (call $___errno_location) (i32.const 75) @@ -2827,7 +2827,7 @@ ) (i32.const 10) ) - (block + (block i32 (set_local $5 (i32.load8_s (tee_local $10 @@ -2862,7 +2862,7 @@ (get_local $8) ) ) - (block + (block i32 (set_local $7 (get_local $13) ) @@ -2991,7 +2991,7 @@ ) (block (set_local $13 - (block $jumpthreading$outer$0 + (block $jumpthreading$outer$0 i32 (block $jumpthreading$inner$0 (br_if $jumpthreading$inner$0 (i32.ge_u @@ -3124,7 +3124,7 @@ (get_local $7) (i32.const 0) ) - (block + (block i32 (set_local $17 (i32.sub (i32.const 0) @@ -3136,7 +3136,7 @@ (i32.const 8192) ) ) - (block + (block i32 (set_local $17 (get_local $7) ) @@ -3245,7 +3245,7 @@ ) ) (set_local $9 - (block $label$break$L46 + (block $label$break$L46 i32 (if (i32.eq (i32.load8_s @@ -3253,7 +3253,7 @@ ) (i32.const 46) ) - (block + (block i32 (if (i32.ne (i32.shr_s @@ -3420,7 +3420,7 @@ ) (if (get_local $33) - (block + (block i32 (set_local $7 (i32.load (tee_local $5 @@ -3445,7 +3445,7 @@ ) (get_local $9) ) - (block + (block i32 (set_local $7 (i32.const 0) ) @@ -3453,7 +3453,7 @@ ) ) ) - (block + (block i32 (set_local $7 (i32.const -1) ) @@ -4266,7 +4266,7 @@ ) (i32.const 0) ) - (block + (block i32 (set_local $30 (i32.const 1) ) @@ -4282,13 +4282,13 @@ (get_local $10) (i32.const 2048) ) - (block + (block i32 (set_local $30 (i32.const 1) ) (i32.const 4111) ) - (block + (block i32 (set_local $30 (tee_local $1 (i32.and @@ -4314,7 +4314,7 @@ (get_local $5) ) (set_local $5 - (block $do-once$56 + (block $do-once$56 i32 (if (i32.or (i32.lt_u @@ -4336,7 +4336,7 @@ (i32.const 0) ) ) - (block + (block i32 (if (tee_local $5 (f64.ne @@ -4411,7 +4411,7 @@ ) ) (get_local $22) - (block + (block f64 (set_local $14 (f64.const 8) ) @@ -4499,7 +4499,7 @@ ) (get_local $37) ) - (block + (block i32 (i32.store8 (get_local $48) (i32.const 48) @@ -4592,7 +4592,7 @@ ) ) (set_local $5 - (block $do-once$64 + (block $do-once$64 i32 (if (i32.eq (i32.sub @@ -4606,7 +4606,7 @@ ) (i32.const 1) ) - (block + (block i32 (br_if $do-once$64 (get_local $6) (i32.and @@ -4807,7 +4807,7 @@ (i32.lt_s (if (get_local $5) - (block + (block i32 (i32.store (get_local $20) (tee_local $5 @@ -4827,7 +4827,7 @@ ) (get_local $5) ) - (block + (block i32 (set_local $14 (get_local $22) ) @@ -4901,7 +4901,7 @@ ) ) (set_local $9 - (block $do-once$70 + (block $do-once$70 i32 (if (i32.lt_u (tee_local $7 @@ -4913,7 +4913,7 @@ (get_local $9) ) (get_local $9) - (block + (block i32 (set_local $5 (i32.const 0) ) @@ -5099,13 +5099,13 @@ (select (get_local $8) (tee_local $5 - (block $do-once$78 + (block $do-once$78 i32 (if (i32.lt_u (get_local $5) (get_local $6) ) - (block + (block i32 (set_local $44 (i32.add (i32.shl @@ -5362,7 +5362,7 @@ (i32.const -9) ) ) - (block + (block i32 (set_local $7 (i32.add (i32.add @@ -5509,10 +5509,10 @@ ) ) (set_local $22 - (block $do-once$90 + (block $do-once$90 f64 (if (get_local $30) - (block + (block f64 (br_if $do-once$90 (get_local $22) (i32.ne @@ -5583,7 +5583,7 @@ ) (get_local $5) ) - (block + (block i32 (i32.store (tee_local $5 (i32.add @@ -5684,7 +5684,7 @@ ) (get_local $5) ) - (block + (block i32 (set_local $11 (get_local $6) ) @@ -5745,10 +5745,10 @@ ) ) (set_local $19 - (block $do-once$98 + (block $do-once$98 i32 (if (get_local $21) - (block + (block i32 (set_local $16 (if (i32.and @@ -5772,7 +5772,7 @@ (i32.const -5) ) ) - (block + (block i32 (set_local $6 (i32.add (get_local $16) @@ -5787,7 +5787,7 @@ (get_local $11) ) ) - (block + (block i32 (set_local $6 (i32.add (get_local $16) @@ -5915,7 +5915,7 @@ ) (i32.const 102) ) - (block + (block i32 (set_local $5 (select (get_local $16) @@ -5942,7 +5942,7 @@ ) (i32.const 0) ) - (block + (block i32 (set_local $5 (select (get_local $16) @@ -5974,7 +5974,7 @@ ) ) ) - (block + (block i32 (set_local $5 (get_local $19) ) @@ -6014,7 +6014,7 @@ (i32.const 102) ) ) - (block + (block i32 (set_local $6 (select (get_local $11) @@ -6027,7 +6027,7 @@ ) (i32.const 0) ) - (block + (block i32 (if (i32.lt_s (i32.sub @@ -6461,7 +6461,7 @@ ) (get_local $34) ) - (block + (block i32 (i32.store8 (get_local $38) (i32.const 48) @@ -6673,7 +6673,7 @@ ) ) ) - (block + (block i32 (set_local $7 (select (i32.const 0) @@ -6737,7 +6737,7 @@ (i32.const 32) ) (get_local $5) - (block + (block i32 (drop (call $___fwritex (get_local $36) @@ -7251,7 +7251,7 @@ ) ) ) - (block + (block i32 (set_local $11 (select (get_local $7) @@ -7281,7 +7281,7 @@ ) (get_local $6) ) - (block + (block i32 (set_local $11 (i32.const 0) ) @@ -7938,7 +7938,7 @@ ) ) ) - (block + (block i32 (loop $while-in$1 (set_local $3 (call $___uremdi3 @@ -8160,7 +8160,7 @@ (tee_local $1 (if (get_local $3) - (block + (block i32 (drop (call $___fwritex (get_local $5) @@ -9824,7 +9824,7 @@ (get_local $2) ) ) - (block + (block i32 (if (i32.eqz (tee_local $5 @@ -11742,7 +11742,7 @@ ) ) ) - (block + (block i32 (i32.store (i32.const 192) (get_local $2) @@ -11974,7 +11974,7 @@ ) (i32.const 1) ) - (block + (block i32 (set_local $5 (i32.and (get_local $1) @@ -12598,7 +12598,7 @@ (i32.const 480) (i32.shl (tee_local $3 - (block $do-once$69 + (block $do-once$69 i32 (if (tee_local $0 (i32.shr_u @@ -12606,7 +12606,7 @@ (i32.const 8) ) ) - (block + (block i32 (br_if $do-once$69 (i32.const 31) (i32.gt_u diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise index 525553e72..c6123841a 100644 --- a/test/emcc_hello_world.fromasm.imprecise +++ b/test/emcc_hello_world.fromasm.imprecise @@ -281,7 +281,7 @@ (i32.const 52) ) ) - (block $switch$0 + (block $switch$0 f64 (block $switch-default$3 (block $switch-case$2 (block $switch-case$1 @@ -304,7 +304,7 @@ (get_local $0) (f64.const 0) ) - (block + (block i32 (set_local $0 (call $_frexp (f64.mul @@ -667,7 +667,7 @@ ) (i32.const 0) ) - (block + (block i32 (i32.store (get_local $0) (i32.const -1) @@ -687,10 +687,10 @@ (func $_fflush (param $0 i32) (result i32) (local $1 i32) (local $2 i32) - (block $do-once$0 + (block $do-once$0 i32 (if (get_local $0) - (block + (block i32 (if (i32.le_s (i32.load offset=76 @@ -719,7 +719,7 @@ (if (get_local $2) (get_local $1) - (block + (block i32 (call $___unlockfile (get_local $0) ) @@ -727,7 +727,7 @@ ) ) ) - (block + (block i32 (set_local $0 (if (i32.load @@ -957,7 +957,7 @@ ) ) (set_local $0 - (block $jumpthreading$outer$1 + (block $jumpthreading$outer$1 i32 (block $jumpthreading$inner$1 (block $jumpthreading$inner$0 (loop $while-in$1 @@ -969,7 +969,7 @@ (i32.load (i32.const 16) ) - (block + (block i32 (call $_pthread_cleanup_push (i32.const 5) (get_local $0) @@ -1001,7 +1001,7 @@ ) (get_local $3) ) - (block + (block i32 (i32.store (get_local $8) (i32.load @@ -1050,7 +1050,7 @@ ) ) ) - (block + (block i32 (i32.store (get_local $6) (tee_local $3 @@ -1090,7 +1090,7 @@ (get_local $4) (i32.const 2) ) - (block + (block i32 (i32.store (get_local $6) (i32.add @@ -1108,7 +1108,7 @@ ) (get_local $12) ) - (block + (block i32 (set_local $3 (get_local $1) ) @@ -1301,7 +1301,7 @@ (i32.const 0) ) (i32.const -1) - (block + (block i32 (set_local $12 (if (i32.gt_s @@ -1360,7 +1360,7 @@ (get_local $8) (get_local $9) ) - (block + (block i32 (set_local $2 (i32.load (tee_local $7 @@ -1420,7 +1420,7 @@ ) (if (get_local $2) - (block + (block i32 (drop (call_indirect $FUNCSIG$iiii (get_local $0) @@ -1583,7 +1583,7 @@ ) (drop (call $_memcpy - (block $label$break$L10 + (block $label$break$L10 i32 (if (i32.gt_s (i32.load8_s offset=75 @@ -1591,7 +1591,7 @@ ) (i32.const -1) ) - (block + (block i32 (set_local $3 (get_local $1) ) @@ -1670,7 +1670,7 @@ (get_local $5) ) ) - (block + (block i32 (set_local $2 (i32.const 0) ) @@ -1735,7 +1735,7 @@ ) (i32.const 8) ) - (block + (block i32 (i32.store (get_local $0) (i32.or @@ -1745,7 +1745,7 @@ ) (i32.const -1) ) - (block + (block i32 (i32.store offset=8 (get_local $0) (i32.const 0) @@ -1780,10 +1780,10 @@ ) ) (func $_wcrtomb (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (block $do-once$0 + (block $do-once$0 i32 (if (get_local $0) - (block + (block i32 (if (i32.lt_u (get_local $1) @@ -1909,7 +1909,7 @@ ) (i32.const 1048576) ) - (block + (block i32 (i32.store8 (get_local $0) (i32.and @@ -1970,7 +1970,7 @@ ) (i32.const 4) ) - (block + (block i32 (i32.store (call $___errno_location) (i32.const 84) @@ -2247,7 +2247,7 @@ (get_local $0) (i32.const -4096) ) - (block + (block i32 (i32.store (call $___errno_location) (i32.sub @@ -2267,7 +2267,7 @@ (local $4 i32) (local $5 i32) (local $6 i32) - (block $jumpthreading$outer$0 + (block $jumpthreading$outer$0 i32 (block $jumpthreading$inner$0 (br_if $jumpthreading$inner$0 (i32.le_u @@ -2607,7 +2607,7 @@ (get_local $15) ) ) - (block + (block i32 (i32.store (call $___errno_location) (i32.const 75) @@ -2820,7 +2820,7 @@ ) (i32.const 10) ) - (block + (block i32 (set_local $5 (i32.load8_s (tee_local $10 @@ -2855,7 +2855,7 @@ (get_local $8) ) ) - (block + (block i32 (set_local $7 (get_local $13) ) @@ -2984,7 +2984,7 @@ ) (block (set_local $13 - (block $jumpthreading$outer$0 + (block $jumpthreading$outer$0 i32 (block $jumpthreading$inner$0 (br_if $jumpthreading$inner$0 (i32.ge_u @@ -3117,7 +3117,7 @@ (get_local $7) (i32.const 0) ) - (block + (block i32 (set_local $17 (i32.sub (i32.const 0) @@ -3129,7 +3129,7 @@ (i32.const 8192) ) ) - (block + (block i32 (set_local $17 (get_local $7) ) @@ -3238,7 +3238,7 @@ ) ) (set_local $9 - (block $label$break$L46 + (block $label$break$L46 i32 (if (i32.eq (i32.load8_s @@ -3246,7 +3246,7 @@ ) (i32.const 46) ) - (block + (block i32 (if (i32.ne (i32.shr_s @@ -3413,7 +3413,7 @@ ) (if (get_local $33) - (block + (block i32 (set_local $7 (i32.load (tee_local $5 @@ -3438,7 +3438,7 @@ ) (get_local $9) ) - (block + (block i32 (set_local $7 (i32.const 0) ) @@ -3446,7 +3446,7 @@ ) ) ) - (block + (block i32 (set_local $7 (i32.const -1) ) @@ -4259,7 +4259,7 @@ ) (i32.const 0) ) - (block + (block i32 (set_local $30 (i32.const 1) ) @@ -4275,13 +4275,13 @@ (get_local $10) (i32.const 2048) ) - (block + (block i32 (set_local $30 (i32.const 1) ) (i32.const 4111) ) - (block + (block i32 (set_local $30 (tee_local $1 (i32.and @@ -4307,7 +4307,7 @@ (get_local $5) ) (set_local $5 - (block $do-once$56 + (block $do-once$56 i32 (if (i32.or (i32.lt_u @@ -4329,7 +4329,7 @@ (i32.const 0) ) ) - (block + (block i32 (if (tee_local $5 (f64.ne @@ -4404,7 +4404,7 @@ ) ) (get_local $22) - (block + (block f64 (set_local $14 (f64.const 8) ) @@ -4492,7 +4492,7 @@ ) (get_local $37) ) - (block + (block i32 (i32.store8 (get_local $48) (i32.const 48) @@ -4585,7 +4585,7 @@ ) ) (set_local $5 - (block $do-once$64 + (block $do-once$64 i32 (if (i32.eq (i32.sub @@ -4599,7 +4599,7 @@ ) (i32.const 1) ) - (block + (block i32 (br_if $do-once$64 (get_local $6) (i32.and @@ -4800,7 +4800,7 @@ (i32.lt_s (if (get_local $5) - (block + (block i32 (i32.store (get_local $20) (tee_local $5 @@ -4820,7 +4820,7 @@ ) (get_local $5) ) - (block + (block i32 (set_local $14 (get_local $22) ) @@ -4894,7 +4894,7 @@ ) ) (set_local $9 - (block $do-once$70 + (block $do-once$70 i32 (if (i32.lt_u (tee_local $7 @@ -4906,7 +4906,7 @@ (get_local $9) ) (get_local $9) - (block + (block i32 (set_local $5 (i32.const 0) ) @@ -5092,13 +5092,13 @@ (select (get_local $8) (tee_local $5 - (block $do-once$78 + (block $do-once$78 i32 (if (i32.lt_u (get_local $5) (get_local $6) ) - (block + (block i32 (set_local $44 (i32.add (i32.shl @@ -5355,7 +5355,7 @@ (i32.const -9) ) ) - (block + (block i32 (set_local $7 (i32.add (i32.add @@ -5502,10 +5502,10 @@ ) ) (set_local $22 - (block $do-once$90 + (block $do-once$90 f64 (if (get_local $30) - (block + (block f64 (br_if $do-once$90 (get_local $22) (i32.ne @@ -5576,7 +5576,7 @@ ) (get_local $5) ) - (block + (block i32 (i32.store (tee_local $5 (i32.add @@ -5677,7 +5677,7 @@ ) (get_local $5) ) - (block + (block i32 (set_local $11 (get_local $6) ) @@ -5738,10 +5738,10 @@ ) ) (set_local $19 - (block $do-once$98 + (block $do-once$98 i32 (if (get_local $21) - (block + (block i32 (set_local $16 (if (i32.and @@ -5765,7 +5765,7 @@ (i32.const -5) ) ) - (block + (block i32 (set_local $6 (i32.add (get_local $16) @@ -5780,7 +5780,7 @@ (get_local $11) ) ) - (block + (block i32 (set_local $6 (i32.add (get_local $16) @@ -5908,7 +5908,7 @@ ) (i32.const 102) ) - (block + (block i32 (set_local $5 (select (get_local $16) @@ -5935,7 +5935,7 @@ ) (i32.const 0) ) - (block + (block i32 (set_local $5 (select (get_local $16) @@ -5967,7 +5967,7 @@ ) ) ) - (block + (block i32 (set_local $5 (get_local $19) ) @@ -6007,7 +6007,7 @@ (i32.const 102) ) ) - (block + (block i32 (set_local $6 (select (get_local $11) @@ -6020,7 +6020,7 @@ ) (i32.const 0) ) - (block + (block i32 (if (i32.lt_s (i32.sub @@ -6454,7 +6454,7 @@ ) (get_local $34) ) - (block + (block i32 (i32.store8 (get_local $38) (i32.const 48) @@ -6666,7 +6666,7 @@ ) ) ) - (block + (block i32 (set_local $7 (select (i32.const 0) @@ -6730,7 +6730,7 @@ (i32.const 32) ) (get_local $5) - (block + (block i32 (drop (call $___fwritex (get_local $36) @@ -7244,7 +7244,7 @@ ) ) ) - (block + (block i32 (set_local $11 (select (get_local $7) @@ -7274,7 +7274,7 @@ ) (get_local $6) ) - (block + (block i32 (set_local $11 (i32.const 0) ) @@ -7931,7 +7931,7 @@ ) ) ) - (block + (block i32 (loop $while-in$1 (set_local $3 (call $___uremdi3 @@ -8153,7 +8153,7 @@ (tee_local $1 (if (get_local $3) - (block + (block i32 (drop (call $___fwritex (get_local $5) @@ -9817,7 +9817,7 @@ (get_local $2) ) ) - (block + (block i32 (if (i32.eqz (tee_local $5 @@ -11735,7 +11735,7 @@ ) ) ) - (block + (block i32 (i32.store (i32.const 192) (get_local $2) @@ -11967,7 +11967,7 @@ ) (i32.const 1) ) - (block + (block i32 (set_local $5 (i32.and (get_local $1) @@ -12591,7 +12591,7 @@ (i32.const 480) (i32.shl (tee_local $3 - (block $do-once$69 + (block $do-once$69 i32 (if (tee_local $0 (i32.shr_u @@ -12599,7 +12599,7 @@ (i32.const 8) ) ) - (block + (block i32 (br_if $do-once$69 (i32.const 31) (i32.gt_u diff --git a/test/emcc_hello_world.fromasm.imprecise.no-opts b/test/emcc_hello_world.fromasm.imprecise.no-opts index 7c9e27d25..a2e8496a5 100644 --- a/test/emcc_hello_world.fromasm.imprecise.no-opts +++ b/test/emcc_hello_world.fromasm.imprecise.no-opts @@ -30296,7 +30296,7 @@ ) ) (return - (block + (block i32 (block (set_global $tempRet0 (get_local $h) @@ -30331,7 +30331,7 @@ ) ) (return - (block + (block i32 (block (set_global $tempRet0 (get_local $h) @@ -30907,7 +30907,7 @@ ) ) (return - (block + (block i32 (block (set_global $tempRet0 (i32.add @@ -31310,7 +31310,7 @@ (get_local $__stackBase__) ) (return - (block + (block i32 (block (set_global $tempRet0 (get_local $$10$1) @@ -31351,7 +31351,7 @@ ) ) (return - (block + (block i32 (block (set_global $tempRet0 (i32.or @@ -31428,7 +31428,7 @@ (get_local $__stackBase__) ) (return - (block + (block i32 (block (set_global $tempRet0 (i32.load diff --git a/test/emcc_hello_world.fromasm.no-opts b/test/emcc_hello_world.fromasm.no-opts index 6799d2c5e..771e63313 100644 --- a/test/emcc_hello_world.fromasm.no-opts +++ b/test/emcc_hello_world.fromasm.no-opts @@ -30302,7 +30302,7 @@ ) ) (return - (block + (block i32 (block (set_global $tempRet0 (get_local $h) @@ -30337,7 +30337,7 @@ ) ) (return - (block + (block i32 (block (set_global $tempRet0 (get_local $h) @@ -30913,7 +30913,7 @@ ) ) (return - (block + (block i32 (block (set_global $tempRet0 (i32.add @@ -31316,7 +31316,7 @@ (get_local $__stackBase__) ) (return - (block + (block i32 (block (set_global $tempRet0 (get_local $$10$1) @@ -31357,7 +31357,7 @@ ) ) (return - (block + (block i32 (block (set_global $tempRet0 (i32.or @@ -31434,7 +31434,7 @@ (get_local $__stackBase__) ) (return - (block + (block i32 (block (set_global $tempRet0 (i32.load diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 8f8837c4c..41d64089e 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -21,10 +21,10 @@ BinaryenFloat64: 4 (elem (i32.const 0) "$kitchen()sinker") (func "$kitchen()sinker" (type $iiIfF) (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) (local $4 i32) - (block $the-body + (block $the-body i32 (block $the-nothing (drop - (block $the-value + (block $the-value i32 (drop (i32.clz (i32.const -10) @@ -1612,10 +1612,10 @@ int main() { (elem (i32.const 0) "$kitchen()sinker") (func "$kitchen()sinker" (type $iiIfF) (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) (local $4 i32) - (block $the-body + (block $the-body i32 (block $the-nothing (drop - (block $the-value + (block $the-value i32 (drop (i32.clz (i32.const -10) diff --git a/test/example/c-api-kitchen-sink.txt.txt b/test/example/c-api-kitchen-sink.txt.txt index abe64601c..10a698717 100644 --- a/test/example/c-api-kitchen-sink.txt.txt +++ b/test/example/c-api-kitchen-sink.txt.txt @@ -16,10 +16,10 @@ (elem (i32.const 0) "$kitchen()sinker") (func "$kitchen()sinker" (type $iiIfF) (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) (local $4 i32) - (block $the-body + (block $the-body i32 (block $the-nothing (drop - (block $the-value + (block $the-value i32 (drop (i32.clz (i32.const -10) diff --git a/test/kitchen_sink.wast b/test/kitchen_sink.wast index 01fc1e241..c6cd0a8b3 100644 --- a/test/kitchen_sink.wast +++ b/test/kitchen_sink.wast @@ -3,7 +3,7 @@ (data (i32.const 1026) "\14\00") (type $0 (func (result i32))) (func $kitchensink (type $0) (result i32) - (block $block0 + (block $block0 i32 (drop (i32.add (i32.const 10) diff --git a/test/kitchen_sink.wast.fromBinary b/test/kitchen_sink.wast.fromBinary index 4c3da110c..5aba809f6 100644 --- a/test/kitchen_sink.wast.fromBinary +++ b/test/kitchen_sink.wast.fromBinary @@ -3,7 +3,7 @@ (data (i32.const 1026) "\14\00") (type $0 (func (result i32))) (func $kitchensink (type $0) (result i32) - (block $label$0 + (block $label$0 i32 (drop (i32.add (i32.const 10) diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm index 9cf9336a4..a07d71fd4 100644 --- a/test/memorygrowth.fromasm +++ b/test/memorygrowth.fromasm @@ -1757,7 +1757,7 @@ (get_local $33) ) ) - (block + (block i32 (if (i32.eqz (tee_local $6 @@ -3195,7 +3195,7 @@ (if (i32.eq (tee_local $9 - (block $label$break$b + (block $label$break$b i32 (if (i32.and (i32.load @@ -3204,7 +3204,7 @@ (i32.const 4) ) (i32.const 188) - (block + (block i32 (block $label$break$c (if (tee_local $16 @@ -3848,7 +3848,7 @@ ) ) ) - (block + (block i32 (i32.store (i32.const 1224) (get_local $20) @@ -4091,7 +4091,7 @@ ) (i32.const 1) ) - (block + (block i32 (set_local $5 (i32.and (get_local $2) @@ -4721,7 +4721,7 @@ (i32.const 1512) (i32.shl (tee_local $6 - (block $do-once$67 + (block $do-once$67 i32 (if (tee_local $0 (i32.shr_u @@ -4729,7 +4729,7 @@ (i32.const 8) ) ) - (block + (block i32 (br_if $do-once$67 (i32.const 31) (i32.gt_u @@ -7947,7 +7947,7 @@ (i32.load (i32.const 1160) ) - (block + (block i32 (call $ra (i32.const 1) (get_local $0) @@ -7979,7 +7979,7 @@ ) (get_local $9) ) - (block + (block i32 (i32.store (get_local $11) (i32.load @@ -8044,7 +8044,7 @@ ) ) ) - (block + (block i32 (i32.store (get_local $8) (tee_local $3 @@ -8084,7 +8084,7 @@ (get_local $4) (i32.const 2) ) - (block + (block i32 (i32.store (get_local $8) (i32.add @@ -8102,7 +8102,7 @@ ) (get_local $14) ) - (block + (block i32 (set_local $3 (get_local $5) ) @@ -8313,7 +8313,7 @@ ) ) (set_local $1 - (block $label$break$b + (block $label$break$b i32 (if (i32.gt_s (i32.load8_s offset=75 @@ -8321,7 +8321,7 @@ ) (i32.const -1) ) - (block + (block i32 (set_local $3 (get_local $1) ) @@ -8406,7 +8406,7 @@ (get_local $3) ) ) - (block + (block i32 (set_local $2 (i32.const 0) ) @@ -8597,10 +8597,10 @@ (func $_a (param $0 i32) (result i32) (local $1 i32) (local $2 i32) - (block $do-once$0 + (block $do-once$0 i32 (if (get_local $0) - (block + (block i32 (if (i32.le_s (i32.load offset=76 @@ -8629,7 +8629,7 @@ (if (get_local $2) (get_local $1) - (block + (block i32 (call $Ta (get_local $0) ) @@ -8637,7 +8637,7 @@ ) ) ) - (block + (block i32 (set_local $0 (if (i32.load @@ -9325,7 +9325,7 @@ ) ) (set_local $0 - (block $do-once$0 + (block $do-once$0 i32 (if (i32.lt_s (call $cb @@ -9335,7 +9335,7 @@ (i32.const 0) ) (i32.const 1) - (block + (block i32 (if (i32.ne (i32.load8_s offset=75 @@ -9434,7 +9434,7 @@ ) (i32.const 8) ) - (block + (block i32 (i32.store (get_local $0) (i32.or @@ -9444,7 +9444,7 @@ ) (i32.const -1) ) - (block + (block i32 (i32.store offset=8 (get_local $0) (i32.const 0) @@ -9497,7 +9497,7 @@ ) (i32.const -1) ) - (block + (block i32 (set_local $5 (i32.eqz (call $Ya @@ -9515,7 +9515,7 @@ (if (get_local $5) (get_local $0) - (block + (block i32 (call $Ta (get_local $3) ) @@ -9591,7 +9591,7 @@ ) (i32.const 0) ) - (block + (block i32 (i32.store (get_local $0) (i32.const -1) @@ -9767,7 +9767,7 @@ (get_local $0) (i32.const -4096) ) - (block + (block i32 (i32.store (call $Qa) (i32.sub diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise index 847a8dd9a..ea085352f 100644 --- a/test/memorygrowth.fromasm.imprecise +++ b/test/memorygrowth.fromasm.imprecise @@ -1755,7 +1755,7 @@ (get_local $33) ) ) - (block + (block i32 (if (i32.eqz (tee_local $6 @@ -3193,7 +3193,7 @@ (if (i32.eq (tee_local $9 - (block $label$break$b + (block $label$break$b i32 (if (i32.and (i32.load @@ -3202,7 +3202,7 @@ (i32.const 4) ) (i32.const 188) - (block + (block i32 (block $label$break$c (if (tee_local $16 @@ -3846,7 +3846,7 @@ ) ) ) - (block + (block i32 (i32.store (i32.const 1224) (get_local $20) @@ -4089,7 +4089,7 @@ ) (i32.const 1) ) - (block + (block i32 (set_local $5 (i32.and (get_local $2) @@ -4719,7 +4719,7 @@ (i32.const 1512) (i32.shl (tee_local $6 - (block $do-once$67 + (block $do-once$67 i32 (if (tee_local $0 (i32.shr_u @@ -4727,7 +4727,7 @@ (i32.const 8) ) ) - (block + (block i32 (br_if $do-once$67 (i32.const 31) (i32.gt_u @@ -7945,7 +7945,7 @@ (i32.load (i32.const 1160) ) - (block + (block i32 (call $ra (i32.const 1) (get_local $0) @@ -7977,7 +7977,7 @@ ) (get_local $9) ) - (block + (block i32 (i32.store (get_local $11) (i32.load @@ -8042,7 +8042,7 @@ ) ) ) - (block + (block i32 (i32.store (get_local $8) (tee_local $3 @@ -8082,7 +8082,7 @@ (get_local $4) (i32.const 2) ) - (block + (block i32 (i32.store (get_local $8) (i32.add @@ -8100,7 +8100,7 @@ ) (get_local $14) ) - (block + (block i32 (set_local $3 (get_local $5) ) @@ -8311,7 +8311,7 @@ ) ) (set_local $1 - (block $label$break$b + (block $label$break$b i32 (if (i32.gt_s (i32.load8_s offset=75 @@ -8319,7 +8319,7 @@ ) (i32.const -1) ) - (block + (block i32 (set_local $3 (get_local $1) ) @@ -8404,7 +8404,7 @@ (get_local $3) ) ) - (block + (block i32 (set_local $2 (i32.const 0) ) @@ -8595,10 +8595,10 @@ (func $_a (param $0 i32) (result i32) (local $1 i32) (local $2 i32) - (block $do-once$0 + (block $do-once$0 i32 (if (get_local $0) - (block + (block i32 (if (i32.le_s (i32.load offset=76 @@ -8627,7 +8627,7 @@ (if (get_local $2) (get_local $1) - (block + (block i32 (call $Ta (get_local $0) ) @@ -8635,7 +8635,7 @@ ) ) ) - (block + (block i32 (set_local $0 (if (i32.load @@ -9323,7 +9323,7 @@ ) ) (set_local $0 - (block $do-once$0 + (block $do-once$0 i32 (if (i32.lt_s (call $cb @@ -9333,7 +9333,7 @@ (i32.const 0) ) (i32.const 1) - (block + (block i32 (if (i32.ne (i32.load8_s offset=75 @@ -9432,7 +9432,7 @@ ) (i32.const 8) ) - (block + (block i32 (i32.store (get_local $0) (i32.or @@ -9442,7 +9442,7 @@ ) (i32.const -1) ) - (block + (block i32 (i32.store offset=8 (get_local $0) (i32.const 0) @@ -9495,7 +9495,7 @@ ) (i32.const -1) ) - (block + (block i32 (set_local $5 (i32.eqz (call $Ya @@ -9513,7 +9513,7 @@ (if (get_local $5) (get_local $0) - (block + (block i32 (call $Ta (get_local $3) ) @@ -9589,7 +9589,7 @@ ) (i32.const 0) ) - (block + (block i32 (i32.store (get_local $0) (i32.const -1) @@ -9765,7 +9765,7 @@ (get_local $0) (i32.const -4096) ) - (block + (block i32 (i32.store (call $Qa) (i32.sub diff --git a/test/min.fromasm.imprecise.no-opts b/test/min.fromasm.imprecise.no-opts index c0fcb1917..fb30c334b 100644 --- a/test/min.fromasm.imprecise.no-opts +++ b/test/min.fromasm.imprecise.no-opts @@ -21,7 +21,7 @@ (local $n f32) (set_local $n (f32.neg - (block + (block f32 (i32.store (get_local $k) (get_local $p) diff --git a/test/min.fromasm.no-opts b/test/min.fromasm.no-opts index c0fcb1917..fb30c334b 100644 --- a/test/min.fromasm.no-opts +++ b/test/min.fromasm.no-opts @@ -21,7 +21,7 @@ (local $n f32) (set_local $n (f32.neg - (block + (block f32 (i32.store (get_local $k) (get_local $p) diff --git a/test/min.wast b/test/min.wast index e5472fb77..53587b679 100644 --- a/test/min.wast +++ b/test/min.wast @@ -16,7 +16,7 @@ (local $n f32) (tee_local $n (f32.neg - (block $block0 + (block $block0 f32 (i32.store (get_local $k) (get_local $p) @@ -29,7 +29,7 @@ ) ) (func $littleswitch (type $2) (param $x i32) (result i32) - (block $topmost + (block $topmost i32 (block $switch-case$2 (block $switch-case$1 (br_table $switch-case$1 $switch-case$2 $switch-case$1 @@ -50,7 +50,7 @@ ) ) (func $f1 (type $3) (param $i1 i32) (param $i2 i32) (param $i3 i32) (result i32) - (block $topmost + (block $topmost i32 (get_local $i3) ) ) diff --git a/test/min.wast.fromBinary b/test/min.wast.fromBinary index 33515c61c..56b97fc0d 100644 --- a/test/min.wast.fromBinary +++ b/test/min.wast.fromBinary @@ -16,7 +16,7 @@ (local $var$2 f32) (tee_local $var$2 (f32.neg - (block $label$0 + (block $label$0 f32 (i32.store (get_local $var$0) (get_local $var$1) @@ -29,7 +29,7 @@ ) ) (func $littleswitch (type $2) (param $var$0 i32) (result i32) - (block $label$0 + (block $label$0 i32 (block $label$1 (block $label$2 (br_table $label$2 $label$1 $label$2 @@ -50,7 +50,7 @@ ) ) (func $f1 (type $3) (param $var$0 i32) (param $var$1 i32) (param $var$2 i32) (result i32) - (block $label$0 + (block $label$0 i32 (get_local $var$2) ) ) diff --git a/test/passes/duplicate-function-elimination.txt b/test/passes/duplicate-function-elimination.txt index 75a5c8f16..333155c80 100644 --- a/test/passes/duplicate-function-elimination.txt +++ b/test/passes/duplicate-function-elimination.txt @@ -293,7 +293,7 @@ (type $0 (func)) (func $keep2 (type $0) (drop - (block $foo + (block $foo i32 (br_table $foo $foo (i32.const 0) (i32.const 0) @@ -303,7 +303,7 @@ ) (func $other (type $0) (drop - (block $bar + (block $bar i32 (br_table $bar $bar (i32.const 0) (i32.const 1) diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt index 2cef4b5ac..3c51c8f99 100644 --- a/test/passes/remove-unused-brs.txt +++ b/test/passes/remove-unused-brs.txt @@ -145,7 +145,7 @@ ) ) (func $b13 (type $2) (result i32) - (block $topmost + (block $topmost i32 (if (i32.const 1) (block $block1 @@ -170,12 +170,12 @@ ) ) (func $b14 (type $2) (result i32) - (block $topmost + (block $topmost i32 (select - (block $block1 + (block $block1 i32 (i32.const 12) ) - (block $block3 + (block $block3 i32 (i32.const 27) ) (i32.const 1) @@ -283,8 +283,8 @@ ) ) (func $ret-value (type $2) (result i32) - (block $block0 - (block $block1 + (block $block0 i32 + (block $block1 i32 (i32.const 1) ) ) @@ -326,7 +326,7 @@ ) ) (if - (block $block6 + (block $block6 i32 (block $block7 (drop (i32.const 2) @@ -343,7 +343,7 @@ ) ) (if - (block $a + (block $a i32 (i32.const 0) ) (block $a @@ -407,7 +407,7 @@ (i32.const 1) ) ) - (block $do-once$0 + (block $do-once$0 i32 (if (tee_local $x (i32.const 1) @@ -620,7 +620,7 @@ (block (call $loops) (drop - (block $out2 + (block $out2 i32 (i32.const 1) ) ) @@ -693,7 +693,7 @@ ) ) (func $br_if_in_block (type $2) (result i32) - (block $outval + (block $outval i32 (block $in (br_if $in (i32.const 1) @@ -730,8 +730,8 @@ ) (func $threading (type $1) (drop - (block $value-out - (block $value-in + (block $value-out i32 + (block $value-in i32 (block $out (block $in (br_if $out @@ -765,11 +765,11 @@ (func $if-to-br_if-conflict (type $3) (param $x i32) (param $y i32) (result i32) (block $leave (set_local $y - (block $out + (block $out i32 (if (get_local $x) (br $out - (block $block1 + (block $block1 i32 (set_local $x (i32.const 0) ) @@ -792,14 +792,14 @@ (func $if-to-br_if-conflict2 (type $3) (param $x i32) (param $y i32) (result i32) (block $leave (set_local $y - (block $out + (block $out i32 (if (get_local $x) (br_if $leave (i32.const 1) ) (br $out - (block $block2 + (block $block2 i32 (set_local $x (i32.const 0) ) @@ -819,11 +819,11 @@ (func $if-to-br_if-value-sideeffect (type $3) (param $x i32) (param $y i32) (result i32) (block $leave (set_local $y - (block $out + (block $out i32 (if (get_local $x) (br $out - (block $block1 + (block $block1 i32 (drop (call $if-to-br_if-value-sideeffect (i32.const 0) diff --git a/test/passes/remove-unused-names_merge-blocks.txt b/test/passes/remove-unused-names_merge-blocks.txt index 4557f3da4..ae60d4155 100644 --- a/test/passes/remove-unused-names_merge-blocks.txt +++ b/test/passes/remove-unused-names_merge-blocks.txt @@ -126,7 +126,7 @@ (local $x i32) (drop (i32.eqz - (block + (block i32 (i32.const 10) ) ) @@ -174,7 +174,7 @@ (func $binary (type $3) (drop (i32.add - (block + (block i32 (i32.const 10) ) (i32.const 20) @@ -204,7 +204,7 @@ (drop (i32.add (i32.const 10) - (block + (block i32 (i32.const 20) ) ) @@ -232,10 +232,10 @@ ) (drop (i32.add - (block + (block i32 (i32.const 10) ) - (block + (block i32 (i32.const 20) ) ) @@ -287,7 +287,7 @@ (drop (i32.add (unreachable) - (block + (block i32 (drop (i32.const 10) ) @@ -331,7 +331,7 @@ ) (drop (select - (block + (block i32 (i32.const 10) ) (i32.const 30) @@ -347,7 +347,7 @@ (drop (select (i32.const 20) - (block + (block i32 (i32.const 30) ) (i32.const 50) @@ -363,7 +363,7 @@ (select (i32.const 20) (i32.const 40) - (block + (block i32 (i32.const 50) ) ) @@ -373,10 +373,10 @@ ) (drop (select - (block + (block i32 (i32.const 10) ) - (block + (block i32 (i32.const 20) ) (i32.const 40) @@ -387,11 +387,11 @@ ) (drop (select - (block + (block i32 (i32.const 10) ) (i32.const 30) - (block + (block i32 (i32.const 40) ) ) @@ -402,10 +402,10 @@ (drop (select (i32.const 20) - (block + (block i32 (i32.const 30) ) - (block + (block i32 (i32.const 40) ) ) @@ -430,13 +430,13 @@ (drop (select (unreachable) - (block + (block i32 (drop (i32.const 30) ) (i32.const 40) ) - (block + (block i32 (drop (i32.const 50) ) @@ -468,7 +468,7 @@ (select (i32.const 20) (unreachable) - (block + (block i32 (drop (i32.const 50) ) @@ -541,7 +541,7 @@ (i32.const 20) ) (drop - (block $out2 + (block $out2 i32 (drop (i32.const 10) ) @@ -559,7 +559,7 @@ ) (func $calls (type $3) (call $call-i - (block + (block i32 (i32.const 10) ) ) @@ -601,7 +601,7 @@ ) (call $call-ii (unreachable) - (block + (block i32 (drop (i32.const 20) ) @@ -670,7 +670,7 @@ ) (call_indirect $ii (unreachable) - (block + (block i32 (drop (i32.const 30) ) @@ -683,7 +683,7 @@ (local $0 f64) (local $1 f64) (if - (block + (block i32 (nop) (f64.gt (get_local $0) diff --git a/test/passes/simplify-locals.txt b/test/passes/simplify-locals.txt index 498d97d58..f2aa8d0d9 100644 --- a/test/passes/simplify-locals.txt +++ b/test/passes/simplify-locals.txt @@ -223,7 +223,7 @@ (call $waka) (nop) (set_local $a - (block $block0 + (block $block0 i32 (block $block1 (nop) (i32.store @@ -238,7 +238,7 @@ ) (call $waka) (set_local $a - (block $block2 + (block $block2 i32 (block $block4 (nop) (i32.store @@ -257,7 +257,7 @@ ) (call $waka) (set_local $a - (block $block5 + (block $block5 i32 (block $block6 (nop) (i32.store @@ -280,7 +280,7 @@ ) (call $waka) (set_local $a - (block $block7 + (block $block7 i32 (block $block8 (nop) (i32.store @@ -306,7 +306,7 @@ (nop) (nop) (drop - (block $b + (block $b i32 (block $c (br $b (i32.const 1337) @@ -563,7 +563,7 @@ (get_local $__stackBase__) ) (return - (block $block12 + (block $block12 i32 (i32.store (i32.const 168) (get_local $$10$1) @@ -575,11 +575,11 @@ (func $block-returns (type $FUNCSIG$v) (local $x i32) (set_local $x - (block $out + (block $out i32 (nop) (br_if $out (tee_local $x - (block $waka + (block $waka i32 (nop) (br_if $waka (tee_local $x @@ -600,11 +600,11 @@ (set_local $x (if (i32.const 1) - (block + (block i32 (nop) (i32.const 13) ) - (block + (block i32 (nop) (i32.const 24) ) @@ -616,11 +616,11 @@ (tee_local $x (if (i32.const 1) - (block $block3 + (block $block3 i32 (nop) (i32.const 14) ) - (block $block5 + (block $block5 i32 (nop) (i32.const 25) ) @@ -685,7 +685,7 @@ (func $no-out-of-label (type $8) (param $x i32) (param $y i32) (loop $moar (set_local $x - (block $block0 + (block $block0 i32 (br_if $moar (get_local $x) ) @@ -698,7 +698,7 @@ ) (block $moar (set_local $y - (block $block1 + (block $block1 i32 (br_if $moar (get_local $y) ) @@ -714,7 +714,7 @@ (local $e i32) (loop $while-in$1 (set_local $a - (block $while-out$0 + (block $while-out$0 i32 (set_local $e (get_local $a) ) diff --git a/test/passes/vacuum.txt b/test/passes/vacuum.txt index b7339ed20..c2fb9fc29 100644 --- a/test/passes/vacuum.txt +++ b/test/passes/vacuum.txt @@ -22,12 +22,12 @@ (block $two-in-a-block ) (set_local $x - (block $result-used + (block $result-used i32 (get_local $x) ) ) (set_local $x - (block $two-and-result-used + (block $two-and-result-used i32 (get_local $y) ) ) @@ -123,7 +123,7 @@ (if (if (get_local $d) - (block $block1 + (block $block1 i32 (f64.ne (f64.promote/f32 (f32.load @@ -186,7 +186,7 @@ (local $$11 i32) (loop $while-in$1 (drop - (block $jumpthreading$outer$8 + (block $jumpthreading$outer$8 i32 (block $jumpthreading$inner$8 (br $jumpthreading$outer$8 (i32.const 0) diff --git a/test/unit.fromasm b/test/unit.fromasm index daa696a0c..ea0ff0843 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -400,7 +400,7 @@ (i32.const 3) ) ) - (block + (block i32 (drop (call $lb (i32.const 4) @@ -421,7 +421,7 @@ ) ) ) - (block + (block i32 (drop (call $lb (i32.const 8) @@ -492,7 +492,7 @@ ) ) (func $phi (result i32) - (block $do-once$0 + (block $do-once$0 i32 (br_if $do-once$0 (i32.const 0) (call $lb diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index 5cd06cda0..5ea81aad3 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -381,7 +381,7 @@ (i32.const 3) ) ) - (block + (block i32 (drop (call $lb (i32.const 4) @@ -402,7 +402,7 @@ ) ) ) - (block + (block i32 (drop (call $lb (i32.const 8) @@ -473,7 +473,7 @@ ) ) (func $phi (result i32) - (block $do-once$0 + (block $do-once$0 i32 (br_if $do-once$0 (i32.const 0) (call $lb diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index ed7ec429f..91118673a 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -178,13 +178,13 @@ (local $J f64) (set_local $J (f64.sub - (block + (block f64 (drop (f64.const 0.1) ) (f64.const 5.1) ) - (block + (block f64 (drop (f64.const 3.2) ) @@ -386,7 +386,7 @@ (local $z f32) (local $asm2wasm_i32_temp i32) (set_local $x - (block + (block i32 (set_local $asm2wasm_i32_temp (i32.const 0) ) @@ -633,20 +633,20 @@ (i32.add (i32.add (i32.add - (block + (block i32 (drop (i32.const 1) ) (get_local $x) ) - (block + (block i32 (drop (i32.const 2) ) (i32.const 3) ) ) - (block + (block i32 (block (block (drop @@ -663,19 +663,19 @@ (i32.const 7) ) ) - (block + (block i32 (drop (i32.const 8) ) - (block + (block i32 (drop (i32.const 9) ) - (block + (block i32 (drop (i32.const 10) ) - (block + (block i32 (drop (i32.const 11) ) @@ -691,7 +691,7 @@ (i32.add (i32.add (i32.add - (block + (block i32 (drop (call $lb (i32.const 1) @@ -699,7 +699,7 @@ ) (get_local $x) ) - (block + (block i32 (drop (call $lb (i32.const 2) @@ -710,7 +710,7 @@ ) ) ) - (block + (block i32 (block (block (drop @@ -735,25 +735,25 @@ ) ) ) - (block + (block i32 (drop (call $lb (i32.const 8) ) ) - (block + (block i32 (drop (call $lb (i32.const 9) ) ) - (block + (block i32 (drop (call $lb (i32.const 10) ) ) - (block + (block i32 (drop (call $lb (i32.const 11) @@ -891,7 +891,7 @@ (func $useSetGlobal (result i32) (local $x i32) (set_local $x - (block + (block i32 (set_global $Int (i32.const 10) ) @@ -902,7 +902,7 @@ (i32.const 20) ) (return - (block + (block i32 (set_global $Int (i32.const 30) ) @@ -912,7 +912,7 @@ ) (func $usesSetGlobal2 (result i32) (return - (block + (block i32 (block (set_global $Int (i32.const 40) diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index faaa013e9..aeece2db3 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -184,13 +184,13 @@ (local $J f64) (set_local $J (f64.sub - (block + (block f64 (drop (f64.const 0.1) ) (f64.const 5.1) ) - (block + (block f64 (drop (f64.const 3.2) ) @@ -392,7 +392,7 @@ (local $z f32) (local $asm2wasm_i32_temp i32) (set_local $x - (block + (block i32 (set_local $asm2wasm_i32_temp (i32.const 0) ) @@ -639,20 +639,20 @@ (i32.add (i32.add (i32.add - (block + (block i32 (drop (i32.const 1) ) (get_local $x) ) - (block + (block i32 (drop (i32.const 2) ) (i32.const 3) ) ) - (block + (block i32 (block (block (drop @@ -669,19 +669,19 @@ (i32.const 7) ) ) - (block + (block i32 (drop (i32.const 8) ) - (block + (block i32 (drop (i32.const 9) ) - (block + (block i32 (drop (i32.const 10) ) - (block + (block i32 (drop (i32.const 11) ) @@ -697,7 +697,7 @@ (i32.add (i32.add (i32.add - (block + (block i32 (drop (call $lb (i32.const 1) @@ -705,7 +705,7 @@ ) (get_local $x) ) - (block + (block i32 (drop (call $lb (i32.const 2) @@ -716,7 +716,7 @@ ) ) ) - (block + (block i32 (block (block (drop @@ -741,25 +741,25 @@ ) ) ) - (block + (block i32 (drop (call $lb (i32.const 8) ) ) - (block + (block i32 (drop (call $lb (i32.const 9) ) ) - (block + (block i32 (drop (call $lb (i32.const 10) ) ) - (block + (block i32 (drop (call $lb (i32.const 11) @@ -897,7 +897,7 @@ (func $useSetGlobal (result i32) (local $x i32) (set_local $x - (block + (block i32 (set_global $Int (i32.const 10) ) @@ -908,7 +908,7 @@ (i32.const 20) ) (return - (block + (block i32 (set_global $Int (i32.const 30) ) @@ -918,7 +918,7 @@ ) (func $usesSetGlobal2 (result i32) (return - (block + (block i32 (block (set_global $Int (i32.const 40) diff --git a/test/unit.wast b/test/unit.wast index afa376035..fab6705d2 100644 --- a/test/unit.wast +++ b/test/unit.wast @@ -37,7 +37,7 @@ ) (func $importedDoubles (type $4) (result f64) (local $temp f64) - (block $topmost + (block $topmost f64 (set_local $temp (f64.add (f64.add @@ -91,7 +91,7 @@ (local $t f64) (local $Int f64) (local $Double i32) - (block $topmost + (block $topmost f64 (if (f64.gt (get_local $x) @@ -177,13 +177,13 @@ (local $J f64) (set_local $J (f64.sub - (block $block0 + (block $block0 f64 (drop (f64.const 0.1) ) (f64.const 5.1) ) - (block $block1 + (block $block1 f64 (drop (f64.const 3.2) ) @@ -193,7 +193,7 @@ ) ) (func $switcher (type $6) (param $x i32) (result i32) - (block $topmost + (block $topmost i32 (block $switch$0 (block $switch-default$3 (block $switch-case$2 @@ -291,7 +291,7 @@ ) (func $big_uint_div_u (type $5) (result i32) (local $x i32) - (block $topmost + (block $topmost i32 (set_local $x (i32.and (i32.div_u @@ -340,7 +340,7 @@ (local $asm2wasm_i32_temp i32) (block $block0 (set_local $x - (block $block1 + (block $block1 i32 (set_local $asm2wasm_i32_temp (i32.const 0) ) diff --git a/test/unit.wast.fromBinary b/test/unit.wast.fromBinary index 8423c4740..1080d5d20 100644 --- a/test/unit.wast.fromBinary +++ b/test/unit.wast.fromBinary @@ -37,7 +37,7 @@ ) (func $importedDoubles (type $4) (result f64) (local $var$0 f64) - (block $label$0 + (block $label$0 f64 (set_local $var$0 (f64.add (f64.add @@ -95,7 +95,7 @@ (local $var$2 i32) (local $var$3 f64) (local $var$4 f64) - (block $label$0 + (block $label$0 f64 (if (f64.gt (get_local $var$0) @@ -189,13 +189,13 @@ (local $var$0 f64) (set_local $var$0 (f64.sub - (block $label$0 + (block $label$0 f64 (drop (f64.const 0.1) ) (f64.const 5.1) ) - (block $label$1 + (block $label$1 f64 (drop (f64.const 3.2) ) @@ -205,7 +205,7 @@ ) ) (func $switcher (type $6) (param $var$0 i32) (result i32) - (block $label$0 + (block $label$0 i32 (block $label$1 (block $label$2 (block $label$3 @@ -299,7 +299,7 @@ ) (func $big_uint_div_u (type $5) (result i32) (local $var$0 i32) - (block $label$0 + (block $label$0 i32 (set_local $var$0 (i32.and (i32.div_u @@ -348,7 +348,7 @@ (local $var$3 f64) (block $label$0 (set_local $var$0 - (block $label$1 + (block $label$1 i32 (set_local $var$1 (i32.const 0) ) @@ -428,7 +428,7 @@ (nop) ) (func $block_and_after (type $5) (result i32) - (block $label$0 + (block $label$0 i32 (block $label$1 (drop (i32.const 1) -- cgit v1.2.3 From 0a9df805f688d5eab8be380ab7c9dde115d88852 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 16 Sep 2016 17:55:58 -0700 Subject: br_if returns its value --- src/passes/RemoveUnusedBrs.cpp | 7 ++-- src/wasm-builder.h | 6 +++ src/wasm-interpreter.h | 7 ++-- src/wasm.h | 6 ++- test/emcc_O2_hello_world.fromasm | 12 +++--- test/emcc_O2_hello_world.fromasm.imprecise | 12 +++--- test/emcc_hello_world.fromasm | 64 +++++++++++++++++------------- test/emcc_hello_world.fromasm.imprecise | 64 +++++++++++++++++------------- test/example/c-api-kitchen-sink.txt | 16 +++++--- test/example/c-api-kitchen-sink.txt.txt | 8 ++-- test/memorygrowth.fromasm | 12 +++--- test/memorygrowth.fromasm.imprecise | 12 +++--- test/passes/remove-unused-brs.txt | 8 ++-- test/passes/remove-unused-brs.wast | 8 ++-- test/unit.fromasm | 10 +++-- test/unit.fromasm.imprecise | 10 +++-- 16 files changed, 157 insertions(+), 105 deletions(-) (limited to 'src') diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index fa8ab2f6c..15482de25 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -146,11 +146,10 @@ struct RemoveUnusedBrs : public WalkerPass br_if (condition) Break* br = curr->ifTrue->dynCast(); if (br && !br->condition) { // TODO: if there is a condition, join them - // if the br has a value, then if => br_if means we always execute the value, and also the order is value,condition vs condition,value if (canTurnIfIntoBrIf(curr->condition, br->value)) { br->condition = curr->condition; br->finalize(); - replaceCurrent(br); + replaceCurrent(Builder(*getModule()).dropIfConcretelyTyped(br)); anotherCycle = true; } } @@ -407,18 +406,18 @@ struct RemoveUnusedBrs : public WalkerPassifTrue->dynCast(); if (ifTrueBreak && !ifTrueBreak->condition && canTurnIfIntoBrIf(iff->condition, ifTrueBreak->value)) { // we are an if-else where the ifTrue is a break without a condition, so we can do this - list[i] = ifTrueBreak; ifTrueBreak->condition = iff->condition; ifTrueBreak->finalize(); + list[i] = Builder(*getModule()).dropIfConcretelyTyped(ifTrueBreak); ExpressionManipulator::spliceIntoBlock(curr, i + 1, iff->ifFalse); continue; } // otherwise, perhaps we can flip the if auto* ifFalseBreak = iff->ifFalse->dynCast(); if (ifFalseBreak && !ifFalseBreak->condition && canTurnIfIntoBrIf(iff->condition, ifFalseBreak->value)) { - list[i] = ifFalseBreak; ifFalseBreak->condition = Builder(*getModule()).makeUnary(EqZInt32, iff->condition); ifFalseBreak->finalize(); + list[i] = Builder(*getModule()).dropIfConcretelyTyped(ifFalseBreak); ExpressionManipulator::spliceIntoBlock(curr, i + 1, iff->ifTrue); continue; } diff --git a/src/wasm-builder.h b/src/wasm-builder.h index f9b2e73f6..546d72391 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -339,6 +339,12 @@ public: input->finalize(); return ret; } + + // Drop an expression if it has a concrete type + Expression* dropIfConcretelyTyped(Expression* curr) { + if (!isConcreteWasmType(curr->type)) return curr; + return makeDrop(curr); + } }; } // namespace wasm diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 292d6a521..5d4e7d7b4 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -155,18 +155,19 @@ public: Flow visitBreak(Break *curr) { NOTE_ENTER("Break"); bool condition = true; - Flow flow(curr->name); + Flow flow; if (curr->value) { flow = visit(curr->value); if (flow.breaking()) return flow; - flow.breakTo = curr->name; } if (curr->condition) { Flow conditionFlow = visit(curr->condition); if (conditionFlow.breaking()) return conditionFlow; condition = conditionFlow.value.getInteger() != 0; + if (!condition) return flow; } - return condition ? flow : Flow(); + flow.breakTo = curr->name; + return flow; } Flow visitSwitch(Switch *curr) { NOTE_ENTER("Switch"); diff --git a/src/wasm.h b/src/wasm.h index 4d5cf4d70..1bce0bac9 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1027,7 +1027,11 @@ public: void finalize() { if (condition) { - type = none; + if (value) { + type = value->type; + } else { + type = none; + } } else { type = unreachable; } diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm index b8e25baa5..072d9f97f 100644 --- a/test/emcc_O2_hello_world.fromasm +++ b/test/emcc_O2_hello_world.fromasm @@ -4674,11 +4674,13 @@ ) ) (block i32 - (br_if $do-once$67 - (i32.const 31) - (i32.gt_u - (get_local $15) - (i32.const 16777215) + (drop + (br_if $do-once$67 + (i32.const 31) + (i32.gt_u + (get_local $15) + (i32.const 16777215) + ) ) ) (i32.or diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise index f2b2c401c..233a485b8 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise +++ b/test/emcc_O2_hello_world.fromasm.imprecise @@ -4672,11 +4672,13 @@ ) ) (block i32 - (br_if $do-once$67 - (i32.const 31) - (i32.gt_u - (get_local $15) - (i32.const 16777215) + (drop + (br_if $do-once$67 + (i32.const 31) + (i32.gt_u + (get_local $15) + (i32.const 16777215) + ) ) ) (i32.or diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index 24f6d4f75..a12c7fe56 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -4607,15 +4607,17 @@ (i32.const 1) ) (block i32 - (br_if $do-once$64 - (get_local $6) - (i32.and - (get_local $16) + (drop + (br_if $do-once$64 + (get_local $6) (i32.and - (get_local $12) - (f64.eq - (get_local $14) - (f64.const 0) + (get_local $16) + (i32.and + (get_local $12) + (f64.eq + (get_local $14) + (f64.const 0) + ) ) ) ) @@ -4965,10 +4967,12 @@ ) ) ) - (br_if $do-once$70 - (get_local $9) - (i32.eqz - (get_local $5) + (drop + (br_if $do-once$70 + (get_local $9) + (i32.eqz + (get_local $5) + ) ) ) (i32.store @@ -5175,10 +5179,12 @@ ) ) ) - (br_if $do-once$78 - (get_local $5) - (i32.eqz - (get_local $9) + (drop + (br_if $do-once$78 + (get_local $5) + (i32.eqz + (get_local $9) + ) ) ) (i32.store @@ -5513,13 +5519,15 @@ (if (get_local $30) (block f64 - (br_if $do-once$90 - (get_local $22) - (i32.ne - (i32.load8_s - (get_local $36) + (drop + (br_if $do-once$90 + (get_local $22) + (i32.ne + (i32.load8_s + (get_local $36) + ) + (i32.const 45) ) - (i32.const 45) ) ) (set_local $14 @@ -12607,11 +12615,13 @@ ) ) (block i32 - (br_if $do-once$69 - (i32.const 31) - (i32.gt_u - (get_local $2) - (i32.const 16777215) + (drop + (br_if $do-once$69 + (i32.const 31) + (i32.gt_u + (get_local $2) + (i32.const 16777215) + ) ) ) (i32.or diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise index c6123841a..75534025e 100644 --- a/test/emcc_hello_world.fromasm.imprecise +++ b/test/emcc_hello_world.fromasm.imprecise @@ -4600,15 +4600,17 @@ (i32.const 1) ) (block i32 - (br_if $do-once$64 - (get_local $6) - (i32.and - (get_local $16) + (drop + (br_if $do-once$64 + (get_local $6) (i32.and - (get_local $12) - (f64.eq - (get_local $14) - (f64.const 0) + (get_local $16) + (i32.and + (get_local $12) + (f64.eq + (get_local $14) + (f64.const 0) + ) ) ) ) @@ -4958,10 +4960,12 @@ ) ) ) - (br_if $do-once$70 - (get_local $9) - (i32.eqz - (get_local $5) + (drop + (br_if $do-once$70 + (get_local $9) + (i32.eqz + (get_local $5) + ) ) ) (i32.store @@ -5168,10 +5172,12 @@ ) ) ) - (br_if $do-once$78 - (get_local $5) - (i32.eqz - (get_local $9) + (drop + (br_if $do-once$78 + (get_local $5) + (i32.eqz + (get_local $9) + ) ) ) (i32.store @@ -5506,13 +5512,15 @@ (if (get_local $30) (block f64 - (br_if $do-once$90 - (get_local $22) - (i32.ne - (i32.load8_s - (get_local $36) + (drop + (br_if $do-once$90 + (get_local $22) + (i32.ne + (i32.load8_s + (get_local $36) + ) + (i32.const 45) ) - (i32.const 45) ) ) (set_local $14 @@ -12600,11 +12608,13 @@ ) ) (block i32 - (br_if $do-once$69 - (i32.const 31) - (i32.gt_u - (get_local $2) - (i32.const 16777215) + (drop + (br_if $do-once$69 + (i32.const 31) + (i32.gt_u + (get_local $2) + (i32.const 16777215) + ) ) ) (i32.or diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 41d64089e..28d7b759b 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -422,9 +422,11 @@ BinaryenFloat64: 4 (i32.const 0) ) ) - (br_if $the-value - (i32.const 1) - (i32.const 0) + (drop + (br_if $the-value + (i32.const 1) + (i32.const 0) + ) ) (br_if $the-nothing (i32.const 2) @@ -2013,9 +2015,11 @@ int main() { (i32.const 0) ) ) - (br_if $the-value - (i32.const 1) - (i32.const 0) + (drop + (br_if $the-value + (i32.const 1) + (i32.const 0) + ) ) (br_if $the-nothing (i32.const 2) diff --git a/test/example/c-api-kitchen-sink.txt.txt b/test/example/c-api-kitchen-sink.txt.txt index 10a698717..f66b714eb 100644 --- a/test/example/c-api-kitchen-sink.txt.txt +++ b/test/example/c-api-kitchen-sink.txt.txt @@ -417,9 +417,11 @@ (i32.const 0) ) ) - (br_if $the-value - (i32.const 1) - (i32.const 0) + (drop + (br_if $the-value + (i32.const 1) + (i32.const 0) + ) ) (br_if $the-nothing (i32.const 2) diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm index a07d71fd4..7efde4442 100644 --- a/test/memorygrowth.fromasm +++ b/test/memorygrowth.fromasm @@ -4730,11 +4730,13 @@ ) ) (block i32 - (br_if $do-once$67 - (i32.const 31) - (i32.gt_u - (get_local $14) - (i32.const 16777215) + (drop + (br_if $do-once$67 + (i32.const 31) + (i32.gt_u + (get_local $14) + (i32.const 16777215) + ) ) ) (i32.or diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise index ea085352f..1a93b6e60 100644 --- a/test/memorygrowth.fromasm.imprecise +++ b/test/memorygrowth.fromasm.imprecise @@ -4728,11 +4728,13 @@ ) ) (block i32 - (br_if $do-once$67 - (i32.const 31) - (i32.gt_u - (get_local $14) - (i32.const 16777215) + (drop + (br_if $do-once$67 + (i32.const 31) + (i32.gt_u + (get_local $14) + (i32.const 16777215) + ) ) ) (i32.or diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt index 3c51c8f99..da19d7ac8 100644 --- a/test/passes/remove-unused-brs.txt +++ b/test/passes/remove-unused-brs.txt @@ -152,9 +152,11 @@ (drop (i32.const 12) ) - (br_if $topmost - (i32.const 1) - (i32.const 1) + (drop + (br_if $topmost + (i32.const 1) + (i32.const 1) + ) ) ) (block $block3 diff --git a/test/passes/remove-unused-brs.wast b/test/passes/remove-unused-brs.wast index 995ab2d3a..50d936dc7 100644 --- a/test/passes/remove-unused-brs.wast +++ b/test/passes/remove-unused-brs.wast @@ -158,9 +158,11 @@ (drop (i32.const 12) ) - (br_if $topmost - (i32.const 1) - (i32.const 1) + (drop + (br_if $topmost + (i32.const 1) + (i32.const 1) + ) ) ) (block $block3 diff --git a/test/unit.fromasm b/test/unit.fromasm index ea0ff0843..fe8b616f4 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -493,10 +493,12 @@ ) (func $phi (result i32) (block $do-once$0 i32 - (br_if $do-once$0 - (i32.const 0) - (call $lb - (i32.const 1) + (drop + (br_if $do-once$0 + (i32.const 0) + (call $lb + (i32.const 1) + ) ) ) (i32.const 1) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index 5ea81aad3..8752f179a 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -474,10 +474,12 @@ ) (func $phi (result i32) (block $do-once$0 i32 - (br_if $do-once$0 - (i32.const 0) - (call $lb - (i32.const 1) + (drop + (br_if $do-once$0 + (i32.const 0) + (call $lb + (i32.const 1) + ) ) ) (i32.const 1) -- cgit v1.2.3 From 4ebe1f0c41c3d9311853b79f2cbeb4ec5b4b886c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 16 Sep 2016 19:05:48 -0700 Subject: use export name as internal name if no internal name, for better s-expr debugging --- src/wasm-s-parser.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index a39eb59dc..75d6fed1d 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -441,6 +441,9 @@ private: i++; } } + if (exportName.is() && !name.is()) { + name = exportName; // useful for debugging + } return i; } -- cgit v1.2.3 From d46a737d421d53f68fc13d55fe405cf8c3c5d4c0 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 16 Sep 2016 20:30:09 -0700 Subject: parse empty modules without error --- src/wasm-s-parser.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 75d6fed1d..f244a08f9 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -274,6 +274,7 @@ public: // Assumes control of and modifies the input. SExpressionWasmBuilder(Module& wasm, Element& module, Name* moduleName = nullptr) : wasm(wasm), allocator(wasm.allocator), importCounter(0), globalCounter(0) { assert(module[0]->str() == MODULE); + if (module.size() == 1) return; Index i = 1; if (module[i]->dollared()) { if (moduleName) { -- cgit v1.2.3 From 0201f77b30f875de0d0fc8e407ffc985d47f8535 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 16 Sep 2016 21:08:58 -0700 Subject: support module operations in shell tests --- src/shared-constants.h | 1 - src/tools/wasm-shell.cpp | 83 ++++++++++++++++++++++++++++++++---------------- src/wasm-interpreter.h | 11 +++++++ src/wasm-s-parser.h | 4 +-- src/wasm.cpp | 1 - 5 files changed, 68 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/shared-constants.h b/src/shared-constants.h index e37879088..2d656f0eb 100644 --- a/src/shared-constants.h +++ b/src/shared-constants.h @@ -49,7 +49,6 @@ extern Name GROW_WASM_MEMORY, FAKE_RETURN, SPECTEST, PRINT, - INVOKE, EXIT; } // namespace wasm diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp index ddb2f8a85..e0bc5d7e9 100644 --- a/src/tools/wasm-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -37,28 +37,51 @@ using namespace wasm; Name ASSERT_RETURN("assert_return"), ASSERT_TRAP("assert_trap"), ASSERT_INVALID("assert_invalid"), - ASSERT_MALFORMED("assert_malformed"); + ASSERT_MALFORMED("assert_malformed"), + INVOKE("invoke"), + GET("get"); + +// Modules named in the file + +std::map> modules; +std::map> builders; +std::map> interfaces; +std::map> instances; // -// An invocation into a module +// An operation on a module // -struct Invocation { +struct Operation { ModuleInstance* instance; - IString name; + Name operation; + Name name; LiteralList arguments; - Invocation(Element& invoke, ModuleInstance* instance, SExpressionWasmBuilder& builder) : instance(instance) { - assert(invoke[0]->str() == INVOKE); - name = invoke[1]->str(); - for (size_t j = 2; j < invoke.size(); j++) { - Expression* argument = builder.parseExpression(*invoke[j]); + Operation(Element& element, ModuleInstance* instanceInit, SExpressionWasmBuilder& builder) : instance(instanceInit) { + operation = element[0]->str(); + Index i = 1; + if (element.size() >= 3 && element[2]->isStr()) { + // module also specified + Name moduleName = element[i++]->str(); + instance = instances[moduleName].get(); + } + name = element[i++]->str(); + for (size_t j = i; j < element.size(); j++) { + Expression* argument = builder.parseExpression(*element[j]); arguments.push_back(argument->dynCast()->value); } } - Literal invoke() { - return instance->callExport(name, arguments); + Literal operate() { + if (operation == INVOKE) { + return instance->callExport(name, arguments); + } else if (operation == GET) { + return instance->getExport(name); + } else { + Fatal() << "unknown operation: " << operation << '\n'; + WASM_UNREACHABLE(); + } } }; @@ -75,15 +98,17 @@ static void verify_result(Literal a, Literal b) { } } -static void run_asserts(size_t* i, bool* checked, Module* wasm, +static void run_asserts(Name moduleName, size_t* i, bool* checked, Module* wasm, Element* root, - std::unique_ptr* builder, + SExpressionWasmBuilder* builder, Name entry) { - std::unique_ptr interface; - std::unique_ptr instance; + ModuleInstance* instance = nullptr; if (wasm) { - interface = wasm::make_unique(); // prefix make_unique to work around visual studio bugs - instance = wasm::make_unique(*wasm, interface.get()); + auto tempInterface = wasm::make_unique(); // prefix make_unique to work around visual studio bugs + auto tempInstance = wasm::make_unique(*wasm, tempInterface.get()); + interfaces[moduleName].swap(tempInterface); + instances[moduleName].swap(tempInstance); + instance = instances[moduleName].get(); if (entry.is()) { Function* function = wasm->getFunction(entry); if (!function) { @@ -139,23 +164,23 @@ static void run_asserts(size_t* i, bool* checked, Module* wasm, } } else if (id == INVOKE) { assert(wasm); - Invocation invocation(curr, instance.get(), *builder->get()); - invocation.invoke(); + Operation operation(curr, instance, *builder); + operation.operate(); } else if (wasm) { // if no wasm, we skipped the module // an invoke test bool trapped = false; WASM_UNUSED(trapped); Literal result; try { - Invocation invocation(*curr[1], instance.get(), *builder->get()); - result = invocation.invoke(); + Operation operation(*curr[1], instance, *builder); + result = operation.operate(); } catch (const TrapException&) { trapped = true; } if (id == ASSERT_RETURN) { assert(!trapped); if (curr.size() >= 3) { - Literal expected = builder->get() + Literal expected = builder ->parseExpression(*curr[2]) ->dynCast() ->value; @@ -234,14 +259,16 @@ int main(int argc, const char* argv[]) { Colors::green(std::cerr); std::cerr << "BUILDING MODULE [line: " << curr.line << "]\n"; Colors::normal(std::cerr); - Module wasm; - std::unique_ptr builder; - builder = wasm::make_unique(wasm, *root[i]); + auto module = wasm::make_unique(); + Name moduleName; + auto builder = wasm::make_unique(*module, *root[i], &moduleName); + builders[moduleName].swap(builder); + modules[moduleName].swap(module); i++; - assert(WasmValidator().validate(wasm)); - run_asserts(&i, &checked, &wasm, &root, &builder, entry); + assert(WasmValidator().validate(*modules[moduleName])); + run_asserts(moduleName, &i, &checked, modules[moduleName].get(), &root, builders[moduleName].get(), entry); } else { - run_asserts(&i, &checked, nullptr, &root, nullptr, entry); + run_asserts(Name(), &i, &checked, nullptr, &root, nullptr, entry); } } } catch (ParseException& p) { diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 5d4e7d7b4..f699ba6f8 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -554,12 +554,23 @@ public: } } + // call an exported function Literal callExport(Name name, LiteralList& arguments) { Export *export_ = wasm.checkExport(name); if (!export_) externalInterface->trap("callExport not found"); return callFunction(export_->value, arguments); } + // get an exported global + Literal getExport(Name name) { + Export *export_ = wasm.checkExport(name); + if (!export_) externalInterface->trap("getExport external not found"); + Name internalName = export_->value; + auto iter = globals.find(internalName); + if (iter == globals.end()) externalInterface->trap("getExport internal not found"); + return iter->second; + } + std::string printFunctionStack() { std::string ret = "/== (binaryen interpreter stack trace)\n"; for (int i = int(functionStack.size()) - 1; i >= 0; i--) { diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index f244a08f9..0f11bd521 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1473,7 +1473,7 @@ private: ex->kind = Export::Table; } else if (inner[0]->str() == GLOBAL) { ex->value = inner[1]->str(); - ex->kind = Export::Table; + ex->kind = Export::Global; } else { WASM_UNREACHABLE(); } @@ -1487,7 +1487,7 @@ private: ex->kind = Export::Table; } else if (s[2]->str() == GLOBAL) { ex->value = s[3]->str(); - ex->kind = Export::Table; + ex->kind = Export::Global; } else { WASM_UNREACHABLE(); } diff --git a/src/wasm.cpp b/src/wasm.cpp index 144cabd16..8badaa6be 100644 --- a/src/wasm.cpp +++ b/src/wasm.cpp @@ -74,7 +74,6 @@ Name GROW_WASM_MEMORY("__growWasmMemory"), FAKE_RETURN("fake_return_waka123"), SPECTEST("spectest"), PRINT("print"), - INVOKE("invoke"), EXIT("exit"); // core AST type checking -- cgit v1.2.3 From 456e3e8625064370281629c71d9c29d8f7d09d06 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sat, 17 Sep 2016 15:31:27 -0700 Subject: parsing and validation fixes --- src/wasm-s-parser.h | 30 ++++++++++++++--------- src/wasm-validator.h | 10 +++++++- test/passes/dce.wast | 3 ++- test/passes/duplicate-function-elimination.wast | 12 ++++++--- test/passes/remove-unused-functions.wast | 3 ++- test/passes/remove-unused-names_merge-blocks.wast | 3 ++- 6 files changed, 42 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 0f11bd521..abe0c4700 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -212,6 +212,10 @@ private: if (depth == 0) { break; } + } else if (input[0] == '\n') { + line++; + lineStart = input; + input++; } else { input++; } @@ -442,9 +446,11 @@ private: i++; } } +#if 0 if (exportName.is() && !name.is()) { name = exportName; // useful for debugging } +#endif return i; } @@ -461,6 +467,7 @@ private: ex->name = exportName; ex->value = name; ex->kind = Export::Function; + if (wasm.checkExport(ex->name)) throw ParseException("duplicate export", s.line, s.col); wasm.addExport(ex.release()); } functionCounter++; @@ -1394,6 +1401,7 @@ private: ex->name = inner[1]->str(); ex->value = wasm.memory.name; ex->kind = Export::Memory; + if (wasm.checkExport(ex->name)) throw ParseException("duplicate export", s.line, s.col); wasm.addExport(ex.release()); i++; } else { @@ -1461,32 +1469,27 @@ private: ex->name = s[1]->str(); if (s[2]->isList()) { auto& inner = *s[2]; + ex->value = inner[1]->str(); if (inner[0]->str() == FUNC) { - ex->value = inner[1]->str(); ex->kind = Export::Function; } else if (inner[0]->str() == MEMORY) { if (!hasMemory) throw ParseException("memory exported but no memory"); - ex->value = Name::fromInt(0); ex->kind = Export::Memory; } else if (inner[0]->str() == TABLE) { - ex->value = Name::fromInt(0); ex->kind = Export::Table; } else if (inner[0]->str() == GLOBAL) { - ex->value = inner[1]->str(); ex->kind = Export::Global; } else { WASM_UNREACHABLE(); } } else if (!s[2]->dollared() && !std::isdigit(s[2]->str()[0])) { + ex->value = s[3]->str(); if (s[2]->str() == MEMORY) { if (!hasMemory) throw ParseException("memory exported but no memory"); - ex->value = Name::fromInt(0); ex->kind = Export::Memory; } else if (s[2]->str() == TABLE) { - ex->value = Name::fromInt(0); ex->kind = Export::Table; } else if (s[2]->str() == GLOBAL) { - ex->value = s[3]->str(); ex->kind = Export::Global; } else { WASM_UNREACHABLE(); @@ -1496,6 +1499,7 @@ private: ex->value = s[2]->str(); ex->kind = Export::Function; } + if (wasm.checkExport(ex->name)) throw ParseException("duplicate export", s.line, s.col); wasm.addExport(ex.release()); } @@ -1591,6 +1595,7 @@ private: ex->name = inner[1]->str(); ex->value = global->name; ex->kind = Export::Global; + if (wasm.checkExport(ex->name)) throw ParseException("duplicate export", s.line, s.col); wasm.addExport(ex.release()); i++; } else { @@ -1609,11 +1614,9 @@ private: seenTable = true; Index i = 1; if (i == s.size()) return; // empty table in old notation -#if 0 // TODO: new table notation if (s[i]->dollared()) { wasm.table.name = s[i++]->str(); } -#endif if (i == s.size()) return; if (s[i]->isList()) { auto& inner = *s[i]; @@ -1622,6 +1625,7 @@ private: ex->name = inner[1]->str(); ex->value = wasm.table.name; ex->kind = Export::Table; + if (wasm.checkExport(ex->name)) throw ParseException("duplicate export", s.line, s.col); wasm.addExport(ex.release()); i++; } else { @@ -1639,8 +1643,12 @@ private: // first element isn't dollared, and isn't anyfunc. this could be old syntax for (table 0 1) which means function 0 and 1, or it could be (table initial max? type), look for type if (s[s.size() - 1]->str() == ANYFUNC) { // (table initial max? type) - wasm.table.initial = atoi(s[i]->c_str()); - wasm.table.max = atoi(s[i + 1]->c_str()); + if (i < s.size() - 1) { + wasm.table.initial = atoi(s[i++]->c_str()); + } + if (i < s.size() - 1) { + wasm.table.max = atoi(s[i++]->c_str()); + } return; } } diff --git a/src/wasm-validator.h b/src/wasm-validator.h index e23221337..1d3b5c41b 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -394,7 +394,15 @@ public: break; } } - shouldBeTrue(found, name, "module exports must be found"); + shouldBeTrue(found, name, "module function exports must be found"); + } else if (exp->kind == Export::Global) { + shouldBeTrue(curr->checkGlobal(name), name, "module global exports must be found"); + } else if (exp->kind == Export::Table) { + shouldBeTrue(name == Name("0") || name == curr->table.name, name, "module table exports must be found"); + } else if (exp->kind == Export::Memory) { + shouldBeTrue(name == Name("0") || name == curr->memory.name, name, "module memory exports must be found"); + } else { + WASM_UNREACHABLE(); } Name exportName = exp->name; shouldBeFalse(exportNames.count(exportName) > 0, exportName, "module exports must be unique"); diff --git a/test/passes/dce.wast b/test/passes/dce.wast index 61b3138e5..9795bda80 100644 --- a/test/passes/dce.wast +++ b/test/passes/dce.wast @@ -2,7 +2,8 @@ (memory 10) (type $ii (func (param i32 i32))) (type $1 (func)) - (table $call-me) + (table 1 1 anyfunc) + (elem (i32.const 0) $call-me) (func $call-me (type $ii) (param $0 i32) (param $1 i32) (nop) ) diff --git a/test/passes/duplicate-function-elimination.wast b/test/passes/duplicate-function-elimination.wast index 959737f40..fcd2378e1 100644 --- a/test/passes/duplicate-function-elimination.wast +++ b/test/passes/duplicate-function-elimination.wast @@ -54,7 +54,8 @@ (type $0 (func)) (export "keep2" $keep2) (export "other" $other) - (table $keep2 $other $caller) + (table 3 3 anyfunc) + (elem (i32.const 0) $keep2 $other $caller) (func $keep2 (type $0) (nop) ) @@ -460,7 +461,8 @@ (module (memory 0) (type $T (func)) - (table $erase $other) + (table 2 2 anyfunc) + (elem (i32.const 0) $erase $other) (func $erase (type $T) (call_indirect $T (i32.const 0) @@ -475,7 +477,8 @@ (module (memory 0) (type $T (func)) - (table $keep2 $other) + (table 2 2 anyfunc) + (elem (i32.const 0) $keep2 $other) (func $keep2 (type $T) (call_indirect $T (i32.const 0) @@ -491,7 +494,8 @@ (memory 0) (type $T (func)) (type $S (func)) - (table $keep2 $other) + (table 2 2 anyfunc) + (elem (i32.const 0) $keep2 $other) (func $keep2 (type $T) (call_indirect $T (i32.const 0) diff --git a/test/passes/remove-unused-functions.wast b/test/passes/remove-unused-functions.wast index 9449a25cb..19b72f2ac 100644 --- a/test/passes/remove-unused-functions.wast +++ b/test/passes/remove-unused-functions.wast @@ -3,7 +3,8 @@ (start $start) (type $0 (func)) (export "exported" $exported) - (table $called_indirect) + (table 1 1 anyfunc) + (elem (i32.const 0) $called_indirect) (func $start (type $0) (call $called0) ) diff --git a/test/passes/remove-unused-names_merge-blocks.wast b/test/passes/remove-unused-names_merge-blocks.wast index 562c5bbba..64bc8ab7f 100644 --- a/test/passes/remove-unused-names_merge-blocks.wast +++ b/test/passes/remove-unused-names_merge-blocks.wast @@ -4,7 +4,8 @@ (type $ii (func (param i32 i32))) (type $iii (func (param i32 i32 i32))) (type $3 (func)) - (table $call-i) + (table 1 1 anyfunc) + (elem (i32.const 0) $call-i) (func $call-i (type $i) (param $0 i32) (nop) ) -- cgit v1.2.3 From 5f6a5dea206fafd140534f8c494208eb96f7994a Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 19 Sep 2016 12:01:18 -0700 Subject: new-style import parsing --- src/wasm-s-parser.h | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index abe0c4700..5acae1e6b 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -372,12 +372,22 @@ private: } } + bool isImport(Element& curr) { + for (Index i = 0; i < curr.size(); i++) { + auto& x = *curr[i]; + if (x.isList() && x.size() > 0 && x[0]->isStr() && x[0]->str() == IMPORT) return true; + } + return false; + } + void preParseImports(Element& curr) { IString id = curr[0]->str(); if (id == IMPORT) parseImport(curr); + if (id == FUNC && isImport(curr)) parseFunction(curr, true /* preParseImport */); } void parseModuleElement(Element& curr) { + if (isImport(curr)) return; // already done IString id = curr[0]->str(); if (id == START) return parseStart(curr); if (id == FUNC) return parseFunction(curr); @@ -454,7 +464,7 @@ private: return i; } - void parseFunction(Element& s) { + void parseFunction(Element& s, bool preParseImport = false) { size_t i = 1; Name name, exportName; i = parseFunctionNames(s, name, exportName); @@ -481,6 +491,7 @@ private: WasmType result = none; Name type; Block* autoBlock = nullptr; // we may need to add a block for the very top level + Name importModule, importBase; auto makeFunction = [&]() { currFunction = std::unique_ptr(Builder(wasm).makeFunction( name, @@ -530,7 +541,7 @@ private: } else if (id == TYPE) { Name name = curr[1]->str(); type = name; - if (!wasm.checkFunctionType(name)) throw ParseException("unknown function"); + if (!wasm.checkFunctionType(name)) throw ParseException("unknown function type"); FunctionType* type = wasm.getFunctionType(name); result = type->result; for (size_t j = 0; j < type->params.size(); j++) { @@ -539,6 +550,9 @@ private: typeParams.emplace_back(name, currType); currLocalTypes[name] = currType; } + } else if (id == IMPORT) { + importModule = curr[1]->str(); + importBase = curr[2]->str(); } else { // body if (typeParams.size() > 0 && params.size() == 0) { @@ -554,6 +568,26 @@ private: } } } + if (importModule.is()) { + // this is an import, actually + assert(preParseImport); + std::unique_ptr im = make_unique(); + im->name = name; + if (!im->name.is()) { + im->name = Name::fromInt(importCounter); + } + importCounter++; + im->module = importModule; + im->base = importBase; + im->kind = Import::Function; + im->functionType = wasm.getFunctionType(type); + wasm.addImport(im.release()); + assert(!currFunction); + currLocalTypes.clear(); + labelStack.clear(); + return; + } + assert(!preParseImport); if (brokeToAutoBlock) { ensureAutoBlock(); autoBlock->name = FAKE_RETURN; @@ -1520,10 +1554,11 @@ private: newStyle = false; // either (param..) or (result..) } } + Index newStyleInner = 1; if (s.size() > 3 && s[3]->isStr()) { im->name = s[i++]->str(); - } else if (newStyle) { - im->name = (*s[3])[1]->str(); + } else if (newStyle && (*s[3])[newStyleInner]->isStr()) { + im->name = (*s[3])[newStyleInner++]->str(); } else { im->name = Name::fromInt(importCounter); } @@ -1547,7 +1582,7 @@ private: im->base = s[i++]->str(); // parse internals Element& inner = newStyle ? *s[3] : s; - Index j = newStyle ? 2 : i; + Index j = newStyle ? newStyleInner : i; if (im->kind == Import::Function) { std::unique_ptr type = make_unique(); if (inner.size() > j) { -- cgit v1.2.3 From 38dc263c303be13bec2fcee713bdb18fa89057c8 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 19 Sep 2016 14:02:57 -0700 Subject: global parsing --- src/shared-constants.h | 1 + src/wasm-binary.h | 1 + src/wasm-s-parser.h | 38 +++++++++++++++++++++++++++++++++----- src/wasm.cpp | 1 + src/wasm.h | 1 + 5 files changed, 37 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/shared-constants.h b/src/shared-constants.h index 2d656f0eb..923ccc7de 100644 --- a/src/shared-constants.h +++ b/src/shared-constants.h @@ -47,6 +47,7 @@ extern Name GROW_WASM_MEMORY, BR, ANYFUNC, FAKE_RETURN, + MUT, SPECTEST, PRINT, EXIT; diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 9b8451b98..147746c82 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1653,6 +1653,7 @@ public: auto curr = new Global; curr->type = getWasmType(); curr->init = readExpression(); + curr->mutable_ = true; // TODO wasm.addGlobal(curr); } } diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 5acae1e6b..b4fcd3466 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -383,7 +383,10 @@ private: void preParseImports(Element& curr) { IString id = curr[0]->str(); if (id == IMPORT) parseImport(curr); - if (id == FUNC && isImport(curr)) parseFunction(curr, true /* preParseImport */); + if (isImport(curr)) { + if (id == FUNC) parseFunction(curr, true /* preParseImport */); + else throw ParseException("fancy import we don't support yet", curr.line, curr.col); + } } void parseModuleElement(Element& curr) { @@ -1022,6 +1025,7 @@ private: Expression* makeSetGlobal(Element& s) { auto ret = allocator.alloc(); ret->name = s[1]->str(); + if (wasm.checkGlobal(ret->name) && !wasm.checkGlobal(ret->name)->mutable_) throw ParseException("set_global of immutable", s.line, s.col); ret->value = parseExpression(s[2]); return ret; } @@ -1513,6 +1517,8 @@ private: ex->kind = Export::Table; } else if (inner[0]->str() == GLOBAL) { ex->kind = Export::Global; + auto* global = wasm.getGlobal(ex->value); + if (global->mutable_) throw ParseException("cannot export a mutable global", s.line, s.col); } else { WASM_UNREACHABLE(); } @@ -1609,7 +1615,14 @@ private: } im->functionType = ensureFunctionType(getSig(type.get()), &wasm); } else if (im->kind == Import::Global) { - im->globalType = stringToWasmType(inner[j]->str()); + if (inner[j]->isStr()) { + im->globalType = stringToWasmType(inner[j]->str()); + } else { + auto& inner2 = *inner[j]; + assert(inner2[0]->str() == MUT); + im->globalType = stringToWasmType(inner2[1]->str()); + throw ParseException("cannot import a mutable global", s.line, s.col); + } } wasm.addImport(im.release()); } @@ -1623,7 +1636,10 @@ private: global->name = Name::fromInt(globalCounter); } globalCounter++; - if (s[i]->isList()) { + bool mutable_ = false; + WasmType type = none; + bool exported = false; + while (s[i]->isList()) { auto& inner = *s[i]; if (inner[0]->str() == EXPORT) { auto ex = make_unique(); @@ -1632,13 +1648,25 @@ private: ex->kind = Export::Global; if (wasm.checkExport(ex->name)) throw ParseException("duplicate export", s.line, s.col); wasm.addExport(ex.release()); + exported = true; + i++; + } else if (inner[0]->str() == IMPORT) { + throw ParseException("TODO: import in the middle of a global definition", s.line, s.col); + } else if (inner[0]->str() == MUT) { + mutable_ = true; + type = stringToWasmType(inner[1]->str()); i++; } else { - WASM_UNREACHABLE(); + break; } } - global->type = stringToWasmType(s[i++]->str()); + if (exported && mutable_) throw ParseException("cannot export a mutable global", s.line, s.col); + if (type == none) { + type = stringToWasmType(s[i++]->str()); + } + global->type = type; global->init = parseExpression(s[i++]); + global->mutable_ = mutable_; assert(i == s.size()); wasm.addGlobal(global.release()); } diff --git a/src/wasm.cpp b/src/wasm.cpp index 8badaa6be..a910575f0 100644 --- a/src/wasm.cpp +++ b/src/wasm.cpp @@ -72,6 +72,7 @@ Name GROW_WASM_MEMORY("__growWasmMemory"), BR("br"), ANYFUNC("anyfunc"), FAKE_RETURN("fake_return_waka123"), + MUT("mut"), SPECTEST("spectest"), PRINT("print"), EXIT("exit"); diff --git a/src/wasm.h b/src/wasm.h index 1bce0bac9..5c20a3a10 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1523,6 +1523,7 @@ public: Name name; WasmType type; Expression* init; + bool mutable_; }; class Module { -- cgit v1.2.3 From ba0a6541885d324b9562a79a8977ed8733191b7f Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 19 Sep 2016 17:18:59 -0700 Subject: globals mutability fixes --- src/asm2wasm.h | 12 ++++ src/passes/Print.cpp | 6 +- src/wasm-binary.h | 9 ++- src/wasm-s-parser.h | 3 +- src/wasm-validator.h | 2 +- test/emcc_O2_hello_world.fromasm | 66 +++++++++++---------- test/emcc_O2_hello_world.fromasm.imprecise | 66 +++++++++++---------- test/emcc_O2_hello_world.fromasm.imprecise.no-opts | 66 +++++++++++---------- test/emcc_O2_hello_world.fromasm.no-opts | 66 +++++++++++---------- test/emcc_hello_world.fromasm | 69 ++++++++++++---------- test/emcc_hello_world.fromasm.imprecise | 69 ++++++++++++---------- test/emcc_hello_world.fromasm.imprecise.no-opts | 69 ++++++++++++---------- test/emcc_hello_world.fromasm.no-opts | 69 ++++++++++++---------- test/memorygrowth.fromasm | 66 +++++++++++---------- test/memorygrowth.fromasm.imprecise | 66 +++++++++++---------- test/memorygrowth.fromasm.imprecise.no-opts | 66 +++++++++++---------- test/memorygrowth.fromasm.no-opts | 66 +++++++++++---------- test/min.fromasm | 5 +- test/min.fromasm.imprecise | 5 +- test/min.fromasm.imprecise.no-opts | 5 +- test/min.fromasm.no-opts | 5 +- test/unit.fromasm | 19 +++--- test/unit.fromasm.imprecise | 19 +++--- test/unit.fromasm.imprecise.no-opts | 19 +++--- test/unit.fromasm.no-opts | 19 +++--- 25 files changed, 526 insertions(+), 406 deletions(-) (limited to 'src') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index bce67a582..1c528d7f3 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -177,6 +177,7 @@ private: else if (type == f64) value = Literal(double(0)); else WASM_UNREACHABLE(); global->init = wasm.allocator.alloc()->set(value); + global->mutable_ = true; wasm.addGlobal(global); } @@ -502,9 +503,20 @@ void Asm2WasmBuilder::processAsm(Ref ast) { type = WasmType::f64; } if (type != WasmType::none) { + // we need imported globals to be mutable, but wasm doesn't support that yet, so we must + // import an immutable and create a mutable global initialized to its value + import->name = Name(std::string(import->name.str) + "$asm2wasm$import"); import->kind = Import::Global; import->globalType = type; mappedGlobals.emplace(name, type); + { + auto global = new Global(); + global->name = name; + global->type = type; + global->init = builder.makeGetGlobal(import->name, type); + global->mutable_ = true; + wasm.addGlobal(global); + } } else { import->kind = Import::Function; } diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 4cb363e66..06a8758c5 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -563,7 +563,11 @@ struct PrintSExpression : public Visitor { void visitGlobal(Global *curr) { printOpening(o, "global "); printName(curr->name) << ' '; - o << printWasmType(curr->type) << ' '; + if (curr->mutable_) { + o << "(mut " << printWasmType(curr->type) << ") "; + } else { + o << printWasmType(curr->type) << ' '; + } visit(curr->init); o << ')'; } diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 147746c82..1bc18e687 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1293,8 +1293,13 @@ public: else if (match(BinaryConsts::Section::FunctionSignatures)) readFunctionSignatures(); else if (match(BinaryConsts::Section::Functions)) readFunctions(); else if (match(BinaryConsts::Section::ExportTable)) readExports(); - else if (match(BinaryConsts::Section::Globals)) readGlobals(); - else if (match(BinaryConsts::Section::DataSegments)) readDataSegments(); + else if (match(BinaryConsts::Section::Globals)) { + readGlobals(); + // imports can read global imports, so we run getGlobalName and create the mapping + // but after we read globals, we need to add the internal globals too, so do that here + mappedGlobals.clear(); // wipe the mapping + getGlobalName(0); // force rebuild + } else if (match(BinaryConsts::Section::DataSegments)) readDataSegments(); else if (match(BinaryConsts::Section::FunctionTable)) readFunctionTable(); else if (match(BinaryConsts::Section::Names)) readNames(); else { diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index b4fcd3466..6280de7d3 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1517,8 +1517,7 @@ private: ex->kind = Export::Table; } else if (inner[0]->str() == GLOBAL) { ex->kind = Export::Global; - auto* global = wasm.getGlobal(ex->value); - if (global->mutable_) throw ParseException("cannot export a mutable global", s.line, s.col); + if (wasm.checkGlobal(ex->value) && wasm.getGlobal(ex->value)->mutable_) throw ParseException("cannot export a mutable global", s.line, s.col); } else { WASM_UNREACHABLE(); } diff --git a/src/wasm-validator.h b/src/wasm-validator.h index 1d3b5c41b..6c6792228 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -335,7 +335,7 @@ public: } void visitGlobal(Global* curr) { - shouldBeTrue(curr->init->is(), curr->name, "global init must be valid"); + shouldBeTrue(curr->init->is() || curr->init->is(), curr->name, "global init must be valid"); shouldBeEqual(curr->type, curr->init->type, nullptr, "global init must have correct type"); } diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm index 072d9f97f..53a7cf917 100644 --- a/test/emcc_O2_hello_world.fromasm +++ b/test/emcc_O2_hello_world.fromasm @@ -8,12 +8,12 @@ (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$v (func)) (type $FUNCSIG$vii (func (param i32 i32))) - (import "env" "STACKTOP" (global $STACKTOP i32)) - (import "env" "STACK_MAX" (global $STACK_MAX i32)) - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) - (import "env" "ABORT" (global $ABORT i32)) - (import "global" "NaN" (global $nan f64)) - (import "global" "Infinity" (global $inf f64)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "ABORT" (global $ABORT$asm2wasm$import i32)) + (import "global" "NaN" (global $nan$asm2wasm$import f64)) + (import "global" "Infinity" (global $inf$asm2wasm$import f64)) (import "env" "abort" (func $abort (param i32))) (import "env" "_pthread_cleanup_pop" (func $_pthread_cleanup_pop (param i32))) (import "env" "_pthread_self" (func $_pthread_self (result i32))) @@ -52,30 +52,36 @@ (export "dynCall_ii" (func $dynCall_ii)) (export "dynCall_iiii" (func $dynCall_iiii)) (export "dynCall_vi" (func $dynCall_vi)) - (global $__THREW__ i32 (i32.const 0)) - (global $threwValue i32 (i32.const 0)) - (global $setjmpId i32 (i32.const 0)) - (global $undef i32 (i32.const 0)) - (global $tempInt i32 (i32.const 0)) - (global $tempBigInt i32 (i32.const 0)) - (global $tempBigIntP i32 (i32.const 0)) - (global $tempBigIntS i32 (i32.const 0)) - (global $tempBigIntR f64 (f64.const 0)) - (global $tempBigIntI i32 (i32.const 0)) - (global $tempBigIntD i32 (i32.const 0)) - (global $tempValue i32 (i32.const 0)) - (global $tempDouble f64 (f64.const 0)) - (global $tempRet0 i32 (i32.const 0)) - (global $tempRet1 i32 (i32.const 0)) - (global $tempRet2 i32 (i32.const 0)) - (global $tempRet3 i32 (i32.const 0)) - (global $tempRet4 i32 (i32.const 0)) - (global $tempRet5 i32 (i32.const 0)) - (global $tempRet6 i32 (i32.const 0)) - (global $tempRet7 i32 (i32.const 0)) - (global $tempRet8 i32 (i32.const 0)) - (global $tempRet9 i32 (i32.const 0)) - (global $tempFloat f64 (f64.const 0)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) + (global $STACK_MAX (mut i32) (get_global $STACK_MAX$asm2wasm$import)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $ABORT (mut i32) (get_global $ABORT$asm2wasm$import)) + (global $__THREW__ (mut i32) (i32.const 0)) + (global $threwValue (mut i32) (i32.const 0)) + (global $setjmpId (mut i32) (i32.const 0)) + (global $undef (mut i32) (i32.const 0)) + (global $nan (mut f64) (get_global $nan$asm2wasm$import)) + (global $inf (mut f64) (get_global $inf$asm2wasm$import)) + (global $tempInt (mut i32) (i32.const 0)) + (global $tempBigInt (mut i32) (i32.const 0)) + (global $tempBigIntP (mut i32) (i32.const 0)) + (global $tempBigIntS (mut i32) (i32.const 0)) + (global $tempBigIntR (mut f64) (f64.const 0)) + (global $tempBigIntI (mut i32) (i32.const 0)) + (global $tempBigIntD (mut i32) (i32.const 0)) + (global $tempValue (mut i32) (i32.const 0)) + (global $tempDouble (mut f64) (f64.const 0)) + (global $tempRet0 (mut i32) (i32.const 0)) + (global $tempRet1 (mut i32) (i32.const 0)) + (global $tempRet2 (mut i32) (i32.const 0)) + (global $tempRet3 (mut i32) (i32.const 0)) + (global $tempRet4 (mut i32) (i32.const 0)) + (global $tempRet5 (mut i32) (i32.const 0)) + (global $tempRet6 (mut i32) (i32.const 0)) + (global $tempRet7 (mut i32) (i32.const 0)) + (global $tempRet8 (mut i32) (i32.const 0)) + (global $tempRet9 (mut i32) (i32.const 0)) + (global $tempFloat (mut f64) (f64.const 0)) (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $0 i32) (result i32) diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise index 233a485b8..603308902 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise +++ b/test/emcc_O2_hello_world.fromasm.imprecise @@ -7,12 +7,12 @@ (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$v (func)) (type $FUNCSIG$vii (func (param i32 i32))) - (import "env" "STACKTOP" (global $STACKTOP i32)) - (import "env" "STACK_MAX" (global $STACK_MAX i32)) - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) - (import "env" "ABORT" (global $ABORT i32)) - (import "global" "NaN" (global $nan f64)) - (import "global" "Infinity" (global $inf f64)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "ABORT" (global $ABORT$asm2wasm$import i32)) + (import "global" "NaN" (global $nan$asm2wasm$import f64)) + (import "global" "Infinity" (global $inf$asm2wasm$import f64)) (import "env" "abort" (func $abort (param i32))) (import "env" "_pthread_cleanup_pop" (func $_pthread_cleanup_pop (param i32))) (import "env" "_pthread_self" (func $_pthread_self (result i32))) @@ -50,30 +50,36 @@ (export "dynCall_ii" (func $dynCall_ii)) (export "dynCall_iiii" (func $dynCall_iiii)) (export "dynCall_vi" (func $dynCall_vi)) - (global $__THREW__ i32 (i32.const 0)) - (global $threwValue i32 (i32.const 0)) - (global $setjmpId i32 (i32.const 0)) - (global $undef i32 (i32.const 0)) - (global $tempInt i32 (i32.const 0)) - (global $tempBigInt i32 (i32.const 0)) - (global $tempBigIntP i32 (i32.const 0)) - (global $tempBigIntS i32 (i32.const 0)) - (global $tempBigIntR f64 (f64.const 0)) - (global $tempBigIntI i32 (i32.const 0)) - (global $tempBigIntD i32 (i32.const 0)) - (global $tempValue i32 (i32.const 0)) - (global $tempDouble f64 (f64.const 0)) - (global $tempRet0 i32 (i32.const 0)) - (global $tempRet1 i32 (i32.const 0)) - (global $tempRet2 i32 (i32.const 0)) - (global $tempRet3 i32 (i32.const 0)) - (global $tempRet4 i32 (i32.const 0)) - (global $tempRet5 i32 (i32.const 0)) - (global $tempRet6 i32 (i32.const 0)) - (global $tempRet7 i32 (i32.const 0)) - (global $tempRet8 i32 (i32.const 0)) - (global $tempRet9 i32 (i32.const 0)) - (global $tempFloat f64 (f64.const 0)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) + (global $STACK_MAX (mut i32) (get_global $STACK_MAX$asm2wasm$import)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $ABORT (mut i32) (get_global $ABORT$asm2wasm$import)) + (global $__THREW__ (mut i32) (i32.const 0)) + (global $threwValue (mut i32) (i32.const 0)) + (global $setjmpId (mut i32) (i32.const 0)) + (global $undef (mut i32) (i32.const 0)) + (global $nan (mut f64) (get_global $nan$asm2wasm$import)) + (global $inf (mut f64) (get_global $inf$asm2wasm$import)) + (global $tempInt (mut i32) (i32.const 0)) + (global $tempBigInt (mut i32) (i32.const 0)) + (global $tempBigIntP (mut i32) (i32.const 0)) + (global $tempBigIntS (mut i32) (i32.const 0)) + (global $tempBigIntR (mut f64) (f64.const 0)) + (global $tempBigIntI (mut i32) (i32.const 0)) + (global $tempBigIntD (mut i32) (i32.const 0)) + (global $tempValue (mut i32) (i32.const 0)) + (global $tempDouble (mut f64) (f64.const 0)) + (global $tempRet0 (mut i32) (i32.const 0)) + (global $tempRet1 (mut i32) (i32.const 0)) + (global $tempRet2 (mut i32) (i32.const 0)) + (global $tempRet3 (mut i32) (i32.const 0)) + (global $tempRet4 (mut i32) (i32.const 0)) + (global $tempRet5 (mut i32) (i32.const 0)) + (global $tempRet6 (mut i32) (i32.const 0)) + (global $tempRet7 (mut i32) (i32.const 0)) + (global $tempRet8 (mut i32) (i32.const 0)) + (global $tempRet9 (mut i32) (i32.const 0)) + (global $tempFloat (mut f64) (f64.const 0)) (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $0 i32) (result i32) diff --git a/test/emcc_O2_hello_world.fromasm.imprecise.no-opts b/test/emcc_O2_hello_world.fromasm.imprecise.no-opts index 8db740bfc..97d2e41d0 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise.no-opts +++ b/test/emcc_O2_hello_world.fromasm.imprecise.no-opts @@ -7,12 +7,12 @@ (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$v (func)) (type $FUNCSIG$vii (func (param i32 i32))) - (import "env" "STACKTOP" (global $STACKTOP i32)) - (import "env" "STACK_MAX" (global $STACK_MAX i32)) - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) - (import "env" "ABORT" (global $ABORT i32)) - (import "global" "NaN" (global $nan f64)) - (import "global" "Infinity" (global $inf f64)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "ABORT" (global $ABORT$asm2wasm$import i32)) + (import "global" "NaN" (global $nan$asm2wasm$import f64)) + (import "global" "Infinity" (global $inf$asm2wasm$import f64)) (import "env" "abort" (func $abort (param i32))) (import "env" "_pthread_cleanup_pop" (func $_pthread_cleanup_pop (param i32))) (import "env" "_pthread_self" (func $_pthread_self (result i32))) @@ -50,30 +50,36 @@ (export "dynCall_ii" (func $dynCall_ii)) (export "dynCall_iiii" (func $dynCall_iiii)) (export "dynCall_vi" (func $dynCall_vi)) - (global $__THREW__ i32 (i32.const 0)) - (global $threwValue i32 (i32.const 0)) - (global $setjmpId i32 (i32.const 0)) - (global $undef i32 (i32.const 0)) - (global $tempInt i32 (i32.const 0)) - (global $tempBigInt i32 (i32.const 0)) - (global $tempBigIntP i32 (i32.const 0)) - (global $tempBigIntS i32 (i32.const 0)) - (global $tempBigIntR f64 (f64.const 0)) - (global $tempBigIntI i32 (i32.const 0)) - (global $tempBigIntD i32 (i32.const 0)) - (global $tempValue i32 (i32.const 0)) - (global $tempDouble f64 (f64.const 0)) - (global $tempRet0 i32 (i32.const 0)) - (global $tempRet1 i32 (i32.const 0)) - (global $tempRet2 i32 (i32.const 0)) - (global $tempRet3 i32 (i32.const 0)) - (global $tempRet4 i32 (i32.const 0)) - (global $tempRet5 i32 (i32.const 0)) - (global $tempRet6 i32 (i32.const 0)) - (global $tempRet7 i32 (i32.const 0)) - (global $tempRet8 i32 (i32.const 0)) - (global $tempRet9 i32 (i32.const 0)) - (global $tempFloat f64 (f64.const 0)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) + (global $STACK_MAX (mut i32) (get_global $STACK_MAX$asm2wasm$import)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $ABORT (mut i32) (get_global $ABORT$asm2wasm$import)) + (global $__THREW__ (mut i32) (i32.const 0)) + (global $threwValue (mut i32) (i32.const 0)) + (global $setjmpId (mut i32) (i32.const 0)) + (global $undef (mut i32) (i32.const 0)) + (global $nan (mut f64) (get_global $nan$asm2wasm$import)) + (global $inf (mut f64) (get_global $inf$asm2wasm$import)) + (global $tempInt (mut i32) (i32.const 0)) + (global $tempBigInt (mut i32) (i32.const 0)) + (global $tempBigIntP (mut i32) (i32.const 0)) + (global $tempBigIntS (mut i32) (i32.const 0)) + (global $tempBigIntR (mut f64) (f64.const 0)) + (global $tempBigIntI (mut i32) (i32.const 0)) + (global $tempBigIntD (mut i32) (i32.const 0)) + (global $tempValue (mut i32) (i32.const 0)) + (global $tempDouble (mut f64) (f64.const 0)) + (global $tempRet0 (mut i32) (i32.const 0)) + (global $tempRet1 (mut i32) (i32.const 0)) + (global $tempRet2 (mut i32) (i32.const 0)) + (global $tempRet3 (mut i32) (i32.const 0)) + (global $tempRet4 (mut i32) (i32.const 0)) + (global $tempRet5 (mut i32) (i32.const 0)) + (global $tempRet6 (mut i32) (i32.const 0)) + (global $tempRet7 (mut i32) (i32.const 0)) + (global $tempRet8 (mut i32) (i32.const 0)) + (global $tempRet9 (mut i32) (i32.const 0)) + (global $tempFloat (mut f64) (f64.const 0)) (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $i1 i32) (result i32) diff --git a/test/emcc_O2_hello_world.fromasm.no-opts b/test/emcc_O2_hello_world.fromasm.no-opts index bdc00ad43..48340942f 100644 --- a/test/emcc_O2_hello_world.fromasm.no-opts +++ b/test/emcc_O2_hello_world.fromasm.no-opts @@ -7,12 +7,12 @@ (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$v (func)) (type $FUNCSIG$vii (func (param i32 i32))) - (import "env" "STACKTOP" (global $STACKTOP i32)) - (import "env" "STACK_MAX" (global $STACK_MAX i32)) - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) - (import "env" "ABORT" (global $ABORT i32)) - (import "global" "NaN" (global $nan f64)) - (import "global" "Infinity" (global $inf f64)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "ABORT" (global $ABORT$asm2wasm$import i32)) + (import "global" "NaN" (global $nan$asm2wasm$import f64)) + (import "global" "Infinity" (global $inf$asm2wasm$import f64)) (import "env" "abort" (func $abort (param i32))) (import "env" "_pthread_cleanup_pop" (func $_pthread_cleanup_pop (param i32))) (import "env" "_pthread_self" (func $_pthread_self (result i32))) @@ -51,30 +51,36 @@ (export "dynCall_ii" (func $dynCall_ii)) (export "dynCall_iiii" (func $dynCall_iiii)) (export "dynCall_vi" (func $dynCall_vi)) - (global $__THREW__ i32 (i32.const 0)) - (global $threwValue i32 (i32.const 0)) - (global $setjmpId i32 (i32.const 0)) - (global $undef i32 (i32.const 0)) - (global $tempInt i32 (i32.const 0)) - (global $tempBigInt i32 (i32.const 0)) - (global $tempBigIntP i32 (i32.const 0)) - (global $tempBigIntS i32 (i32.const 0)) - (global $tempBigIntR f64 (f64.const 0)) - (global $tempBigIntI i32 (i32.const 0)) - (global $tempBigIntD i32 (i32.const 0)) - (global $tempValue i32 (i32.const 0)) - (global $tempDouble f64 (f64.const 0)) - (global $tempRet0 i32 (i32.const 0)) - (global $tempRet1 i32 (i32.const 0)) - (global $tempRet2 i32 (i32.const 0)) - (global $tempRet3 i32 (i32.const 0)) - (global $tempRet4 i32 (i32.const 0)) - (global $tempRet5 i32 (i32.const 0)) - (global $tempRet6 i32 (i32.const 0)) - (global $tempRet7 i32 (i32.const 0)) - (global $tempRet8 i32 (i32.const 0)) - (global $tempRet9 i32 (i32.const 0)) - (global $tempFloat f64 (f64.const 0)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) + (global $STACK_MAX (mut i32) (get_global $STACK_MAX$asm2wasm$import)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $ABORT (mut i32) (get_global $ABORT$asm2wasm$import)) + (global $__THREW__ (mut i32) (i32.const 0)) + (global $threwValue (mut i32) (i32.const 0)) + (global $setjmpId (mut i32) (i32.const 0)) + (global $undef (mut i32) (i32.const 0)) + (global $nan (mut f64) (get_global $nan$asm2wasm$import)) + (global $inf (mut f64) (get_global $inf$asm2wasm$import)) + (global $tempInt (mut i32) (i32.const 0)) + (global $tempBigInt (mut i32) (i32.const 0)) + (global $tempBigIntP (mut i32) (i32.const 0)) + (global $tempBigIntS (mut i32) (i32.const 0)) + (global $tempBigIntR (mut f64) (f64.const 0)) + (global $tempBigIntI (mut i32) (i32.const 0)) + (global $tempBigIntD (mut i32) (i32.const 0)) + (global $tempValue (mut i32) (i32.const 0)) + (global $tempDouble (mut f64) (f64.const 0)) + (global $tempRet0 (mut i32) (i32.const 0)) + (global $tempRet1 (mut i32) (i32.const 0)) + (global $tempRet2 (mut i32) (i32.const 0)) + (global $tempRet3 (mut i32) (i32.const 0)) + (global $tempRet4 (mut i32) (i32.const 0)) + (global $tempRet5 (mut i32) (i32.const 0)) + (global $tempRet6 (mut i32) (i32.const 0)) + (global $tempRet7 (mut i32) (i32.const 0)) + (global $tempRet8 (mut i32) (i32.const 0)) + (global $tempRet9 (mut i32) (i32.const 0)) + (global $tempFloat (mut f64) (f64.const 0)) (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $i1 i32) (result i32) diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index a12c7fe56..26e13e794 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -9,13 +9,13 @@ (type $FUNCSIG$v (func)) (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) - (import "env" "STACKTOP" (global $STACKTOP i32)) - (import "env" "STACK_MAX" (global $STACK_MAX i32)) - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) - (import "env" "ABORT" (global $ABORT i32)) - (import "env" "cttz_i8" (global $cttz_i8 i32)) - (import "global" "NaN" (global $nan f64)) - (import "global" "Infinity" (global $inf f64)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "ABORT" (global $ABORT$asm2wasm$import i32)) + (import "env" "cttz_i8" (global $cttz_i8$asm2wasm$import i32)) + (import "global" "NaN" (global $nan$asm2wasm$import f64)) + (import "global" "Infinity" (global $inf$asm2wasm$import f64)) (import "env" "abort" (func $abort)) (import "env" "nullFunc_ii" (func $nullFunc_ii (param i32))) (import "env" "nullFunc_iiii" (func $nullFunc_iiii (param i32))) @@ -66,30 +66,37 @@ (export "dynCall_iiii" (func $dynCall_iiii)) (export "dynCall_vi" (func $dynCall_vi)) (export "___udivmoddi4" (func $___udivmoddi4)) - (global $__THREW__ i32 (i32.const 0)) - (global $threwValue i32 (i32.const 0)) - (global $setjmpId i32 (i32.const 0)) - (global $undef i32 (i32.const 0)) - (global $tempInt i32 (i32.const 0)) - (global $tempBigInt i32 (i32.const 0)) - (global $tempBigIntP i32 (i32.const 0)) - (global $tempBigIntS i32 (i32.const 0)) - (global $tempBigIntR f64 (f64.const 0)) - (global $tempBigIntI i32 (i32.const 0)) - (global $tempBigIntD i32 (i32.const 0)) - (global $tempValue i32 (i32.const 0)) - (global $tempDouble f64 (f64.const 0)) - (global $tempRet0 i32 (i32.const 0)) - (global $tempRet1 i32 (i32.const 0)) - (global $tempRet2 i32 (i32.const 0)) - (global $tempRet3 i32 (i32.const 0)) - (global $tempRet4 i32 (i32.const 0)) - (global $tempRet5 i32 (i32.const 0)) - (global $tempRet6 i32 (i32.const 0)) - (global $tempRet7 i32 (i32.const 0)) - (global $tempRet8 i32 (i32.const 0)) - (global $tempRet9 i32 (i32.const 0)) - (global $tempFloat f64 (f64.const 0)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) + (global $STACK_MAX (mut i32) (get_global $STACK_MAX$asm2wasm$import)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $ABORT (mut i32) (get_global $ABORT$asm2wasm$import)) + (global $cttz_i8 (mut i32) (get_global $cttz_i8$asm2wasm$import)) + (global $__THREW__ (mut i32) (i32.const 0)) + (global $threwValue (mut i32) (i32.const 0)) + (global $setjmpId (mut i32) (i32.const 0)) + (global $undef (mut i32) (i32.const 0)) + (global $nan (mut f64) (get_global $nan$asm2wasm$import)) + (global $inf (mut f64) (get_global $inf$asm2wasm$import)) + (global $tempInt (mut i32) (i32.const 0)) + (global $tempBigInt (mut i32) (i32.const 0)) + (global $tempBigIntP (mut i32) (i32.const 0)) + (global $tempBigIntS (mut i32) (i32.const 0)) + (global $tempBigIntR (mut f64) (f64.const 0)) + (global $tempBigIntI (mut i32) (i32.const 0)) + (global $tempBigIntD (mut i32) (i32.const 0)) + (global $tempValue (mut i32) (i32.const 0)) + (global $tempDouble (mut f64) (f64.const 0)) + (global $tempRet0 (mut i32) (i32.const 0)) + (global $tempRet1 (mut i32) (i32.const 0)) + (global $tempRet2 (mut i32) (i32.const 0)) + (global $tempRet3 (mut i32) (i32.const 0)) + (global $tempRet4 (mut i32) (i32.const 0)) + (global $tempRet5 (mut i32) (i32.const 0)) + (global $tempRet6 (mut i32) (i32.const 0)) + (global $tempRet7 (mut i32) (i32.const 0)) + (global $tempRet8 (mut i32) (i32.const 0)) + (global $tempRet9 (mut i32) (i32.const 0)) + (global $tempFloat (mut f64) (f64.const 0)) (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $0 i32) (result i32) diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise index 75534025e..e78774569 100644 --- a/test/emcc_hello_world.fromasm.imprecise +++ b/test/emcc_hello_world.fromasm.imprecise @@ -7,13 +7,13 @@ (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) - (import "env" "STACKTOP" (global $STACKTOP i32)) - (import "env" "STACK_MAX" (global $STACK_MAX i32)) - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) - (import "env" "ABORT" (global $ABORT i32)) - (import "env" "cttz_i8" (global $cttz_i8 i32)) - (import "global" "NaN" (global $nan f64)) - (import "global" "Infinity" (global $inf f64)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "ABORT" (global $ABORT$asm2wasm$import i32)) + (import "env" "cttz_i8" (global $cttz_i8$asm2wasm$import i32)) + (import "global" "NaN" (global $nan$asm2wasm$import f64)) + (import "global" "Infinity" (global $inf$asm2wasm$import f64)) (import "env" "abort" (func $abort)) (import "env" "nullFunc_ii" (func $nullFunc_ii (param i32))) (import "env" "nullFunc_iiii" (func $nullFunc_iiii (param i32))) @@ -59,30 +59,37 @@ (export "dynCall_iiii" (func $dynCall_iiii)) (export "dynCall_vi" (func $dynCall_vi)) (export "___udivmoddi4" (func $___udivmoddi4)) - (global $__THREW__ i32 (i32.const 0)) - (global $threwValue i32 (i32.const 0)) - (global $setjmpId i32 (i32.const 0)) - (global $undef i32 (i32.const 0)) - (global $tempInt i32 (i32.const 0)) - (global $tempBigInt i32 (i32.const 0)) - (global $tempBigIntP i32 (i32.const 0)) - (global $tempBigIntS i32 (i32.const 0)) - (global $tempBigIntR f64 (f64.const 0)) - (global $tempBigIntI i32 (i32.const 0)) - (global $tempBigIntD i32 (i32.const 0)) - (global $tempValue i32 (i32.const 0)) - (global $tempDouble f64 (f64.const 0)) - (global $tempRet0 i32 (i32.const 0)) - (global $tempRet1 i32 (i32.const 0)) - (global $tempRet2 i32 (i32.const 0)) - (global $tempRet3 i32 (i32.const 0)) - (global $tempRet4 i32 (i32.const 0)) - (global $tempRet5 i32 (i32.const 0)) - (global $tempRet6 i32 (i32.const 0)) - (global $tempRet7 i32 (i32.const 0)) - (global $tempRet8 i32 (i32.const 0)) - (global $tempRet9 i32 (i32.const 0)) - (global $tempFloat f64 (f64.const 0)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) + (global $STACK_MAX (mut i32) (get_global $STACK_MAX$asm2wasm$import)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $ABORT (mut i32) (get_global $ABORT$asm2wasm$import)) + (global $cttz_i8 (mut i32) (get_global $cttz_i8$asm2wasm$import)) + (global $__THREW__ (mut i32) (i32.const 0)) + (global $threwValue (mut i32) (i32.const 0)) + (global $setjmpId (mut i32) (i32.const 0)) + (global $undef (mut i32) (i32.const 0)) + (global $nan (mut f64) (get_global $nan$asm2wasm$import)) + (global $inf (mut f64) (get_global $inf$asm2wasm$import)) + (global $tempInt (mut i32) (i32.const 0)) + (global $tempBigInt (mut i32) (i32.const 0)) + (global $tempBigIntP (mut i32) (i32.const 0)) + (global $tempBigIntS (mut i32) (i32.const 0)) + (global $tempBigIntR (mut f64) (f64.const 0)) + (global $tempBigIntI (mut i32) (i32.const 0)) + (global $tempBigIntD (mut i32) (i32.const 0)) + (global $tempValue (mut i32) (i32.const 0)) + (global $tempDouble (mut f64) (f64.const 0)) + (global $tempRet0 (mut i32) (i32.const 0)) + (global $tempRet1 (mut i32) (i32.const 0)) + (global $tempRet2 (mut i32) (i32.const 0)) + (global $tempRet3 (mut i32) (i32.const 0)) + (global $tempRet4 (mut i32) (i32.const 0)) + (global $tempRet5 (mut i32) (i32.const 0)) + (global $tempRet6 (mut i32) (i32.const 0)) + (global $tempRet7 (mut i32) (i32.const 0)) + (global $tempRet8 (mut i32) (i32.const 0)) + (global $tempRet9 (mut i32) (i32.const 0)) + (global $tempFloat (mut f64) (f64.const 0)) (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $0 i32) (result i32) diff --git a/test/emcc_hello_world.fromasm.imprecise.no-opts b/test/emcc_hello_world.fromasm.imprecise.no-opts index a2e8496a5..e9335450b 100644 --- a/test/emcc_hello_world.fromasm.imprecise.no-opts +++ b/test/emcc_hello_world.fromasm.imprecise.no-opts @@ -7,13 +7,13 @@ (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) - (import "env" "STACKTOP" (global $STACKTOP i32)) - (import "env" "STACK_MAX" (global $STACK_MAX i32)) - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) - (import "env" "ABORT" (global $ABORT i32)) - (import "env" "cttz_i8" (global $cttz_i8 i32)) - (import "global" "NaN" (global $nan f64)) - (import "global" "Infinity" (global $inf f64)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "ABORT" (global $ABORT$asm2wasm$import i32)) + (import "env" "cttz_i8" (global $cttz_i8$asm2wasm$import i32)) + (import "global" "NaN" (global $nan$asm2wasm$import f64)) + (import "global" "Infinity" (global $inf$asm2wasm$import f64)) (import "env" "abort" (func $abort)) (import "env" "nullFunc_ii" (func $nullFunc_ii (param i32))) (import "env" "nullFunc_iiii" (func $nullFunc_iiii (param i32))) @@ -59,30 +59,37 @@ (export "dynCall_iiii" (func $dynCall_iiii)) (export "dynCall_vi" (func $dynCall_vi)) (export "___udivmoddi4" (func $___udivmoddi4)) - (global $__THREW__ i32 (i32.const 0)) - (global $threwValue i32 (i32.const 0)) - (global $setjmpId i32 (i32.const 0)) - (global $undef i32 (i32.const 0)) - (global $tempInt i32 (i32.const 0)) - (global $tempBigInt i32 (i32.const 0)) - (global $tempBigIntP i32 (i32.const 0)) - (global $tempBigIntS i32 (i32.const 0)) - (global $tempBigIntR f64 (f64.const 0)) - (global $tempBigIntI i32 (i32.const 0)) - (global $tempBigIntD i32 (i32.const 0)) - (global $tempValue i32 (i32.const 0)) - (global $tempDouble f64 (f64.const 0)) - (global $tempRet0 i32 (i32.const 0)) - (global $tempRet1 i32 (i32.const 0)) - (global $tempRet2 i32 (i32.const 0)) - (global $tempRet3 i32 (i32.const 0)) - (global $tempRet4 i32 (i32.const 0)) - (global $tempRet5 i32 (i32.const 0)) - (global $tempRet6 i32 (i32.const 0)) - (global $tempRet7 i32 (i32.const 0)) - (global $tempRet8 i32 (i32.const 0)) - (global $tempRet9 i32 (i32.const 0)) - (global $tempFloat f64 (f64.const 0)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) + (global $STACK_MAX (mut i32) (get_global $STACK_MAX$asm2wasm$import)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $ABORT (mut i32) (get_global $ABORT$asm2wasm$import)) + (global $cttz_i8 (mut i32) (get_global $cttz_i8$asm2wasm$import)) + (global $__THREW__ (mut i32) (i32.const 0)) + (global $threwValue (mut i32) (i32.const 0)) + (global $setjmpId (mut i32) (i32.const 0)) + (global $undef (mut i32) (i32.const 0)) + (global $nan (mut f64) (get_global $nan$asm2wasm$import)) + (global $inf (mut f64) (get_global $inf$asm2wasm$import)) + (global $tempInt (mut i32) (i32.const 0)) + (global $tempBigInt (mut i32) (i32.const 0)) + (global $tempBigIntP (mut i32) (i32.const 0)) + (global $tempBigIntS (mut i32) (i32.const 0)) + (global $tempBigIntR (mut f64) (f64.const 0)) + (global $tempBigIntI (mut i32) (i32.const 0)) + (global $tempBigIntD (mut i32) (i32.const 0)) + (global $tempValue (mut i32) (i32.const 0)) + (global $tempDouble (mut f64) (f64.const 0)) + (global $tempRet0 (mut i32) (i32.const 0)) + (global $tempRet1 (mut i32) (i32.const 0)) + (global $tempRet2 (mut i32) (i32.const 0)) + (global $tempRet3 (mut i32) (i32.const 0)) + (global $tempRet4 (mut i32) (i32.const 0)) + (global $tempRet5 (mut i32) (i32.const 0)) + (global $tempRet6 (mut i32) (i32.const 0)) + (global $tempRet7 (mut i32) (i32.const 0)) + (global $tempRet8 (mut i32) (i32.const 0)) + (global $tempRet9 (mut i32) (i32.const 0)) + (global $tempFloat (mut f64) (f64.const 0)) (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $size i32) (result i32) diff --git a/test/emcc_hello_world.fromasm.no-opts b/test/emcc_hello_world.fromasm.no-opts index 771e63313..9fa2a2895 100644 --- a/test/emcc_hello_world.fromasm.no-opts +++ b/test/emcc_hello_world.fromasm.no-opts @@ -8,13 +8,13 @@ (type $FUNCSIG$v (func)) (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) - (import "env" "STACKTOP" (global $STACKTOP i32)) - (import "env" "STACK_MAX" (global $STACK_MAX i32)) - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) - (import "env" "ABORT" (global $ABORT i32)) - (import "env" "cttz_i8" (global $cttz_i8 i32)) - (import "global" "NaN" (global $nan f64)) - (import "global" "Infinity" (global $inf f64)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "ABORT" (global $ABORT$asm2wasm$import i32)) + (import "env" "cttz_i8" (global $cttz_i8$asm2wasm$import i32)) + (import "global" "NaN" (global $nan$asm2wasm$import f64)) + (import "global" "Infinity" (global $inf$asm2wasm$import f64)) (import "env" "abort" (func $abort)) (import "env" "nullFunc_ii" (func $nullFunc_ii (param i32))) (import "env" "nullFunc_iiii" (func $nullFunc_iiii (param i32))) @@ -65,30 +65,37 @@ (export "dynCall_iiii" (func $dynCall_iiii)) (export "dynCall_vi" (func $dynCall_vi)) (export "___udivmoddi4" (func $___udivmoddi4)) - (global $__THREW__ i32 (i32.const 0)) - (global $threwValue i32 (i32.const 0)) - (global $setjmpId i32 (i32.const 0)) - (global $undef i32 (i32.const 0)) - (global $tempInt i32 (i32.const 0)) - (global $tempBigInt i32 (i32.const 0)) - (global $tempBigIntP i32 (i32.const 0)) - (global $tempBigIntS i32 (i32.const 0)) - (global $tempBigIntR f64 (f64.const 0)) - (global $tempBigIntI i32 (i32.const 0)) - (global $tempBigIntD i32 (i32.const 0)) - (global $tempValue i32 (i32.const 0)) - (global $tempDouble f64 (f64.const 0)) - (global $tempRet0 i32 (i32.const 0)) - (global $tempRet1 i32 (i32.const 0)) - (global $tempRet2 i32 (i32.const 0)) - (global $tempRet3 i32 (i32.const 0)) - (global $tempRet4 i32 (i32.const 0)) - (global $tempRet5 i32 (i32.const 0)) - (global $tempRet6 i32 (i32.const 0)) - (global $tempRet7 i32 (i32.const 0)) - (global $tempRet8 i32 (i32.const 0)) - (global $tempRet9 i32 (i32.const 0)) - (global $tempFloat f64 (f64.const 0)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) + (global $STACK_MAX (mut i32) (get_global $STACK_MAX$asm2wasm$import)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $ABORT (mut i32) (get_global $ABORT$asm2wasm$import)) + (global $cttz_i8 (mut i32) (get_global $cttz_i8$asm2wasm$import)) + (global $__THREW__ (mut i32) (i32.const 0)) + (global $threwValue (mut i32) (i32.const 0)) + (global $setjmpId (mut i32) (i32.const 0)) + (global $undef (mut i32) (i32.const 0)) + (global $nan (mut f64) (get_global $nan$asm2wasm$import)) + (global $inf (mut f64) (get_global $inf$asm2wasm$import)) + (global $tempInt (mut i32) (i32.const 0)) + (global $tempBigInt (mut i32) (i32.const 0)) + (global $tempBigIntP (mut i32) (i32.const 0)) + (global $tempBigIntS (mut i32) (i32.const 0)) + (global $tempBigIntR (mut f64) (f64.const 0)) + (global $tempBigIntI (mut i32) (i32.const 0)) + (global $tempBigIntD (mut i32) (i32.const 0)) + (global $tempValue (mut i32) (i32.const 0)) + (global $tempDouble (mut f64) (f64.const 0)) + (global $tempRet0 (mut i32) (i32.const 0)) + (global $tempRet1 (mut i32) (i32.const 0)) + (global $tempRet2 (mut i32) (i32.const 0)) + (global $tempRet3 (mut i32) (i32.const 0)) + (global $tempRet4 (mut i32) (i32.const 0)) + (global $tempRet5 (mut i32) (i32.const 0)) + (global $tempRet6 (mut i32) (i32.const 0)) + (global $tempRet7 (mut i32) (i32.const 0)) + (global $tempRet8 (mut i32) (i32.const 0)) + (global $tempRet9 (mut i32) (i32.const 0)) + (global $tempFloat (mut f64) (f64.const 0)) (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $size i32) (result i32) diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm index 7efde4442..9c335557f 100644 --- a/test/memorygrowth.fromasm +++ b/test/memorygrowth.fromasm @@ -7,12 +7,12 @@ (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$v (func)) (type $FUNCSIG$vii (func (param i32 i32))) - (import "env" "STACKTOP" (global $r i32)) - (import "env" "STACK_MAX" (global $s i32)) - (import "env" "tempDoublePtr" (global $t i32)) - (import "env" "ABORT" (global $u i32)) - (import "global" "NaN" (global $z f64)) - (import "global" "Infinity" (global $A f64)) + (import "env" "STACKTOP" (global $r$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $s$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $t$asm2wasm$import i32)) + (import "env" "ABORT" (global $u$asm2wasm$import i32)) + (import "global" "NaN" (global $z$asm2wasm$import f64)) + (import "global" "Infinity" (global $A$asm2wasm$import f64)) (import "env" "abort" (func $ja (param i32))) (import "env" "_pthread_cleanup_pop" (func $oa (param i32))) (import "env" "___lock" (func $pa (param i32))) @@ -50,30 +50,36 @@ (export "dynCall_iiii" (func $lb)) (export "dynCall_vi" (func $mb)) (export "__growWasmMemory" (func $__growWasmMemory)) - (global $v i32 (i32.const 0)) - (global $w i32 (i32.const 0)) - (global $x i32 (i32.const 0)) - (global $y i32 (i32.const 0)) - (global $B i32 (i32.const 0)) - (global $C i32 (i32.const 0)) - (global $D i32 (i32.const 0)) - (global $E i32 (i32.const 0)) - (global $F f64 (f64.const 0)) - (global $G i32 (i32.const 0)) - (global $H i32 (i32.const 0)) - (global $I i32 (i32.const 0)) - (global $J f64 (f64.const 0)) - (global $K i32 (i32.const 0)) - (global $L i32 (i32.const 0)) - (global $M i32 (i32.const 0)) - (global $N i32 (i32.const 0)) - (global $O i32 (i32.const 0)) - (global $P i32 (i32.const 0)) - (global $Q i32 (i32.const 0)) - (global $R i32 (i32.const 0)) - (global $S i32 (i32.const 0)) - (global $T i32 (i32.const 0)) - (global $za f64 (f64.const 0)) + (global $r (mut i32) (get_global $r$asm2wasm$import)) + (global $s (mut i32) (get_global $s$asm2wasm$import)) + (global $t (mut i32) (get_global $t$asm2wasm$import)) + (global $u (mut i32) (get_global $u$asm2wasm$import)) + (global $v (mut i32) (i32.const 0)) + (global $w (mut i32) (i32.const 0)) + (global $x (mut i32) (i32.const 0)) + (global $y (mut i32) (i32.const 0)) + (global $z (mut f64) (get_global $z$asm2wasm$import)) + (global $A (mut f64) (get_global $A$asm2wasm$import)) + (global $B (mut i32) (i32.const 0)) + (global $C (mut i32) (i32.const 0)) + (global $D (mut i32) (i32.const 0)) + (global $E (mut i32) (i32.const 0)) + (global $F (mut f64) (f64.const 0)) + (global $G (mut i32) (i32.const 0)) + (global $H (mut i32) (i32.const 0)) + (global $I (mut i32) (i32.const 0)) + (global $J (mut f64) (f64.const 0)) + (global $K (mut i32) (i32.const 0)) + (global $L (mut i32) (i32.const 0)) + (global $M (mut i32) (i32.const 0)) + (global $N (mut i32) (i32.const 0)) + (global $O (mut i32) (i32.const 0)) + (global $P (mut i32) (i32.const 0)) + (global $Q (mut i32) (i32.const 0)) + (global $R (mut i32) (i32.const 0)) + (global $S (mut i32) (i32.const 0)) + (global $T (mut i32) (i32.const 0)) + (global $za (mut f64) (f64.const 0)) (table 8 8 anyfunc) (elem (i32.const 0) $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $0 i32) (result i32) diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise index 1a93b6e60..258fbd3ad 100644 --- a/test/memorygrowth.fromasm.imprecise +++ b/test/memorygrowth.fromasm.imprecise @@ -6,12 +6,12 @@ (type $FUNCSIG$v (func)) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (import "env" "STACKTOP" (global $r i32)) - (import "env" "STACK_MAX" (global $s i32)) - (import "env" "tempDoublePtr" (global $t i32)) - (import "env" "ABORT" (global $u i32)) - (import "global" "NaN" (global $z f64)) - (import "global" "Infinity" (global $A f64)) + (import "env" "STACKTOP" (global $r$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $s$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $t$asm2wasm$import i32)) + (import "env" "ABORT" (global $u$asm2wasm$import i32)) + (import "global" "NaN" (global $z$asm2wasm$import f64)) + (import "global" "Infinity" (global $A$asm2wasm$import f64)) (import "env" "abort" (func $ja (param i32))) (import "env" "_pthread_cleanup_pop" (func $oa (param i32))) (import "env" "___lock" (func $pa (param i32))) @@ -48,30 +48,36 @@ (export "dynCall_iiii" (func $lb)) (export "dynCall_vi" (func $mb)) (export "__growWasmMemory" (func $__growWasmMemory)) - (global $v i32 (i32.const 0)) - (global $w i32 (i32.const 0)) - (global $x i32 (i32.const 0)) - (global $y i32 (i32.const 0)) - (global $B i32 (i32.const 0)) - (global $C i32 (i32.const 0)) - (global $D i32 (i32.const 0)) - (global $E i32 (i32.const 0)) - (global $F f64 (f64.const 0)) - (global $G i32 (i32.const 0)) - (global $H i32 (i32.const 0)) - (global $I i32 (i32.const 0)) - (global $J f64 (f64.const 0)) - (global $K i32 (i32.const 0)) - (global $L i32 (i32.const 0)) - (global $M i32 (i32.const 0)) - (global $N i32 (i32.const 0)) - (global $O i32 (i32.const 0)) - (global $P i32 (i32.const 0)) - (global $Q i32 (i32.const 0)) - (global $R i32 (i32.const 0)) - (global $S i32 (i32.const 0)) - (global $T i32 (i32.const 0)) - (global $za f64 (f64.const 0)) + (global $r (mut i32) (get_global $r$asm2wasm$import)) + (global $s (mut i32) (get_global $s$asm2wasm$import)) + (global $t (mut i32) (get_global $t$asm2wasm$import)) + (global $u (mut i32) (get_global $u$asm2wasm$import)) + (global $v (mut i32) (i32.const 0)) + (global $w (mut i32) (i32.const 0)) + (global $x (mut i32) (i32.const 0)) + (global $y (mut i32) (i32.const 0)) + (global $z (mut f64) (get_global $z$asm2wasm$import)) + (global $A (mut f64) (get_global $A$asm2wasm$import)) + (global $B (mut i32) (i32.const 0)) + (global $C (mut i32) (i32.const 0)) + (global $D (mut i32) (i32.const 0)) + (global $E (mut i32) (i32.const 0)) + (global $F (mut f64) (f64.const 0)) + (global $G (mut i32) (i32.const 0)) + (global $H (mut i32) (i32.const 0)) + (global $I (mut i32) (i32.const 0)) + (global $J (mut f64) (f64.const 0)) + (global $K (mut i32) (i32.const 0)) + (global $L (mut i32) (i32.const 0)) + (global $M (mut i32) (i32.const 0)) + (global $N (mut i32) (i32.const 0)) + (global $O (mut i32) (i32.const 0)) + (global $P (mut i32) (i32.const 0)) + (global $Q (mut i32) (i32.const 0)) + (global $R (mut i32) (i32.const 0)) + (global $S (mut i32) (i32.const 0)) + (global $T (mut i32) (i32.const 0)) + (global $za (mut f64) (f64.const 0)) (table 8 8 anyfunc) (elem (i32.const 0) $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $0 i32) (result i32) diff --git a/test/memorygrowth.fromasm.imprecise.no-opts b/test/memorygrowth.fromasm.imprecise.no-opts index 8c5e6f8af..cd2c80cc0 100644 --- a/test/memorygrowth.fromasm.imprecise.no-opts +++ b/test/memorygrowth.fromasm.imprecise.no-opts @@ -6,12 +6,12 @@ (type $FUNCSIG$v (func)) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (import "env" "STACKTOP" (global $r i32)) - (import "env" "STACK_MAX" (global $s i32)) - (import "env" "tempDoublePtr" (global $t i32)) - (import "env" "ABORT" (global $u i32)) - (import "global" "NaN" (global $z f64)) - (import "global" "Infinity" (global $A f64)) + (import "env" "STACKTOP" (global $r$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $s$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $t$asm2wasm$import i32)) + (import "env" "ABORT" (global $u$asm2wasm$import i32)) + (import "global" "NaN" (global $z$asm2wasm$import f64)) + (import "global" "Infinity" (global $A$asm2wasm$import f64)) (import "env" "abort" (func $ja (param i32))) (import "env" "_pthread_cleanup_pop" (func $oa (param i32))) (import "env" "___lock" (func $pa (param i32))) @@ -48,30 +48,36 @@ (export "dynCall_iiii" (func $lb)) (export "dynCall_vi" (func $mb)) (export "__growWasmMemory" (func $__growWasmMemory)) - (global $v i32 (i32.const 0)) - (global $w i32 (i32.const 0)) - (global $x i32 (i32.const 0)) - (global $y i32 (i32.const 0)) - (global $B i32 (i32.const 0)) - (global $C i32 (i32.const 0)) - (global $D i32 (i32.const 0)) - (global $E i32 (i32.const 0)) - (global $F f64 (f64.const 0)) - (global $G i32 (i32.const 0)) - (global $H i32 (i32.const 0)) - (global $I i32 (i32.const 0)) - (global $J f64 (f64.const 0)) - (global $K i32 (i32.const 0)) - (global $L i32 (i32.const 0)) - (global $M i32 (i32.const 0)) - (global $N i32 (i32.const 0)) - (global $O i32 (i32.const 0)) - (global $P i32 (i32.const 0)) - (global $Q i32 (i32.const 0)) - (global $R i32 (i32.const 0)) - (global $S i32 (i32.const 0)) - (global $T i32 (i32.const 0)) - (global $za f64 (f64.const 0)) + (global $r (mut i32) (get_global $r$asm2wasm$import)) + (global $s (mut i32) (get_global $s$asm2wasm$import)) + (global $t (mut i32) (get_global $t$asm2wasm$import)) + (global $u (mut i32) (get_global $u$asm2wasm$import)) + (global $v (mut i32) (i32.const 0)) + (global $w (mut i32) (i32.const 0)) + (global $x (mut i32) (i32.const 0)) + (global $y (mut i32) (i32.const 0)) + (global $z (mut f64) (get_global $z$asm2wasm$import)) + (global $A (mut f64) (get_global $A$asm2wasm$import)) + (global $B (mut i32) (i32.const 0)) + (global $C (mut i32) (i32.const 0)) + (global $D (mut i32) (i32.const 0)) + (global $E (mut i32) (i32.const 0)) + (global $F (mut f64) (f64.const 0)) + (global $G (mut i32) (i32.const 0)) + (global $H (mut i32) (i32.const 0)) + (global $I (mut i32) (i32.const 0)) + (global $J (mut f64) (f64.const 0)) + (global $K (mut i32) (i32.const 0)) + (global $L (mut i32) (i32.const 0)) + (global $M (mut i32) (i32.const 0)) + (global $N (mut i32) (i32.const 0)) + (global $O (mut i32) (i32.const 0)) + (global $P (mut i32) (i32.const 0)) + (global $Q (mut i32) (i32.const 0)) + (global $R (mut i32) (i32.const 0)) + (global $S (mut i32) (i32.const 0)) + (global $T (mut i32) (i32.const 0)) + (global $za (mut f64) (f64.const 0)) (table 8 8 anyfunc) (elem (i32.const 0) $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $a i32) (result i32) diff --git a/test/memorygrowth.fromasm.no-opts b/test/memorygrowth.fromasm.no-opts index 4bcafb28b..0b50f1248 100644 --- a/test/memorygrowth.fromasm.no-opts +++ b/test/memorygrowth.fromasm.no-opts @@ -6,12 +6,12 @@ (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$v (func)) (type $FUNCSIG$vii (func (param i32 i32))) - (import "env" "STACKTOP" (global $r i32)) - (import "env" "STACK_MAX" (global $s i32)) - (import "env" "tempDoublePtr" (global $t i32)) - (import "env" "ABORT" (global $u i32)) - (import "global" "NaN" (global $z f64)) - (import "global" "Infinity" (global $A f64)) + (import "env" "STACKTOP" (global $r$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $s$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $t$asm2wasm$import i32)) + (import "env" "ABORT" (global $u$asm2wasm$import i32)) + (import "global" "NaN" (global $z$asm2wasm$import f64)) + (import "global" "Infinity" (global $A$asm2wasm$import f64)) (import "env" "abort" (func $ja (param i32))) (import "env" "_pthread_cleanup_pop" (func $oa (param i32))) (import "env" "___lock" (func $pa (param i32))) @@ -49,30 +49,36 @@ (export "dynCall_iiii" (func $lb)) (export "dynCall_vi" (func $mb)) (export "__growWasmMemory" (func $__growWasmMemory)) - (global $v i32 (i32.const 0)) - (global $w i32 (i32.const 0)) - (global $x i32 (i32.const 0)) - (global $y i32 (i32.const 0)) - (global $B i32 (i32.const 0)) - (global $C i32 (i32.const 0)) - (global $D i32 (i32.const 0)) - (global $E i32 (i32.const 0)) - (global $F f64 (f64.const 0)) - (global $G i32 (i32.const 0)) - (global $H i32 (i32.const 0)) - (global $I i32 (i32.const 0)) - (global $J f64 (f64.const 0)) - (global $K i32 (i32.const 0)) - (global $L i32 (i32.const 0)) - (global $M i32 (i32.const 0)) - (global $N i32 (i32.const 0)) - (global $O i32 (i32.const 0)) - (global $P i32 (i32.const 0)) - (global $Q i32 (i32.const 0)) - (global $R i32 (i32.const 0)) - (global $S i32 (i32.const 0)) - (global $T i32 (i32.const 0)) - (global $za f64 (f64.const 0)) + (global $r (mut i32) (get_global $r$asm2wasm$import)) + (global $s (mut i32) (get_global $s$asm2wasm$import)) + (global $t (mut i32) (get_global $t$asm2wasm$import)) + (global $u (mut i32) (get_global $u$asm2wasm$import)) + (global $v (mut i32) (i32.const 0)) + (global $w (mut i32) (i32.const 0)) + (global $x (mut i32) (i32.const 0)) + (global $y (mut i32) (i32.const 0)) + (global $z (mut f64) (get_global $z$asm2wasm$import)) + (global $A (mut f64) (get_global $A$asm2wasm$import)) + (global $B (mut i32) (i32.const 0)) + (global $C (mut i32) (i32.const 0)) + (global $D (mut i32) (i32.const 0)) + (global $E (mut i32) (i32.const 0)) + (global $F (mut f64) (f64.const 0)) + (global $G (mut i32) (i32.const 0)) + (global $H (mut i32) (i32.const 0)) + (global $I (mut i32) (i32.const 0)) + (global $J (mut f64) (f64.const 0)) + (global $K (mut i32) (i32.const 0)) + (global $L (mut i32) (i32.const 0)) + (global $M (mut i32) (i32.const 0)) + (global $N (mut i32) (i32.const 0)) + (global $O (mut i32) (i32.const 0)) + (global $P (mut i32) (i32.const 0)) + (global $Q (mut i32) (i32.const 0)) + (global $R (mut i32) (i32.const 0)) + (global $S (mut i32) (i32.const 0)) + (global $T (mut i32) (i32.const 0)) + (global $za (mut f64) (f64.const 0)) (table 8 8 anyfunc) (elem (i32.const 0) $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $a i32) (result i32) diff --git a/test/min.fromasm b/test/min.fromasm index a912c2dad..a52a6e876 100644 --- a/test/min.fromasm +++ b/test/min.fromasm @@ -1,14 +1,15 @@ (module (memory 256 256) (data (get_global $memoryBase) "min.asm.js") - (import "env" "tempDoublePtr" (global $tDP i32)) + (import "env" "tempDoublePtr" (global $tDP$asm2wasm$import i32)) (import "env" "memory" (memory $memory)) (import "env" "table" (table $table)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "floats" (func $floats)) (export "getTempRet0" (func $ub)) - (global $M i32 (i32.const 0)) + (global $tDP (mut i32) (get_global $tDP$asm2wasm$import)) + (global $M (mut i32) (i32.const 0)) (func $floats (param $0 f32) (result f32) (local $1 f32) (f32.add diff --git a/test/min.fromasm.imprecise b/test/min.fromasm.imprecise index a57298eef..495c600d1 100644 --- a/test/min.fromasm.imprecise +++ b/test/min.fromasm.imprecise @@ -1,13 +1,14 @@ (module (memory 256 256) - (import "env" "tempDoublePtr" (global $tDP i32)) + (import "env" "tempDoublePtr" (global $tDP$asm2wasm$import i32)) (import "env" "memory" (memory $memory)) (import "env" "table" (table $table)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "floats" (func $floats)) (export "getTempRet0" (func $ub)) - (global $M i32 (i32.const 0)) + (global $tDP (mut i32) (get_global $tDP$asm2wasm$import)) + (global $M (mut i32) (i32.const 0)) (func $floats (param $0 f32) (result f32) (local $1 f32) (f32.add diff --git a/test/min.fromasm.imprecise.no-opts b/test/min.fromasm.imprecise.no-opts index fb30c334b..60303aa74 100644 --- a/test/min.fromasm.imprecise.no-opts +++ b/test/min.fromasm.imprecise.no-opts @@ -1,13 +1,14 @@ (module (memory 256 256) - (import "env" "tempDoublePtr" (global $tDP i32)) + (import "env" "tempDoublePtr" (global $tDP$asm2wasm$import i32)) (import "env" "memory" (memory $memory)) (import "env" "table" (table $table)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "floats" (func $floats)) (export "getTempRet0" (func $ub)) - (global $M i32 (i32.const 0)) + (global $tDP (mut i32) (get_global $tDP$asm2wasm$import)) + (global $M (mut i32) (i32.const 0)) (func $floats (param $f f32) (result f32) (local $t f32) (return diff --git a/test/min.fromasm.no-opts b/test/min.fromasm.no-opts index fb30c334b..60303aa74 100644 --- a/test/min.fromasm.no-opts +++ b/test/min.fromasm.no-opts @@ -1,13 +1,14 @@ (module (memory 256 256) - (import "env" "tempDoublePtr" (global $tDP i32)) + (import "env" "tempDoublePtr" (global $tDP$asm2wasm$import i32)) (import "env" "memory" (memory $memory)) (import "env" "table" (table $table)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "floats" (func $floats)) (export "getTempRet0" (func $ub)) - (global $M i32 (i32.const 0)) + (global $tDP (mut i32) (get_global $tDP$asm2wasm$import)) + (global $M (mut i32) (i32.const 0)) (func $floats (param $f f32) (result f32) (local $t f32) (return diff --git a/test/unit.fromasm b/test/unit.fromasm index fe8b616f4..300ac4a5b 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -9,11 +9,11 @@ (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$dd (func (param f64) (result f64))) (type $FUNCSIG$i (func (result i32))) - (import "global" "NaN" (global $t f64)) - (import "global" "Infinity" (global $u f64)) - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) - (import "env" "gb" (global $n i32)) - (import "env" "STACKTOP" (global $STACKTOP i32)) + (import "global" "NaN" (global $t$asm2wasm$import f64)) + (import "global" "Infinity" (global $u$asm2wasm$import f64)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "gb" (global $n$asm2wasm$import i32)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32))) (import "env" "abort" (func $abort (param f64) (result f64))) (import "env" "print" (func $print (param i32))) @@ -28,8 +28,13 @@ (import "env" "tableBase" (global $tableBase i32)) (export "big_negative" (func $big_negative)) (export "pick" (func $big_negative)) - (global $Int i32 (i32.const 0)) - (global $Double f64 (f64.const 0)) + (global $t (mut f64) (get_global $t$asm2wasm$import)) + (global $u (mut f64) (get_global $u$asm2wasm$import)) + (global $Int (mut i32) (i32.const 0)) + (global $Double (mut f64) (f64.const 0)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $n (mut i32) (get_global $n$asm2wasm$import)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) (table 10 10 anyfunc) (elem (i32.const 0) $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) (func $big_negative diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index 8752f179a..3238ef902 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -6,11 +6,11 @@ (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$dd (func (param f64) (result f64))) (type $FUNCSIG$i (func (result i32))) - (import "global" "NaN" (global $t f64)) - (import "global" "Infinity" (global $u f64)) - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) - (import "env" "gb" (global $n i32)) - (import "env" "STACKTOP" (global $STACKTOP i32)) + (import "global" "NaN" (global $t$asm2wasm$import f64)) + (import "global" "Infinity" (global $u$asm2wasm$import f64)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "gb" (global $n$asm2wasm$import i32)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32))) (import "env" "abort" (func $abort (param f64) (result f64))) (import "env" "print" (func $print (param i32))) @@ -23,8 +23,13 @@ (import "env" "tableBase" (global $tableBase i32)) (export "big_negative" (func $big_negative)) (export "pick" (func $big_negative)) - (global $Int i32 (i32.const 0)) - (global $Double f64 (f64.const 0)) + (global $t (mut f64) (get_global $t$asm2wasm$import)) + (global $u (mut f64) (get_global $u$asm2wasm$import)) + (global $Int (mut i32) (i32.const 0)) + (global $Double (mut f64) (f64.const 0)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $n (mut i32) (get_global $n$asm2wasm$import)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) (table 10 10 anyfunc) (elem (i32.const 0) $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) (func $big_negative diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index 91118673a..e8bb300b0 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -6,11 +6,11 @@ (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$dd (func (param f64) (result f64))) (type $FUNCSIG$i (func (result i32))) - (import "global" "NaN" (global $t f64)) - (import "global" "Infinity" (global $u f64)) - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) - (import "env" "gb" (global $n i32)) - (import "env" "STACKTOP" (global $STACKTOP i32)) + (import "global" "NaN" (global $t$asm2wasm$import f64)) + (import "global" "Infinity" (global $u$asm2wasm$import f64)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "gb" (global $n$asm2wasm$import i32)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32))) (import "env" "abort" (func $abort (param f64) (result f64))) (import "env" "print" (func $print (param i32))) @@ -23,8 +23,13 @@ (import "env" "tableBase" (global $tableBase i32)) (export "big_negative" (func $big_negative)) (export "pick" (func $exportMe)) - (global $Int i32 (i32.const 0)) - (global $Double f64 (f64.const 0)) + (global $t (mut f64) (get_global $t$asm2wasm$import)) + (global $u (mut f64) (get_global $u$asm2wasm$import)) + (global $Int (mut i32) (i32.const 0)) + (global $Double (mut f64) (f64.const 0)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $n (mut i32) (get_global $n$asm2wasm$import)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) (table 10 10 anyfunc) (elem (i32.const 0) $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index aeece2db3..09fb6fc6f 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -8,11 +8,11 @@ (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$dd (func (param f64) (result f64))) (type $FUNCSIG$i (func (result i32))) - (import "global" "NaN" (global $t f64)) - (import "global" "Infinity" (global $u f64)) - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) - (import "env" "gb" (global $n i32)) - (import "env" "STACKTOP" (global $STACKTOP i32)) + (import "global" "NaN" (global $t$asm2wasm$import f64)) + (import "global" "Infinity" (global $u$asm2wasm$import f64)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "gb" (global $n$asm2wasm$import i32)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32))) (import "env" "abort" (func $abort (param f64) (result f64))) (import "env" "print" (func $print (param i32))) @@ -27,8 +27,13 @@ (import "env" "tableBase" (global $tableBase i32)) (export "big_negative" (func $big_negative)) (export "pick" (func $exportMe)) - (global $Int i32 (i32.const 0)) - (global $Double f64 (f64.const 0)) + (global $t (mut f64) (get_global $t$asm2wasm$import)) + (global $u (mut f64) (get_global $u$asm2wasm$import)) + (global $Int (mut i32) (i32.const 0)) + (global $Double (mut f64) (f64.const 0)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $n (mut i32) (get_global $n$asm2wasm$import)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) (table 10 10 anyfunc) (elem (i32.const 0) $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative -- cgit v1.2.3 From e9e6b5aeee24f36e92c1e02de6eff31154ca4f07 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 19 Sep 2016 20:36:33 -0700 Subject: import parsing fixes --- src/asm_v_wasm.h | 10 ++++++++++ src/wasm-s-parser.h | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/asm_v_wasm.h b/src/asm_v_wasm.h index 7a4a0be31..53881861c 100644 --- a/src/asm_v_wasm.h +++ b/src/asm_v_wasm.h @@ -54,6 +54,16 @@ std::string getSig(WasmType result, const ListType& operands) { return ret; } +template +std::string getSigFromStructs(WasmType result, const ListType& operands) { + std::string ret; + ret += getSig(result); + for (auto operand : operands) { + ret += getSig(operand.type); + } + return ret; +} + WasmType sigToWasmType(char sig); FunctionType* sigToFunctionType(std::string sig); diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 6280de7d3..592c84803 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -571,6 +571,18 @@ private: } } } + // see https://github.com/WebAssembly/spec/pull/301 + if (type.isNull()) { + // if no function type name provided, then we generated one + std::unique_ptr functionType = std::unique_ptr(sigToFunctionType(getSigFromStructs(result, params))); + for (auto& existing : wasm.functionTypes) { + if (existing->structuralComparison(*functionType)) { + type = existing->name; + break; + } + } + if (!type.is()) throw ParseException("no function type [internal error?]", s.line, s.col); + } if (importModule.is()) { // this is an import, actually assert(preParseImport); @@ -603,18 +615,6 @@ private: body = allocator.alloc(); } if (currFunction->result != result) throw ParseException("bad func declaration", s.line, s.col); - // see https://github.com/WebAssembly/spec/pull/301 - if (type.isNull()) { - // if no function type name provided, then we generated one - std::unique_ptr functionType = std::unique_ptr(sigToFunctionType(getSig(currFunction.get()))); - for (auto& existing : wasm.functionTypes) { - if (existing->structuralComparison(*functionType)) { - type = existing->name; - break; - } - } - if (!type.is()) throw ParseException("no function type [internal error?]", s.line, s.col); - } currFunction->body = body; currFunction->type = type; -- cgit v1.2.3 From 552d700c7e21afae03e55b6d6574a67946510972 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 10:38:36 -0700 Subject: global importing fixes: use the right counter for globals and for functions --- src/tools/wasm-shell.cpp | 13 ++++++++++- src/wasm-s-parser.h | 60 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 59 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp index e0bc5d7e9..320ed01e9 100644 --- a/src/tools/wasm-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -38,6 +38,7 @@ Name ASSERT_RETURN("assert_return"), ASSERT_TRAP("assert_trap"), ASSERT_INVALID("assert_invalid"), ASSERT_MALFORMED("assert_malformed"), + ASSERT_UNLINKABLE("assert_unlinkable"), INVOKE("invoke"), GET("get"); @@ -139,7 +140,7 @@ static void run_asserts(Name moduleName, size_t* i, bool* checked, Module* wasm, Colors::green(std::cerr); std::cerr << " [line: " << curr.line << "]\n"; Colors::normal(std::cerr); - if (id == ASSERT_INVALID || id == ASSERT_MALFORMED) { + if (id == ASSERT_INVALID || id == ASSERT_MALFORMED || id == ASSERT_UNLINKABLE) { // a module invalidity test Module wasm; bool invalid = false; @@ -155,6 +156,16 @@ static void run_asserts(Name moduleName, size_t* i, bool* checked, Module* wasm, // maybe parsed ok, but otherwise incorrect invalid = !WasmValidator().validate(wasm); } + if (!invalid && id == ASSERT_UNLINKABLE) { + // validate "instantiating" the mdoule + for (auto& import : wasm.imports) { + if (import->module != SPECTEST || import->base != PRINT) { + std::cerr << "unknown import: " << import->module << '.' << import->base << '\n'; + invalid = true; + break; + } + } + } if (!invalid) { Colors::red(std::cerr); std::cerr << "[should have been invalid]\n"; diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 592c84803..0d2a44407 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -80,7 +80,7 @@ public: } Element* operator[](unsigned i) { - if (i >= list().size()) throw ParseException("expected more elements in list", line, col); + if (i >= list().size()) assert(0 && "expected more elements in list"); return list()[i]; } @@ -270,13 +270,12 @@ class SExpressionWasmBuilder { MixedArena& allocator; std::vector functionNames; int functionCounter; - int importCounter; int globalCounter; std::map functionTypes; // we need to know function return types before we parse their contents public: // Assumes control of and modifies the input. - SExpressionWasmBuilder(Module& wasm, Element& module, Name* moduleName = nullptr) : wasm(wasm), allocator(wasm.allocator), importCounter(0), globalCounter(0) { + SExpressionWasmBuilder(Module& wasm, Element& module, Name* moduleName = nullptr) : wasm(wasm), allocator(wasm.allocator), globalCounter(0) { assert(module[0]->str() == MODULE); if (module.size() == 1) return; Index i = 1; @@ -385,6 +384,7 @@ private: if (id == IMPORT) parseImport(curr); if (isImport(curr)) { if (id == FUNC) parseFunction(curr, true /* preParseImport */); + else if (id == GLOBAL) parseGlobal(curr, true /* preParseImport */); else throw ParseException("fancy import we don't support yet", curr.line, curr.col); } } @@ -589,9 +589,8 @@ private: std::unique_ptr im = make_unique(); im->name = name; if (!im->name.is()) { - im->name = Name::fromInt(importCounter); + im->name = name; } - importCounter++; im->module = importModule; im->base = importBase; im->kind = Import::Function; @@ -640,6 +639,10 @@ private: abort(); } + bool isWasmType(IString str) { + return stringToWasmType(str, true) != none; + } + public: Expression* parseExpression(Element* s) { return parseExpression(*s); @@ -1562,12 +1565,26 @@ private: Index newStyleInner = 1; if (s.size() > 3 && s[3]->isStr()) { im->name = s[i++]->str(); - } else if (newStyle && (*s[3])[newStyleInner]->isStr()) { - im->name = (*s[3])[newStyleInner++]->str(); - } else { - im->name = Name::fromInt(importCounter); + } else if (newStyle && newStyleInner < s[3]->size() && (*s[3])[newStyleInner]->isStr()) { + auto str = (*s[3])[newStyleInner]->str(); + if (!isWasmType(str)) { + im->name = str; + newStyleInner++; + } + } + if (!im->name.is()) { + if (im->kind == Import::Function) { + im->name = Name::fromInt(functionCounter++); + } else if (im->kind == Import::Global) { + im->name = Name::fromInt(globalCounter++); + } else if (im->kind == Import::Memory) { + im->name = Name::fromInt(0); + } else if (im->kind == Import::Table) { + im->name = Name::fromInt(0); + } else { + WASM_UNREACHABLE(); + } } - importCounter++; if (!s[i]->quoted()) { if (s[i]->str() == MEMORY) { im->kind = Import::Memory; @@ -1626,7 +1643,7 @@ private: wasm.addImport(im.release()); } - void parseGlobal(Element& s) { + void parseGlobal(Element& s, bool preParseImport = false) { std::unique_ptr global = make_unique(); size_t i = 1; if (s[i]->dollared()) { @@ -1638,7 +1655,8 @@ private: bool mutable_ = false; WasmType type = none; bool exported = false; - while (s[i]->isList()) { + Name importModule, importBase; + while (i < s.size() && s[i]->isList()) { auto& inner = *s[i]; if (inner[0]->str() == EXPORT) { auto ex = make_unique(); @@ -1650,7 +1668,9 @@ private: exported = true; i++; } else if (inner[0]->str() == IMPORT) { - throw ParseException("TODO: import in the middle of a global definition", s.line, s.col); + importModule = inner[1]->str(); + importBase = inner[2]->str(); + i++; } else if (inner[0]->str() == MUT) { mutable_ = true; type = stringToWasmType(inner[1]->str()); @@ -1663,6 +1683,20 @@ private: if (type == none) { type = stringToWasmType(s[i++]->str()); } + if (importModule.is()) { + // this is an import, actually + assert(preParseImport); + if (mutable_) throw ParseException("cannot import a mutable global", s.line, s.col); + std::unique_ptr im = make_unique(); + im->name = global->name; + im->module = importModule; + im->base = importBase; + im->kind = Import::Global; + im->globalType = type; + wasm.addImport(im.release()); + return; + } + assert(!preParseImport); global->type = type; global->init = parseExpression(s[i++]); global->mutable_ = mutable_; -- cgit v1.2.3 From 1338ad989ba30007bc1ba7f0fd05237a9fbec474 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 11:04:14 -0700 Subject: support spectest.global --- src/shell-interface.h | 15 ++++++++++++++- src/wasm-interpreter.h | 6 +++++- src/wasm-s-parser.h | 8 ++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/shell-interface.h b/src/shell-interface.h index ee9ff166a..4d125ea09 100644 --- a/src/shell-interface.h +++ b/src/shell-interface.h @@ -111,7 +111,20 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { } } - void importGlobals(std::map& globals, Module& wasm) override {} + void importGlobals(std::map& globals, Module& wasm) override { + // add spectest globals + for (auto& import : wasm.imports) { + if (import->kind == Import::Global && import->module == SPECTEST && import->base == GLOBAL) { + switch (import->globalType) { + case i32: globals[import->name] = Literal(int32_t(666)); break; + case i64: globals[import->name] = Literal(int64_t(666)); break; + case f32: globals[import->name] = Literal(float(666.6)); break; + case f64: globals[import->name] = Literal(double(666.6)); break; + default: WASM_UNREACHABLE(); + } + } + } + } Literal callImport(Import *import, LiteralList& arguments) override { if (import->module == SPECTEST && import->base == PRINT) { diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index f699ba6f8..9bd813b84 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -707,6 +707,7 @@ public: auto name = curr->name; NOTE_EVAL1(name); NOTE_EVAL1(instance.globals[name]); + assert(instance.globals.find(name) != instance.globals.end()); return instance.globals[name]; } Flow visitSetGlobal(SetGlobal *curr) { @@ -787,7 +788,10 @@ public: assert(!flow.breaking() || flow.breakTo == RETURN_FLOW); // cannot still be breaking, it means we missed our stop Literal ret = flow.value; if (function->result == none) ret = Literal(); - assert(function->result == ret.type); + if (function->result != ret.type) { + std::cerr << "calling " << function->name << " resulted in " << ret << " but the function type is " << function->result << '\n'; + abort(); + } callDepth = previousCallDepth; // may decrease more than one, if we jumped up the stack // if we jumped up the stack, we also need to pop higher frames while (functionStack.size() > previousFunctionStackSize) { diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 0d2a44407..525cc29f7 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1646,7 +1646,7 @@ private: void parseGlobal(Element& s, bool preParseImport = false) { std::unique_ptr global = make_unique(); size_t i = 1; - if (s[i]->dollared()) { + if (s[i]->dollared() && !(s[i]->isStr() && isWasmType(s[i]->str()))) { global->name = s[i++]->str(); } else { global->name = Name::fromInt(globalCounter); @@ -1698,7 +1698,11 @@ private: } assert(!preParseImport); global->type = type; - global->init = parseExpression(s[i++]); + if (i < s.size()) { + global->init = parseExpression(s[i++]); + } else { + throw ParseException("global without init", s.line, s.col); + } global->mutable_ = mutable_; assert(i == s.size()); wasm.addGlobal(global.release()); -- cgit v1.2.3 From 469d90aaf3d708ffcb0f9f28b29120524055ba6f Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 11:13:23 -0700 Subject: validate spectest.print as a function --- src/tools/wasm-shell.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp index 320ed01e9..83d39c9d4 100644 --- a/src/tools/wasm-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -159,7 +159,13 @@ static void run_asserts(Name moduleName, size_t* i, bool* checked, Module* wasm, if (!invalid && id == ASSERT_UNLINKABLE) { // validate "instantiating" the mdoule for (auto& import : wasm.imports) { - if (import->module != SPECTEST || import->base != PRINT) { + if (import->module == SPECTEST && import->base == PRINT) { + if (import->kind != Import::Function) { + std::cerr << "spectest.print should be a function, but is " << import->kind << '\n'; + invalid = true; + break; + } + } else { std::cerr << "unknown import: " << import->module << '.' << import->base << '\n'; invalid = true; break; -- cgit v1.2.3 From 6e6abe73ddf77755c08ba473c52d111fa8fda768 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 11:13:46 -0700 Subject: mark table as present if seen as an import --- src/wasm-s-parser.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 525cc29f7..0ab2ed0dc 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1556,6 +1556,7 @@ private: im->kind = Import::Memory; } else if ((*s[3])[0]->str() == TABLE) { im->kind = Import::Table; + seenTable = true; } else if ((*s[3])[0]->str() == GLOBAL) { im->kind = Import::Global; } else { -- cgit v1.2.3 From 4a2c27df27f3415ecd9950110ceddde84008dae4 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 11:46:38 -0700 Subject: table parsing and executing fixes --- src/shell-interface.h | 3 ++- src/wasm-s-parser.h | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/shell-interface.h b/src/shell-interface.h index 4d125ea09..8cb7c2672 100644 --- a/src/shell-interface.h +++ b/src/shell-interface.h @@ -143,7 +143,8 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { Literal callTable(Index index, LiteralList& arguments, WasmType result, ModuleInstance& instance) override { if (index >= table.size()) trap("callTable overflow"); - auto* func = instance.wasm.getFunction(table[index]); + auto* func = instance.wasm.checkFunction(table[index]); + if (!func) trap("uninitialized table element"); if (func->params.size() != arguments.size()) trap("callIndirect: bad # of arguments"); for (size_t i = 0; i < func->params.size(); i++) { if (func->params[i] != arguments[i].type) { diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 0ab2ed0dc..fde62d7ce 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -62,6 +62,8 @@ class Element { bool dollared_; bool quoted_; + #define element_assert(condition) assert((condition) ? true : (std::cerr << "on: " << *this << '\n' && 0)); + public: Element(MixedArena& allocator) : isList_(true), list_(allocator), line(-1), col(-1) {} @@ -80,7 +82,7 @@ public: } Element* operator[](unsigned i) { - if (i >= list().size()) assert(0 && "expected more elements in list"); + if (i >= list().size()) element_assert(0 && "expected more elements in list"); return list()[i]; } @@ -91,12 +93,12 @@ public: // string methods IString str() { - assert(!isList_); + element_assert(!isList_); return str_; } const char* c_str() { - assert(!isList_); + element_assert(!isList_); return str_.str; } @@ -1640,6 +1642,13 @@ private: im->globalType = stringToWasmType(inner2[1]->str()); throw ParseException("cannot import a mutable global", s.line, s.col); } + } else if (im->kind == Import::Table) { + if (j < inner.size() - 1) { + wasm.table.initial = atoi(inner[j++]->c_str()); + } + if (j < inner.size() - 1) { + wasm.table.max = atoi(inner[j++]->c_str()); + } } wasm.addImport(im.release()); } @@ -1760,13 +1769,11 @@ private: void parseElem(Element& s, Index i = 1) { if (!seenTable) throw ParseException("elem without table", s.line, s.col); - Expression* offset; - if (s[i]->isList()) { - // there is an init expression - offset = parseExpression(s[i++]); - } else { - offset = allocator.alloc()->set(Literal(int32_t(0))); + if (!s[i]->isList()) { + // the table is named + i++; } + auto* offset = parseExpression(s[i++]); Table::Segment segment(offset); for (; i < s.size(); i++) { segment.data.push_back(getFunctionName(*s[i])); -- cgit v1.2.3 From 48a0da1be94a8cabb36dc84d0bc6203c20c22b15 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 12:01:44 -0700 Subject: memory and table parsing fixes --- src/wasm-s-parser.h | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index fde62d7ce..6d9f4aec2 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -387,6 +387,7 @@ private: if (isImport(curr)) { if (id == FUNC) parseFunction(curr, true /* preParseImport */); else if (id == GLOBAL) parseGlobal(curr, true /* preParseImport */); + else if (id == TABLE) parseTable(curr, true /* preParseImport */); else throw ParseException("fancy import we don't support yet", curr.line, curr.col); } } @@ -1490,13 +1491,11 @@ private: void parseData(Element& s) { if (!hasMemory) throw ParseException("data but no memory"); Index i = 1; - Expression* offset; - if (i < s.size() && s[i]->isList()) { - // there is an init expression - offset = parseExpression(s[i++]); - } else { - offset = allocator.alloc()->set(Literal(int32_t(0))); + if (!s[i]->isList()) { + // the memory is named + i++; } + auto* offset = parseExpression(s[i++]); std::vector data; while (i < s.size()) { const char *input = s[i++]->c_str(); @@ -1556,8 +1555,10 @@ private: im->kind = Import::Function; } else if ((*s[3])[0]->str() == MEMORY) { im->kind = Import::Memory; + hasMemory = true; } else if ((*s[3])[0]->str() == TABLE) { im->kind = Import::Table; + if (seenTable) throw ParseException("more than one table"); seenTable = true; } else if ((*s[3])[0]->str() == GLOBAL) { im->kind = Import::Global; @@ -1649,6 +1650,13 @@ private: if (j < inner.size() - 1) { wasm.table.max = atoi(inner[j++]->c_str()); } + } else if (im->kind == Import::Memory) { + if (j < inner.size() - 1) { + wasm.memory.initial = atoi(inner[j++]->c_str()); + } + if (j < inner.size() - 1) { + wasm.memory.max = atoi(inner[j++]->c_str()); + } } wasm.addImport(im.release()); } @@ -1720,7 +1728,8 @@ private: bool seenTable = false; - void parseTable(Element& s) { + void parseTable(Element& s, bool preParseImport = false) { + if (seenTable) throw ParseException("more than one table"); seenTable = true; Index i = 1; if (i == s.size()) return; // empty table in old notation @@ -1728,6 +1737,7 @@ private: wasm.table.name = s[i++]->str(); } if (i == s.size()) return; + Name importModule, importBase; if (s[i]->isList()) { auto& inner = *s[i]; if (inner[0]->str() == EXPORT) { @@ -1738,6 +1748,10 @@ private: if (wasm.checkExport(ex->name)) throw ParseException("duplicate export", s.line, s.col); wasm.addExport(ex.release()); i++; + } else if (inner[0]->str() == IMPORT) { + importModule = inner[1]->str(); + importBase = inner[2]->str(); + i++; } else { WASM_UNREACHABLE(); } -- cgit v1.2.3 From 2aa7ba43b59782243cd4960df43c7936292c41f4 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 13:16:51 -0700 Subject: memory parsing fixes --- src/wasm-s-parser.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 6d9f4aec2..9ed38e8da 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -388,6 +388,7 @@ private: if (id == FUNC) parseFunction(curr, true /* preParseImport */); else if (id == GLOBAL) parseGlobal(curr, true /* preParseImport */); else if (id == TABLE) parseTable(curr, true /* preParseImport */); + else if (id == MEMORY) parseMemory(curr, true /* preParseImport */); else throw ParseException("fancy import we don't support yet", curr.line, curr.col); } } @@ -1432,12 +1433,14 @@ private: bool hasMemory = false; - void parseMemory(Element& s) { + void parseMemory(Element& s, bool preParseImport = false) { + if (hasMemory) throw ParseException("too many memories"); hasMemory = true; Index i = 1; if (s[i]->dollared()) { wasm.memory.name = s[i++]->str(); } + Name importModule, importBase; if (s[i]->isList()) { auto& inner = *s[i]; if (inner[0]->str() == EXPORT) { @@ -1448,6 +1451,10 @@ private: if (wasm.checkExport(ex->name)) throw ParseException("duplicate export", s.line, s.col); wasm.addExport(ex.release()); i++; + } else if (inner[0]->str() == IMPORT) { + importModule = inner[1]->str(); + importBase = inner[2]->str(); + i++; } else { assert(inner.size() > 0 ? inner[0]->str() != IMPORT : true); // (memory (data ..)) format @@ -1555,6 +1562,7 @@ private: im->kind = Import::Function; } else if ((*s[3])[0]->str() == MEMORY) { im->kind = Import::Memory; + if (hasMemory) throw ParseException("too many memories"); hasMemory = true; } else if ((*s[3])[0]->str() == TABLE) { im->kind = Import::Table; @@ -1650,11 +1658,12 @@ private: if (j < inner.size() - 1) { wasm.table.max = atoi(inner[j++]->c_str()); } + // ends with the table element type } else if (im->kind == Import::Memory) { - if (j < inner.size() - 1) { + if (j < inner.size()) { wasm.memory.initial = atoi(inner[j++]->c_str()); } - if (j < inner.size() - 1) { + if (j < inner.size()) { wasm.memory.max = atoi(inner[j++]->c_str()); } } -- cgit v1.2.3 From 947cd3f224623f2d1e76f3c6cc30487ea8fd79ef Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 13:45:16 -0700 Subject: memory and table printing fixes --- src/passes/Print.cpp | 44 ++++++++++++++++++---- test/emcc_O2_hello_world.fromasm | 6 +-- test/emcc_O2_hello_world.fromasm.imprecise | 6 +-- test/emcc_O2_hello_world.fromasm.imprecise.no-opts | 6 +-- test/emcc_O2_hello_world.fromasm.no-opts | 6 +-- test/emcc_hello_world.fromasm | 6 +-- test/emcc_hello_world.fromasm.imprecise | 6 +-- test/emcc_hello_world.fromasm.imprecise.no-opts | 6 +-- test/emcc_hello_world.fromasm.no-opts | 6 +-- test/empty.fromasm | 5 +-- test/empty.fromasm.imprecise | 5 +-- test/empty.fromasm.imprecise.no-opts | 5 +-- test/empty.fromasm.no-opts | 5 +-- test/hello_world.fromasm | 5 +-- test/hello_world.fromasm.imprecise | 5 +-- test/hello_world.fromasm.imprecise.no-opts | 5 +-- test/hello_world.fromasm.no-opts | 5 +-- test/memorygrowth.fromasm | 6 +-- test/memorygrowth.fromasm.imprecise | 6 +-- test/memorygrowth.fromasm.imprecise.no-opts | 6 +-- test/memorygrowth.fromasm.no-opts | 6 +-- test/min.fromasm | 5 +-- test/min.fromasm.imprecise | 5 +-- test/min.fromasm.imprecise.no-opts | 5 +-- test/min.fromasm.no-opts | 5 +-- test/two_sides.fromasm | 5 +-- test/two_sides.fromasm.imprecise | 5 +-- test/two_sides.fromasm.imprecise.no-opts | 5 +-- test/two_sides.fromasm.no-opts | 5 +-- test/unit.fromasm | 6 +-- test/unit.fromasm.imprecise | 6 +-- test/unit.fromasm.imprecise.no-opts | 6 +-- test/unit.fromasm.no-opts | 6 +-- 33 files changed, 100 insertions(+), 120 deletions(-) (limited to 'src') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 06a8758c5..363147b98 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -540,8 +540,8 @@ struct PrintSExpression : public Visitor { printText(o, curr->base.str) << ' '; switch (curr->kind) { case Export::Function: if (curr->functionType) visitFunctionType(curr->functionType, &curr->name); break; - case Export::Table: o << "(table " << curr->name << ")"; break; - case Export::Memory: o << "(memory " << curr->name << ")"; break; + case Export::Table: printTableHeader(&currModule->table); break; + case Export::Memory: printMemoryHeader(&currModule->memory); break; case Export::Global: o << "(global " << curr->name << ' ' << printWasmType(curr->globalType) << ")"; break; default: WASM_UNREACHABLE(); } @@ -606,11 +606,26 @@ struct PrintSExpression : public Visitor { } decIndent(); } - void visitTable(Table *curr) { + void printTableHeader(Table* curr) { printOpening(o, "table") << ' '; o << curr->initial; if (curr->max && curr->max != Table::kMaxSize) o << ' ' << curr->max; - o << " anyfunc)\n"; + o << " anyfunc)"; + } + void visitTable(Table *curr) { + // if table wasn't imported, declare it + bool found = false; + for (auto& import : currModule->imports) { + if (import->kind == Import::Table) { + found = true; + break; + } + } + if (!found) { + doIndent(o, indent); + printTableHeader(curr); + o << '\n'; + } doIndent(o, indent); for (auto& segment : curr->segments) { printOpening(o, "elem ", true); @@ -622,11 +637,26 @@ struct PrintSExpression : public Visitor { o << ')'; } } - void visitMemory(Memory* curr) { + void printMemoryHeader(Memory* curr) { printOpening(o, "memory") << ' '; o << curr->initial; if (curr->max && curr->max != Memory::kMaxSize) o << ' ' << curr->max; - o << ")\n"; + o << ")"; + } + void visitMemory(Memory* curr) { + // if memory wasn't imported, declare it + bool found = false; + for (auto& import : currModule->imports) { + if (import->kind == Import::Memory) { + found = true; + break; + } + } + if (!found) { + doIndent(o, indent); + printMemoryHeader(curr); + o << '\n'; + } for (auto segment : curr->segments) { doIndent(o, indent); printOpening(o, "data ", true); @@ -659,7 +689,6 @@ struct PrintSExpression : public Visitor { currModule = curr; printOpening(o, "module", true); incIndent(); - doIndent(o, indent); visitMemory(&curr->memory); if (curr->start.is()) { doIndent(o, indent); @@ -689,7 +718,6 @@ struct PrintSExpression : public Visitor { o << maybeNewLine; } if (curr->table.segments.size() > 0 || curr->table.initial > 0 || curr->table.max != Table::kMaxSize) { - doIndent(o, indent); visitTable(&curr->table); o << maybeNewLine; } diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm index 53a7cf917..624cd3fd1 100644 --- a/test/emcc_O2_hello_world.fromasm +++ b/test/emcc_O2_hello_world.fromasm @@ -1,5 +1,4 @@ (module - (memory 256 256) (data (get_global $memoryBase) "emcc_O2_hello_world.asm.js") (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) @@ -30,8 +29,8 @@ (import "env" "___syscall140" (func $___syscall140 (param i32 i32) (result i32))) (import "env" "___syscall146" (func $___syscall146 (param i32 i32) (result i32))) (import "asm2wasm" "i32u-div" (func $i32u-div (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 18 18 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_free" (func $_free)) @@ -82,7 +81,6 @@ (global $tempRet8 (mut i32) (i32.const 0)) (global $tempRet9 (mut i32) (i32.const 0)) (global $tempFloat (mut f64) (f64.const 0)) - (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $0 i32) (result i32) (local $1 i32) diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise index 603308902..7b84b9c38 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise +++ b/test/emcc_O2_hello_world.fromasm.imprecise @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) @@ -28,8 +27,8 @@ (import "env" "___unlock" (func $___unlock (param i32))) (import "env" "___syscall140" (func $___syscall140 (param i32 i32) (result i32))) (import "env" "___syscall146" (func $___syscall146 (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 18 18 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_free" (func $_free)) @@ -80,7 +79,6 @@ (global $tempRet8 (mut i32) (i32.const 0)) (global $tempRet9 (mut i32) (i32.const 0)) (global $tempFloat (mut f64) (f64.const 0)) - (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $0 i32) (result i32) (local $1 i32) diff --git a/test/emcc_O2_hello_world.fromasm.imprecise.no-opts b/test/emcc_O2_hello_world.fromasm.imprecise.no-opts index 97d2e41d0..0a5967f3e 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise.no-opts +++ b/test/emcc_O2_hello_world.fromasm.imprecise.no-opts @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) @@ -28,8 +27,8 @@ (import "env" "___unlock" (func $___unlock (param i32))) (import "env" "___syscall140" (func $___syscall140 (param i32 i32) (result i32))) (import "env" "___syscall146" (func $___syscall146 (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 18 18 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_free" (func $_free)) @@ -80,7 +79,6 @@ (global $tempRet8 (mut i32) (i32.const 0)) (global $tempRet9 (mut i32) (i32.const 0)) (global $tempFloat (mut f64) (f64.const 0)) - (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $i1 i32) (result i32) (local $i2 i32) diff --git a/test/emcc_O2_hello_world.fromasm.no-opts b/test/emcc_O2_hello_world.fromasm.no-opts index 48340942f..f40a19522 100644 --- a/test/emcc_O2_hello_world.fromasm.no-opts +++ b/test/emcc_O2_hello_world.fromasm.no-opts @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) @@ -29,8 +28,8 @@ (import "env" "___syscall140" (func $___syscall140 (param i32 i32) (result i32))) (import "env" "___syscall146" (func $___syscall146 (param i32 i32) (result i32))) (import "asm2wasm" "i32u-div" (func $i32u-div (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 18 18 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_free" (func $_free)) @@ -81,7 +80,6 @@ (global $tempRet8 (mut i32) (i32.const 0)) (global $tempRet9 (mut i32) (i32.const 0)) (global $tempFloat (mut f64) (f64.const 0)) - (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $i1 i32) (result i32) (local $i2 i32) diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index 26e13e794..f2074155b 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -1,5 +1,4 @@ (module - (memory 256 256) (data (get_global $memoryBase) "emcc_hello_world.asm.js") (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$id (func (param f64) (result i32))) @@ -39,8 +38,8 @@ (import "asm2wasm" "i32s-rem" (func $i32s-rem (param i32 i32) (result i32))) (import "asm2wasm" "i32u-rem" (func $i32u-rem (param i32 i32) (result i32))) (import "asm2wasm" "i32u-div" (func $i32u-div (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 18 18 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_i64Subtract" (func $_i64Subtract)) @@ -97,7 +96,6 @@ (global $tempRet8 (mut i32) (i32.const 0)) (global $tempRet9 (mut i32) (i32.const 0)) (global $tempFloat (mut f64) (f64.const 0)) - (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $0 i32) (result i32) (local $1 i32) diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise index e78774569..a43f347b1 100644 --- a/test/emcc_hello_world.fromasm.imprecise +++ b/test/emcc_hello_world.fromasm.imprecise @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) @@ -32,8 +31,8 @@ (import "env" "_pthread_cleanup_push" (func $_pthread_cleanup_push (param i32 i32))) (import "env" "_sysconf" (func $_sysconf (param i32) (result i32))) (import "env" "___syscall146" (func $___syscall146 (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 18 18 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_i64Subtract" (func $_i64Subtract)) @@ -90,7 +89,6 @@ (global $tempRet8 (mut i32) (i32.const 0)) (global $tempRet9 (mut i32) (i32.const 0)) (global $tempFloat (mut f64) (f64.const 0)) - (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $0 i32) (result i32) (local $1 i32) diff --git a/test/emcc_hello_world.fromasm.imprecise.no-opts b/test/emcc_hello_world.fromasm.imprecise.no-opts index e9335450b..fa62da5fd 100644 --- a/test/emcc_hello_world.fromasm.imprecise.no-opts +++ b/test/emcc_hello_world.fromasm.imprecise.no-opts @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) @@ -32,8 +31,8 @@ (import "env" "_pthread_cleanup_push" (func $_pthread_cleanup_push (param i32 i32))) (import "env" "_sysconf" (func $_sysconf (param i32) (result i32))) (import "env" "___syscall146" (func $___syscall146 (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 18 18 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_i64Subtract" (func $_i64Subtract)) @@ -90,7 +89,6 @@ (global $tempRet8 (mut i32) (i32.const 0)) (global $tempRet9 (mut i32) (i32.const 0)) (global $tempFloat (mut f64) (f64.const 0)) - (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $size i32) (result i32) (local $ret i32) diff --git a/test/emcc_hello_world.fromasm.no-opts b/test/emcc_hello_world.fromasm.no-opts index 9fa2a2895..6942c296b 100644 --- a/test/emcc_hello_world.fromasm.no-opts +++ b/test/emcc_hello_world.fromasm.no-opts @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$id (func (param f64) (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) @@ -38,8 +37,8 @@ (import "asm2wasm" "i32s-rem" (func $i32s-rem (param i32 i32) (result i32))) (import "asm2wasm" "i32u-rem" (func $i32u-rem (param i32 i32) (result i32))) (import "asm2wasm" "i32u-div" (func $i32u-div (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 18 18 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_i64Subtract" (func $_i64Subtract)) @@ -96,7 +95,6 @@ (global $tempRet8 (mut i32) (i32.const 0)) (global $tempRet9 (mut i32) (i32.const 0)) (global $tempFloat (mut f64) (f64.const 0)) - (table 18 18 anyfunc) (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $size i32) (result i32) (local $ret i32) diff --git a/test/empty.fromasm b/test/empty.fromasm index 67c1135d4..83d404801 100644 --- a/test/empty.fromasm +++ b/test/empty.fromasm @@ -1,8 +1,7 @@ (module - (memory 256 256) (data (get_global $memoryBase) "empty.asm.js") - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) ) diff --git a/test/empty.fromasm.imprecise b/test/empty.fromasm.imprecise index 5fbd4b5f8..7e9ff6f81 100644 --- a/test/empty.fromasm.imprecise +++ b/test/empty.fromasm.imprecise @@ -1,7 +1,6 @@ (module - (memory 256 256) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) ) diff --git a/test/empty.fromasm.imprecise.no-opts b/test/empty.fromasm.imprecise.no-opts index 5fbd4b5f8..7e9ff6f81 100644 --- a/test/empty.fromasm.imprecise.no-opts +++ b/test/empty.fromasm.imprecise.no-opts @@ -1,7 +1,6 @@ (module - (memory 256 256) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) ) diff --git a/test/empty.fromasm.no-opts b/test/empty.fromasm.no-opts index 5fbd4b5f8..7e9ff6f81 100644 --- a/test/empty.fromasm.no-opts +++ b/test/empty.fromasm.no-opts @@ -1,7 +1,6 @@ (module - (memory 256 256) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) ) diff --git a/test/hello_world.fromasm b/test/hello_world.fromasm index 23aba7d9d..02625d09e 100644 --- a/test/hello_world.fromasm +++ b/test/hello_world.fromasm @@ -1,8 +1,7 @@ (module - (memory 256 256) (data (get_global $memoryBase) "hello_world.asm.js") - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "add" (func $add)) diff --git a/test/hello_world.fromasm.imprecise b/test/hello_world.fromasm.imprecise index 6bfc4bf68..21ac8112c 100644 --- a/test/hello_world.fromasm.imprecise +++ b/test/hello_world.fromasm.imprecise @@ -1,7 +1,6 @@ (module - (memory 256 256) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "add" (func $add)) diff --git a/test/hello_world.fromasm.imprecise.no-opts b/test/hello_world.fromasm.imprecise.no-opts index 31ce2e573..8ef16e1e0 100644 --- a/test/hello_world.fromasm.imprecise.no-opts +++ b/test/hello_world.fromasm.imprecise.no-opts @@ -1,7 +1,6 @@ (module - (memory 256 256) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "add" (func $add)) diff --git a/test/hello_world.fromasm.no-opts b/test/hello_world.fromasm.no-opts index 31ce2e573..8ef16e1e0 100644 --- a/test/hello_world.fromasm.no-opts +++ b/test/hello_world.fromasm.no-opts @@ -1,7 +1,6 @@ (module - (memory 256 256) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "add" (func $add)) diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm index 9c335557f..7847fa1dc 100644 --- a/test/memorygrowth.fromasm +++ b/test/memorygrowth.fromasm @@ -1,5 +1,4 @@ (module - (memory 256 256) (data (get_global $memoryBase) "memorygrowth.asm.js") (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) @@ -26,8 +25,8 @@ (import "env" "___unlock" (func $xa (param i32))) (import "env" "___syscall146" (func $ya (param i32 i32) (result i32))) (import "asm2wasm" "i32u-div" (func $i32u-div (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 8 8 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_free" (func $fb)) @@ -80,7 +79,6 @@ (global $S (mut i32) (i32.const 0)) (global $T (mut i32) (i32.const 0)) (global $za (mut f64) (f64.const 0)) - (table 8 8 anyfunc) (elem (i32.const 0) $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $0 i32) (result i32) (local $1 i32) diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise index 258fbd3ad..febb33861 100644 --- a/test/memorygrowth.fromasm.imprecise +++ b/test/memorygrowth.fromasm.imprecise @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) @@ -24,8 +23,8 @@ (import "env" "___syscall54" (func $wa (param i32 i32) (result i32))) (import "env" "___unlock" (func $xa (param i32))) (import "env" "___syscall146" (func $ya (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 8 8 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_free" (func $fb)) @@ -78,7 +77,6 @@ (global $S (mut i32) (i32.const 0)) (global $T (mut i32) (i32.const 0)) (global $za (mut f64) (f64.const 0)) - (table 8 8 anyfunc) (elem (i32.const 0) $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $0 i32) (result i32) (local $1 i32) diff --git a/test/memorygrowth.fromasm.imprecise.no-opts b/test/memorygrowth.fromasm.imprecise.no-opts index cd2c80cc0..0de4e25b3 100644 --- a/test/memorygrowth.fromasm.imprecise.no-opts +++ b/test/memorygrowth.fromasm.imprecise.no-opts @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) @@ -24,8 +23,8 @@ (import "env" "___syscall54" (func $wa (param i32 i32) (result i32))) (import "env" "___unlock" (func $xa (param i32))) (import "env" "___syscall146" (func $ya (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 8 8 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_free" (func $fb)) @@ -78,7 +77,6 @@ (global $S (mut i32) (i32.const 0)) (global $T (mut i32) (i32.const 0)) (global $za (mut f64) (f64.const 0)) - (table 8 8 anyfunc) (elem (i32.const 0) $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $a i32) (result i32) (local $b i32) diff --git a/test/memorygrowth.fromasm.no-opts b/test/memorygrowth.fromasm.no-opts index 0b50f1248..124e87a18 100644 --- a/test/memorygrowth.fromasm.no-opts +++ b/test/memorygrowth.fromasm.no-opts @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) @@ -25,8 +24,8 @@ (import "env" "___unlock" (func $xa (param i32))) (import "env" "___syscall146" (func $ya (param i32 i32) (result i32))) (import "asm2wasm" "i32u-div" (func $i32u-div (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 8 8 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_free" (func $fb)) @@ -79,7 +78,6 @@ (global $S (mut i32) (i32.const 0)) (global $T (mut i32) (i32.const 0)) (global $za (mut f64) (f64.const 0)) - (table 8 8 anyfunc) (elem (i32.const 0) $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $a i32) (result i32) (local $b i32) diff --git a/test/min.fromasm b/test/min.fromasm index a52a6e876..0c5a14670 100644 --- a/test/min.fromasm +++ b/test/min.fromasm @@ -1,9 +1,8 @@ (module - (memory 256 256) (data (get_global $memoryBase) "min.asm.js") (import "env" "tempDoublePtr" (global $tDP$asm2wasm$import i32)) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "floats" (func $floats)) diff --git a/test/min.fromasm.imprecise b/test/min.fromasm.imprecise index 495c600d1..485e2593c 100644 --- a/test/min.fromasm.imprecise +++ b/test/min.fromasm.imprecise @@ -1,8 +1,7 @@ (module - (memory 256 256) (import "env" "tempDoublePtr" (global $tDP$asm2wasm$import i32)) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "floats" (func $floats)) diff --git a/test/min.fromasm.imprecise.no-opts b/test/min.fromasm.imprecise.no-opts index 60303aa74..89326688f 100644 --- a/test/min.fromasm.imprecise.no-opts +++ b/test/min.fromasm.imprecise.no-opts @@ -1,8 +1,7 @@ (module - (memory 256 256) (import "env" "tempDoublePtr" (global $tDP$asm2wasm$import i32)) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "floats" (func $floats)) diff --git a/test/min.fromasm.no-opts b/test/min.fromasm.no-opts index 60303aa74..89326688f 100644 --- a/test/min.fromasm.no-opts +++ b/test/min.fromasm.no-opts @@ -1,8 +1,7 @@ (module - (memory 256 256) (import "env" "tempDoublePtr" (global $tDP$asm2wasm$import i32)) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "floats" (func $floats)) diff --git a/test/two_sides.fromasm b/test/two_sides.fromasm index 9ddb1a9ac..e6595d04b 100644 --- a/test/two_sides.fromasm +++ b/test/two_sides.fromasm @@ -1,10 +1,9 @@ (module - (memory 256 256) (data (get_global $memoryBase) "two_sides.asm.js") (type $FUNCSIG$id (func (param f64) (result i32))) (import "asm2wasm" "f64-to-int" (func $f64-to-int (param f64) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_test" (func $_test)) diff --git a/test/two_sides.fromasm.imprecise b/test/two_sides.fromasm.imprecise index 1578c86da..428c56a97 100644 --- a/test/two_sides.fromasm.imprecise +++ b/test/two_sides.fromasm.imprecise @@ -1,7 +1,6 @@ (module - (memory 256 256) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_test" (func $_test)) diff --git a/test/two_sides.fromasm.imprecise.no-opts b/test/two_sides.fromasm.imprecise.no-opts index a8a338489..e695bc124 100644 --- a/test/two_sides.fromasm.imprecise.no-opts +++ b/test/two_sides.fromasm.imprecise.no-opts @@ -1,7 +1,6 @@ (module - (memory 256 256) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_test" (func $_test)) diff --git a/test/two_sides.fromasm.no-opts b/test/two_sides.fromasm.no-opts index 56c2062cf..cb693267a 100644 --- a/test/two_sides.fromasm.no-opts +++ b/test/two_sides.fromasm.no-opts @@ -1,9 +1,8 @@ (module - (memory 256 256) (type $FUNCSIG$id (func (param f64) (result i32))) (import "asm2wasm" "f64-to-int" (func $f64-to-int (param f64) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "_test" (func $_test)) diff --git a/test/unit.fromasm b/test/unit.fromasm index 300ac4a5b..fb9f239da 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -1,5 +1,4 @@ (module - (memory 256 256) (data (get_global $memoryBase) "unit.asm.js") (type $FUNCSIG$id (func (param f64) (result i32))) (type $FUNCSIG$ddd (func (param f64 f64) (result f64))) @@ -22,8 +21,8 @@ (import "asm2wasm" "f64-to-int" (func $f64-to-int (param f64) (result i32))) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "asm2wasm" "i32u-div" (func $i32u-div (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 10 10 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "big_negative" (func $big_negative)) @@ -35,7 +34,6 @@ (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) (global $n (mut i32) (get_global $n$asm2wasm$import)) (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) - (table 10 10 anyfunc) (elem (i32.const 0) $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) (func $big_negative (nop) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index 3238ef902..ad130ea82 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$ddd (func (param f64 f64) (result f64))) (type $FUNCSIG$vf (func (param f32))) (type $FUNCSIG$vi (func (param i32))) @@ -17,8 +16,8 @@ (import "env" "h" (func $h (param i32))) (import "env" "return_int" (func $return_int (result i32))) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 10 10 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "big_negative" (func $big_negative)) @@ -30,7 +29,6 @@ (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) (global $n (mut i32) (get_global $n$asm2wasm$import)) (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) - (table 10 10 anyfunc) (elem (i32.const 0) $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) (func $big_negative (nop) diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index e8bb300b0..636238f17 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$ddd (func (param f64 f64) (result f64))) (type $FUNCSIG$vf (func (param f32))) (type $FUNCSIG$vi (func (param i32))) @@ -17,8 +16,8 @@ (import "env" "h" (func $h (param i32))) (import "env" "return_int" (func $return_int (result i32))) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 10 10 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "big_negative" (func $big_negative)) @@ -30,7 +29,6 @@ (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) (global $n (mut i32) (get_global $n$asm2wasm$import)) (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) - (table 10 10 anyfunc) (elem (i32.const 0) $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative (local $temp f64) diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index 09fb6fc6f..0684c1464 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$id (func (param f64) (result i32))) (type $FUNCSIG$ddd (func (param f64 f64) (result f64))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) @@ -21,8 +20,8 @@ (import "asm2wasm" "f64-to-int" (func $f64-to-int (param f64) (result i32))) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "asm2wasm" "i32u-div" (func $i32u-div (param i32 i32) (result i32))) - (import "env" "memory" (memory $memory)) - (import "env" "table" (table $table)) + (import "env" "memory" (memory 256 256)) + (import "env" "table" (table 10 10 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (export "big_negative" (func $big_negative)) @@ -34,7 +33,6 @@ (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) (global $n (mut i32) (get_global $n$asm2wasm$import)) (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) - (table 10 10 anyfunc) (elem (i32.const 0) $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative (local $temp f64) -- cgit v1.2.3 From dc3990106d0363da5fc0e9e1de766459bf67161c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 13:55:19 -0700 Subject: max memory and table fixes --- src/wasm-s-parser.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 9ed38e8da..e1fa8fa19 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1657,6 +1657,8 @@ private: } if (j < inner.size() - 1) { wasm.table.max = atoi(inner[j++]->c_str()); + } else { + wasm.table.max = wasm.table.initial; } // ends with the table element type } else if (im->kind == Import::Memory) { @@ -1665,6 +1667,8 @@ private: } if (j < inner.size()) { wasm.memory.max = atoi(inner[j++]->c_str()); + } else { + wasm.memory.max = wasm.memory.initial; } } wasm.addImport(im.release()); -- cgit v1.2.3 From 3308ed63f2556dc969ea9fffd265705469e797e4 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 14:39:05 -0700 Subject: table elem parsing fixes --- src/wasm-s-parser.h | 35 ++++++++++++++++++++++++++++------- src/wasm-validator.h | 1 - 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index e1fa8fa19..e2c0dbcee 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -132,8 +132,12 @@ public: void dump() { std::cout << "dumping " << this << " : " << *this << ".\n"; } + + #undef element_assert }; +#define element_assert(condition, element) assert((condition) ? true : (std::cerr << "on: " << element << " at " << element.line << ":" << element.col << '\n' && 0)); + // // Generic S-Expression parsing into lists // @@ -655,7 +659,7 @@ public: #define abort_on(str) { throw ParseException(std::string("abort_on ") + str); } Expression* parseExpression(Element& s) { - if (!s.isList()) throw ParseException("invalid node for parseExpression, needed list", s.line, s.col); + element_assert(s.isList(), s); IString id = s[0]->str(); const char *str = id.str; const char *dot = strchr(str, '.'); @@ -1311,6 +1315,7 @@ private: } Expression* makeCallIndirect(Element& s) { + if (!seenTable) throw ParseException("no table"); auto ret = allocator.alloc(); IString type = s[1]->str(); auto* fullType = wasm.checkFunctionType(type); @@ -1773,8 +1778,12 @@ private: if (!s[i]->dollared()) { if (s[i]->str() == ANYFUNC) { // (table type (elem ..)) - parseElem(*s[i + 1]); - wasm.table.initial = wasm.table.max = wasm.table.segments[0].data.size(); + parseInnerElem(*s[i + 1]); + if (wasm.table.segments.size() > 0) { + wasm.table.initial = wasm.table.max = wasm.table.segments[0].data.size(); + } else { + wasm.table.initial = wasm.table.max = 0; + } return; } // first element isn't dollared, and isn't anyfunc. this could be old syntax for (table 0 1) which means function 0 and 1, or it could be (table initial max? type), look for type @@ -1790,17 +1799,29 @@ private: } } // old notation (table func1 func2 ..) - parseElem(s, i); - wasm.table.initial = wasm.table.max = wasm.table.segments[0].data.size(); + parseInnerElem(s, i); + if (wasm.table.segments.size() > 0) { + wasm.table.initial = wasm.table.max = wasm.table.segments[0].data.size(); + } else { + wasm.table.initial = wasm.table.max = 0; + } } - void parseElem(Element& s, Index i = 1) { - if (!seenTable) throw ParseException("elem without table", s.line, s.col); + void parseElem(Element& s) { + Index i = 1; if (!s[i]->isList()) { // the table is named i++; } auto* offset = parseExpression(s[i++]); + parseInnerElem(s, i, offset); + } + + void parseInnerElem(Element& s, Index i = 1, Expression* offset = nullptr) { + if (!seenTable) throw ParseException("elem without table", s.line, s.col); + if (!offset) { + offset = allocator.alloc()->set(Literal(int32_t(0))); + } Table::Segment segment(offset); for (; i < s.size(); i++) { segment.data.push_back(getFunctionName(*s[i])); diff --git a/src/wasm-validator.h b/src/wasm-validator.h index 6c6792228..988d1104d 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -179,7 +179,6 @@ public: } } void visitCallIndirect(CallIndirect *curr) { - shouldBeTrue(getModule()->table.segments.size() > 0, curr, "no table"); auto* type = getModule()->checkFunctionType(curr->fullType); if (!shouldBeTrue(!!type, curr, "call_indirect type must exist")) return; shouldBeEqualOrFirstIsUnreachable(curr->target->type, i32, curr, "indirect call target must be an i32"); -- cgit v1.2.3 From 98f2a79dd9ceb95c8df55d3fd755a886e65c567f Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 14:47:54 -0700 Subject: memory data parsing fixes --- src/wasm-s-parser.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index e2c0dbcee..b53ee44b5 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1463,7 +1463,7 @@ private: } else { assert(inner.size() > 0 ? inner[0]->str() != IMPORT : true); // (memory (data ..)) format - parseData(*s[i]); + parseInnerData(*s[i]); wasm.memory.initial = wasm.memory.segments[0].data.size(); return; } @@ -1508,6 +1508,10 @@ private: i++; } auto* offset = parseExpression(s[i++]); + parseInnerData(s, i, offset); + } + + void parseInnerData(Element& s, Index i = 1, Expression* offset = nullptr) { std::vector data; while (i < s.size()) { const char *input = s[i++]->c_str(); @@ -1515,6 +1519,9 @@ private: stringToBinary(input, size, data); } } + if (!offset) { + offset = allocator.alloc()->set(Literal(int32_t(0))); + } wasm.memory.segments.emplace_back(offset, data.data(), data.size()); } -- cgit v1.2.3 From 64bfe1d84db6c0b9b63aa27bb2c2cb1d79f3f504 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 16:18:21 -0700 Subject: function numbering fix in wasm-s-parser --- src/wasm-s-parser.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index b53ee44b5..f9a43e69b 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -304,12 +304,17 @@ public: binaryBuilder.read(); return; } + Index implementedFunctions = 0; functionCounter = 0; for (unsigned j = i; j < module.size(); j++) { - preParseFunctionType(*module[j]); - preParseImports(*module[j]); + auto& s = *module[j]; + preParseFunctionType(s); + preParseImports(s); + if (s[0]->str() == FUNC && !isImport(s)) { + implementedFunctions++; + } } - functionCounter = 0; + functionCounter -= implementedFunctions; // we go through the functions again, now parsing them, and the counter begins from where imports ended for (unsigned j = i; j < module.size(); j++) { parseModuleElement(*module[j]); } -- cgit v1.2.3 From e0b2af0827e98fb91f4ff90b57b7579da1608365 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Sep 2016 17:00:38 -0700 Subject: refactor wasm.h to remove numericIndex hacks, and move indexing to the parsers --- src/binaryen-c.cpp | 1 + src/passes/OptimizeInstructions.cpp | 23 ++++++----- src/wasm-binary.h | 10 +++-- src/wasm-interpreter.h | 12 +++--- src/wasm-s-parser.h | 52 ++++++++++++++++++------- src/wasm.h | 47 +++++----------------- test/passes/coalesce-locals-learning.txt | 4 +- test/passes/coalesce-locals-learning.wast | 4 +- test/passes/coalesce-locals.txt | 4 +- test/passes/coalesce-locals.wast | 4 +- test/passes/duplicate-function-elimination.txt | 2 +- test/passes/duplicate-function-elimination.wast | 2 +- test/passes/remove-unused-brs.txt | 2 +- test/passes/remove-unused-brs.wast | 2 +- 14 files changed, 88 insertions(+), 81 deletions(-) (limited to 'src') diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 3ce24bdbd..14fc4680d 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -128,6 +128,7 @@ BinaryenFunctionTypeRef BinaryenAddFunctionType(BinaryenModuleRef module, const auto* wasm = (Module*)module; auto* ret = new FunctionType; if (name) ret->name = name; + else ret->name = Name::fromInt(wasm->functionTypes.size()); ret->result = WasmType(result); for (BinaryenIndex i = 0; i < numParams; i++) { ret->params.push_back(WasmType(paramTypes[i])); diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 669a19b89..48639a341 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -55,15 +55,20 @@ struct PatternDatabase { input = strdup( #include "OptimizeInstructions.wast.processed" ); - SExpressionParser parser(input); - Element& root = *parser.root; - SExpressionWasmBuilder builder(wasm, *root[0]); - // parse module form - auto* func = wasm.getFunction("patterns"); - auto* body = func->body->cast(); - for (auto* item : body->list) { - auto* pair = item->cast(); - patternMap[pair->list[0]->_id].emplace_back(pair->list[0], pair->list[1]); + try { + SExpressionParser parser(input); + Element& root = *parser.root; + SExpressionWasmBuilder builder(wasm, *root[0]); + // parse module form + auto* func = wasm.getFunction("patterns"); + auto* body = func->body->cast(); + for (auto* item : body->list) { + auto* pair = item->cast(); + patternMap[pair->list[0]->_id].emplace_back(pair->list[0], pair->list[1]); + } + } catch (ParseException& p) { + p.dump(std::cerr); + Fatal() << "error in parsing wasm binary"; } } diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 1bc18e687..85aaf9279 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -652,7 +652,7 @@ public: if (debug) std::cerr << "write one at" << o.size() << std::endl; size_t sizePos = writeU32LEBPlaceholder(); size_t start = o.size(); - Function* function = wasm->getFunction(i); + Function* function = wasm->functions[i].get(); mappedLocals.clear(); numLocalsByType.clear(); if (debug) std::cerr << "writing" << function->name << std::endl; @@ -1495,6 +1495,7 @@ public: assert(numResults == 1); curr->result = getWasmType(); } + curr->name = Name::fromInt(wasm.functionTypes.size()); wasm.addFunctionType(curr); } } @@ -1526,7 +1527,7 @@ public: case Import::Function: { auto index = getU32LEB(); assert(index < wasm.functionTypes.size()); - curr->functionType = wasm.getFunctionType(index); + curr->functionType = wasm.functionTypes[index].get(); assert(curr->functionType->name.is()); functionImportIndexes.push_back(curr->name); break; @@ -1551,7 +1552,7 @@ public: for (size_t i = 0; i < num; i++) { if (debug) std::cerr << "read one" << std::endl; auto index = getU32LEB(); - functionTypes.push_back(wasm.getFunctionType(index)); + functionTypes.push_back(wasm.functionTypes[index].get()); } } @@ -1659,6 +1660,7 @@ public: curr->type = getWasmType(); curr->init = readExpression(); curr->mutable_ = true; // TODO + curr->name = Name("global$" + std::to_string(wasm.globals.size())); wasm.addGlobal(curr); } } @@ -1998,7 +2000,7 @@ public: if (debug) std::cerr << "zz node: CallIndirect" << std::endl; auto arity = getU32LEB(); WASM_UNUSED(arity); - auto* fullType = wasm.getFunctionType(getU32LEB()); + auto* fullType = wasm.functionTypes.at(getU32LEB()).get(); curr->fullType = fullType->name; auto num = fullType->params.size(); assert(num == arity); diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 9bd813b84..942ba1ab6 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -51,14 +51,14 @@ class Flow { public: Flow() {} Flow(Literal value) : value(value) {} - Flow(IString breakTo) : breakTo(breakTo) {} + Flow(Name breakTo) : breakTo(breakTo) {} Literal value; - IString breakTo; // if non-null, a break is going on + Name breakTo; // if non-null, a break is going on bool breaking() { return breakTo.is(); } - void clearIf(IString target) { + void clearIf(Name target) { if (breakTo == target) { breakTo.clear(); } @@ -589,7 +589,7 @@ private: std::vector functionStack; // Call a function, starting an invocation. - Literal callFunction(IString name, LiteralList& arguments) { + Literal callFunction(Name name, LiteralList& arguments) { // if the last call ended in a jump up the stack, it might have left stuff for us to clean up here callDepth = 0; functionStack.clear(); @@ -598,7 +598,7 @@ private: public: // Internal function call. Must be public so that callTable implementations can use it (refactor?) - Literal callFunctionInternal(IString name, LiteralList& arguments) { + Literal callFunctionInternal(Name name, LiteralList& arguments) { class FunctionScope { public: @@ -757,7 +757,7 @@ public: return Literal(int32_t(ret)); } case HasFeature: { - IString id = curr->nameOperand; + Name id = curr->nameOperand; if (id == WASM) return Literal(1); return Literal((int32_t)0); } diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index f9a43e69b..a914b6598 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -275,6 +275,8 @@ class SExpressionWasmBuilder { Module& wasm; MixedArena& allocator; std::vector functionNames; + std::vector functionTypeNames; + std::vector globalNames; int functionCounter; int globalCounter; std::map functionTypes; // we need to know function return types before we parse their contents @@ -346,8 +348,8 @@ private: if (curr.size() > 2) throw ParseException("invalid result arity", curr.line, curr.col); functionTypes[name] = stringToWasmType(curr[1]->str()); } else if (id == TYPE) { - Name typeName = curr[1]->str(); - if (!wasm.checkFunctionType(typeName)) throw ParseException("unknown function", curr.line, curr.col); + Name typeName = getFunctionTypeName(*curr[1]); + if (!wasm.checkFunctionType(typeName)) throw ParseException("unknown function type", curr.line, curr.col); type = wasm.getFunctionType(typeName); functionTypes[name] = type->result; } else if (id == PARAM && curr.size() > 1) { @@ -377,6 +379,8 @@ private: } } if (need) { + functionType->name = Name::fromInt(wasm.functionTypes.size()); + functionTypeNames.push_back(functionType->name); wasm.addFunctionType(functionType.release()); } } @@ -441,11 +445,22 @@ private: } else { // index size_t offset = atoi(s.str().c_str()); - if (offset >= functionNames.size()) throw ParseException("unknown function"); + if (offset >= functionNames.size()) throw ParseException("unknown function in getFunctionName"); return functionNames[offset]; } } + Name getFunctionTypeName(Element& s) { + if (s.dollared()) { + return s.str(); + } else { + // index + size_t offset = atoi(s.str().c_str()); + if (offset >= functionTypeNames.size()) throw ParseException("unknown function type in getFunctionTypeName"); + return functionTypeNames[offset]; + } + } + void parseStart(Element& s) { wasm.addStart(getFunctionName(*s[1])); } @@ -484,9 +499,18 @@ private: size_t i = 1; Name name, exportName; i = parseFunctionNames(s, name, exportName); - if (!name.is()) { - // unnamed, use an index - name = Name::fromInt(functionCounter); + if (!preParseImport) { + if (!name.is()) { + // unnamed, use an index + name = Name::fromInt(functionCounter); + } + functionCounter++; + } else { + // just preparsing, functionCounter was incremented by preParseFunctionType + if (!name.is()) { + // unnamed, use an index + name = functionNames[functionCounter - 1]; + } } if (exportName.is()) { auto ex = make_unique(); @@ -496,7 +520,6 @@ private: if (wasm.checkExport(ex->name)) throw ParseException("duplicate export", s.line, s.col); wasm.addExport(ex.release()); } - functionCounter++; Expression* body = nullptr; localIndex = 0; otherIndex = 0; @@ -555,7 +578,7 @@ private: if (curr.size() > 2) throw ParseException("invalid result arity", curr.line, curr.col); result = stringToWasmType(curr[1]->str()); } else if (id == TYPE) { - Name name = curr[1]->str(); + Name name = getFunctionTypeName(*curr[1]); type = name; if (!wasm.checkFunctionType(name)) throw ParseException("unknown function type"); FunctionType* type = wasm.getFunctionType(name); @@ -601,9 +624,6 @@ private: assert(preParseImport); std::unique_ptr im = make_unique(); im->name = name; - if (!im->name.is()) { - im->name = name; - } im->module = importModule; im->base = importBase; im->kind = Import::Function; @@ -629,7 +649,6 @@ private: if (currFunction->result != result) throw ParseException("bad func declaration", s.line, s.col); currFunction->body = body; currFunction->type = type; - wasm.addFunction(currFunction.release()); currLocalTypes.clear(); labelStack.clear(); @@ -1293,7 +1312,7 @@ private: } Expression* makeCall(Element& s) { - auto target = s[1]->str(); + auto target = getFunctionName(*s[1]); auto* import = wasm.checkImport(target); if (import && import->kind == Import::Function) { auto ret = allocator.alloc(); @@ -1604,8 +1623,10 @@ private: if (!im->name.is()) { if (im->kind == Import::Function) { im->name = Name::fromInt(functionCounter++); + functionNames.push_back(im->name); } else if (im->kind == Import::Global) { im->name = Name::fromInt(globalCounter++); + globalNames.push_back(im->name); } else if (im->kind == Import::Memory) { im->name = Name::fromInt(0); } else if (im->kind == Import::Table) { @@ -1700,6 +1721,7 @@ private: global->name = Name::fromInt(globalCounter); } globalCounter++; + globalNames.push_back(global->name); bool mutable_ = false; WasmType type = none; bool exported = false; @@ -1861,6 +1883,10 @@ private: type->result = stringToWasmType(curr[1]->str()); } } + if (!type->name.is()) { + type->name = Name::fromInt(wasm.functionTypes.size()); + } + functionTypeNames.push_back(type->name); wasm.addFunctionType(type.release()); } }; diff --git a/src/wasm.h b/src/wasm.h index 5c20a3a10..53b4e2938 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1552,12 +1552,6 @@ private: public: Module() {}; - FunctionType* getFunctionType(Index i) { assert(i < functionTypes.size()); return functionTypes[i].get(); } - Import* getImport(Index i) { assert(i < imports.size()); return imports[i].get(); } - Export* getExport(Index i) { assert(i < exports.size()); return exports[i].get(); } - Function* getFunction(Index i) { assert(i < functions.size()); return functions[i].get(); } - Global* getGlobal(Index i) { assert(i < globals.size()); return globals[i].get(); } - FunctionType* getFunctionType(Name name) { assert(functionTypesMap.count(name)); return functionTypesMap[name]; } Import* getImport(Name name) { assert(importsMap.count(name)); return importsMap[name]; } Export* getExport(Name name) { assert(exportsMap.count(name)); return exportsMap[name]; } @@ -1570,56 +1564,35 @@ public: Function* checkFunction(Name name) { if (!functionsMap.count(name)) return nullptr; return functionsMap[name]; } Global* checkGlobal(Name name) { if (!globalsMap.count(name)) return nullptr; return globalsMap[name]; } - FunctionType* checkFunctionType(Index i) { if (i >= functionTypes.size()) return nullptr; return functionTypes[i].get(); } - Import* checkImport(Index i) { if (i >= imports.size()) return nullptr; return imports[i].get(); } - Export* checkExport(Index i) { if (i >= exports.size()) return nullptr; return exports[i].get(); } - Function* checkFunction(Index i) { if (i >= functions.size()) return nullptr; return functions[i].get(); } - Global* checkGlobal(Index i) { if (i >= globals.size()) return nullptr; return globals[i].get(); } - void addFunctionType(FunctionType* curr) { - Name numericName = Name::fromInt(functionTypes.size()); // TODO: remove all these, assert on names already existing, do numeric stuff in wasm-s-parser etc. - if (curr->name.isNull()) { - curr->name = numericName; - } + assert(curr->name.is()); functionTypes.push_back(std::unique_ptr(curr)); + assert(functionTypesMap.find(curr->name) == functionTypesMap.end()); functionTypesMap[curr->name] = curr; - functionTypesMap[numericName] = curr; } void addImport(Import* curr) { - Name numericName = Name::fromInt(imports.size()); - if (curr->name.isNull()) { - curr->name = numericName; - } + assert(curr->name.is()); imports.push_back(std::unique_ptr(curr)); + assert(importsMap.find(curr->name) == importsMap.end()); importsMap[curr->name] = curr; - importsMap[numericName] = curr; } void addExport(Export* curr) { - Name numericName = Name::fromInt(exports.size()); - if (curr->name.isNull()) { - curr->name = numericName; - } + assert(curr->name.is()); exports.push_back(std::unique_ptr(curr)); + assert(exportsMap.find(curr->name) == exportsMap.end()); exportsMap[curr->name] = curr; - exportsMap[numericName] = curr; } void addFunction(Function* curr) { - Name numericName = Name::fromInt(functions.size()); - if (curr->name.isNull()) { - curr->name = numericName; - } + assert(curr->name.is()); functions.push_back(std::unique_ptr(curr)); + assert(functionsMap.find(curr->name) == functionsMap.end()); functionsMap[curr->name] = curr; - functionsMap[numericName] = curr; } void addGlobal(Global* curr) { - Name numericName = Name::fromInt(globals.size()); - if (curr->name.isNull()) { - curr->name = numericName; - } + assert(curr->name.is()); globals.push_back(std::unique_ptr(curr)); + assert(globalsMap.find(curr->name) == globalsMap.end()); globalsMap[curr->name] = curr; - globalsMap[numericName] = curr; } void addStart(const Name &s) { diff --git a/test/passes/coalesce-locals-learning.txt b/test/passes/coalesce-locals-learning.txt index f5622d097..06b96b497 100644 --- a/test/passes/coalesce-locals-learning.txt +++ b/test/passes/coalesce-locals-learning.txt @@ -281,7 +281,7 @@ (get_local $1) ) ) - (func $if-through2 (type $2) + (func $if-through3 (type $2) (local $0 i32) (local $1 i32) (set_local $0 @@ -440,7 +440,7 @@ (get_local $4) ) ) - (func $interfere-in-dead (type $2) + (func $interfere-in-dead4 (type $2) (local $0 i32) (local $1 i32) (block $block diff --git a/test/passes/coalesce-locals-learning.wast b/test/passes/coalesce-locals-learning.wast index 469a034ba..23fc9cba8 100644 --- a/test/passes/coalesce-locals-learning.wast +++ b/test/passes/coalesce-locals-learning.wast @@ -289,7 +289,7 @@ (get_local $y) ) ) - (func $if-through2 (type $2) + (func $if-through3 (type $2) (local $x i32) (local $y i32) (set_local $x @@ -453,7 +453,7 @@ (get_local $w) ) ) - (func $interfere-in-dead (type $2) + (func $interfere-in-dead4 (type $2) (local $x i32) (local $y i32) (block $block diff --git a/test/passes/coalesce-locals.txt b/test/passes/coalesce-locals.txt index db7098ab6..a6af3d5d1 100644 --- a/test/passes/coalesce-locals.txt +++ b/test/passes/coalesce-locals.txt @@ -281,7 +281,7 @@ (get_local $1) ) ) - (func $if-through2 (type $2) + (func $if-through3 (type $2) (local $0 i32) (local $1 i32) (set_local $0 @@ -438,7 +438,7 @@ (get_local $4) ) ) - (func $interfere-in-dead (type $2) + (func $interfere-in-dead4 (type $2) (local $0 i32) (local $1 i32) (block $block diff --git a/test/passes/coalesce-locals.wast b/test/passes/coalesce-locals.wast index cd763af10..da71b7665 100644 --- a/test/passes/coalesce-locals.wast +++ b/test/passes/coalesce-locals.wast @@ -289,7 +289,7 @@ (get_local $y) ) ) - (func $if-through2 (type $2) + (func $if-through3 (type $2) (local $x i32) (local $y i32) (set_local $x @@ -451,7 +451,7 @@ (get_local $w) ) ) - (func $interfere-in-dead (type $2) + (func $interfere-in-dead4 (type $2) (local $x i32) (local $y i32) (block $block diff --git a/test/passes/duplicate-function-elimination.txt b/test/passes/duplicate-function-elimination.txt index 333155c80..e9cabe2ad 100644 --- a/test/passes/duplicate-function-elimination.txt +++ b/test/passes/duplicate-function-elimination.txt @@ -368,7 +368,7 @@ (memory 0) (type $FUNCSIG$v (func)) (import "env" "i" (func $i)) - (import "env" "j" (func $i)) + (import "env" "j" (func $j)) (func $erase (type $FUNCSIG$v) (call $i) ) diff --git a/test/passes/duplicate-function-elimination.wast b/test/passes/duplicate-function-elimination.wast index fcd2378e1..ba429ed30 100644 --- a/test/passes/duplicate-function-elimination.wast +++ b/test/passes/duplicate-function-elimination.wast @@ -438,7 +438,7 @@ (memory 0) (type $FUNCSIG$v (func)) (import $i "env" "i") - (import $i "env" "j") + (import $j "env" "j") (func $erase (type $FUNCSIG$v) (call $i) ) diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt index da19d7ac8..7d76db7f0 100644 --- a/test/passes/remove-unused-brs.txt +++ b/test/passes/remove-unused-brs.txt @@ -191,7 +191,7 @@ ) ) ) - (func $b15 (type $1) + (func $b15b (type $1) (block $topmost (if (i32.const 18) diff --git a/test/passes/remove-unused-brs.wast b/test/passes/remove-unused-brs.wast index 50d936dc7..24995b235 100644 --- a/test/passes/remove-unused-brs.wast +++ b/test/passes/remove-unused-brs.wast @@ -198,7 +198,7 @@ ) ) ) - (func $b15 (type $1) + (func $b15b (type $1) (block $topmost (if (i32.const 18) -- cgit v1.2.3 From 228b9a1cfc89ede2dcc064de9b2e60f53a047128 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 21 Sep 2016 12:20:59 -0700 Subject: loop block signatures --- src/wasm-s-parser.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index a914b6598..6e0eda826 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1287,16 +1287,20 @@ private: auto ret = allocator.alloc(); size_t i = 1; Name out; - if (s.size() > i + 1 && s[i]->isStr() && s[i + 1]->isStr()) { // out can only be named if both are + if (s.size() > i + 1 && s[i]->dollared() && s[i + 1]->dollared()) { // out can only be named if both are out = s[i]->str(); i++; } - if (s.size() > i && s[i]->isStr()) { + if (s.size() > i && s[i]->dollared()) { ret->name = s[i]->str(); i++; } else { ret->name = getPrefixedName("loop-in"); } + if (i < s.size() && s[i]->isStr()) { + // block signature + i++; // TODO: parse the signature + } labelStack.push_back(ret->name); ret->body = makeMaybeBlock(s, i); labelStack.pop_back(); -- cgit v1.2.3 From 3355792fba29e62f02cf1f1acb3a219cf5a69970 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 21 Sep 2016 13:33:51 -0700 Subject: new if label behavior --- src/wasm-s-parser.h | 54 +++++++++++++++------------------------ test/passes/remove-unused-brs.txt | 16 ++++++------ 2 files changed, 29 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 6e0eda826..ace7c31d7 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1227,44 +1227,32 @@ private: Expression* makeIf(Element& s) { auto ret = allocator.alloc(); Index i = 1; + Name label; + if (s[i]->dollared()) { + // the if is labeled + label = s[i++]->str(); + } else { + label = getPrefixedName("if"); + } + labelStack.push_back(label); if (s[i]->isStr()) { - // if type + // if type, TODO: parse? i++; } ret->condition = parseExpression(s[i++]); - - // ifTrue and ifFalse may get implicit blocks - auto handle = [&](const char* title, Element& s) { - Name name = getPrefixedName(title); - bool explicitThenElse = false; - if (s[0]->str() == THEN || s[0]->str() == ELSE) { - explicitThenElse = true; - if (s[1]->isStr() && s[1]->dollared()) { - name = s[1]->str(); - } - } - labelStack.push_back(name); - auto* ret = parseExpression(&s); - labelStack.pop_back(); - if (explicitThenElse) { - ret->dynCast()->name = name; - } else { - // add a block if we must - if (BreakSeeker::has(ret, name)) { - auto* block = allocator.alloc(); - block->name = name; - block->list.push_back(ret); - block->finalize(); - ret = block; - } - } - return ret; - }; - - ret->ifTrue = handle("if-true", *s[i++]); + ret->ifTrue = parseExpression(*s[i++]); if (i < s.size()) { - ret->ifFalse = handle("if-else", *s[i++]); - ret->finalize(); + ret->ifFalse = parseExpression(*s[i++]); + } + ret->finalize(); + labelStack.pop_back(); + // create a break target if we must + if (BreakSeeker::has(ret, label)) { + auto* block = allocator.alloc(); + block->name = label; + block->list.push_back(ret); + block->finalize(); + return block; } return ret; } diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt index 7d76db7f0..33ec51ea5 100644 --- a/test/passes/remove-unused-brs.txt +++ b/test/passes/remove-unused-brs.txt @@ -299,7 +299,7 @@ (i32.const 1) ) (block $block2 - (block $block3 + (block $block1 (drop (i32.const 2) ) @@ -313,7 +313,7 @@ (if (i32.const 0) (block $block4 - (block $block5 + (block $block3 (drop (i32.const 2) ) @@ -329,7 +329,7 @@ ) (if (block $block6 i32 - (block $block7 + (block $block5 (drop (i32.const 2) ) @@ -349,14 +349,14 @@ (i32.const 0) ) (block $a - (block $block11 + (block $block7 (drop (i32.const 1) ) ) ) (block $a - (block $block13 + (block $block8 (drop (i32.const 2) ) @@ -535,7 +535,7 @@ (block $out (if (i32.const 0) - (block $block15 + (block $block13 (drop (i32.const 1) ) @@ -580,7 +580,7 @@ (block $out (if (i32.const 0) - (block $block22 + (block $block17 (drop (i32.const 1) ) @@ -801,7 +801,7 @@ (i32.const 1) ) (br $out - (block $block2 i32 + (block $block1 i32 (set_local $x (i32.const 0) ) -- cgit v1.2.3 From d8229dcfa82a24809a17384df4220b4f3e70a82b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 21 Sep 2016 14:14:04 -0700 Subject: fix start section in binary format --- src/wasm-binary.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 85aaf9279..9dd0d60d6 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1714,8 +1714,8 @@ public: } // now that we have names for each function, apply things - if (startIndex != static_cast(-1) && startIndex < wasm.functions.size()) { - wasm.start = wasm.functions[startIndex]->name; + if (startIndex != static_cast(-1)) { + wasm.start = getFunctionIndexName(startIndex); } for (auto& iter : exportIndexes) { -- cgit v1.2.3 From da134d909f0b9dbd49545ceed77e37721b32f0d1 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 21 Sep 2016 14:57:37 -0700 Subject: auto-generated import names must be unique by kind --- src/wasm-s-parser.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index ace7c31d7..bf2ab7739 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -461,6 +461,17 @@ private: } } + Name getGlobalName(Element& s) { + if (s.dollared()) { + return s.str(); + } else { + // index + size_t offset = atoi(s.str().c_str()); + if (offset >= globalNames.size()) throw ParseException("unknown global in getGlobalName"); + return globalNames[offset]; + } + } + void parseStart(Element& s) { wasm.addStart(getFunctionName(*s[1])); } @@ -1043,7 +1054,7 @@ private: Expression* makeGetGlobal(Element& s) { auto ret = allocator.alloc(); - ret->name = s[1]->str(); + ret->name = getGlobalName(*s[1]); auto* global = wasm.checkGlobal(ret->name); if (global) { ret->type = global->type; @@ -1059,7 +1070,7 @@ private: Expression* makeSetGlobal(Element& s) { auto ret = allocator.alloc(); - ret->name = s[1]->str(); + ret->name = getGlobalName(*s[1]); if (wasm.checkGlobal(ret->name) && !wasm.checkGlobal(ret->name)->mutable_) throw ParseException("set_global of immutable", s.line, s.col); ret->value = parseExpression(s[2]); return ret; @@ -1605,24 +1616,20 @@ private: Index newStyleInner = 1; if (s.size() > 3 && s[3]->isStr()) { im->name = s[i++]->str(); - } else if (newStyle && newStyleInner < s[3]->size() && (*s[3])[newStyleInner]->isStr()) { - auto str = (*s[3])[newStyleInner]->str(); - if (!isWasmType(str)) { - im->name = str; - newStyleInner++; - } + } else if (newStyle && newStyleInner < s[3]->size() && (*s[3])[newStyleInner]->dollared()) { + im->name = (*s[3])[newStyleInner++]->str(); } if (!im->name.is()) { if (im->kind == Import::Function) { - im->name = Name::fromInt(functionCounter++); + im->name = Name("import$function$" + std::to_string(functionCounter++)); functionNames.push_back(im->name); } else if (im->kind == Import::Global) { - im->name = Name::fromInt(globalCounter++); + im->name = Name("import$global" + std::to_string(globalCounter++)); globalNames.push_back(im->name); } else if (im->kind == Import::Memory) { - im->name = Name::fromInt(0); + im->name = Name("import$memory$" + std::to_string(0)); } else if (im->kind == Import::Table) { - im->name = Name::fromInt(0); + im->name = Name("import$table$" + std::to_string(0)); } else { WASM_UNREACHABLE(); } -- cgit v1.2.3 From c79bbb19b59161e0768674816b477f74355912b1 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 21 Sep 2016 15:30:12 -0700 Subject: error on putting spectest.print in a table --- src/shell-interface.h | 4 ++++ src/tools/wasm-shell.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+) (limited to 'src') diff --git a/src/shell-interface.h b/src/shell-interface.h index 8cb7c2672..b9a90131b 100644 --- a/src/shell-interface.h +++ b/src/shell-interface.h @@ -122,6 +122,10 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { case f64: globals[import->name] = Literal(double(666.6)); break; default: WASM_UNREACHABLE(); } + } else if (import->kind == Import::Memory && import->module == SPECTEST && import->base == MEMORY) { + // imported memory has initial 1 and max 2 + wasm.memory.initial = 1; + wasm.memory.max = 2; } } } diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp index 83d39c9d4..670f5783d 100644 --- a/src/tools/wasm-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -171,6 +171,17 @@ static void run_asserts(Name moduleName, size_t* i, bool* checked, Module* wasm, break; } } + for (auto& segment : wasm.table.segments) { + for (auto name : segment.data) { + // spec tests consider it illegal to use spectest.print in a table + if (auto* import = wasm.checkImport(name)) { + if (import->module == SPECTEST && import->base == PRINT) { + std::cerr << "cannot put spectest.print in table\n"; + invalid = true; + } + } + } + } } if (!invalid) { Colors::red(std::cerr); -- cgit v1.2.3 From 740e36eab98d679387fea60cd642591a69ce809f Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 21 Sep 2016 17:59:50 -0700 Subject: fix use of endOfFunction in an uninitialized state in wasm-binary --- src/wasm-binary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 9dd0d60d6..bbfde5b21 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1567,7 +1567,7 @@ public: std::vector functions; // we store functions here before wasm.addFunction after we know their names std::map> functionCalls; // at index i we have all calls to the defined function i Function* currFunction = nullptr; - size_t endOfFunction; + Index endOfFunction = -1; // before we see a function (like global init expressions), there is no end of function to check void readFunctions() { if (debug) std::cerr << "== readFunctions" << std::endl; -- cgit v1.2.3