summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2022-10-18 13:54:22 -0500
committerGitHub <noreply@github.com>2022-10-18 13:54:22 -0500
commit8377174c3bb56b58cda054b3210799439004e229 (patch)
tree0d172db76ef1409b4c2e4134a39e1418dfbb52fc /src
parent6bef18672fae68ee4976a7b26f277f6caa32734f (diff)
downloadbinaryen-8377174c3bb56b58cda054b3210799439004e229.tar.gz
binaryen-8377174c3bb56b58cda054b3210799439004e229.tar.bz2
binaryen-8377174c3bb56b58cda054b3210799439004e229.zip
Parse and emit `array.len` without a type annotation (#5151)
Test that we can still parse the old annotated form as well.
Diffstat (limited to 'src')
-rw-r--r--src/passes/Print.cpp9
-rw-r--r--src/wasm-binary.h3
-rw-r--r--src/wasm/wasm-binary.cpp7
-rw-r--r--src/wasm/wasm-s-parser.cpp11
-rw-r--r--src/wasm/wasm-stack.cpp2
5 files changed, 15 insertions, 17 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 0f4a314ae..d0f19f78e 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2236,14 +2236,7 @@ struct PrintExpressionContents
printMedium(o, "array.set ");
TypeNamePrinter(o, wasm).print(curr->ref->type.getHeapType());
}
- void visitArrayLen(ArrayLen* curr) {
- printMedium(o, "array.len ");
- if (curr->ref->type == Type::unreachable) {
- TypeNamePrinter(o, wasm).print(HeapType::array);
- } else {
- TypeNamePrinter(o, wasm).print(curr->ref->type.getHeapType());
- }
- }
+ void visitArrayLen(ArrayLen* curr) { printMedium(o, "array.len"); }
void visitArrayCopy(ArrayCopy* curr) {
if (printUnreachableOrNullReplacement(curr->srcRef) ||
printUnreachableOrNullReplacement(curr->destRef)) {
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 709c0c9f9..db123515a 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -1111,8 +1111,9 @@ enum ASTNodes {
ArrayGetS = 0x14,
ArrayGetU = 0x15,
ArraySet = 0x16,
- ArrayLen = 0x17,
+ ArrayLenAnnotated = 0x17,
ArrayCopy = 0x18,
+ ArrayLen = 0x19,
ArrayInitStatic = 0x1a,
ArrayNew = 0x1b,
ArrayNewDefault = 0x1c,
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 13c28f151..54c904459 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -7111,11 +7111,12 @@ bool WasmBinaryBuilder::maybeVisitArraySet(Expression*& out, uint32_t code) {
}
bool WasmBinaryBuilder::maybeVisitArrayLen(Expression*& out, uint32_t code) {
- if (code != BinaryConsts::ArrayLen) {
+ if (code == BinaryConsts::ArrayLenAnnotated) {
+ // Ignore the type annotation and don't bother validating it.
+ getU32LEB();
+ } else if (code != BinaryConsts::ArrayLen) {
return false;
}
- // Ignore the type annotation and don't bother validating it.
- getU32LEB();
auto* ref = popNonVoidExpression();
out = Builder(wasm).makeArrayLen(ref);
return true;
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 41a0619f9..78ac84f42 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -3027,9 +3027,14 @@ Expression* SExpressionWasmBuilder::makeArraySet(Element& s) {
}
Expression* SExpressionWasmBuilder::makeArrayLen(Element& s) {
- // Ignore the type annotation and don't bother validating it.
- parseHeapType(*s[1]);
- auto ref = parseExpression(*s[2]);
+ // There may or may not be a type annotation.
+ Index i = 1;
+ try {
+ parseHeapType(*s[i]);
+ ++i;
+ } catch (...) {
+ }
+ auto ref = parseExpression(*s[i]);
return Builder(wasm).makeArrayLen(ref);
}
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index 7c1c121d5..f30e4be82 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -2169,8 +2169,6 @@ void BinaryInstWriter::visitArraySet(ArraySet* curr) {
void BinaryInstWriter::visitArrayLen(ArrayLen* curr) {
o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::ArrayLen);
- // Unused type index.
- o << U32LEB(0);
}
void BinaryInstWriter::visitArrayCopy(ArrayCopy* curr) {