diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/asm2wasm.h | 1 | ||||
-rw-r--r-- | src/binaryen-c.cpp | 1 | ||||
-rw-r--r-- | src/passes/Print.cpp | 6 | ||||
-rw-r--r-- | src/shared-constants.h | 2 | ||||
-rw-r--r-- | src/wasm-binary.h | 1 | ||||
-rw-r--r-- | src/wasm-linker.cpp | 3 | ||||
-rw-r--r-- | src/wasm-s-parser.h | 25 | ||||
-rw-r--r-- | src/wasm.cpp | 2 | ||||
-rw-r--r-- | src/wasm.h | 5 |
9 files changed, 44 insertions, 2 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index c0f13ff8f..868aa31d3 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -666,6 +666,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) { IString curr = contents[k][1]->getIString(); wasm.table.names.push_back(curr); } + wasm.table.initial = wasm.table.max = wasm.table.names.size(); } else { abort_on("invalid var element", pair); } diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index b0e241ab3..d7f866663 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -732,6 +732,7 @@ void BinaryenSetFunctionTable(BinaryenModuleRef module, BinaryenFunctionRef* fun for (BinaryenIndex i = 0; i < numFuncs; i++) { wasm->table.names.push_back(((Function*)funcs[i])->name); } + wasm->table.initial = wasm->table.max = wasm->table.names.size(); } // Memory. One per module diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index eb97eead5..711cc8a84 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -575,7 +575,11 @@ struct PrintSExpression : public Visitor<PrintSExpression> { decIndent(); } void visitTable(Table *curr) { - printOpening(o, "table"); + printOpening(o, "table") << ' ' << curr->initial; + if (curr->max && curr->max != Table::kMaxSize) o << ' ' << curr->max; + o << " anyfunc)\n"; + doIndent(o, indent); + printOpening(o, "elem", true); for (auto name : curr->names) { o << ' '; printName(name); diff --git a/src/shared-constants.h b/src/shared-constants.h index 8599d8144..f0148cb67 100644 --- a/src/shared-constants.h +++ b/src/shared-constants.h @@ -29,6 +29,7 @@ extern Name GROW_WASM_MEMORY, EXPORT, IMPORT, TABLE, + ELEM, LOCAL, TYPE, CALL, @@ -44,6 +45,7 @@ extern Name GROW_WASM_MEMORY, NEG_NAN, CASE, BR, + ANYFUNC, FAKE_RETURN, ASSERT_RETURN, ASSERT_TRAP, diff --git a/src/wasm-binary.h b/src/wasm-binary.h index b67a79c3d..d405c91dc 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1648,6 +1648,7 @@ public: assert(index < wasm.functions.size()); wasm.table.names.push_back(wasm.functions[index]->name); } + wasm.table.initial = wasm.table.max = wasm.table.names.size(); } void readDataSegments() { diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp index 1f06c6ec2..29f439bfb 100644 --- a/src/wasm-linker.cpp +++ b/src/wasm-linker.cpp @@ -223,6 +223,9 @@ void Linker::layout() { if (out.symbolInfo.implementedFunctions.count("free")) { exportFunction("free", true); } + + // finalize function table + out.wasm.table.initial = out.wasm.table.max = out.wasm.table.names.size(); } bool Linker::linkObject(S2WasmBuilder& builder) { diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 87217cd20..7f652da5a 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -372,6 +372,7 @@ private: if (id == IMPORT) return; // already done if (id == GLOBAL) return parseGlobal(curr); if (id == TABLE) return parseTable(curr); + if (id == ELEM) return parseElem(curr); if (id == TYPE) return; // already done std::cerr << "bad module element " << id.str << '\n'; throw ParseException("unknown module element", curr.line, curr.col); @@ -1424,7 +1425,29 @@ private: } void parseTable(Element& s) { - for (size_t i = 1; i < s.size(); i++) { + if (s.size() == 1) return; // empty table in old notation + if (!s[1]->dollared()) { + if (s[1]->str() == ANYFUNC) { + // (table type (elem ..)) + parseElem(*s[2]); + wasm.table.initial = wasm.table.max = wasm.table.names.size(); + return; + } + // first element isn't dollared, and isn't anyfunc. this could be old syntax for (table 0 1) which means function 0 and 1, or it could be (table initial max? type), look for type + if (s[s.size() - 1]->str() == ANYFUNC) { + // (table initial max? type) + wasm.table.initial = atoi(s[1]->c_str()); + wasm.table.max = atoi(s[2]->c_str()); + return; + } + } + // old notation (table func1 func2 ..) + parseElem(s); + wasm.table.initial = wasm.table.max = wasm.table.names.size(); + } + + void parseElem(Element& s) { + for (Index i = 1; i < s.size(); i++) { wasm.table.names.push_back(getFunctionName(*s[i])); } } diff --git a/src/wasm.cpp b/src/wasm.cpp index 2138ec34d..8cfdee759 100644 --- a/src/wasm.cpp +++ b/src/wasm.cpp @@ -54,6 +54,7 @@ Name GROW_WASM_MEMORY("__growWasmMemory"), EXPORT("export"), IMPORT("import"), TABLE("table"), + ELEM("elem"), LOCAL("local"), TYPE("type"), CALL("call"), @@ -69,6 +70,7 @@ Name GROW_WASM_MEMORY("__growWasmMemory"), NEG_NAN("-nan"), CASE("case"), BR("br"), + ANYFUNC("anyfunc"), FAKE_RETURN("fake_return_waka123"), ASSERT_RETURN("assert_return"), ASSERT_TRAP("assert_trap"), diff --git a/src/wasm.h b/src/wasm.h index c0129cf23..82933bda0 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1432,7 +1432,12 @@ public: class Table { public: + static const Index kMaxSize = Index(-1); + + Address initial, max; std::vector<Name> names; + + Table() : initial(0), max(kMaxSize) {} }; class Memory { |