diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-binary.h | 6 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 51 |
2 files changed, 17 insertions, 40 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index cf0428625..a866881f5 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1523,7 +1523,7 @@ public: // their names std::vector<Function*> functionImports; // at index i we have all refs to the function i - std::map<Index, std::vector<Expression*>> functionRefs; + std::map<Index, std::vector<Name*>> functionRefs; Function* currFunction = nullptr; // before we see a function (like global init expressions), there is no end of // function to check @@ -1535,7 +1535,7 @@ public: // their names std::vector<Table*> tableImports; // at index i we have all references to the table i - std::map<Index, std::vector<Expression*>> tableRefs; + std::map<Index, std::vector<Name*>> tableRefs; std::map<Index, Name> elemTables; @@ -1552,7 +1552,7 @@ public: // their names std::vector<Global*> globalImports; // at index i we have all refs to the global i - std::map<Index, std::vector<Expression*>> globalRefs; + std::map<Index, std::vector<Name*>> globalRefs; // Throws a parsing error if we are not in a function context void requireFunctionContext(const char* error); diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 9f28c00bb..2f2eb5e39 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2990,43 +2990,19 @@ void WasmBinaryBuilder::processNames() { for (auto& [index, refs] : functionRefs) { for (auto* ref : refs) { - if (auto* call = ref->dynCast<Call>()) { - call->target = getFunctionName(index); - } else if (auto* refFunc = ref->dynCast<RefFunc>()) { - refFunc->func = getFunctionName(index); - } else { - WASM_UNREACHABLE("Invalid type in function references"); - } + *ref = getFunctionName(index); } } for (auto& [index, refs] : tableRefs) { for (auto* ref : refs) { - if (auto* callIndirect = ref->dynCast<CallIndirect>()) { - callIndirect->table = getTableName(index); - } else if (auto* get = ref->dynCast<TableGet>()) { - get->table = getTableName(index); - } else if (auto* set = ref->dynCast<TableSet>()) { - set->table = getTableName(index); - } else if (auto* size = ref->dynCast<TableSize>()) { - size->table = getTableName(index); - } else if (auto* grow = ref->dynCast<TableGrow>()) { - grow->table = getTableName(index); - } else { - WASM_UNREACHABLE("Invalid type in table references"); - } + *ref = getTableName(index); } } for (auto& [index, refs] : globalRefs) { for (auto* ref : refs) { - if (auto* get = ref->dynCast<GlobalGet>()) { - get->name = getGlobalName(index); - } else if (auto* set = ref->dynCast<GlobalSet>()) { - set->name = getGlobalName(index); - } else { - WASM_UNREACHABLE("Invalid type in global references"); - } + *ref = getGlobalName(index); } } @@ -3170,7 +3146,7 @@ void WasmBinaryBuilder::readElementSegments() { auto sig = getTypeByFunctionIndex(index); // Use a placeholder name for now auto* refFunc = Builder(wasm).makeRefFunc(Name::fromInt(index), sig); - functionRefs[index].push_back(refFunc); + functionRefs[index].push_back(&refFunc->func); segmentData.push_back(refFunc); } } @@ -4313,7 +4289,8 @@ void WasmBinaryBuilder::visitCall(Call* curr) { curr->operands[num - i - 1] = popNonVoidExpression(); } curr->type = sig.results; - functionRefs[index].push_back(curr); // we don't know function names yet + // We don't know function names yet. + functionRefs[index].push_back(&curr->target); curr->finalize(); } @@ -4330,7 +4307,7 @@ void WasmBinaryBuilder::visitCallIndirect(CallIndirect* curr) { curr->operands[num - i - 1] = popNonVoidExpression(); } // Defer setting the table name for later, when we know it. - tableRefs[tableIdx].push_back(curr); + tableRefs[tableIdx].push_back(&curr->table); curr->finalize(); } @@ -4377,7 +4354,7 @@ void WasmBinaryBuilder::visitGlobalGet(GlobalGet* curr) { curr->name = glob->name; curr->type = glob->type; } - globalRefs[index].push_back(curr); // we don't know the final name yet + globalRefs[index].push_back(&curr->name); // we don't know the final name yet } void WasmBinaryBuilder::visitGlobalSet(GlobalSet* curr) { @@ -4394,7 +4371,7 @@ void WasmBinaryBuilder::visitGlobalSet(GlobalSet* curr) { curr->name = globals[adjustedIndex]->name; } curr->value = popNonVoidExpression(); - globalRefs[index].push_back(curr); // we don't know the final name yet + globalRefs[index].push_back(&curr->name); // we don't know the final name yet curr->finalize(); } @@ -5204,7 +5181,7 @@ bool WasmBinaryBuilder::maybeVisitTableSize(Expression*& out, uint32_t code) { auto* curr = allocator.alloc<TableSize>(); curr->finalize(); // Defer setting the table name for later, when we know it. - tableRefs[tableIdx].push_back(curr); + tableRefs[tableIdx].push_back(&curr->table); out = curr; return true; } @@ -5222,7 +5199,7 @@ bool WasmBinaryBuilder::maybeVisitTableGrow(Expression*& out, uint32_t code) { curr->value = popNonVoidExpression(); curr->finalize(); // Defer setting the table name for later, when we know it. - tableRefs[tableIdx].push_back(curr); + tableRefs[tableIdx].push_back(&curr->table); out = curr; return true; } @@ -6585,7 +6562,7 @@ void WasmBinaryBuilder::visitRefFunc(RefFunc* curr) { // be verified in the next line. (Also, note that functionRefs[index] may // write to an odd place in the functionRefs map if index is invalid, but that // is harmless.) - functionRefs[index].push_back(curr); + functionRefs[index].push_back(&curr->func); // To support typed function refs, we give the reference not just a general // funcref, but a specific subtype with the actual signature. curr->finalize(Type(getTypeByFunctionIndex(index), NonNullable)); @@ -6608,7 +6585,7 @@ void WasmBinaryBuilder::visitTableGet(TableGet* curr) { curr->type = tables[tableIdx]->type; curr->finalize(); // Defer setting the table name for later, when we know it. - tableRefs[tableIdx].push_back(curr); + tableRefs[tableIdx].push_back(&curr->table); } void WasmBinaryBuilder::visitTableSet(TableSet* curr) { @@ -6621,7 +6598,7 @@ void WasmBinaryBuilder::visitTableSet(TableSet* curr) { curr->index = popNonVoidExpression(); curr->finalize(); // Defer setting the table name for later, when we know it. - tableRefs[tableIdx].push_back(curr); + tableRefs[tableIdx].push_back(&curr->table); } void WasmBinaryBuilder::visitTryOrTryInBlock(Expression*& out) { |