diff options
author | Alon Zakai <alonzakai@gmail.com> | 2018-09-19 15:50:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-19 15:50:30 -0700 |
commit | fe88b47749115009da0447e340cbdc86edf30984 (patch) | |
tree | 7dfd9aba7086c8aa6dff4877ac1ee3b9d78bc5ce /src/wasm/wasm.cpp | |
parent | a53356ab155a7d8c2f334dc9a3c1432bacbc78fe (diff) | |
download | binaryen-fe88b47749115009da0447e340cbdc86edf30984.tar.gz binaryen-fe88b47749115009da0447e340cbdc86edf30984.tar.bz2 binaryen-fe88b47749115009da0447e340cbdc86edf30984.zip |
Unify imported and non-imported things (#1678)
Fixes #1649
This moves us to a single object for functions, which can be imported or nor, and likewise for globals (as a result, GetGlobals do not need to check if the global is imported or not, etc.). All imported things now inherit from Importable, which has the module and base of the import, and if they are set then it is an import.
For convenient iteration, there are a few helpers like
ModuleUtils::iterDefinedGlobals(wasm, [&](Global* global) {
.. use global ..
});
as often iteration only cares about imported or defined (non-imported) things.
Diffstat (limited to 'src/wasm/wasm.cpp')
-rw-r--r-- | src/wasm/wasm.cpp | 57 |
1 files changed, 10 insertions, 47 deletions
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index ac3623cee..ad4d6343a 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -53,7 +53,6 @@ Name GROW_WASM_MEMORY("__growWasmMemory"), LOCAL("local"), TYPE("type"), CALL("call"), - CALL_IMPORT("call_import"), CALL_INDIRECT("call_indirect"), BLOCK("block"), BR_IF("br_if"), @@ -83,7 +82,6 @@ const char* getExpressionName(Expression* curr) { case Expression::Id::BreakId: return "break"; case Expression::Id::SwitchId: return "switch"; case Expression::Id::CallId: return "call"; - case Expression::Id::CallImportId: return "call_import"; case Expression::Id::CallIndirectId: return "call_indirect"; case Expression::Id::GetLocalId: return "get_local"; case Expression::Id::SetLocalId: return "set_local"; @@ -324,10 +322,6 @@ void Call::finalize() { handleUnreachableOperands(this); } -void CallImport::finalize() { - handleUnreachableOperands(this); -} - void CallIndirect::finalize() { handleUnreachableOperands(this); if (target->type == unreachable) { @@ -650,14 +644,6 @@ FunctionType* Module::getFunctionType(Name name) { return iter->second; } -Import* Module::getImport(Name name) { - auto iter = importsMap.find(name); - if (iter == importsMap.end()) { - Fatal() << "Module::getImport: " << name << " does not exist"; - } - return iter->second; -} - Export* Module::getExport(Name name) { auto iter = exportsMap.find(name); if (iter == exportsMap.end()) { @@ -690,14 +676,6 @@ FunctionType* Module::getFunctionTypeOrNull(Name name) { return iter->second; } -Import* Module::getImportOrNull(Name name) { - auto iter = importsMap.find(name); - if (iter == importsMap.end()) { - return nullptr; - } - return iter->second; -} - Export* Module::getExportOrNull(Name name) { auto iter = exportsMap.find(name); if (iter == exportsMap.end()) { @@ -733,17 +711,6 @@ void Module::addFunctionType(FunctionType* curr) { functionTypesMap[curr->name] = curr; } -void Module::addImport(Import* curr) { - if (!curr->name.is()) { - Fatal() << "Module::addImport: empty name"; - } - if (getImportOrNull(curr->name)) { - Fatal() << "Module::addImport: " << curr->name << " already exists"; - } - imports.push_back(std::unique_ptr<Import>(curr)); - importsMap[curr->name] = curr; -} - void Module::addExport(Export* curr) { if (!curr->name.is()) { Fatal() << "Module::addExport: empty name"; @@ -781,14 +748,14 @@ void Module::addStart(const Name& s) { start = s; } -void Module::removeImport(Name name) { - for (size_t i = 0; i < imports.size(); i++) { - if (imports[i]->name == name) { - imports.erase(imports.begin() + i); +void Module::removeFunctionType(Name name) { + for (size_t i = 0; i < functionTypes.size(); i++) { + if (functionTypes[i]->name == name) { + functionTypes.erase(functionTypes.begin() + i); break; } } - importsMap.erase(name); + functionTypesMap.erase(name); } void Module::removeExport(Name name) { @@ -811,14 +778,14 @@ void Module::removeFunction(Name name) { functionsMap.erase(name); } -void Module::removeFunctionType(Name name) { - for (size_t i = 0; i < functionTypes.size(); i++) { - if (functionTypes[i]->name == name) { - functionTypes.erase(functionTypes.begin() + i); +void Module::removeGlobal(Name name) { + for (size_t i = 0; i < globals.size(); i++) { + if (globals[i]->name == name) { + globals.erase(globals.begin() + i); break; } } - functionTypesMap.erase(name); + globalsMap.erase(name); } // TODO: remove* for other elements @@ -832,10 +799,6 @@ void Module::updateMaps() { for (auto& curr : functionTypes) { functionTypesMap[curr->name] = curr.get(); } - importsMap.clear(); - for (auto& curr : imports) { - importsMap[curr->name] = curr.get(); - } exportsMap.clear(); for (auto& curr : exports) { exportsMap[curr->name] = curr.get(); |