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/wasm-binary.h | 121 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 52 deletions(-) (limited to 'src/wasm-binary.h') 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; -- 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/wasm-binary.h') 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/wasm-binary.h') 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 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/wasm-binary.h') 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 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/wasm-binary.h') 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 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/wasm-binary.h') 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