diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 3f0cfbabb3d..b0c83c43715 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -3113,7 +3114,14 @@ void PrintSExpression::visitElementSegment(ElementSegment* curr) { } o << ' '; + bool needExplicitOffset = Measurer{}.measure(curr->offset) > 1; + if (needExplicitOffset) { + o << "(offset "; + } visit(curr->offset); + if (needExplicitOffset) { + o << ')'; + } if (usesExpressions || currModule->tables.size() > 1) { o << ' '; @@ -3183,7 +3191,14 @@ void PrintSExpression::visitDataSegment(DataSegment* curr) { curr->memory.print(o); o << ") "; } + bool needExplicitOffset = Measurer{}.measure(curr->offset) > 1; + if (needExplicitOffset) { + o << "(offset "; + } visit(curr->offset); + if (needExplicitOffset) { + o << ")"; + } o << ' '; } String::printEscaped(o, {curr->data.data(), curr->data.size()}); diff --git a/test/lit/validation/extended-const.wast b/test/lit/validation/extended-const.wast index 6b506671fce..054c5e28e59 100644 --- a/test/lit/validation/extended-const.wast +++ b/test/lit/validation/extended-const.wast @@ -11,14 +11,20 @@ ;; EXTENDED: (global.get $gimport$0) ;; EXTENDED: (i32.const 42) ;; EXTENDED: )) -;; EXTENDED: (data $0 (i32.sub +;; EXTENDED: (data $0 (offset (i32.sub ;; EXTENDED: (global.get $gimport$0) ;; EXTENDED: (i32.const 10) -;; EXTENDED: ) "hello world") +;; EXTENDED: )) "hello world") +;; EXTENDED: (elem $0 (offset (i32.sub +;; EXTENDED: (global.get $gimport$0) +;; EXTENDED: (i32.const 10) +;; EXTENDED: ))) (module (import "env" "global" (global i32)) (memory 1 1) + (table 1 1 funcref) (global i32 (i32.add (global.get 0) (i32.const 42))) (data (offset (i32.sub (global.get 0) (i32.const 10))) "hello world") + (elem (offset (i32.sub (global.get 0) (i32.const 10))) func) )