Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/wat-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1439,11 +1439,13 @@ void WatWriter::FlushExprTreeStack() {

void WatWriter::WriteInitExpr(const ExprList& expr) {
if (!expr.empty()) {
WritePuts("(", NextChar::None);
WriteExprList(expr);
/* Init expressions are always written folded. These positions accept a
* single folded expression, so wrapping a sequence of instructions in one
* pair of parentheses would produce output that cannot be parsed back. */
WriteFoldedExprList(expr);
FlushExprTreeStack();
/* clear the next char, so we don't write a newline after the expr */
next_char_ = NextChar::None;
WritePuts(")", NextChar::Space);
next_char_ = NextChar::Space;
}
}

Expand Down
30 changes: 30 additions & 0 deletions test/roundtrip/extended-const.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
;;; TOOL: run-roundtrip
;;; ARGS: --stdout --enable-extended-const
(module
(global $g_import (import "foo" "bar") i32)
(memory 1)
(table 1 funcref)
(func)
(global (mut i32) (i32.sub (i32.const 44) (i32.const 3)))
(global i32 (i32.const 45))
(data (i32.add (global.get $g_import) (i32.const 42)) "hello")
(elem (i32.mul (i32.const 4) (global.get $g_import)) func 0)
)
(;; STDOUT ;;;
(module
(type (;0;) (func))
(import "foo" "bar" (global (;0;) i32))
(func (;0;) (type 0))
(table (;0;) 1 funcref)
(memory (;0;) 1)
(global (;1;) (mut i32) (i32.sub
(i32.const 44)
(i32.const 3)))
(global (;2;) i32 (i32.const 45))
(elem (;0;) (i32.mul
(i32.const 4)
(global.get 0)) func 0)
(data (;0;) (i32.add
(global.get 0)
(i32.const 42)) "hello"))
;;; STDOUT ;;)
3 changes: 3 additions & 0 deletions test/run-roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def main(args):
parser.add_argument('--enable-annotations', action='store_true')
parser.add_argument('--enable-code-metadata', action='store_true')
parser.add_argument('--enable-custom-page-sizes', action='store_true')
parser.add_argument('--enable-extended-const', action='store_true')
# --inline-exports can reorder exports, so skip roundtrip check
parser.add_argument('--inline-exports', action='store_true',
help="write exports inline and skip end-to-end roundtrip check")
Expand Down Expand Up @@ -144,6 +145,7 @@ def main(args):
'--enable-annotations': options.enable_annotations,
'--enable-code-metadata': options.enable_code_metadata,
'--enable-custom-page-sizes': options.enable_custom_page_sizes,
'--enable-extended-const': options.enable_extended_const,
'--reloc': options.reloc,
'--no-check': options.no_check,
})
Expand All @@ -167,6 +169,7 @@ def main(args):
'--enable-annotations': options.enable_annotations,
'--enable-code-metadata': options.enable_code_metadata,
'--enable-custom-page-sizes': options.enable_custom_page_sizes,
'--enable-extended-const': options.enable_extended_const,
'--inline-exports': options.inline_exports,
'--inline-imports': options.inline_imports,
'--no-debug-names': not options.debug_names,
Expand Down
Loading