summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/wabt/opcode.h8
-rw-r--r--include/wabt/type-checker.h4
-rw-r--r--src/type-checker.cc41
3 files changed, 19 insertions, 34 deletions
diff --git a/include/wabt/opcode.h b/include/wabt/opcode.h
index 16afb2ee..24b45ab6 100644
--- a/include/wabt/opcode.h
+++ b/include/wabt/opcode.h
@@ -69,14 +69,6 @@ struct Opcode {
Type GetParamType(int n) const { return GetInfo().param_types[n - 1]; }
Address GetMemorySize() const { return GetInfo().memory_size; }
- // If this is a load/store op, the type depends on the memory used.
- Type GetMemoryParam(Type param,
- const Limits* limits,
- bool has_address_operands) {
- return limits && limits->is_64 && has_address_operands ? Type(Type::I64)
- : param;
- }
-
// Get the byte sequence for this opcode, including prefix.
std::vector<uint8_t> GetBytes() const;
diff --git a/include/wabt/type-checker.h b/include/wabt/type-checker.h
index cfee13d5..fcfe51cf 100644
--- a/include/wabt/type-checker.h
+++ b/include/wabt/type-checker.h
@@ -171,9 +171,7 @@ class TypeChecker {
Type expected2,
Type expected3,
const char* desc);
- Result CheckOpcode1(Opcode opcode,
- const Limits* limits = nullptr,
- bool has_address_operands = false);
+ Result CheckOpcode1(Opcode opcode, const Limits* limits = nullptr);
Result CheckOpcode2(Opcode opcode, const Limits* limits = nullptr);
Result CheckOpcode3(Opcode opcode,
const Limits* limits1 = nullptr,
diff --git a/src/type-checker.cc b/src/type-checker.cc
index 01b5e233..aadcfd01 100644
--- a/src/type-checker.cc
+++ b/src/type-checker.cc
@@ -317,24 +317,22 @@ Result TypeChecker::PopAndCheck3Types(Type expected1,
return result;
}
-Result TypeChecker::CheckOpcode1(Opcode opcode,
- const Limits* limits,
- bool has_address_operands) {
- Result result =
- PopAndCheck1Type(opcode.GetMemoryParam(
- opcode.GetParamType1(), limits,
- has_address_operands || opcode.GetMemorySize() != 0),
- opcode.GetName());
- PushType(has_address_operands
- ? opcode.GetMemoryParam(opcode.GetResultType(), limits, true)
- : opcode.GetResultType());
+// Some paramater types depend on the memory being used.
+// For example load/store operands, or memory.fill operands.
+static Type GetMemoryParam(Type param, const Limits* limits) {
+ return limits ? limits->IndexType() : param;
+}
+
+Result TypeChecker::CheckOpcode1(Opcode opcode, const Limits* limits) {
+ Result result = PopAndCheck1Type(
+ GetMemoryParam(opcode.GetParamType1(), limits), opcode.GetName());
+ PushType(opcode.GetResultType());
return result;
}
Result TypeChecker::CheckOpcode2(Opcode opcode, const Limits* limits) {
Result result =
- PopAndCheck2Types(opcode.GetMemoryParam(opcode.GetParamType1(), limits,
- opcode.GetMemorySize() != 0),
+ PopAndCheck2Types(GetMemoryParam(opcode.GetParamType1(), limits),
opcode.GetParamType2(), opcode.GetName());
PushType(opcode.GetResultType());
return result;
@@ -344,15 +342,10 @@ Result TypeChecker::CheckOpcode3(Opcode opcode,
const Limits* limits1,
const Limits* limits2,
const Limits* limits3) {
- bool has_address_operands = limits1 || limits2 || limits3;
- Result result =
- PopAndCheck3Types(opcode.GetMemoryParam(opcode.GetParamType1(), limits1,
- has_address_operands),
- opcode.GetMemoryParam(opcode.GetParamType2(), limits2,
- has_address_operands),
- opcode.GetMemoryParam(opcode.GetParamType3(), limits3,
- has_address_operands),
- opcode.GetName());
+ Result result = PopAndCheck3Types(
+ GetMemoryParam(opcode.GetParamType1(), limits1),
+ GetMemoryParam(opcode.GetParamType2(), limits2),
+ GetMemoryParam(opcode.GetParamType3(), limits3), opcode.GetName());
PushType(opcode.GetResultType());
return result;
}
@@ -726,7 +719,9 @@ Result TypeChecker::OnMemoryFill(const Limits& limits) {
}
Result TypeChecker::OnMemoryGrow(const Limits& limits) {
- return CheckOpcode1(Opcode::MemoryGrow, &limits, true);
+ Result result = PopAndCheck1Type(limits.IndexType(), "memory.grow");
+ PushType(limits.IndexType());
+ return result;
}
Result TypeChecker::OnMemoryInit(uint32_t segment, const Limits& limits) {