ir/opcodes: Implement IR::AreTypesCompatible
Type-checking is now occuring in more than one place.
This commit is contained in:
parent
9782e7da3f
commit
192a0029be
5 changed files with 10 additions and 3 deletions
|
@ -77,7 +77,7 @@ std::string DumpBlock(const IR::Block& block) {
|
||||||
|
|
||||||
Type actual_type = arg.GetType();
|
Type actual_type = arg.GetType();
|
||||||
Type expected_type = GetArgTypeOf(op, arg_index);
|
Type expected_type = GetArgTypeOf(op, arg_index);
|
||||||
if (actual_type != expected_type && actual_type != Type::Opaque && expected_type != Type::Opaque) {
|
if (!AreTypesCompatible(actual_type, expected_type)) {
|
||||||
ret += Common::StringFromFormat("<type error: %s != %s>", GetNameOf(actual_type), GetNameOf(expected_type));
|
ret += Common::StringFromFormat("<type error: %s != %s>", GetNameOf(actual_type), GetNameOf(expected_type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ Value Inst::GetArg(size_t index) const {
|
||||||
|
|
||||||
void Inst::SetArg(size_t index, Value value) {
|
void Inst::SetArg(size_t index, Value value) {
|
||||||
DEBUG_ASSERT(index < GetNumArgsOf(op));
|
DEBUG_ASSERT(index < GetNumArgsOf(op));
|
||||||
DEBUG_ASSERT(value.GetType() == GetArgTypeOf(op, index) || Type::Opaque == GetArgTypeOf(op, index));
|
DEBUG_ASSERT(AreTypesCompatible(value.GetType(), GetArgTypeOf(op, index)));
|
||||||
|
|
||||||
if (!args[index].IsImmediate()) {
|
if (!args[index].IsImmediate()) {
|
||||||
UndoUse(args[index]);
|
UndoUse(args[index]);
|
||||||
|
|
|
@ -56,5 +56,9 @@ const char* GetNameOf(Type type) {
|
||||||
return names.at(static_cast<size_t>(type));
|
return names.at(static_cast<size_t>(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AreTypesCompatible(Type t1, Type t2) {
|
||||||
|
return t1 == t2 || t1 == Type::Opaque || t2 == Type::Opaque;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace IR
|
} // namespace IR
|
||||||
} // namespace Dynarmic
|
} // namespace Dynarmic
|
||||||
|
|
|
@ -56,5 +56,8 @@ const char* GetNameOf(Opcode op);
|
||||||
/// Get the name of a type.
|
/// Get the name of a type.
|
||||||
const char* GetNameOf(Type type);
|
const char* GetNameOf(Type type);
|
||||||
|
|
||||||
|
/// @returns true if t1 and t2 are compatible types
|
||||||
|
bool AreTypesCompatible(Type t1, Type t2);
|
||||||
|
|
||||||
} // namespace Arm
|
} // namespace Arm
|
||||||
} // namespace Dynarmic
|
} // namespace Dynarmic
|
||||||
|
|
|
@ -20,7 +20,7 @@ void VerificationPass(const IR::Block& block) {
|
||||||
for (size_t i = 0; i < inst.NumArgs(); i++) {
|
for (size_t i = 0; i < inst.NumArgs(); i++) {
|
||||||
IR::Type t1 = inst.GetArg(i).GetType();
|
IR::Type t1 = inst.GetArg(i).GetType();
|
||||||
IR::Type t2 = IR::GetArgTypeOf(inst.GetOpcode(), i);
|
IR::Type t2 = IR::GetArgTypeOf(inst.GetOpcode(), i);
|
||||||
if (t1 != t2 && t1 != IR::Type::Opaque && t2 != IR::Type::Opaque) {
|
if (!IR::AreTypesCompatible(t1, t2)) {
|
||||||
puts(IR::DumpBlock(block).c_str());
|
puts(IR::DumpBlock(block).c_str());
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue