From cbeb4c9f9ba7c8f50fcb938ef668842bbd5dacb4 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 7 Oct 2016 10:57:50 -0700 Subject: 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. --- src/passes/Print.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src') 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 { 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 { 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 { 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) { -- cgit v1.2.3