summaryrefslogtreecommitdiff
path: root/src/interp/binary-reader-interp.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/interp/binary-reader-interp.cc')
-rw-r--r--src/interp/binary-reader-interp.cc41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/interp/binary-reader-interp.cc b/src/interp/binary-reader-interp.cc
index 6757f252..d847fa8e 100644
--- a/src/interp/binary-reader-interp.cc
+++ b/src/interp/binary-reader-interp.cc
@@ -142,6 +142,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
wabt::Result OnLocalDeclCount(Index count) override;
wabt::Result OnLocalDecl(Index decl_index, Index count, Type type) override;
+ wabt::Result OnOpcode(Opcode Opcode) override;
wabt::Result OnAtomicLoadExpr(Opcode opcode,
uint32_t alignment_log2,
Address offset) override;
@@ -218,6 +219,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
Index table_index,
bool passive,
Type elem_type) override;
+ wabt::Result BeginElemSegmentInitExpr(Index index) override;
wabt::Result EndElemSegmentInitExpr(Index index) override;
wabt::Result OnElemSegmentElemExprCount(Index index, Index count) override;
wabt::Result OnElemSegmentElemExpr_RefNull(Index segment_index) override;
@@ -228,6 +230,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
wabt::Result BeginDataSegment(Index index,
Index memory_index,
bool passive) override;
+ wabt::Result BeginDataSegmentInitExpr(Index index) override;
wabt::Result OnDataSegmentData(Index index,
const void* data,
Address size) override;
@@ -302,6 +305,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
wabt::Result CheckAlign(uint32_t alignment_log2, Address natural_alignment);
wabt::Result CheckAtomicAlign(uint32_t alignment_log2,
Address natural_alignment);
+ wabt::Result CheckInFunction();
wabt::Result AppendExport(Module* module,
ExternalKind kind,
@@ -1047,9 +1051,22 @@ wabt::Result BinaryReaderInterp::BeginElemSegment(Index index,
return wabt::Result::Ok;
}
+wabt::Result BinaryReaderInterp::BeginElemSegmentInitExpr(Index index) {
+ init_expr_value_.type = Type::Void;
+ return wabt::Result::Ok;
+}
+
wabt::Result BinaryReaderInterp::EndElemSegmentInitExpr(Index index) {
assert(segment_is_passive_ == false);
- assert(init_expr_value_.type == Type::I32);
+
+ if (init_expr_value_.type != Type::I32) {
+ PrintError(
+ "type mismatch in elem segment initializer expression, expected i32 "
+ "but got %s",
+ GetTypeName(init_expr_value_.type));
+ return wabt::Result::Error;
+ }
+
table_offset_ = init_expr_value_.value.i32;
return wabt::Result::Ok;
}
@@ -1114,6 +1131,11 @@ wabt::Result BinaryReaderInterp::BeginDataSegment(Index index,
return wabt::Result::Ok;
}
+wabt::Result BinaryReaderInterp::BeginDataSegmentInitExpr(Index index) {
+ init_expr_value_.type = Type::Void;
+ return wabt::Result::Ok;
+}
+
wabt::Result BinaryReaderInterp::OnDataSegmentData(Index index,
const void* src_data,
Address size) {
@@ -1124,6 +1146,14 @@ wabt::Result BinaryReaderInterp::OnDataSegmentData(Index index,
memcpy(segment->data.data(), src_data, size);
}
} else {
+ if (init_expr_value_.type != Type::I32) {
+ PrintError(
+ "type mismatch in data segment initializer expression, expected i32 "
+ "but got %s",
+ GetTypeName(init_expr_value_.type));
+ return wabt::Result::Error;
+ }
+
// An active segment still is present in the segment index space, but
// cannot be used with `memory.init` (it's as if it has already been
// dropped).
@@ -1131,7 +1161,6 @@ wabt::Result BinaryReaderInterp::OnDataSegmentData(Index index,
assert(module_->memory_index != kInvalidIndex);
Memory* memory = env_->GetMemory(module_->memory_index);
- assert(init_expr_value_.type == Type::I32);
Address address = init_expr_value_.value.i32;
data_segment_infos_.emplace_back(memory, address, src_data, size);
}
@@ -1251,6 +1280,14 @@ wabt::Result BinaryReaderInterp::CheckAtomicAlign(uint32_t alignment_log2,
return wabt::Result::Ok;
}
+wabt::Result BinaryReaderInterp::OnOpcode(Opcode opcode) {
+ if (current_func_ == nullptr || label_stack_.size() == 0) {
+ PrintError("Unexpected instruction after end of function");
+ return wabt::Result::Error;
+ }
+ return wabt::Result::Ok;
+}
+
wabt::Result BinaryReaderInterp::OnUnaryExpr(wabt::Opcode opcode) {
CHECK_RESULT(typechecker_.OnUnary(opcode));
CHECK_RESULT(EmitOpcode(opcode));