value: Add IsIdentity function

This commit is contained in:
MerryMage 2020-04-20 16:11:51 +01:00
parent 8db4d65587
commit 2ae68b13ed
2 changed files with 21 additions and 17 deletions

View file

@ -61,10 +61,16 @@ Value::Value(Cond value) : type(Type::Cond) {
inner.imm_cond = value; inner.imm_cond = value;
} }
bool Value::IsImmediate() const { bool Value::IsIdentity() const {
if (type == Type::Opaque) if (type == Type::Opaque)
return inner.inst->GetOpcode() == Opcode::Identity ? inner.inst->GetArg(0).IsImmediate() : false; return inner.inst->GetOpcode() == Opcode::Identity;
return true; return false;
}
bool Value::IsImmediate() const {
if (IsIdentity())
return inner.inst->GetArg(0).IsImmediate();
return type != Type::Opaque;
} }
bool Value::IsEmpty() const { bool Value::IsEmpty() const {
@ -72,13 +78,10 @@ bool Value::IsEmpty() const {
} }
Type Value::GetType() const { Type Value::GetType() const {
if (type == Type::Opaque) { if (IsIdentity())
if (inner.inst->GetOpcode() == Opcode::Identity) { return inner.inst->GetArg(0).GetType();
return inner.inst->GetArg(0).GetType(); if (type == Type::Opaque)
} else { return inner.inst->GetType();
return inner.inst->GetType();
}
}
return type; return type;
} }
@ -108,49 +111,49 @@ Inst* Value::GetInst() const {
} }
bool Value::GetU1() const { bool Value::GetU1() const {
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity) if (IsIdentity())
return inner.inst->GetArg(0).GetU1(); return inner.inst->GetArg(0).GetU1();
ASSERT(type == Type::U1); ASSERT(type == Type::U1);
return inner.imm_u1; return inner.imm_u1;
} }
u8 Value::GetU8() const { u8 Value::GetU8() const {
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity) if (IsIdentity())
return inner.inst->GetArg(0).GetU8(); return inner.inst->GetArg(0).GetU8();
ASSERT(type == Type::U8); ASSERT(type == Type::U8);
return inner.imm_u8; return inner.imm_u8;
} }
u16 Value::GetU16() const { u16 Value::GetU16() const {
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity) if (IsIdentity())
return inner.inst->GetArg(0).GetU16(); return inner.inst->GetArg(0).GetU16();
ASSERT(type == Type::U16); ASSERT(type == Type::U16);
return inner.imm_u16; return inner.imm_u16;
} }
u32 Value::GetU32() const { u32 Value::GetU32() const {
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity) if (IsIdentity())
return inner.inst->GetArg(0).GetU32(); return inner.inst->GetArg(0).GetU32();
ASSERT(type == Type::U32); ASSERT(type == Type::U32);
return inner.imm_u32; return inner.imm_u32;
} }
u64 Value::GetU64() const { u64 Value::GetU64() const {
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity) if (IsIdentity())
return inner.inst->GetArg(0).GetU64(); return inner.inst->GetArg(0).GetU64();
ASSERT(type == Type::U64); ASSERT(type == Type::U64);
return inner.imm_u64; return inner.imm_u64;
} }
Value::CoprocessorInfo Value::GetCoprocInfo() const { Value::CoprocessorInfo Value::GetCoprocInfo() const {
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity) if (IsIdentity())
return inner.inst->GetArg(0).GetCoprocInfo(); return inner.inst->GetArg(0).GetCoprocInfo();
ASSERT(type == Type::CoprocInfo); ASSERT(type == Type::CoprocInfo);
return inner.imm_coproc; return inner.imm_coproc;
} }
Cond Value::GetCond() const { Cond Value::GetCond() const {
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity) if (IsIdentity())
return inner.inst->GetArg(0).GetCond(); return inner.inst->GetArg(0).GetCond();
ASSERT(type == Type::Cond); ASSERT(type == Type::Cond);
return inner.imm_cond; return inner.imm_cond;

View file

@ -49,6 +49,7 @@ public:
explicit Value(CoprocessorInfo value); explicit Value(CoprocessorInfo value);
explicit Value(Cond value); explicit Value(Cond value);
bool IsIdentity() const;
bool IsEmpty() const; bool IsEmpty() const;
bool IsImmediate() const; bool IsImmediate() const;
Type GetType() const; Type GetType() const;