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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
|
|
|
#include "frontend/ir/microinstruction.h"
|
|
|
|
#include "frontend/ir/value.h"
|
|
|
|
|
|
|
|
namespace Dynarmic {
|
|
|
|
namespace IR {
|
|
|
|
|
|
|
|
Value::Value(Inst* value) : type(Type::Opaque) {
|
|
|
|
inner.inst = value;
|
|
|
|
}
|
|
|
|
|
2018-01-05 20:30:41 +00:00
|
|
|
Value::Value(A32::Reg value) : type(Type::A32Reg) {
|
2018-01-01 15:23:56 +00:00
|
|
|
inner.imm_a32regref = value;
|
2016-08-17 15:53:36 +01:00
|
|
|
}
|
|
|
|
|
2018-01-05 20:30:41 +00:00
|
|
|
Value::Value(A32::ExtReg value) : type(Type::A32ExtReg) {
|
2018-01-01 15:23:56 +00:00
|
|
|
inner.imm_a32extregref = value;
|
2016-08-17 15:53:36 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 23:05:27 +00:00
|
|
|
Value::Value(A64::Reg value) : type(Type::A64Reg) {
|
|
|
|
inner.imm_a64regref = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value::Value(A64::Vec value) : type(Type::A64Vec) {
|
|
|
|
inner.imm_a64vecref = value;
|
|
|
|
}
|
|
|
|
|
2016-08-17 15:53:36 +01:00
|
|
|
Value::Value(bool value) : type(Type::U1) {
|
|
|
|
inner.imm_u1 = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value::Value(u8 value) : type(Type::U8) {
|
|
|
|
inner.imm_u8 = value;
|
|
|
|
}
|
|
|
|
|
2017-01-29 22:58:11 +00:00
|
|
|
Value::Value(u16 value) : type(Type::U16) {
|
|
|
|
inner.imm_u16 = value;
|
|
|
|
}
|
|
|
|
|
2016-08-17 15:53:36 +01:00
|
|
|
Value::Value(u32 value) : type(Type::U32) {
|
|
|
|
inner.imm_u32 = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value::Value(u64 value) : type(Type::U64) {
|
|
|
|
inner.imm_u64 = value;
|
|
|
|
}
|
|
|
|
|
2016-12-31 10:46:13 +00:00
|
|
|
Value::Value(std::array<u8, 8> value) : type(Type::CoprocInfo) {
|
|
|
|
inner.imm_coproc = value;
|
|
|
|
}
|
|
|
|
|
2018-01-18 11:36:48 +00:00
|
|
|
Value::Value(Cond value) : type(Type::Cond) {
|
|
|
|
inner.imm_cond = value;
|
|
|
|
}
|
|
|
|
|
2016-08-17 15:53:36 +01:00
|
|
|
bool Value::IsImmediate() const {
|
|
|
|
if (type == Type::Opaque)
|
|
|
|
return inner.inst->GetOpcode() == Opcode::Identity ? inner.inst->GetArg(0).IsImmediate() : false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::IsEmpty() const {
|
|
|
|
return type == Type::Void;
|
|
|
|
}
|
|
|
|
|
|
|
|
Type Value::GetType() const {
|
|
|
|
if (type == Type::Opaque) {
|
|
|
|
if (inner.inst->GetOpcode() == Opcode::Identity) {
|
|
|
|
return inner.inst->GetArg(0).GetType();
|
|
|
|
} else {
|
|
|
|
return inner.inst->GetType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2018-01-01 15:23:56 +00:00
|
|
|
A32::Reg Value::GetA32RegRef() const {
|
2018-01-05 20:30:41 +00:00
|
|
|
ASSERT(type == Type::A32Reg);
|
2018-01-01 15:23:56 +00:00
|
|
|
return inner.imm_a32regref;
|
2016-08-17 15:53:36 +01:00
|
|
|
}
|
|
|
|
|
2018-01-01 15:23:56 +00:00
|
|
|
A32::ExtReg Value::GetA32ExtRegRef() const {
|
2018-01-05 20:30:41 +00:00
|
|
|
ASSERT(type == Type::A32ExtReg);
|
2018-01-01 15:23:56 +00:00
|
|
|
return inner.imm_a32extregref;
|
2016-08-17 15:53:36 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 23:05:27 +00:00
|
|
|
A64::Reg Value::GetA64RegRef() const {
|
|
|
|
ASSERT(type == Type::A64Reg);
|
|
|
|
return inner.imm_a64regref;
|
|
|
|
}
|
|
|
|
|
|
|
|
A64::Vec Value::GetA64VecRef() const {
|
|
|
|
ASSERT(type == Type::A64Vec);
|
|
|
|
return inner.imm_a64vecref;
|
|
|
|
}
|
|
|
|
|
2016-08-17 15:53:36 +01:00
|
|
|
Inst* Value::GetInst() const {
|
2017-02-26 23:27:41 +00:00
|
|
|
ASSERT(type == Type::Opaque);
|
2016-08-17 15:53:36 +01:00
|
|
|
return inner.inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::GetU1() const {
|
|
|
|
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity)
|
|
|
|
return inner.inst->GetArg(0).GetU1();
|
2017-02-26 23:27:41 +00:00
|
|
|
ASSERT(type == Type::U1);
|
2016-08-17 15:53:36 +01:00
|
|
|
return inner.imm_u1;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 Value::GetU8() const {
|
|
|
|
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity)
|
|
|
|
return inner.inst->GetArg(0).GetU8();
|
2017-02-26 23:27:41 +00:00
|
|
|
ASSERT(type == Type::U8);
|
2016-08-17 15:53:36 +01:00
|
|
|
return inner.imm_u8;
|
|
|
|
}
|
|
|
|
|
2017-01-29 22:58:11 +00:00
|
|
|
u16 Value::GetU16() const {
|
|
|
|
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity)
|
|
|
|
return inner.inst->GetArg(0).GetU16();
|
2017-02-26 23:27:41 +00:00
|
|
|
ASSERT(type == Type::U16);
|
2017-01-29 22:58:11 +00:00
|
|
|
return inner.imm_u16;
|
|
|
|
}
|
|
|
|
|
2016-08-17 15:53:36 +01:00
|
|
|
u32 Value::GetU32() const {
|
|
|
|
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity)
|
|
|
|
return inner.inst->GetArg(0).GetU32();
|
2017-02-26 23:27:41 +00:00
|
|
|
ASSERT(type == Type::U32);
|
2016-08-17 15:53:36 +01:00
|
|
|
return inner.imm_u32;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 Value::GetU64() const {
|
|
|
|
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity)
|
|
|
|
return inner.inst->GetArg(0).GetU64();
|
2017-02-26 23:27:41 +00:00
|
|
|
ASSERT(type == Type::U64);
|
2016-08-17 15:53:36 +01:00
|
|
|
return inner.imm_u64;
|
|
|
|
}
|
|
|
|
|
2016-12-31 10:46:13 +00:00
|
|
|
std::array<u8, 8> Value::GetCoprocInfo() const {
|
|
|
|
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity)
|
|
|
|
return inner.inst->GetArg(0).GetCoprocInfo();
|
2017-02-26 23:27:41 +00:00
|
|
|
ASSERT(type == Type::CoprocInfo);
|
2016-12-31 10:46:13 +00:00
|
|
|
return inner.imm_coproc;
|
|
|
|
}
|
|
|
|
|
2018-01-18 11:36:48 +00:00
|
|
|
Cond Value::GetCond() const {
|
|
|
|
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity)
|
|
|
|
return inner.inst->GetArg(0).GetCond();
|
|
|
|
ASSERT(type == Type::Cond);
|
|
|
|
return inner.imm_cond;
|
|
|
|
}
|
|
|
|
|
2016-08-17 15:53:36 +01:00
|
|
|
} // namespace IR
|
|
|
|
} // namespace Dynarmic
|