2016-08-17 15:53:36 +01:00
|
|
|
/* This file is part of the dynarmic project.
|
|
|
|
* Copyright (c) 2016 MerryMage
|
|
|
|
* This software may be used and distributed according to the terms of the GNU
|
|
|
|
* General Public License version 2 or any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-01-07 00:11:57 +00:00
|
|
|
#include <type_traits>
|
|
|
|
|
2018-01-05 21:47:23 +00:00
|
|
|
#include "common/assert.h"
|
2016-08-17 15:53:36 +01:00
|
|
|
#include "common/common_types.h"
|
2018-02-11 11:46:18 +00:00
|
|
|
#include "frontend/ir/type.h"
|
2016-08-17 15:53:36 +01:00
|
|
|
|
2018-09-09 01:03:45 +01:00
|
|
|
namespace Dynarmic::A32 {
|
|
|
|
enum class ExtReg;
|
|
|
|
enum class Reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Dynarmic::A64 {
|
|
|
|
enum class Reg;
|
|
|
|
enum class Vec;
|
|
|
|
}
|
|
|
|
|
2018-01-26 13:51:48 +00:00
|
|
|
namespace Dynarmic::IR {
|
2016-08-17 15:53:36 +01:00
|
|
|
|
|
|
|
class Inst;
|
2018-09-09 01:03:45 +01:00
|
|
|
enum class Cond;
|
2016-08-17 15:53:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A representation of a value in the IR.
|
|
|
|
* A value may either be an immediate or the result of a microinstruction.
|
|
|
|
*/
|
2018-01-05 21:47:23 +00:00
|
|
|
class Value {
|
2016-08-17 15:53:36 +01:00
|
|
|
public:
|
2018-08-13 20:35:36 +01:00
|
|
|
using CoprocessorInfo = std::array<u8, 8>;
|
|
|
|
|
2016-08-17 15:53:36 +01:00
|
|
|
Value() : type(Type::Void) {}
|
|
|
|
explicit Value(Inst* value);
|
2018-01-01 15:23:56 +00:00
|
|
|
explicit Value(A32::Reg value);
|
|
|
|
explicit Value(A32::ExtReg value);
|
2018-01-04 23:05:27 +00:00
|
|
|
explicit Value(A64::Reg value);
|
|
|
|
explicit Value(A64::Vec value);
|
2016-08-17 15:53:36 +01:00
|
|
|
explicit Value(bool value);
|
|
|
|
explicit Value(u8 value);
|
2017-01-29 22:58:11 +00:00
|
|
|
explicit Value(u16 value);
|
2016-08-17 15:53:36 +01:00
|
|
|
explicit Value(u32 value);
|
|
|
|
explicit Value(u64 value);
|
2018-08-13 20:35:36 +01:00
|
|
|
explicit Value(CoprocessorInfo value);
|
2018-01-18 11:36:48 +00:00
|
|
|
explicit Value(Cond value);
|
2016-08-17 15:53:36 +01:00
|
|
|
|
|
|
|
bool IsEmpty() const;
|
|
|
|
bool IsImmediate() const;
|
|
|
|
Type GetType() const;
|
|
|
|
|
|
|
|
Inst* GetInst() const;
|
2018-01-01 15:23:56 +00:00
|
|
|
A32::Reg GetA32RegRef() const;
|
|
|
|
A32::ExtReg GetA32ExtRegRef() const;
|
2018-01-04 23:05:27 +00:00
|
|
|
A64::Reg GetA64RegRef() const;
|
|
|
|
A64::Vec GetA64VecRef() const;
|
2016-08-17 15:53:36 +01:00
|
|
|
bool GetU1() const;
|
|
|
|
u8 GetU8() const;
|
2017-01-29 22:58:11 +00:00
|
|
|
u16 GetU16() const;
|
2016-08-17 15:53:36 +01:00
|
|
|
u32 GetU32() const;
|
|
|
|
u64 GetU64() const;
|
2018-08-13 20:35:36 +01:00
|
|
|
CoprocessorInfo GetCoprocInfo() const;
|
2018-01-18 11:36:48 +00:00
|
|
|
Cond GetCond() const;
|
2016-08-17 15:53:36 +01:00
|
|
|
|
2018-09-28 19:46:38 +01:00
|
|
|
/**
|
2018-10-04 10:10:08 +01:00
|
|
|
* Retrieves the immediate of a Value instance as a signed 64-bit value.
|
|
|
|
*
|
|
|
|
* @pre The value contains either a U1, U8, U16, U32, or U64 value.
|
|
|
|
* Breaking this precondition will cause an assertion to be invoked.
|
|
|
|
*/
|
|
|
|
s64 GetImmediateAsS64() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the immediate of a Value instance as an unsigned 64-bit value.
|
2018-09-28 19:46:38 +01:00
|
|
|
*
|
|
|
|
* @pre The value contains either a U1, U8, U16, U32, or U64 value.
|
|
|
|
* Breaking this precondition will cause an assertion to be invoked.
|
|
|
|
*/
|
|
|
|
u64 GetImmediateAsU64() const;
|
|
|
|
|
2018-10-04 10:18:22 +01:00
|
|
|
/**
|
|
|
|
* Determines whether or not the contained value matches the provided signed one.
|
|
|
|
*
|
|
|
|
* Note that this function will always return false if the contained
|
|
|
|
* value is not a a constant value. In other words, if IsImmediate()
|
|
|
|
* would return false on an instance, then so will this function.
|
|
|
|
*
|
|
|
|
* @param value The value to check against the contained value.
|
|
|
|
*/
|
|
|
|
bool IsSignedImmediate(s64 value) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether or not the contained value matches the provided unsigned one.
|
|
|
|
*
|
|
|
|
* Note that this function will always return false if the contained
|
|
|
|
* value is not a a constant value. In other words, if IsImmediate()
|
|
|
|
* would return false on an instance, then so will this function.
|
|
|
|
*
|
|
|
|
* @param value The value to check against the contained value.
|
|
|
|
*/
|
|
|
|
bool IsUnsignedImmediate(u64 value) const;
|
|
|
|
|
2018-10-01 23:35:31 +01:00
|
|
|
/**
|
|
|
|
* Determines whether or not the contained constant value has all bits set.
|
|
|
|
*
|
|
|
|
* @pre The value contains either a U1, U8, U16, U32, or U64 value.
|
|
|
|
* Breaking this precondition will cause an assertion to be invoked.
|
|
|
|
*/
|
|
|
|
bool HasAllBitsSet() const;
|
|
|
|
|
2018-10-04 09:52:44 +01:00
|
|
|
/**
|
|
|
|
* Whether or not the current value contains a representation of zero.
|
|
|
|
*
|
|
|
|
* Note that this function will always return false if the contained
|
|
|
|
* value is not a a constant value. In other words, if IsImmediate()
|
|
|
|
* would return false on an instance, then so will this function.
|
|
|
|
*/
|
|
|
|
bool IsZero() const;
|
|
|
|
|
2016-08-17 15:53:36 +01:00
|
|
|
private:
|
|
|
|
Type type;
|
|
|
|
|
|
|
|
union {
|
|
|
|
Inst* inst; // type == Type::Opaque
|
2018-01-01 15:23:56 +00:00
|
|
|
A32::Reg imm_a32regref;
|
|
|
|
A32::ExtReg imm_a32extregref;
|
2018-01-04 23:05:27 +00:00
|
|
|
A64::Reg imm_a64regref;
|
|
|
|
A64::Vec imm_a64vecref;
|
2016-08-17 15:53:36 +01:00
|
|
|
bool imm_u1;
|
|
|
|
u8 imm_u8;
|
2017-01-29 22:58:11 +00:00
|
|
|
u16 imm_u16;
|
2016-08-17 15:53:36 +01:00
|
|
|
u32 imm_u32;
|
|
|
|
u64 imm_u64;
|
2018-08-13 20:35:36 +01:00
|
|
|
CoprocessorInfo imm_coproc;
|
2018-01-18 11:36:48 +00:00
|
|
|
Cond imm_cond;
|
2016-08-17 15:53:36 +01:00
|
|
|
} inner;
|
|
|
|
};
|
2016-12-31 10:46:13 +00:00
|
|
|
static_assert(sizeof(Value) <= 2 * sizeof(u64), "IR::Value should be kept small in size");
|
2016-08-17 15:53:36 +01:00
|
|
|
|
2018-01-05 21:47:23 +00:00
|
|
|
template <Type type_>
|
|
|
|
class TypedValue final : public Value {
|
|
|
|
public:
|
2018-01-24 02:11:07 +00:00
|
|
|
TypedValue() = default;
|
2018-01-05 21:47:23 +00:00
|
|
|
|
2018-01-07 00:11:57 +00:00
|
|
|
template <Type other_type, typename = std::enable_if_t<(other_type & type_) != Type::Void>>
|
2018-01-05 21:47:23 +00:00
|
|
|
/* implicit */ TypedValue(const TypedValue<other_type>& value) : Value(value) {
|
|
|
|
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>;
|
2018-01-19 01:09:46 +00:00
|
|
|
using U128 = TypedValue<Type::U128>;
|
2018-01-07 00:11:57 +00:00
|
|
|
using U32U64 = TypedValue<Type::U32 | Type::U64>;
|
2018-01-07 11:31:20 +00:00
|
|
|
using UAny = TypedValue<Type::U8 | Type::U16 | Type::U32 | Type::U64>;
|
2018-01-24 15:55:59 +00:00
|
|
|
using UAnyU128 = TypedValue<Type::U8 | Type::U16 | Type::U32 | Type::U64 | Type::U128>;
|
2018-01-07 11:31:20 +00:00
|
|
|
using NZCV = TypedValue<Type::NZCVFlags>;
|
2018-08-18 21:08:34 +01:00
|
|
|
using Table = TypedValue<Type::Table>;
|
2018-01-05 21:47:23 +00:00
|
|
|
|
2018-01-26 13:51:48 +00:00
|
|
|
} // namespace Dynarmic::IR
|