summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-08-10 12:42:39 -0700
committerGitHub <noreply@github.com>2022-08-10 12:42:39 -0700
commit7d1985391571f3a913a47f4673843481ac46b067 (patch)
tree3af401623acbe1c944ed82d81fc5d8cba2438740 /src/wasm/wasm-binary.cpp
parente7cb4fbb4dba2e220d773eaa4d1509f8bd237778 (diff)
downloadbinaryen-7d1985391571f3a913a47f4673843481ac46b067.tar.gz
binaryen-7d1985391571f3a913a47f4673843481ac46b067.tar.bz2
binaryen-7d1985391571f3a913a47f4673843481ac46b067.zip
[Strings] Linear memory string operations should emit a memory index (#4893)
For now this index is always 0, but we must emit it. Also clean up the wat test a little - we don't have validation yet, but we should not validate without a memory in that file.
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 0b4a3d2f4..5399be0b7 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -6984,6 +6984,9 @@ bool WasmBinaryBuilder::maybeVisitStringNew(Expression*& out, uint32_t code) {
Expression* start = nullptr;
Expression* end = nullptr;
if (code == BinaryConsts::StringNewWTF8) {
+ if (getInt8() != 0) {
+ throwError("Unexpected nonzero memory index");
+ }
auto policy = getU32LEB();
switch (policy) {
case BinaryConsts::StringPolicy::UTF8:
@@ -7000,6 +7003,9 @@ bool WasmBinaryBuilder::maybeVisitStringNew(Expression*& out, uint32_t code) {
}
length = popNonVoidExpression();
} else if (code == BinaryConsts::StringNewWTF16) {
+ if (getInt8() != 0) {
+ throwError("Unexpected nonzero memory index");
+ }
op = StringNewWTF16;
length = popNonVoidExpression();
} else if (code == BinaryConsts::StringNewWTF8Array) {
@@ -7080,6 +7086,9 @@ bool WasmBinaryBuilder::maybeVisitStringEncode(Expression*& out,
Expression* start = nullptr;
// TODO: share this code with string.measure?
if (code == BinaryConsts::StringEncodeWTF8) {
+ if (getInt8() != 0) {
+ throwError("Unexpected nonzero memory index");
+ }
auto policy = getU32LEB();
switch (policy) {
case BinaryConsts::StringPolicy::UTF8:
@@ -7092,6 +7101,9 @@ bool WasmBinaryBuilder::maybeVisitStringEncode(Expression*& out,
throwError("bad policy for string.encode");
}
} else if (code == BinaryConsts::StringEncodeWTF16) {
+ if (getInt8() != 0) {
+ throwError("Unexpected nonzero memory index");
+ }
op = StringEncodeWTF16;
} else if (code == BinaryConsts::StringEncodeWTF8Array) {
auto policy = getU32LEB();