diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/module-utils.h | 30 | ||||
-rw-r--r-- | src/passes/Print.cpp | 17 |
2 files changed, 42 insertions, 5 deletions
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h index 1d0512401..d6ee50dd0 100644 --- a/src/ir/module-utils.h +++ b/src/ir/module-utils.h @@ -128,7 +128,35 @@ inline void copyModule(Module& in, Module& out) { out.debugInfoFileNames = in.debugInfoFileNames; } -// Convenient iteration over imported/non-imported functions/globals +// Convenient iteration over imported/non-imported module elements + +template<typename T> +inline void iterImportedMemories(Module& wasm, T visitor) { + if (wasm.memory.exists && wasm.memory.imported()) { + visitor(&wasm.memory); + } +} + +template<typename T> +inline void iterDefinedMemories(Module& wasm, T visitor) { + if (wasm.memory.exists && !wasm.memory.imported()) { + visitor(&wasm.memory); + } +} + +template<typename T> +inline void iterImportedTables(Module& wasm, T visitor) { + if (wasm.table.exists && wasm.table.imported()) { + visitor(&wasm.table); + } +} + +template<typename T> +inline void iterDefinedTables(Module& wasm, T visitor) { + if (wasm.table.exists && !wasm.table.imported()) { + visitor(&wasm.table); + } +} template<typename T> inline void iterImportedGlobals(Module& wasm, T visitor) { diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 3ab1cc75d..3062ed0ee 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -957,6 +957,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> { void printTableHeader(Table* curr) { o << '('; printMedium(o, "table") << ' '; + printName(curr->name, o) << ' '; o << curr->initial; if (curr->hasMax()) o << ' ' << curr->max; o << " anyfunc)"; @@ -1056,16 +1057,24 @@ struct PrintSExpression : public Visitor<PrintSExpression> { visitFunctionType(child.get()); o << ")" << maybeNewLine; } - visitMemory(&curr->memory); - if (curr->table.exists) { - visitTable(&curr->table); // Prints its own newlines - } + ModuleUtils::iterImportedMemories(*curr, [&](Memory* memory) { + visitMemory(memory); + }); + ModuleUtils::iterImportedTables(*curr, [&](Table* table) { + visitTable(table); + }); ModuleUtils::iterImportedGlobals(*curr, [&](Global* global) { visitGlobal(global); }); ModuleUtils::iterImportedFunctions(*curr, [&](Function* func) { visitFunction(func); }); + ModuleUtils::iterDefinedMemories(*curr, [&](Memory* memory) { + visitMemory(memory); + }); + ModuleUtils::iterDefinedTables(*curr, [&](Table* table) { + visitTable(table); + }); ModuleUtils::iterDefinedGlobals(*curr, [&](Global* global) { visitGlobal(global); }); |