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/tools/wasm-shell.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/tools/wasm-shell.cpp')
-rw-r--r-- | src/tools/wasm-shell.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp index 2a59be167..9ad1fa799 100644 --- a/src/tools/wasm-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -146,24 +146,29 @@ static void run_asserts(Name moduleName, size_t* i, bool* checked, Module* wasm, } if (!invalid && id == ASSERT_UNLINKABLE) { // validate "instantiating" the mdoule - for (auto& import : wasm.imports) { + auto reportUnknownImport = [&](Importable* import) { + std::cerr << "unknown import: " << import->module << '.' << import->base << '\n'; + invalid = true; + }; + ModuleUtils::iterImportedGlobals(wasm, reportUnknownImport); + ModuleUtils::iterImportedFunctions(wasm, [&](Importable* import) { if (import->module == SPECTEST && import->base == PRINT) { - if (import->kind != ExternalKind::Function) { - std::cerr << "spectest.print should be a function, but is " << int32_t(import->kind) << '\n'; - invalid = true; - break; - } + // We can handle it. } else { - std::cerr << "unknown import: " << import->module << '.' << import->base << '\n'; - invalid = true; - break; + reportUnknownImport(import); } + }); + if (wasm.memory.imported()) { + reportUnknownImport(&wasm.memory); + } + if (wasm.table.imported()) { + reportUnknownImport(&wasm.table); } for (auto& segment : wasm.table.segments) { for (auto name : segment.data) { // spec tests consider it illegal to use spectest.print in a table - if (auto* import = wasm.getImportOrNull(name)) { - if (import->module == SPECTEST && import->base == PRINT) { + if (auto* import = wasm.getFunction(name)) { + if (import->imported() && import->module == SPECTEST && import->base == PRINT) { std::cerr << "cannot put spectest.print in table\n"; invalid = true; } |