From d78be1d608f75d508d2357518f73130d2f082288 Mon Sep 17 00:00:00 2001 From: Jean-Philip Desjardins Date: Sun, 28 Sep 2014 23:44:54 -0400 Subject: [PATCH] Removed some more unused filed and cleanup MIPSAssembler. --- Source/MIPSAssembler.cpp | 461 +++++++++++------------- Source/MIPSAssembler.h | 13 +- Source/MipsAssemblerDefinitions.cpp | 292 --------------- Source/MipsAssemblerDefinitions.h | 25 -- build_win32/Play.vcxproj | 2 - build_win32/Play.vcxproj.filters | 6 - tools/MipsTest/MipsTest.vcxproj | 2 - tools/MipsTest/MipsTest.vcxproj.filters | 6 - 8 files changed, 208 insertions(+), 599 deletions(-) delete mode 100644 Source/MipsAssemblerDefinitions.cpp delete mode 100644 Source/MipsAssemblerDefinitions.h diff --git a/Source/MIPSAssembler.cpp b/Source/MIPSAssembler.cpp index 62c5075b..af171e87 100644 --- a/Source/MIPSAssembler.cpp +++ b/Source/MIPSAssembler.cpp @@ -1,17 +1,12 @@ #include "MIPSAssembler.h" -#include "MipsAssemblerDefinitions.h" #include "MIPS.h" -#include -#include -#include -#include #include #include "lexical_cast_ex.h" -CMIPSAssembler::CMIPSAssembler(uint32* pPtr) +CMIPSAssembler::CMIPSAssembler(uint32* ptr) : m_nextLabelId(1) -, m_pPtr(pPtr) -, m_pStartPtr(pPtr) +, m_ptr(ptr) +, m_startPtr(ptr) { } @@ -23,7 +18,7 @@ CMIPSAssembler::~CMIPSAssembler() unsigned int CMIPSAssembler::GetProgramSize() { - return static_cast(m_pPtr - m_pStartPtr); + return static_cast(m_ptr - m_startPtr); } CMIPSAssembler::LABEL CMIPSAssembler::CreateLabel() @@ -62,53 +57,53 @@ void CMIPSAssembler::ResolveLabelReferences() { throw std::runtime_error("Jump length too long."); } - uint32& instruction = m_pStartPtr[referencePos]; + uint32& instruction = m_startPtr[referencePos]; instruction &= 0xFFFF0000; instruction |= static_cast(offset); } m_labelReferences.clear(); } -void CMIPSAssembler::ADDIU(unsigned int nRT, unsigned int nRS, uint16 nImmediate) +void CMIPSAssembler::ADDIU(unsigned int rt, unsigned int rs, uint16 immediate) { - (*m_pPtr) = ((0x09) << 26) | (nRS << 21) | (nRT << 16) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x09) << 26) | (rs << 21) | (rt << 16) | immediate; + m_ptr++; } -void CMIPSAssembler::ADDU(unsigned int nRD, unsigned int nRS, unsigned int nRT) +void CMIPSAssembler::ADDU(unsigned int rd, unsigned int rs, unsigned int rt) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | (0x21); - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | (0x21); + m_ptr++; } -void CMIPSAssembler::AND(unsigned int nRD, unsigned int nRS, unsigned int nRT) +void CMIPSAssembler::AND(unsigned int rd, unsigned int rs, unsigned int rt) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | (0x24); - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | (0x24); + m_ptr++; } -void CMIPSAssembler::ANDI(unsigned int nRT, unsigned int nRS, uint16 nImmediate) +void CMIPSAssembler::ANDI(unsigned int rt, unsigned int rs, uint16 immediate) { - (*m_pPtr) = ((0x0C) << 26) | (nRS << 21) | (nRT << 16) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x0C) << 26) | (rs << 21) | (rt << 16) | immediate; + m_ptr++; } -void CMIPSAssembler::BEQ(unsigned int nRS, unsigned int nRT, uint16 nImmediate) +void CMIPSAssembler::BEQ(unsigned int rs, unsigned int rt, uint16 immediate) { - (*m_pPtr) = ((0x04) << 26) | (nRS << 21) | (nRT << 16) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x04) << 26) | (rs << 21) | (rt << 16) | immediate; + m_ptr++; } -void CMIPSAssembler::BEQ(unsigned int nRS, unsigned int nRT, LABEL label) +void CMIPSAssembler::BEQ(unsigned int rs, unsigned int rt, LABEL label) { CreateLabelReference(label); - BEQ(nRS, nRT, 0); + BEQ(rs, rt, 0); } -void CMIPSAssembler::BGEZ(unsigned int nRS, uint16 nImmediate) +void CMIPSAssembler::BGEZ(unsigned int rs, uint16 immediate) { - (*m_pPtr) = ((0x01) << 26) | (nRS << 21) | ((0x01) << 16) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x01) << 26) | (rs << 21) | ((0x01) << 16) | immediate; + m_ptr++; } void CMIPSAssembler::BGEZ(unsigned int rs, LABEL label) @@ -117,160 +112,160 @@ void CMIPSAssembler::BGEZ(unsigned int rs, LABEL label) BGEZ(rs, 0); } -void CMIPSAssembler::BGTZ(unsigned int nRS, uint16 nImmediate) +void CMIPSAssembler::BGTZ(unsigned int rs, uint16 immediate) { - (*m_pPtr) = ((0x07) << 26) | (nRS << 21) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x07) << 26) | (rs << 21) | immediate; + m_ptr++; } -void CMIPSAssembler::BNE(unsigned int nRS, unsigned int nRT, uint16 nImmediate) +void CMIPSAssembler::BNE(unsigned int rs, unsigned int rt, uint16 immediate) { - (*m_pPtr) = ((0x05) << 26) | (nRS << 21) | (nRT << 16) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x05) << 26) | (rs << 21) | (rt << 16) | immediate; + m_ptr++; } -void CMIPSAssembler::BNE(unsigned int nRS, unsigned int nRT, LABEL label) +void CMIPSAssembler::BNE(unsigned int rs, unsigned int rt, LABEL label) { CreateLabelReference(label); - BNE(nRS, nRT, 0); + BNE(rs, rt, 0); } -void CMIPSAssembler::BLEZ(unsigned int nRS, uint16 nImmediate) +void CMIPSAssembler::BLEZ(unsigned int rs, uint16 immediate) { - (*m_pPtr) = ((0x06) << 26) | (nRS << 21) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x06) << 26) | (rs << 21) | immediate; + m_ptr++; } -void CMIPSAssembler::BLTZ(unsigned int nRS, uint16 nImmediate) +void CMIPSAssembler::BLTZ(unsigned int rs, uint16 immediate) { - (*m_pPtr) = ((0x01) << 26) | (nRS << 21) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x01) << 26) | (rs << 21) | immediate; + m_ptr++; } -void CMIPSAssembler::DADDU(unsigned int nRD, unsigned int nRS, unsigned int nRT) +void CMIPSAssembler::DADDU(unsigned int rd, unsigned int rs, unsigned int rt) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | (0x2D); - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | (0x2D); + m_ptr++; } -void CMIPSAssembler::DADDIU(unsigned int nRT, unsigned int nRS, uint16 nImmediate) +void CMIPSAssembler::DADDIU(unsigned int rt, unsigned int rs, uint16 immediate) { - (*m_pPtr) = ((0x19) << 26) | (nRS << 21) | (nRT << 16) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x19) << 26) | (rs << 21) | (rt << 16) | immediate; + m_ptr++; } -void CMIPSAssembler::DSLL(unsigned int nRD, unsigned int nRT, unsigned int nSA) +void CMIPSAssembler::DSLL(unsigned int rd, unsigned int rt, unsigned int sa) { - nSA &= 0x1F; - (*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x38; - m_pPtr++; + sa &= 0x1F; + (*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x38; + m_ptr++; } -void CMIPSAssembler::DSLL32(unsigned int nRD, unsigned int nRT, unsigned int nSA) +void CMIPSAssembler::DSLL32(unsigned int rd, unsigned int rt, unsigned int sa) { - nSA &= 0x1F; - (*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x3C; - m_pPtr++; + sa &= 0x1F; + (*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x3C; + m_ptr++; } -void CMIPSAssembler::DSLLV(unsigned int nRD, unsigned int nRT, unsigned int nRS) +void CMIPSAssembler::DSLLV(unsigned int rd, unsigned int rt, unsigned int rs) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x14; - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x14; + m_ptr++; } -void CMIPSAssembler::DSRA(unsigned int nRD, unsigned int nRT, unsigned int nSA) +void CMIPSAssembler::DSRA(unsigned int rd, unsigned int rt, unsigned int sa) { - nSA &= 0x1F; - (*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x3B; - m_pPtr++; + sa &= 0x1F; + (*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x3B; + m_ptr++; } -void CMIPSAssembler::DSRA32(unsigned int nRD, unsigned int nRT, unsigned int nSA) +void CMIPSAssembler::DSRA32(unsigned int rd, unsigned int rt, unsigned int sa) { - nSA &= 0x1F; - (*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x3F; - m_pPtr++; + sa &= 0x1F; + (*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x3F; + m_ptr++; } -void CMIPSAssembler::DSRAV(unsigned int nRD, unsigned int nRT, unsigned int nRS) +void CMIPSAssembler::DSRAV(unsigned int rd, unsigned int rt, unsigned int rs) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x17; - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x17; + m_ptr++; } -void CMIPSAssembler::DSRL(unsigned int nRD, unsigned int nRT, unsigned int nSA) +void CMIPSAssembler::DSRL(unsigned int rd, unsigned int rt, unsigned int sa) { - nSA &= 0x1F; - (*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x3A; - m_pPtr++; + sa &= 0x1F; + (*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x3A; + m_ptr++; } -void CMIPSAssembler::DSRL32(unsigned int nRD, unsigned int nRT, unsigned int nSA) +void CMIPSAssembler::DSRL32(unsigned int rd, unsigned int rt, unsigned int sa) { - nSA &= 0x1F; - (*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x3E; - m_pPtr++; + sa &= 0x1F; + (*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x3E; + m_ptr++; } -void CMIPSAssembler::DSRLV(unsigned int nRD, unsigned int nRT, unsigned int nRS) +void CMIPSAssembler::DSRLV(unsigned int rd, unsigned int rt, unsigned int rs) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x16; - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x16; + m_ptr++; } -void CMIPSAssembler::DSUBU(unsigned int nRD, unsigned int nRS, unsigned int nRT) +void CMIPSAssembler::DSUBU(unsigned int rd, unsigned int rs, unsigned int rt) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | (0x2F); - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | (0x2F); + m_ptr++; } void CMIPSAssembler::ERET() { - (*m_pPtr) = 0x42000018; - m_pPtr++; + (*m_ptr) = 0x42000018; + m_ptr++; } void CMIPSAssembler::JAL(uint32 address) { - (*m_pPtr) = ((0x03) << 26) | ((address >> 2) & 0x03FFFFFF); - m_pPtr++; + (*m_ptr) = ((0x03) << 26) | ((address >> 2) & 0x03FFFFFF); + m_ptr++; } -void CMIPSAssembler::JALR(unsigned int nRS, unsigned int nRD) +void CMIPSAssembler::JALR(unsigned int rs, unsigned int rd) { - (*m_pPtr) = (nRS << 21) | (nRD << 11) | (0x09); - m_pPtr++; + (*m_ptr) = (rs << 21) | (rd << 11) | (0x09); + m_ptr++; } -void CMIPSAssembler::JR(unsigned int nRS) +void CMIPSAssembler::JR(unsigned int rs) { - (*m_pPtr) = (nRS << 21) | (0x08); - m_pPtr++; + (*m_ptr) = (rs << 21) | (0x08); + m_ptr++; } -void CMIPSAssembler::LD(unsigned int nRT, uint16 nOffset, unsigned int nBase) +void CMIPSAssembler::LD(unsigned int rt, uint16 nOffset, unsigned int nBase) { - (*m_pPtr) = ((0x37) << 26) | (nBase << 21) | (nRT << 16) | nOffset; - m_pPtr++; + (*m_ptr) = ((0x37) << 26) | (nBase << 21) | (rt << 16) | nOffset; + m_ptr++; } -void CMIPSAssembler::LDL(unsigned int nRT, uint16 nOffset, unsigned int nBase) +void CMIPSAssembler::LDL(unsigned int rt, uint16 nOffset, unsigned int nBase) { - (*m_pPtr) = ((0x1A) << 26) | (nBase << 21) | (nRT << 16) | nOffset; - m_pPtr++; + (*m_ptr) = ((0x1A) << 26) | (nBase << 21) | (rt << 16) | nOffset; + m_ptr++; } -void CMIPSAssembler::LDR(unsigned int nRT, uint16 nOffset, unsigned int nBase) +void CMIPSAssembler::LDR(unsigned int rt, uint16 nOffset, unsigned int nBase) { - (*m_pPtr) = ((0x1B) << 26) | (nBase << 21) | (nRT << 16) | nOffset; - m_pPtr++; + (*m_ptr) = ((0x1B) << 26) | (nBase << 21) | (rt << 16) | nOffset; + m_ptr++; } -void CMIPSAssembler::LHU(unsigned int nRT, uint16 nOffset, unsigned int nBase) +void CMIPSAssembler::LHU(unsigned int rt, uint16 nOffset, unsigned int nBase) { - (*m_pPtr) = ((0x25) << 26) | (nBase << 21) | (nRT << 16) | nOffset; - m_pPtr++; + (*m_ptr) = ((0x25) << 26) | (nBase << 21) | (rt << 16) | nOffset; + m_ptr++; } void CMIPSAssembler::LI(unsigned int rt, uint32 immediate) @@ -284,100 +279,100 @@ void CMIPSAssembler::LI(unsigned int rt, uint32 immediate) } } -void CMIPSAssembler::LUI(unsigned int nRT, uint16 nImmediate) +void CMIPSAssembler::LUI(unsigned int rt, uint16 immediate) { - (*m_pPtr) = ((0x0F) << 26) | (nRT << 16) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x0F) << 26) | (rt << 16) | immediate; + m_ptr++; } -void CMIPSAssembler::LQ(unsigned int nRT, uint16 nOffset, unsigned int nBase) +void CMIPSAssembler::LQ(unsigned int rt, uint16 nOffset, unsigned int nBase) { - (*m_pPtr) = ((0x1E) << 26) | (nBase << 21) | (nRT << 16) | nOffset; - m_pPtr++; + (*m_ptr) = ((0x1E) << 26) | (nBase << 21) | (rt << 16) | nOffset; + m_ptr++; } void CMIPSAssembler::LBU(unsigned int rt, uint16 offset, unsigned int base) { - (*m_pPtr) = ((0x24) << 26) | (base << 21) | (rt << 16) | offset; - m_pPtr++; + (*m_ptr) = ((0x24) << 26) | (base << 21) | (rt << 16) | offset; + m_ptr++; } -void CMIPSAssembler::LW(unsigned int nRT, uint16 nOffset, unsigned int nBase) +void CMIPSAssembler::LW(unsigned int rt, uint16 nOffset, unsigned int nBase) { - (*m_pPtr) = ((0x23) << 26) | (nBase << 21) | (nRT << 16) | nOffset; - m_pPtr++; + (*m_ptr) = ((0x23) << 26) | (nBase << 21) | (rt << 16) | nOffset; + m_ptr++; } -void CMIPSAssembler::LWL(unsigned int nRT, uint16 nOffset, unsigned int nBase) +void CMIPSAssembler::LWL(unsigned int rt, uint16 nOffset, unsigned int nBase) { - (*m_pPtr) = ((0x22) << 26) | (nBase << 21) | (nRT << 16) | nOffset; - m_pPtr++; + (*m_ptr) = ((0x22) << 26) | (nBase << 21) | (rt << 16) | nOffset; + m_ptr++; } -void CMIPSAssembler::LWR(unsigned int nRT, uint16 nOffset, unsigned int nBase) +void CMIPSAssembler::LWR(unsigned int rt, uint16 nOffset, unsigned int nBase) { - (*m_pPtr) = ((0x26) << 26) | (nBase << 21) | (nRT << 16) | nOffset; - m_pPtr++; + (*m_ptr) = ((0x26) << 26) | (nBase << 21) | (rt << 16) | nOffset; + m_ptr++; } -void CMIPSAssembler::MFC0(unsigned int nRT, unsigned int nRD) +void CMIPSAssembler::MFC0(unsigned int rt, unsigned int rd) { - (*m_pPtr) = ((0x10) << 26) | (nRT << 16) | (nRD << 11); - m_pPtr++; + (*m_ptr) = ((0x10) << 26) | (rt << 16) | (rd << 11); + m_ptr++; } void CMIPSAssembler::MFHI(unsigned int rd) { - (*m_pPtr) = ((0x00) << 26) | (rd << 11) | (0x10); - m_pPtr++; + (*m_ptr) = ((0x00) << 26) | (rd << 11) | (0x10); + m_ptr++; } void CMIPSAssembler::MFHI1(unsigned int rd) { - (*m_pPtr) = ((0x1C) << 26) | (rd << 11) | (0x10); - m_pPtr++; + (*m_ptr) = ((0x1C) << 26) | (rd << 11) | (0x10); + m_ptr++; } void CMIPSAssembler::MFLO(unsigned int rd) { - (*m_pPtr) = ((0x00) << 26) | (rd << 11) | (0x12); - m_pPtr++; + (*m_ptr) = ((0x00) << 26) | (rd << 11) | (0x12); + m_ptr++; } void CMIPSAssembler::MFLO1(unsigned int rd) { - (*m_pPtr) = ((0x1C) << 26) | (rd << 11) | (0x12); - m_pPtr++; + (*m_ptr) = ((0x1C) << 26) | (rd << 11) | (0x12); + m_ptr++; } -void CMIPSAssembler::MTC0(unsigned int nRT, unsigned int nRD) +void CMIPSAssembler::MTC0(unsigned int rt, unsigned int rd) { - (*m_pPtr) = ((0x10) << 26) | ((0x04) << 21) | (nRT << 16) | (nRD << 11); - m_pPtr++; + (*m_ptr) = ((0x10) << 26) | ((0x04) << 21) | (rt << 16) | (rd << 11); + m_ptr++; } void CMIPSAssembler::MTHI(unsigned int rs) { - (*m_pPtr) = ((0x00) << 26) | (rs << 21) | (0x11); - m_pPtr++; + (*m_ptr) = ((0x00) << 26) | (rs << 21) | (0x11); + m_ptr++; } void CMIPSAssembler::MTHI1(unsigned int rs) { - (*m_pPtr) = ((0x1C) << 26) | (rs << 21) | (0x11); - m_pPtr++; + (*m_ptr) = ((0x1C) << 26) | (rs << 21) | (0x11); + m_ptr++; } void CMIPSAssembler::MTLO(unsigned int rs) { - (*m_pPtr) = ((0x00) << 26) | (rs << 21) | (0x13); - m_pPtr++; + (*m_ptr) = ((0x00) << 26) | (rs << 21) | (0x13); + m_ptr++; } void CMIPSAssembler::MTLO1(unsigned int rs) { - (*m_pPtr) = ((0x1C) << 26) | (rs << 21) | (0x13); - m_pPtr++; + (*m_ptr) = ((0x1C) << 26) | (rs << 21) | (0x13); + m_ptr++; } void CMIPSAssembler::MOV(unsigned int rd, unsigned int rs) @@ -385,177 +380,131 @@ void CMIPSAssembler::MOV(unsigned int rd, unsigned int rs) ADDU(rd, rs, 0); } -void CMIPSAssembler::MULT(unsigned int nRD, unsigned int nRS, unsigned int nRT) +void CMIPSAssembler::MULT(unsigned int rd, unsigned int rs, unsigned int rt) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x18; - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x18; + m_ptr++; } -void CMIPSAssembler::MULTU(unsigned int nRS, unsigned int nRT, unsigned int nRD) +void CMIPSAssembler::MULTU(unsigned int rs, unsigned int rt, unsigned int rd) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x19; - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x19; + m_ptr++; } void CMIPSAssembler::NOP() { - (*m_pPtr) = 0; - m_pPtr++; + (*m_ptr) = 0; + m_ptr++; } -void CMIPSAssembler::NOR(unsigned int nRD, unsigned int nRS, unsigned int nRT) +void CMIPSAssembler::NOR(unsigned int rd, unsigned int rs, unsigned int rt) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x27; - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x27; + m_ptr++; } -void CMIPSAssembler::OR(unsigned int nRD, unsigned int nRS, unsigned int nRT) +void CMIPSAssembler::OR(unsigned int rd, unsigned int rs, unsigned int rt) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x25; - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x25; + m_ptr++; } -void CMIPSAssembler::ORI(unsigned int nRT, unsigned int nRS, uint16 nImmediate) +void CMIPSAssembler::ORI(unsigned int rt, unsigned int rs, uint16 immediate) { - (*m_pPtr) = ((0x0D) << 26) | (nRS << 21) | (nRT << 16) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x0D) << 26) | (rs << 21) | (rt << 16) | immediate; + m_ptr++; } -void CMIPSAssembler::SD(unsigned int nRT, uint16 nOffset, unsigned int nBase) +void CMIPSAssembler::SD(unsigned int rt, uint16 nOffset, unsigned int nBase) { - (*m_pPtr) = ((0x3F) << 26) | (nBase << 21) | (nRT << 16) | nOffset; - m_pPtr++; + (*m_ptr) = ((0x3F) << 26) | (nBase << 21) | (rt << 16) | nOffset; + m_ptr++; } -void CMIPSAssembler::SLL(unsigned int nRD, unsigned int nRT, unsigned int nSA) +void CMIPSAssembler::SLL(unsigned int rd, unsigned int rt, unsigned int sa) { - nSA &= 0x1F; - (*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6); - m_pPtr++; + sa &= 0x1F; + (*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6); + m_ptr++; } -void CMIPSAssembler::SLLV(unsigned int nRD, unsigned int nRT, unsigned int nRS) +void CMIPSAssembler::SLLV(unsigned int rd, unsigned int rt, unsigned int rs) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x04; - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x04; + m_ptr++; } -void CMIPSAssembler::SLT(unsigned int nRD, unsigned int nRS, unsigned int nRT) +void CMIPSAssembler::SLT(unsigned int rd, unsigned int rs, unsigned int rt) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x2A; - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x2A; + m_ptr++; } -void CMIPSAssembler::SLTI(unsigned int nRT, unsigned int nRS, uint16 nImmediate) +void CMIPSAssembler::SLTI(unsigned int rt, unsigned int rs, uint16 immediate) { - (*m_pPtr) = ((0x0A) << 26) | (nRS << 21) | (nRT << 16) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x0A) << 26) | (rs << 21) | (rt << 16) | immediate; + m_ptr++; } -void CMIPSAssembler::SLTIU(unsigned int nRT, unsigned int nRS, uint16 nImmediate) +void CMIPSAssembler::SLTIU(unsigned int rt, unsigned int rs, uint16 immediate) { - (*m_pPtr) = ((0x0B) << 26) | (nRS << 21) | (nRT << 16) | nImmediate; - m_pPtr++; + (*m_ptr) = ((0x0B) << 26) | (rs << 21) | (rt << 16) | immediate; + m_ptr++; } -void CMIPSAssembler::SLTU(unsigned int nRD, unsigned int nRS, unsigned int nRT) +void CMIPSAssembler::SLTU(unsigned int rd, unsigned int rs, unsigned int rt) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x2B; - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x2B; + m_ptr++; } -void CMIPSAssembler::SRA(unsigned int nRD, unsigned int nRT, unsigned int nSA) +void CMIPSAssembler::SRA(unsigned int rd, unsigned int rt, unsigned int sa) { - nSA &= 0x1F; - (*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x03; - m_pPtr++; + sa &= 0x1F; + (*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x03; + m_ptr++; } -void CMIPSAssembler::SRAV(unsigned int nRD, unsigned int nRT, unsigned int nRS) +void CMIPSAssembler::SRAV(unsigned int rd, unsigned int rt, unsigned int rs) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x07; - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x07; + m_ptr++; } -void CMIPSAssembler::SRL(unsigned int nRD, unsigned int nRT, unsigned int nSA) +void CMIPSAssembler::SRL(unsigned int rd, unsigned int rt, unsigned int sa) { - nSA &= 0x1F; - (*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x02; - m_pPtr++; + sa &= 0x1F; + (*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x02; + m_ptr++; } -void CMIPSAssembler::SRLV(unsigned int nRD, unsigned int nRT, unsigned int nRS) +void CMIPSAssembler::SRLV(unsigned int rd, unsigned int rt, unsigned int rs) { - (*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x06; - m_pPtr++; + (*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x06; + m_ptr++; } -void CMIPSAssembler::SQ(unsigned int nRT, uint16 nOffset, unsigned int nBase) +void CMIPSAssembler::SQ(unsigned int rt, uint16 nOffset, unsigned int nBase) { - (*m_pPtr) = ((0x1F) << 26) | (nBase << 21) | (nRT << 16) | nOffset; - m_pPtr++; + (*m_ptr) = ((0x1F) << 26) | (nBase << 21) | (rt << 16) | nOffset; + m_ptr++; } void CMIPSAssembler::SB(unsigned int rt, uint16 offset, unsigned int base) { - (*m_pPtr) = ((0x28) << 26) | (base << 21) | (rt << 16) | offset; - m_pPtr++; + (*m_ptr) = ((0x28) << 26) | (base << 21) | (rt << 16) | offset; + m_ptr++; } -void CMIPSAssembler::SW(unsigned int nRT, uint16 nOffset, unsigned int nBase) +void CMIPSAssembler::SW(unsigned int rt, uint16 nOffset, unsigned int nBase) { - (*m_pPtr) = ((0x2B) << 26) | (nBase << 21) | (nRT << 16) | nOffset; - m_pPtr++; + (*m_ptr) = ((0x2B) << 26) | (nBase << 21) | (rt << 16) | nOffset; + m_ptr++; } void CMIPSAssembler::SYSCALL() { - (*m_pPtr) = 0x0000000C; - m_pPtr++; -} - -void CMIPSAssembler::AssembleString(const char* sCode) -{ - std::string sString(sCode); - boost::tokenizer<> Tokens(sString); - - boost::tokenizer<>::iterator itToken(Tokens.begin()); - - //First token must be the instruction mnemonic - const char* sMnemonic = (*itToken).c_str(); - - bool nFound(false); - - for(unsigned int i = 0; ; i++) - { - MipsAssemblerDefinitions::Instruction* pInstruction(MipsAssemblerDefinitions::g_Instructions[i]); - if(pInstruction == NULL) break; - - if(!strcmp(pInstruction->m_sMnemonic, sMnemonic)) - { - pInstruction->Invoke(Tokens, itToken, this); - nFound = true; - break; - } - } - - if(nFound == false) - { - throw std::runtime_error("Invalid mnemonic specified."); - } -} - -unsigned int CMIPSAssembler::GetRegisterIndex(const char* sRegisterName) -{ - unsigned int nRegister = -1; - for(unsigned int i = 0; i < 32; i++) - { - if(!strcmp(CMIPS::m_sGPRName[i], sRegisterName)) - { - nRegister = i; - break; - } - } - - return nRegister; + (*m_ptr) = 0x0000000C; + m_ptr++; } diff --git a/Source/MIPSAssembler.h b/Source/MIPSAssembler.h index 917198ff..a9c45a54 100644 --- a/Source/MIPSAssembler.h +++ b/Source/MIPSAssembler.h @@ -1,5 +1,4 @@ -#ifndef _MIPSASSEMBLER_H_ -#define _MIPSASSEMBLER_H_ +#pragma once #include "Types.h" #include @@ -97,10 +96,6 @@ public: void SW(unsigned int, uint16, unsigned int); void SYSCALL(); - void AssembleString(const char*); - - static unsigned int GetRegisterIndex(const char*); - private: void ResolveLabelReferences(); void CreateLabelReference(LABEL); @@ -113,11 +108,9 @@ private: typedef std::map LabelMapType; typedef std::multimap LabelReferenceMapType; - uint32* m_pPtr; - uint32* m_pStartPtr; + uint32* m_ptr = nullptr; + uint32* m_startPtr = nullptr; LabelMapType m_labels; LabelReferenceMapType m_labelReferences; unsigned int m_nextLabelId; }; - -#endif diff --git a/Source/MipsAssemblerDefinitions.cpp b/Source/MipsAssemblerDefinitions.cpp deleted file mode 100644 index bce8539b..00000000 --- a/Source/MipsAssemblerDefinitions.cpp +++ /dev/null @@ -1,292 +0,0 @@ -#include "MipsAssemblerDefinitions.h" -#include "MIPSAssembler.h" -#include -#include -#include -#include "lexical_cast_ex.h" -#include "placeholder_def.h" - -namespace MipsAssemblerDefinitions -{ - //RsRtImm Parser - //----------------------------- - struct RsRtImm - { - typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, unsigned int, uint16); - - RsRtImm(const AssemblerFunctionType& assemblerFunction) - : m_assemblerFunction(assemblerFunction) - { - - } - - void operator ()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler) - { - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nRS = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nRT = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(itToken == Tokens.end()) throw std::exception(); - uint16 nImm = lexical_cast_hex((*(++itToken)).c_str()); - - if(nRT == -1) throw std::exception(); - if(nRS == -1) throw std::exception(); - - ((pAssembler)->*(m_assemblerFunction))(nRS, nRT, nImm); - } - - AssemblerFunctionType m_assemblerFunction; - }; - - //RtRsImm Parser - //----------------------------- - struct RtRsImm - { - typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, unsigned int, uint16); - - RtRsImm(const AssemblerFunctionType& assemblerFunction) - : m_assemblerFunction(assemblerFunction) - { - - } - - void operator ()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler) - { - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nRT = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nRS = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(itToken == Tokens.end()) throw std::exception(); - uint16 nImm = lexical_cast_hex((*(++itToken)).c_str()); - - if(nRT == -1) throw std::exception(); - if(nRS == -1) throw std::exception(); - - ((pAssembler)->*(m_assemblerFunction))(nRT, nRS, nImm); - } - - AssemblerFunctionType m_assemblerFunction; - }; - - //RdRsRt Parser - //----------------------------- - struct RdRsRt - { - typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, unsigned int, unsigned int); - - RdRsRt(const AssemblerFunctionType& assemblerFunction) - : m_assemblerFunction(assemblerFunction) - { - - } - - void operator ()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler) - { - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nRD = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nRS = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nRT = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(nRT == -1) throw std::exception(); - if(nRS == -1) throw std::exception(); - if(nRD == -1) throw std::exception(); - - ((pAssembler)->*(m_assemblerFunction))(nRD, nRS, nRT); - } - - AssemblerFunctionType m_assemblerFunction; - }; - - //RsImm Parser - //----------------------------- - struct RsImm - { - typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, uint16); - - RsImm(const AssemblerFunctionType& assemblerFunction) - : m_assemblerFunction(assemblerFunction) - { - - } - - void operator ()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler) - { - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nRS = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(itToken == Tokens.end()) throw std::exception(); - uint16 nImm = lexical_cast_hex((*(++itToken)).c_str()); - - if(nRS == -1) throw std::exception(); - - ((pAssembler)->*(m_assemblerFunction))(nRS, nImm); - } - - AssemblerFunctionType m_assemblerFunction; - }; - - //RtImm Parser - //----------------------------- - struct RtImm - { - typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, uint16); - - RtImm(const AssemblerFunctionType& assemblerFunction) - : m_assemblerFunction(assemblerFunction) - { - - } - - void operator ()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler) - { - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nRT = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(itToken == Tokens.end()) throw std::exception(); - uint16 nImm = lexical_cast_hex((*(++itToken)).c_str()); - - if(nRT == -1) throw std::exception(); - - ((pAssembler)->*(m_assemblerFunction))(nRT, nImm); - } - - AssemblerFunctionType m_assemblerFunction; - }; - - //RtRsSa Parser - //----------------------------- - struct RtRsSa - { - typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, unsigned int, unsigned int); - - RtRsSa(const AssemblerFunctionType& assemblerFunction) - : m_assemblerFunction(assemblerFunction) - { - - } - - void operator()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler) - { - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nRT = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nRS = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nSA = boost::lexical_cast((*(++itToken)).c_str()); - - if(nRT == -1) throw std::exception(); - if(nRS == -1) throw std::exception(); - - ((pAssembler)->*(m_assemblerFunction))(nRT, nRS, nSA); - } - - AssemblerFunctionType m_assemblerFunction; - }; - - //RtOfsBase Parser - //----------------------------- - struct RtOfsBase - { - typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, uint16, unsigned int); - - RtOfsBase(const AssemblerFunctionType& assemblerFunction) - : m_assemblerFunction(assemblerFunction) - { - - } - - void operator ()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler) - { - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nRT = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(itToken == Tokens.end()) throw std::exception(); - uint16 nOfs = lexical_cast_hex((*(++itToken)).c_str()); - - if(itToken == Tokens.end()) throw std::exception(); - unsigned int nBase = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str()); - - if(nBase == -1) throw std::exception(); - if(nRT == -1) throw std::exception(); - - ((pAssembler)->*(m_assemblerFunction))(nRT, nOfs, nBase); - } - - AssemblerFunctionType m_assemblerFunction; - }; - - template - struct SpecInstruction : public Instruction - { - SpecInstruction(const char* sMnemonic, const Functor& Parser) : - Instruction(sMnemonic), - m_Parser(Parser) - { - - } - - virtual void Invoke(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler) - { - m_Parser(Tokens, itToken, pAssembler); - } - - Functor m_Parser; - }; - - //Instruction definitions - //------------------------------- - - SpecInstruction Instruction_ADDU = SpecInstruction("ADDU", RdRsRt(&CMIPSAssembler::ADDU)); - SpecInstruction Instruction_ADDIU = SpecInstruction("ADDIU", RtRsImm(&CMIPSAssembler::ADDIU)); - SpecInstruction Instruction_BEQ = SpecInstruction("BEQ", RsRtImm(&CMIPSAssembler::BEQ)); - SpecInstruction Instruction_BGEZ = SpecInstruction("BGEZ", RsImm(&CMIPSAssembler::BGEZ)); - SpecInstruction Instruction_BLEZ = SpecInstruction("BLEZ", RsImm(&CMIPSAssembler::BLEZ)); - SpecInstruction Instruction_BNE = SpecInstruction("BNE", RsRtImm(&CMIPSAssembler::BNE)); - SpecInstruction Instruction_DADDIU = SpecInstruction("DADDIU", RtRsImm(&CMIPSAssembler::DADDIU)); - SpecInstruction Instruction_DSRA32 = SpecInstruction("DSRA32", RtRsSa(&CMIPSAssembler::DSRA32)); - SpecInstruction Instruction_LHU = SpecInstruction("LHU", RtOfsBase(&CMIPSAssembler::LHU)); - SpecInstruction Instruction_LUI = SpecInstruction("LUI", RtImm(&CMIPSAssembler::LUI)); - SpecInstruction Instruction_LW = SpecInstruction("LW", RtOfsBase(&CMIPSAssembler::LW)); - SpecInstruction Instruction_MULT = SpecInstruction("MULT", RdRsRt(&CMIPSAssembler::MULT)); - SpecInstruction Instruction_OR = SpecInstruction("OR", RdRsRt(&CMIPSAssembler::OR)); - SpecInstruction Instruction_SLL = SpecInstruction("SLL", RtRsSa(&CMIPSAssembler::SLL)); - SpecInstruction Instruction_SLTI = SpecInstruction("SLTI", RtRsImm(&CMIPSAssembler::SLTI)); - SpecInstruction Instruction_SLTIU = SpecInstruction("SLTIU", RtRsImm(&CMIPSAssembler::SLTIU)); - SpecInstruction Instruction_SLTU = SpecInstruction("SLTU", RdRsRt(&CMIPSAssembler::SLTU)); - SpecInstruction Instruction_SRA = SpecInstruction("SRA", RtRsSa(&CMIPSAssembler::SRA)); - - Instruction* g_Instructions[] = - { - &Instruction_ADDU, - &Instruction_ADDIU, - &Instruction_BEQ, - &Instruction_BGEZ, - &Instruction_BLEZ, - &Instruction_BNE, - &Instruction_DADDIU, - &Instruction_DSRA32, - &Instruction_LHU, - &Instruction_LUI, - &Instruction_LW, - &Instruction_MULT, - &Instruction_OR, - &Instruction_SLL, - &Instruction_SLTI, - &Instruction_SLTIU, - &Instruction_SLTU, - &Instruction_SRA, - NULL, - }; - -} - diff --git a/Source/MipsAssemblerDefinitions.h b/Source/MipsAssemblerDefinitions.h deleted file mode 100644 index 94389657..00000000 --- a/Source/MipsAssemblerDefinitions.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _MIPSASSEMBLERDEFINITIONS_H_ -#define _MIPSASSEMBLERDEFINITIONS_H_ - -#include - -class CMIPSAssembler; - -namespace MipsAssemblerDefinitions -{ - struct Instruction - { - Instruction(const char* sMnemonic) : - m_sMnemonic(sMnemonic) - { - - } - - const char* m_sMnemonic; - virtual void Invoke(boost::tokenizer<>&, boost::tokenizer<>::iterator&, CMIPSAssembler*) = 0; - }; - - extern Instruction* g_Instructions[]; -}; - -#endif diff --git a/build_win32/Play.vcxproj b/build_win32/Play.vcxproj index f357cca1..e8859969 100644 --- a/build_win32/Play.vcxproj +++ b/build_win32/Play.vcxproj @@ -340,7 +340,6 @@ - @@ -555,7 +554,6 @@ - diff --git a/build_win32/Play.vcxproj.filters b/build_win32/Play.vcxproj.filters index 2e6cc63b..316bc787 100644 --- a/build_win32/Play.vcxproj.filters +++ b/build_win32/Play.vcxproj.filters @@ -112,9 +112,6 @@ Source Files\Core - - Source Files\Core - Source Files\Core @@ -699,9 +696,6 @@ Source Files\Core - - Source Files\Core - Source Files\Core diff --git a/tools/MipsTest/MipsTest.vcxproj b/tools/MipsTest/MipsTest.vcxproj index 9f9e26f6..c89c2ba7 100644 --- a/tools/MipsTest/MipsTest.vcxproj +++ b/tools/MipsTest/MipsTest.vcxproj @@ -161,7 +161,6 @@ - @@ -191,7 +190,6 @@ - diff --git a/tools/MipsTest/MipsTest.vcxproj.filters b/tools/MipsTest/MipsTest.vcxproj.filters index 5817c5de..0d3e805c 100644 --- a/tools/MipsTest/MipsTest.vcxproj.filters +++ b/tools/MipsTest/MipsTest.vcxproj.filters @@ -70,9 +70,6 @@ Source Files\Play Core - - Source Files\Play Core - Source Files\Tests @@ -141,9 +138,6 @@ Source Files\Play Core - - Source Files\Play Core - Source Files