mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2026-03-07 18:06:28 +00:00
IR: Compile-time type-checking of IR
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/common_types.h"
|
||||
#include "frontend/A32/types.h"
|
||||
|
||||
@@ -18,7 +19,7 @@ class Inst;
|
||||
* A representation of a value in the IR.
|
||||
* A value may either be an immediate or the result of a microinstruction.
|
||||
*/
|
||||
class Value final {
|
||||
class Value {
|
||||
public:
|
||||
Value() : type(Type::Void) {}
|
||||
explicit Value(Inst* value);
|
||||
@@ -62,5 +63,30 @@ private:
|
||||
};
|
||||
static_assert(sizeof(Value) <= 2 * sizeof(u64), "IR::Value should be kept small in size");
|
||||
|
||||
template <Type type_>
|
||||
class TypedValue final : public Value {
|
||||
public:
|
||||
TypedValue() : Value() {}
|
||||
|
||||
template <Type other_type>
|
||||
/* implicit */ TypedValue(const TypedValue<other_type>& value) : Value(value) {
|
||||
static_assert((other_type & type_) != Type::Void);
|
||||
ASSERT((value.GetType() & type_) != Type::Void);
|
||||
}
|
||||
|
||||
explicit TypedValue(const Value& value) : Value(value) {
|
||||
ASSERT((value.GetType() & type_) != Type::Void);
|
||||
}
|
||||
};
|
||||
|
||||
using U1 = TypedValue<Type::U1>;
|
||||
using U8 = TypedValue<Type::U8>;
|
||||
using U16 = TypedValue<Type::U16>;
|
||||
using U32 = TypedValue<Type::U32>;
|
||||
using U64 = TypedValue<Type::U64>;
|
||||
using F32 = TypedValue<Type::F32>;
|
||||
using F64 = TypedValue<Type::F64>;
|
||||
using F32F64 = TypedValue<Type::F32 | Type::F64>;
|
||||
|
||||
} // namespace IR
|
||||
} // namespace Dynarmic
|
||||
|
||||
Reference in New Issue
Block a user