summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binary-reader.cc29
-rw-r--r--src/binary-writer.cc6
2 files changed, 22 insertions, 13 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: