Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print '(offset ...)` in data and element segments #6379

Merged
merged 2 commits into from
Mar 6, 2024
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
15 changes: 15 additions & 0 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <ir/iteration.h>
#include <ir/module-utils.h>
#include <ir/table-utils.h>
#include <ir/utils.h>
#include <pass.h>
#include <pretty_printing.h>
#include <support/string.h>
Expand Down Expand Up @@ -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 << ' ';
Expand Down Expand Up @@ -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()});
Expand Down
10 changes: 8 additions & 2 deletions test/lit/validation/extended-const.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Loading