diff options
author | Derek Schuff <dschuff@chromium.org> | 2016-10-07 10:57:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-07 10:57:50 -0700 |
commit | cbeb4c9f9ba7c8f50fcb938ef668842bbd5dacb4 (patch) | |
tree | 71af10f36b62851530c686d47a361e108f3316e3 /src | |
parent | caf0a3db20bbc03d2261b2c5a112bc0eddd3ca73 (diff) | |
download | binaryen-cbeb4c9f9ba7c8f50fcb938ef668842bbd5dacb4.tar.gz binaryen-cbeb4c9f9ba7c8f50fcb938ef668842bbd5dacb4.tar.bz2 binaryen-cbeb4c9f9ba7c8f50fcb938ef668842bbd5dacb4.zip |
Change print order of top-level module components (#751)
In wast files, the spec and WABT require imports to appear before any
non-import definitions (see also
https://github.com/WebAssembly/wabt/issues/152). This patch re-orders
visitModule in the wast printer to meet this requirement, and more or
less match the order of the binary sections. Also remove extraneous
whitespace around table definitions.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Print.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 590f9bce2..0a2026f25 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -630,8 +630,9 @@ struct PrintSExpression : public Visitor<PrintSExpression> { if (!found) { doIndent(o, indent); printTableHeader(curr); - o << '\n'; } + if (curr->segments.empty()) return; + if (!found) o << '\n'; doIndent(o, indent); for (auto& segment : curr->segments) { // Don't print empty segments @@ -698,12 +699,6 @@ struct PrintSExpression : public Visitor<PrintSExpression> { currModule = curr; printOpening(o, "module", true); incIndent(); - visitMemory(&curr->memory); - if (curr->start.is()) { - doIndent(o, indent); - printOpening(o, "start") << ' ' << curr->start << ')'; - o << maybeNewLine; - } for (auto& child : curr->functionTypes) { doIndent(o, indent); printOpening(o, "type") << ' '; @@ -716,18 +711,24 @@ struct PrintSExpression : public Visitor<PrintSExpression> { visitImport(child.get()); o << maybeNewLine; } - for (auto& child : curr->exports) { - doIndent(o, indent); - visitExport(child.get()); + if (curr->table.exists) { + visitTable(&curr->table); o << maybeNewLine; } + visitMemory(&curr->memory); for (auto& child : curr->globals) { doIndent(o, indent); visitGlobal(child.get()); o << maybeNewLine; } - if (curr->table.exists) { - visitTable(&curr->table); + for (auto& child : curr->exports) { + doIndent(o, indent); + visitExport(child.get()); + o << maybeNewLine; + } + if (curr->start.is()) { + doIndent(o, indent); + printOpening(o, "start") << ' ' << curr->start << ')'; o << maybeNewLine; } for (auto& child : curr->functions) { |