diff options
Diffstat (limited to 'src/passes')
-rw-r--r-- | src/passes/DuplicateFunctionElimination.cpp | 10 | ||||
-rw-r--r-- | src/passes/Print.cpp | 30 | ||||
-rw-r--r-- | src/passes/RemoveUnusedFunctions.cpp | 6 | ||||
-rw-r--r-- | src/passes/ReorderFunctions.cpp | 6 |
4 files changed, 33 insertions, 19 deletions
diff --git a/src/passes/DuplicateFunctionElimination.cpp b/src/passes/DuplicateFunctionElimination.cpp index 961d26ba5..2b8e69b54 100644 --- a/src/passes/DuplicateFunctionElimination.cpp +++ b/src/passes/DuplicateFunctionElimination.cpp @@ -123,10 +123,12 @@ struct DuplicateFunctionElimination : public Pass { replacerRunner.add<FunctionReplacer>(&replacements); replacerRunner.run(); // replace in table - for (auto& name : module->table.names) { - auto iter = replacements.find(name); - if (iter != replacements.end()) { - name = iter->second; + for (auto& segment : module->table.segments) { + for (auto& name : segment.data) { + auto iter = replacements.find(name); + if (iter != replacements.end()) { + name = iter->second; + } } } // replace in start diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 47e503fa4..5eea38bdc 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -575,12 +575,19 @@ struct PrintSExpression : public Visitor<PrintSExpression> { decIndent(); } void visitTable(Table *curr) { - printOpening(o, "table"); - for (auto name : curr->names) { - o << ' '; - printName(name); + printOpening(o, "table") << ' ' << curr->initial; + if (curr->max && curr->max != Table::kMaxSize) o << ' ' << curr->max; + o << " anyfunc)\n"; + doIndent(o, indent); + for (auto& segment : curr->segments) { + printOpening(o, "elem ", true); + visit(segment.offset); + for (auto name : segment.data) { + o << ' '; + printName(name); + } + o << ')'; } - o << ')'; } void visitModule(Module *curr) { currModule = curr; @@ -589,9 +596,12 @@ struct PrintSExpression : public Visitor<PrintSExpression> { doIndent(o, indent); printOpening(o, "memory") << ' ' << curr->memory.initial; if (curr->memory.max && curr->memory.max != Memory::kMaxSize) o << ' ' << curr->memory.max; + o << ")\n"; for (auto segment : curr->memory.segments) { - o << maybeNewLine; - o << (minify ? "" : " ") << "(segment " << segment.offset << " \""; + doIndent(o, indent); + printOpening(o, "data ", true); + visit(segment.offset); + o << " \""; for (size_t i = 0; i < segment.data.size(); i++) { unsigned char c = segment.data[i]; switch (c) { @@ -612,10 +622,8 @@ struct PrintSExpression : public Visitor<PrintSExpression> { } } } - o << "\")"; + o << "\")\n"; } - o << ((curr->memory.segments.size() > 0 && !minify) ? "\n " : "") << ')'; - o << maybeNewLine; if (curr->memory.exportName.is()) { doIndent(o, indent); printOpening(o, "export "); @@ -647,7 +655,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> { visitGlobal(child.get()); o << maybeNewLine; } - if (curr->table.names.size() > 0) { + if (curr->table.segments.size() > 0 || curr->table.initial > 0 || curr->table.max != Table::kMaxSize) { doIndent(o, indent); visitTable(&curr->table); o << maybeNewLine; diff --git a/src/passes/RemoveUnusedFunctions.cpp b/src/passes/RemoveUnusedFunctions.cpp index a2941aff6..78b0f0ffc 100644 --- a/src/passes/RemoveUnusedFunctions.cpp +++ b/src/passes/RemoveUnusedFunctions.cpp @@ -39,8 +39,10 @@ struct RemoveUnusedFunctions : public Pass { root.push_back(module->getFunction(curr->value)); } // For now, all functions that can be called indirectly are marked as roots. - for (auto& curr : module->table.names) { - root.push_back(module->getFunction(curr)); + for (auto& segment : module->table.segments) { + for (auto& curr : segment.data) { + root.push_back(module->getFunction(curr)); + } } // Compute function reachability starting from the root set. DirectCallGraphAnalyzer analyzer(module, root); diff --git a/src/passes/ReorderFunctions.cpp b/src/passes/ReorderFunctions.cpp index 38ef98afb..679fedb61 100644 --- a/src/passes/ReorderFunctions.cpp +++ b/src/passes/ReorderFunctions.cpp @@ -38,8 +38,10 @@ struct ReorderFunctions : public WalkerPass<PostWalker<ReorderFunctions, Visitor for (auto& curr : module->exports) { counts[curr->value]++; } - for (auto& curr : module->table.names) { - counts[curr]++; + for (auto& segment : module->table.segments) { + for (auto& curr : segment.data) { + counts[curr]++; + } } std::sort(module->functions.begin(), module->functions.end(), [this]( const std::unique_ptr<Function>& a, |