summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp68
1 files changed, 66 insertions, 2 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 90a588bb9..721884126 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1715,10 +1715,14 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
throwError("invalid code after atomic prefix: " + std::to_string(code));
break;
}
- case BinaryConsts::TruncSatPrefix: {
+ case BinaryConsts::MiscPrefix: {
auto opcode = getU32LEB();
if (maybeVisitTruncSat(curr, opcode)) break;
- throwError("invalid code after nontrapping float-to-int prefix: " + std::to_string(code));
+ if (maybeVisitMemoryInit(curr, opcode)) break;
+ if (maybeVisitDataDrop(curr, opcode)) break;
+ if (maybeVisitMemoryCopy(curr, opcode)) break;
+ if (maybeVisitMemoryFill(curr, opcode)) break;
+ throwError("invalid code after nontrapping float-to-int prefix: " + std::to_string(opcode));
break;
}
case BinaryConsts::SIMDPrefix: {
@@ -2342,6 +2346,66 @@ bool WasmBinaryBuilder::maybeVisitTruncSat(Expression*& out, uint32_t code) {
return true;
}
+bool WasmBinaryBuilder::maybeVisitMemoryInit(Expression*& out, uint32_t code) {
+ if (code != BinaryConsts::MemoryInit) {
+ return false;
+ }
+ auto* curr = allocator.alloc<MemoryInit>();
+ curr->size = popNonVoidExpression();
+ curr->offset = popNonVoidExpression();
+ curr->dest = popNonVoidExpression();
+ curr->segment = getU32LEB();
+ if (getInt8() != 0) {
+ throwError("Unexpected nonzero memory index");
+ }
+ curr->finalize();
+ out = curr;
+ return true;
+}
+
+bool WasmBinaryBuilder::maybeVisitDataDrop(Expression*& out, uint32_t code) {
+ if (code != BinaryConsts::DataDrop) {
+ return false;
+ }
+ auto* curr = allocator.alloc<DataDrop>();
+ curr->segment = getU32LEB();
+ curr->finalize();
+ out = curr;
+ return true;
+}
+
+bool WasmBinaryBuilder::maybeVisitMemoryCopy(Expression*& out, uint32_t code) {
+ if (code != BinaryConsts::MemoryCopy) {
+ return false;
+ }
+ auto* curr = allocator.alloc<MemoryCopy>();
+ curr->size = popNonVoidExpression();
+ curr->source = popNonVoidExpression();
+ curr->dest = popNonVoidExpression();
+ if (getInt8() != 0 || getInt8() != 0) {
+ throwError("Unexpected nonzero memory index");
+ }
+ curr->finalize();
+ out = curr;
+ return true;
+}
+
+bool WasmBinaryBuilder::maybeVisitMemoryFill(Expression*& out, uint32_t code) {
+ if (code != BinaryConsts::MemoryFill) {
+ return false;
+ }
+ auto* curr = allocator.alloc<MemoryFill>();
+ curr->size = popNonVoidExpression();
+ curr->value = popNonVoidExpression();
+ curr->dest = popNonVoidExpression();
+ if (getInt8() != 0) {
+ throwError("Unexpected nonzero memory index");
+ }
+ curr->finalize();
+ out = curr;
+ return true;
+}
+
bool WasmBinaryBuilder::maybeVisitBinary(Expression*& out, uint8_t code) {
Binary* curr;
#define INT_TYPED_CODE(code) { \