summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-03-06 10:24:54 -0800
committerGitHub <noreply@github.com>2024-03-06 10:24:54 -0800
commit4ca311d83187bad3b5790635efc687b747a1b1e7 (patch)
treee6257f323a97a5d9a4bfe68942468f7da792f3dc /src
parentf44912bf234d5e19a1adb34c770335f4b3190e2a (diff)
downloadbinaryen-4ca311d83187bad3b5790635efc687b747a1b1e7.tar.gz
binaryen-4ca311d83187bad3b5790635efc687b747a1b1e7.tar.bz2
binaryen-4ca311d83187bad3b5790635efc687b747a1b1e7.zip
Print '(offset ...)` in data and element segments (#6379)
Previously we just printed the offset instruction(s) directly, which is a valid shorthand only when there is a single instruction. In the case of extended constant instructions, there can potentially be multiple instructions, in which case the explicit `offset` clause is required. Print the full clause when necessary.
Diffstat (limited to 'src')
-rw-r--r--src/passes/Print.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 3f0cfbabb..b0c83c437 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -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>
@@ -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()});