diff options
-rw-r--r-- | src/binary-reader.cc | 29 | ||||
-rw-r--r-- | src/binary-writer.cc | 6 | ||||
-rw-r--r-- | test/dump/bulk-memory.txt | 34 |
3 files changed, 39 insertions, 30 deletions
diff --git a/src/binary-reader.cc b/src/binary-reader.cc index c01216e4..33fd3337 100644 --- a/src/binary-reader.cc +++ b/src/binary-reader.cc @@ -1343,22 +1343,22 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) { } case Opcode::TableInit: { + Index segment; + CHECK_RESULT(ReadIndex(&segment, "elem segment index")); uint8_t reserved; CHECK_RESULT(ReadU8(&reserved, "reserved table index")); ERROR_UNLESS(reserved == 0, "reserved value must be 0"); - Index segment; - CHECK_RESULT(ReadIndex(&segment, "elem segment index")); CALLBACK(OnTableInitExpr, segment); CALLBACK(OnOpcodeUint32Uint32, segment, reserved); break; } case Opcode::MemoryInit: { + Index segment; + CHECK_RESULT(ReadIndex(&segment, "elem segment index")); uint8_t reserved; CHECK_RESULT(ReadU8(&reserved, "reserved memory index")); ERROR_UNLESS(reserved == 0, "reserved value must be 0"); - Index segment; - CHECK_RESULT(ReadIndex(&segment, "elem segment index")); CALLBACK(OnMemoryInitExpr, segment); CALLBACK(OnOpcodeUint32Uint32, segment, reserved); break; @@ -1377,26 +1377,33 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) { break; } - case Opcode::MemoryCopy: case Opcode::MemoryFill: { uint8_t reserved; CHECK_RESULT(ReadU8(&reserved, "reserved memory index")); ERROR_UNLESS(reserved == 0, "reserved value must be 0"); - if (opcode == Opcode::MemoryCopy) { - CALLBACK(OnMemoryCopyExpr); - } else { - CALLBACK(OnMemoryFillExpr); - } + CALLBACK(OnMemoryFillExpr); CALLBACK(OnOpcodeUint32, reserved); break; } + case Opcode::MemoryCopy: { + uint8_t reserved; + CHECK_RESULT(ReadU8(&reserved, "reserved memory index")); + ERROR_UNLESS(reserved == 0, "reserved value must be 0"); + CHECK_RESULT(ReadU8(&reserved, "reserved memory index")); + ERROR_UNLESS(reserved == 0, "reserved value must be 0"); + CALLBACK(OnMemoryCopyExpr); + CALLBACK(OnOpcodeUint32Uint32, reserved, reserved); + break; + } case Opcode::TableCopy: { uint8_t reserved; CHECK_RESULT(ReadU8(&reserved, "reserved table index")); ERROR_UNLESS(reserved == 0, "reserved value must be 0"); + CHECK_RESULT(ReadU8(&reserved, "reserved table index")); + ERROR_UNLESS(reserved == 0, "reserved value must be 0"); CALLBACK(OnTableCopyExpr); - CALLBACK(OnOpcodeUint32, reserved); + CALLBACK(OnOpcodeUint32Uint32, reserved, reserved); break; } diff --git a/src/binary-writer.cc b/src/binary-writer.cc index b6c33ccc..be117869 100644 --- a/src/binary-writer.cc +++ b/src/binary-writer.cc @@ -566,6 +566,7 @@ void BinaryWriter::WriteExpr(const Func* func, const Expr* expr) { case ExprType::MemoryCopy: WriteOpcode(stream_, Opcode::MemoryCopy); WriteU32Leb128(stream_, 0, "memory.copy reserved"); + WriteU32Leb128(stream_, 0, "memory.copy reserved"); break; case ExprType::MemoryDrop: { Index index = @@ -586,8 +587,8 @@ void BinaryWriter::WriteExpr(const Func* func, const Expr* expr) { Index index = module_->GetDataSegmentIndex(cast<MemoryInitExpr>(expr)->var); WriteOpcode(stream_, Opcode::MemoryInit); - WriteU32Leb128(stream_, 0, "memory.init reserved"); WriteU32Leb128(stream_, index, "memory.init segment"); + WriteU32Leb128(stream_, 0, "memory.init reserved"); break; } case ExprType::MemorySize: @@ -597,6 +598,7 @@ void BinaryWriter::WriteExpr(const Func* func, const Expr* expr) { case ExprType::TableCopy: WriteOpcode(stream_, Opcode::TableCopy); WriteU32Leb128(stream_, 0, "table.copy reserved"); + WriteU32Leb128(stream_, 0, "table.copy reserved"); break; case ExprType::TableDrop: { Index index = @@ -609,8 +611,8 @@ void BinaryWriter::WriteExpr(const Func* func, const Expr* expr) { Index index = module_->GetElemSegmentIndex(cast<TableInitExpr>(expr)->var); WriteOpcode(stream_, Opcode::TableInit); - WriteU32Leb128(stream_, 0, "table.init reserved"); WriteU32Leb128(stream_, index, "table.init segment"); + WriteU32Leb128(stream_, 0, "table.init reserved"); break; } case ExprType::Nop: diff --git a/test/dump/bulk-memory.txt b/test/dump/bulk-memory.txt index a3cdae98..d98b6e6f 100644 --- a/test/dump/bulk-memory.txt +++ b/test/dump/bulk-memory.txt @@ -34,21 +34,21 @@ Code Disassembly: 000039: 41 00 | i32.const 0 00003b: 41 00 | i32.const 0 00003d: 41 00 | i32.const 0 - 00003f: fc 0a 00 | memory.copy 0 - 000042: 41 00 | i32.const 0 - 000044: 41 00 | i32.const 0 - 000046: 41 00 | i32.const 0 - 000048: fc 0b 00 | memory.fill 0 - 00004b: 0b | end -00004d func[1]: - 00004e: 41 00 | i32.const 0 - 000050: 41 00 | i32.const 0 - 000052: 41 00 | i32.const 0 - 000054: fc 0c 00 00 | table.init 0 0 - 000058: fc 0d 00 | table.drop 0 - 00005b: 41 00 | i32.const 0 - 00005d: 41 00 | i32.const 0 - 00005f: 41 00 | i32.const 0 - 000061: fc 0e 00 | table.copy 0 - 000064: 0b | end + 00003f: fc 0a 00 00 | memory.copy 0 0 + 000043: 41 00 | i32.const 0 + 000045: 41 00 | i32.const 0 + 000047: 41 00 | i32.const 0 + 000049: fc 0b 00 | memory.fill 0 + 00004c: 0b | end +00004e func[1]: + 00004f: 41 00 | i32.const 0 + 000051: 41 00 | i32.const 0 + 000053: 41 00 | i32.const 0 + 000055: fc 0c 00 00 | table.init 0 0 + 000059: fc 0d 00 | table.drop 0 + 00005c: 41 00 | i32.const 0 + 00005e: 41 00 | i32.const 0 + 000060: 41 00 | i32.const 0 + 000062: fc 0e 00 00 | table.copy 0 0 + 000066: 0b | end ;;; STDOUT ;;) |