summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/interp/binary-reader-interp.cc18
-rw-r--r--src/type-checker.cc22
-rw-r--r--src/type-checker.h7
3 files changed, 18 insertions, 29 deletions
diff --git a/src/interp/binary-reader-interp.cc b/src/interp/binary-reader-interp.cc
index cc0a12fc..7a1bc26e 100644
--- a/src/interp/binary-reader-interp.cc
+++ b/src/interp/binary-reader-interp.cc
@@ -301,7 +301,6 @@ class BinaryReaderInterp : public BinaryReaderNop {
Index* out_keep_count);
Result BeginInitExpr(Type type);
Result EndInitExpr();
- Result CheckEmptyInitExpr();
void EmitBr(Index depth,
Index drop_count,
@@ -644,15 +643,6 @@ Result BinaryReaderInterp::BeginInitExpr(Type type) {
return Result::Ok;
}
-Result BinaryReaderInterp::CheckEmptyInitExpr() {
- assert(reading_init_expr_);
- if (init_expr_.kind != InitExprKind::None) {
- PrintError("expected END opcode after initializer expression");
- return Result::Error;
- }
- return Result::Ok;
-}
-
Result BinaryReaderInterp::EndGlobalInitExpr(Index index) {
CHECK_RESULT(EndInitExpr());
GlobalDesc& global = module_.globals.back();
@@ -1192,7 +1182,6 @@ Result BinaryReaderInterp::OnDropExpr() {
Result BinaryReaderInterp::OnI32ConstExpr(uint32_t value) {
CHECK_RESULT(validator_.OnConst(GetLocation(), Type::I32));
if (reading_init_expr_) {
- CHECK_RESULT(CheckEmptyInitExpr());
init_expr_.kind = InitExprKind::I32;
init_expr_.i32_ = value;
return Result::Ok;
@@ -1204,7 +1193,6 @@ Result BinaryReaderInterp::OnI32ConstExpr(uint32_t value) {
Result BinaryReaderInterp::OnI64ConstExpr(uint64_t value) {
CHECK_RESULT(validator_.OnConst(GetLocation(), Type::I64));
if (reading_init_expr_) {
- CHECK_RESULT(CheckEmptyInitExpr());
init_expr_.kind = InitExprKind::I64;
init_expr_.i64_ = value;
return Result::Ok;
@@ -1216,7 +1204,6 @@ Result BinaryReaderInterp::OnI64ConstExpr(uint64_t value) {
Result BinaryReaderInterp::OnF32ConstExpr(uint32_t value_bits) {
CHECK_RESULT(validator_.OnConst(GetLocation(), Type::F32));
if (reading_init_expr_) {
- CHECK_RESULT(CheckEmptyInitExpr());
init_expr_.kind = InitExprKind::F32;
init_expr_.f32_ = Bitcast<f32>(value_bits);
return Result::Ok;
@@ -1228,7 +1215,6 @@ Result BinaryReaderInterp::OnF32ConstExpr(uint32_t value_bits) {
Result BinaryReaderInterp::OnF64ConstExpr(uint64_t value_bits) {
CHECK_RESULT(validator_.OnConst(GetLocation(), Type::F64));
if (reading_init_expr_) {
- CHECK_RESULT(CheckEmptyInitExpr());
init_expr_.kind = InitExprKind::F64;
init_expr_.f64_ = Bitcast<f64>(value_bits);
return Result::Ok;
@@ -1240,7 +1226,6 @@ Result BinaryReaderInterp::OnF64ConstExpr(uint64_t value_bits) {
Result BinaryReaderInterp::OnV128ConstExpr(v128 value_bits) {
CHECK_RESULT(validator_.OnConst(GetLocation(), Type::V128));
if (reading_init_expr_) {
- CHECK_RESULT(CheckEmptyInitExpr());
init_expr_.kind = InitExprKind::V128;
init_expr_.v128_ = Bitcast<v128>(value_bits);
return Result::Ok;
@@ -1252,7 +1237,6 @@ Result BinaryReaderInterp::OnV128ConstExpr(v128 value_bits) {
Result BinaryReaderInterp::OnGlobalGetExpr(Index global_index) {
CHECK_RESULT(validator_.OnGlobalGet(GetLocation(), Var(global_index)));
if (reading_init_expr_) {
- CHECK_RESULT(CheckEmptyInitExpr());
init_expr_.kind = InitExprKind::GlobalGet;
init_expr_.index_ = global_index;
return Result::Ok;
@@ -1349,7 +1333,6 @@ Result BinaryReaderInterp::OnTableFillExpr(Index table_index) {
Result BinaryReaderInterp::OnRefFuncExpr(Index func_index) {
CHECK_RESULT(validator_.OnRefFunc(GetLocation(), Var(func_index)));
if (reading_init_expr_) {
- CHECK_RESULT(CheckEmptyInitExpr());
init_expr_.kind = InitExprKind::RefFunc;
init_expr_.index_ = func_index;
return Result::Ok;
@@ -1361,7 +1344,6 @@ Result BinaryReaderInterp::OnRefFuncExpr(Index func_index) {
Result BinaryReaderInterp::OnRefNullExpr(Type type) {
CHECK_RESULT(validator_.OnRefNull(GetLocation(), type));
if (reading_init_expr_) {
- CHECK_RESULT(CheckEmptyInitExpr());
init_expr_.kind = InitExprKind::RefNull;
init_expr_.type_ = type;
return Result::Ok;
diff --git a/src/type-checker.cc b/src/type-checker.cc
index 0bce0743..e36bd984 100644
--- a/src/type-checker.cc
+++ b/src/type-checker.cc
@@ -216,7 +216,7 @@ Result TypeChecker::CheckTypeStackEnd(const char* desc) {
Result result = (type_stack_.size() == label->type_stack_limit)
? Result::Ok
: Result::Error;
- PrintStackIfFailed(result, desc);
+ PrintStackIfFailedV(result, desc, {}, /*is_end=*/true);
return result;
}
@@ -356,9 +356,10 @@ Result TypeChecker::CheckOpcode3(Opcode opcode,
return result;
}
-void TypeChecker::PrintStackIfFailed(Result result,
- const char* desc,
- const TypeVector& expected) {
+void TypeChecker::PrintStackIfFailedV(Result result,
+ const char* desc,
+ const TypeVector& expected,
+ bool is_end) {
if (Succeeded(result)) {
return;
}
@@ -395,6 +396,9 @@ void TypeChecker::PrintStackIfFailed(Result result,
}
std::string message = "type mismatch in ";
+ if (is_end) {
+ message = "type mismatch at end of ";
+ }
message += desc;
message += ", expected ";
message += TypesToString(expected);
@@ -620,8 +624,8 @@ Result TypeChecker::OnElse() {
Label* label;
CHECK_RESULT(TopLabel(&label));
result |= CheckLabelType(label, LabelType::If);
- result |= PopAndCheckSignature(label->result_types, "if true branch");
- result |= CheckTypeStackEnd("if true branch");
+ result |= PopAndCheckSignature(label->result_types, "`if true` branch");
+ result |= CheckTypeStackEnd("`if true` branch");
ResetTypeStackToLabel(label);
PushTypes(label->param_types);
label->label_type = LabelType::Else;
@@ -644,8 +648,8 @@ Result TypeChecker::OnEnd(Label* label,
Result TypeChecker::OnEnd() {
Result result = Result::Ok;
static const char* s_label_type_name[] = {
- "function", "init_expr", "block", "loop",
- "if", "if false branch", "try", "try catch"};
+ "function", "initializer expression", "block", "loop",
+ "if", "`if false` branch", "try", "try catch"};
WABT_STATIC_ASSERT(WABT_ARRAY_SIZE(s_label_type_name) == kLabelTypeCount);
Label* label;
CHECK_RESULT(TopLabel(&label));
@@ -971,7 +975,7 @@ Result TypeChecker::EndInitExpr() {
Label* label;
CHECK_RESULT(TopLabel(&label));
result |= CheckLabelType(label, LabelType::InitExpr);
- result |= OnEnd(label, "constant expression", "init_expr");
+ result |= OnEnd(label, "initializer expression", "initializer expression");
return result;
}
diff --git a/src/type-checker.h b/src/type-checker.h
index 4ec623c1..9fd0fe46 100644
--- a/src/type-checker.h
+++ b/src/type-checker.h
@@ -180,11 +180,14 @@ class TypeChecker {
// Minor optimization, check result before constructing the vector to pass
// to the other overload of PrintStackIfFailed.
if (Failed(result)) {
- PrintStackIfFailed(result, desc, {args...});
+ PrintStackIfFailedV(result, desc, {args...}, /*is_end=*/false);
}
}
- void PrintStackIfFailed(Result, const char* desc, const TypeVector&);
+ void PrintStackIfFailedV(Result,
+ const char* desc,
+ const TypeVector&,
+ bool is_end);
ErrorCallback error_callback_;
TypeVector type_stack_;