summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2019-07-26 19:04:45 -0700
committerGitHub <noreply@github.com>2019-07-26 19:04:45 -0700
commitedf001feb62d32c76f20d5564fabfab93035afdf (patch)
treebda476b9243bde99b59c2c770528ce476904f03b /src/passes/Print.cpp
parentccd95f8f5725a8d52557772b3081875babda312f (diff)
downloadbinaryen-edf001feb62d32c76f20d5564fabfab93035afdf.tar.gz
binaryen-edf001feb62d32c76f20d5564fabfab93035afdf.tar.bz2
binaryen-edf001feb62d32c76f20d5564fabfab93035afdf.zip
Fix unreachable prefix in instruction printing (#2265)
When a memory instruction's type is unreachable, i.e., one of its child expressions is unreachable, the instruction will be printed like `unreachable.load`, which is invalid text format. This prints unreachable prefix instruction types as `i32` to just make them pass the parser. It is OK because they are not reachable anyway. Also this removes printing of `?` in atomic.rmw instruction printing.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r--src/passes/Print.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 0c71afc7b..dc973b208 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -55,6 +55,12 @@ static Name printableLocal(Index index, Function* func) {
return name;
}
+// Printing "unreachable" as a instruction prefix type is not valid in wasm text
+// format. Print something else to make it pass.
+static Type forceConcrete(Type type) {
+ return isConcreteType(type) ? type : i32;
+}
+
// Prints the internal contents of an expression: everything but
// the children.
struct PrintExpressionContents
@@ -141,7 +147,7 @@ struct PrintExpressionContents
printName(curr->name, o);
}
void visitLoad(Load* curr) {
- prepareColor(o) << printType(curr->type);
+ prepareColor(o) << printType(forceConcrete(curr->type));
if (curr->isAtomic) {
o << ".atomic";
}
@@ -167,7 +173,7 @@ struct PrintExpressionContents
}
}
void visitStore(Store* curr) {
- prepareColor(o) << printType(curr->valueType);
+ prepareColor(o) << printType(forceConcrete(curr->valueType));
if (curr->isAtomic) {
o << ".atomic";
}
@@ -192,10 +198,8 @@ struct PrintExpressionContents
}
}
static void printRMWSize(std::ostream& o, Type type, uint8_t bytes) {
- prepareColor(o) << printType(type) << ".atomic.rmw";
- if (type == unreachable) {
- o << '?';
- } else if (bytes != getTypeSize(type)) {
+ prepareColor(o) << printType(forceConcrete(type)) << ".atomic.rmw";
+ if (type != unreachable && bytes != getTypeSize(type)) {
if (bytes == 1) {
o << '8';
} else if (bytes == 2) {
@@ -253,7 +257,7 @@ struct PrintExpressionContents
}
void visitAtomicWait(AtomicWait* curr) {
prepareColor(o);
- o << printType(curr->expectedType) << ".atomic.wait";
+ o << printType(forceConcrete(curr->expectedType)) << ".atomic.wait";
if (curr->offset) {
o << " offset=" << curr->offset;
}