From 2188765e2877205ea5e6a323fbd506f5a7f5ef7c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 13 Aug 2018 15:35:36 -0400 Subject: [PATCH] ir/value: Use type alias CoprocessorInfo for std::array Provides a more descriptive label for the interface, and avoids the need to hardcode the array size in multiple places. --- src/frontend/A32/ir_emitter.cpp | 78 ++++++++++++++++----------------- src/frontend/ir/value.cpp | 4 +- src/frontend/ir/value.h | 8 ++-- 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/frontend/A32/ir_emitter.cpp b/src/frontend/A32/ir_emitter.cpp index 136b2e95..a72b1f92 100644 --- a/src/frontend/A32/ir_emitter.cpp +++ b/src/frontend/A32/ir_emitter.cpp @@ -251,75 +251,75 @@ IR::U32 IREmitter::ExclusiveWriteMemory64(const IR::U32& vaddr, const IR::U32& v void IREmitter::CoprocInternalOperation(size_t coproc_no, bool two, size_t opc1, CoprocReg CRd, CoprocReg CRn, CoprocReg CRm, size_t opc2) { ASSERT(coproc_no <= 15); - std::array coproc_info{static_cast(coproc_no), - static_cast(two ? 1 : 0), - static_cast(opc1), - static_cast(CRd), - static_cast(CRn), - static_cast(CRm), - static_cast(opc2)}; + const IR::Value::CoprocessorInfo coproc_info{static_cast(coproc_no), + static_cast(two ? 1 : 0), + static_cast(opc1), + static_cast(CRd), + static_cast(CRn), + static_cast(CRm), + static_cast(opc2)}; Inst(Opcode::A32CoprocInternalOperation, IR::Value(coproc_info)); } void IREmitter::CoprocSendOneWord(size_t coproc_no, bool two, size_t opc1, CoprocReg CRn, CoprocReg CRm, size_t opc2, const IR::U32& word) { ASSERT(coproc_no <= 15); - std::array coproc_info{static_cast(coproc_no), - static_cast(two ? 1 : 0), - static_cast(opc1), - static_cast(CRn), - static_cast(CRm), - static_cast(opc2)}; + const IR::Value::CoprocessorInfo coproc_info{static_cast(coproc_no), + static_cast(two ? 1 : 0), + static_cast(opc1), + static_cast(CRn), + static_cast(CRm), + static_cast(opc2)}; Inst(Opcode::A32CoprocSendOneWord, IR::Value(coproc_info), word); } void IREmitter::CoprocSendTwoWords(size_t coproc_no, bool two, size_t opc, CoprocReg CRm, const IR::U32& word1, const IR::U32& word2) { ASSERT(coproc_no <= 15); - std::array coproc_info{static_cast(coproc_no), - static_cast(two ? 1 : 0), - static_cast(opc), - static_cast(CRm)}; + const IR::Value::CoprocessorInfo coproc_info{static_cast(coproc_no), + static_cast(two ? 1 : 0), + static_cast(opc), + static_cast(CRm)}; Inst(Opcode::A32CoprocSendTwoWords, IR::Value(coproc_info), word1, word2); } IR::U32 IREmitter::CoprocGetOneWord(size_t coproc_no, bool two, size_t opc1, CoprocReg CRn, CoprocReg CRm, size_t opc2) { ASSERT(coproc_no <= 15); - std::array coproc_info{static_cast(coproc_no), - static_cast(two ? 1 : 0), - static_cast(opc1), - static_cast(CRn), - static_cast(CRm), - static_cast(opc2)}; + const IR::Value::CoprocessorInfo coproc_info{static_cast(coproc_no), + static_cast(two ? 1 : 0), + static_cast(opc1), + static_cast(CRn), + static_cast(CRm), + static_cast(opc2)}; return Inst(Opcode::A32CoprocGetOneWord, IR::Value(coproc_info)); } IR::U64 IREmitter::CoprocGetTwoWords(size_t coproc_no, bool two, size_t opc, CoprocReg CRm) { ASSERT(coproc_no <= 15); - std::array coproc_info{static_cast(coproc_no), - static_cast(two ? 1 : 0), - static_cast(opc), - static_cast(CRm)}; + const IR::Value::CoprocessorInfo coproc_info{static_cast(coproc_no), + static_cast(two ? 1 : 0), + static_cast(opc), + static_cast(CRm)}; return Inst(Opcode::A32CoprocGetTwoWords, IR::Value(coproc_info)); } void IREmitter::CoprocLoadWords(size_t coproc_no, bool two, bool long_transfer, CoprocReg CRd, const IR::U32& address, bool has_option, u8 option) { ASSERT(coproc_no <= 15); - std::array coproc_info{static_cast(coproc_no), - static_cast(two ? 1 : 0), - static_cast(long_transfer ? 1 : 0), - static_cast(CRd), - static_cast(has_option ? 1 : 0), - static_cast(option)}; + const IR::Value::CoprocessorInfo coproc_info{static_cast(coproc_no), + static_cast(two ? 1 : 0), + static_cast(long_transfer ? 1 : 0), + static_cast(CRd), + static_cast(has_option ? 1 : 0), + static_cast(option)}; Inst(Opcode::A32CoprocLoadWords, IR::Value(coproc_info), address); } void IREmitter::CoprocStoreWords(size_t coproc_no, bool two, bool long_transfer, CoprocReg CRd, const IR::U32& address, bool has_option, u8 option) { ASSERT(coproc_no <= 15); - std::array coproc_info{static_cast(coproc_no), - static_cast(two ? 1 : 0), - static_cast(long_transfer ? 1 : 0), - static_cast(CRd), - static_cast(has_option ? 1 : 0), - static_cast(option)}; + const IR::Value::CoprocessorInfo coproc_info{static_cast(coproc_no), + static_cast(two ? 1 : 0), + static_cast(long_transfer ? 1 : 0), + static_cast(CRd), + static_cast(has_option ? 1 : 0), + static_cast(option)}; Inst(Opcode::A32CoprocStoreWords, IR::Value(coproc_info), address); } diff --git a/src/frontend/ir/value.cpp b/src/frontend/ir/value.cpp index 7d3851a0..f944646a 100644 --- a/src/frontend/ir/value.cpp +++ b/src/frontend/ir/value.cpp @@ -52,7 +52,7 @@ Value::Value(u64 value) : type(Type::U64) { inner.imm_u64 = value; } -Value::Value(std::array value) : type(Type::CoprocInfo) { +Value::Value(CoprocessorInfo value) : type(Type::CoprocInfo) { inner.imm_coproc = value; } @@ -141,7 +141,7 @@ u64 Value::GetU64() const { return inner.imm_u64; } -std::array Value::GetCoprocInfo() const { +Value::CoprocessorInfo Value::GetCoprocInfo() const { if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity) return inner.inst->GetArg(0).GetCoprocInfo(); ASSERT(type == Type::CoprocInfo); diff --git a/src/frontend/ir/value.h b/src/frontend/ir/value.h index 28e663b1..552a1bed 100644 --- a/src/frontend/ir/value.h +++ b/src/frontend/ir/value.h @@ -25,6 +25,8 @@ class Inst; */ class Value { public: + using CoprocessorInfo = std::array; + Value() : type(Type::Void) {} explicit Value(Inst* value); explicit Value(A32::Reg value); @@ -36,7 +38,7 @@ public: explicit Value(u16 value); explicit Value(u32 value); explicit Value(u64 value); - explicit Value(std::array value); + explicit Value(CoprocessorInfo value); explicit Value(Cond value); bool IsEmpty() const; @@ -53,7 +55,7 @@ public: u16 GetU16() const; u32 GetU32() const; u64 GetU64() const; - std::array GetCoprocInfo() const; + CoprocessorInfo GetCoprocInfo() const; Cond GetCond() const; private: @@ -70,7 +72,7 @@ private: u16 imm_u16; u32 imm_u32; u64 imm_u64; - std::array imm_coproc; + CoprocessorInfo imm_coproc; Cond imm_cond; } inner; };