summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/wasm-binary.h5
-rw-r--r--src/wasm/wasm-binary.cpp38
2 files changed, 11 insertions, 32 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index a00a1df46..07ae01160 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -1519,11 +1519,6 @@ public:
// function to check
Index endOfFunction = -1;
- // we store tables here before wasm.addTable after we know their names
- std::vector<std::unique_ptr<Table>> tables;
- // we store table imports here before wasm.addTableImport after we know
- // their names
- std::vector<Table*> tableImports;
// at index i we have all references to the table i
std::map<Index, std::vector<Name*>> tableRefs;
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 64464fde5..e067ae104 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -2334,7 +2334,6 @@ void WasmBinaryBuilder::readImports() {
throwError("Tables may not be 64-bit");
}
- tableImports.push_back(table.get());
wasm.addTable(std::move(table));
break;
}
@@ -2986,9 +2985,6 @@ void WasmBinaryBuilder::processNames() {
for (auto& global : globals) {
wasm.addGlobal(std::move(global));
}
- for (auto& table : tables) {
- wasm.addTable(std::move(table));
- }
for (auto& segment : elementSegments) {
wasm.addElementSegment(std::move(segment));
}
@@ -3115,7 +3111,7 @@ void WasmBinaryBuilder::readTableDeclarations() {
throwError("Tables may not be 64-bit");
}
- tables.push_back(std::move(table));
+ wasm.addTable(std::move(table));
}
}
@@ -3154,17 +3150,10 @@ void WasmBinaryBuilder::readElementSegments() {
tableIdx = getU32LEB();
}
- Table* table = nullptr;
- auto numTableImports = tableImports.size();
- if (tableIdx < numTableImports) {
- table = tableImports[tableIdx];
- } else if (tableIdx - numTableImports < tables.size()) {
- table = tables[tableIdx - numTableImports].get();
- }
- if (!table) {
+ if (tableIdx >= wasm.tables.size()) {
throwError("Table index out of range.");
}
-
+ auto* table = wasm.tables[tableIdx].get();
segment->table = table->name;
segment->offset = readExpression();
}
@@ -3367,20 +3356,15 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
auto index = getU32LEB();
auto rawName = getInlineString();
auto name = processor.process(rawName);
- auto numTableImports = tableImports.size();
- auto setTableName = [&](Table* table) {
+
+ if (index < wasm.tables.size()) {
+ auto* table = wasm.tables[index].get();
for (auto& segment : elementSegments) {
if (segment->table == table->name) {
segment->table = name;
}
}
table->setExplicitName(name);
- };
-
- if (index < numTableImports) {
- setTableName(tableImports[index]);
- } else if (index - numTableImports < tables.size()) {
- setTableName(tables[index - numTableImports].get());
} else {
std::cerr << "warning: table index out of bounds in name section, "
"table subsection: "
@@ -5226,7 +5210,7 @@ bool WasmBinaryBuilder::maybeVisitTableSize(Expression*& out, uint32_t code) {
return false;
}
Index tableIdx = getU32LEB();
- if (tableIdx >= tables.size()) {
+ if (tableIdx >= wasm.tables.size()) {
throwError("bad table index");
}
auto* curr = allocator.alloc<TableSize>();
@@ -5242,7 +5226,7 @@ bool WasmBinaryBuilder::maybeVisitTableGrow(Expression*& out, uint32_t code) {
return false;
}
Index tableIdx = getU32LEB();
- if (tableIdx >= tables.size()) {
+ if (tableIdx >= wasm.tables.size()) {
throwError("bad table index");
}
auto* curr = allocator.alloc<TableGrow>();
@@ -6634,11 +6618,11 @@ void WasmBinaryBuilder::visitRefEq(RefEq* curr) {
void WasmBinaryBuilder::visitTableGet(TableGet* curr) {
BYN_TRACE("zz node: TableGet\n");
Index tableIdx = getU32LEB();
- if (tableIdx >= tables.size()) {
+ if (tableIdx >= wasm.tables.size()) {
throwError("bad table index");
}
curr->index = popNonVoidExpression();
- curr->type = tables[tableIdx]->type;
+ curr->type = wasm.tables[tableIdx]->type;
curr->finalize();
// Defer setting the table name for later, when we know it.
tableRefs[tableIdx].push_back(&curr->table);
@@ -6647,7 +6631,7 @@ void WasmBinaryBuilder::visitTableGet(TableGet* curr) {
void WasmBinaryBuilder::visitTableSet(TableSet* curr) {
BYN_TRACE("zz node: TableSet\n");
Index tableIdx = getU32LEB();
- if (tableIdx >= tables.size()) {
+ if (tableIdx >= wasm.tables.size()) {
throwError("bad table index");
}
curr->value = popNonVoidExpression();