From 347d358e39d2078bc9f795cac0227a120d5a6690 Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 14 Oct 2012 17:33:51 +1100 Subject: [PATCH] Cleaned up more code related to the code block --- .../N64 System/Recompiler/Code Block.cpp | 39 ++++++++++++++----- .../N64 System/Recompiler/Code Block.h | 12 +++--- .../N64 System/Recompiler/Code Section.cpp | 2 +- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/Source/Project64/N64 System/Recompiler/Code Block.cpp b/Source/Project64/N64 System/Recompiler/Code Block.cpp index 61ce0d90e..8c1b298fa 100644 --- a/Source/Project64/N64 System/Recompiler/Code Block.cpp +++ b/Source/Project64/N64 System/Recompiler/Code Block.cpp @@ -5,7 +5,6 @@ CCodeBlock::CCodeBlock(DWORD VAddrEnter, BYTE * RecompPos) : m_VAddrFirst(VAddrEnter), m_VAddrLast(VAddrEnter), m_CompiledLocation(RecompPos), - m_NoOfSections(1), m_Test(1), m_EnterSection(new CCodeSection(this, VAddrEnter, 1, false)) { @@ -28,6 +27,16 @@ CCodeBlock::CCodeBlock(DWORD VAddrEnter, BYTE * RecompPos) : AnalyseBlock(); } +CCodeBlock::~CCodeBlock() +{ + for (SectionList::iterator itr = m_Sections.begin(); itr != m_Sections.end(); itr++) + { + CCodeSection * Section = *itr; + delete Section; + } + m_Sections.clear(); +} + bool CCodeBlock::SetSection ( CCodeSection * & Section, CCodeSection * CurrentSection, DWORD TargetPC, bool LinkAllowed, DWORD CurrentPC ) { if (Section != NULL) @@ -105,8 +114,9 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection ) { CCodeSection * CurrentSection = EnterSection; - for (DWORD TestPC = EnterSection->m_EnterPC, EndPC = ((EnterSection->m_EnterPC + 0x1000) & 0xFFFFF000); TestPC < EndPC; TestPC += 4) + for (DWORD TestPC = EnterSection->m_EnterPC, EndPC = ((EnterSection->m_EnterPC + 0x1000) & 0xFFFFF000); TestPC <= EndPC; TestPC += 4) { + if (TestPC != EndPC) { SectionMap::const_iterator itr = m_SectionMap.find(TestPC); if (itr != m_SectionMap.end() && CurrentSection != itr->second) @@ -123,6 +133,9 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection ) } CurrentSection = itr->second; } + } else { + CurrentSection->m_EndSection = true; + break; } bool LikelyBranch, EndBlock, IncludeDelaySlot; @@ -306,6 +319,11 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin return false; } break; + case R4300i_JAL: + EndBlock = true; + IncludeDelaySlot = true; + break; + break; case R4300i_BEQ: TargetPC = PC + ((short)Command.offset << 2) + 4; if (Command.rs != 0 || Command.rt != 0) @@ -315,6 +333,8 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin IncludeDelaySlot = true; break; case R4300i_BNE: + case R4300i_BLEZ: + case R4300i_BGTZ: TargetPC = PC + ((short)Command.offset << 2) + 4; ContinuePC = PC + 8; IncludeDelaySlot = true; @@ -343,8 +363,14 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin } break; case R4300i_CP1: - _Notify->BreakPoint(__FILE__,__LINE__); - return false; + switch (Command.fmt) { + case R4300i_COP1_MF: case R4300i_COP1_CF: case R4300i_COP1_MT: case R4300i_COP1_CT: + break; + default: + _Notify->BreakPoint(__FILE__,__LINE__); + return false; + } + break; case R4300i_ANDI: case R4300i_ORI: case R4300i_XORI: case R4300i_LUI: case R4300i_ADDI: case R4300i_ADDIU: case R4300i_SLTI: case R4300i_SLTIU: case R4300i_DADDI: case R4300i_DADDIU: case R4300i_LB: case R4300i_LH: @@ -377,11 +403,6 @@ bool CCodeBlock::Compile() EnterCodeBlock(); - /*if (bLinkBlocks()) { - for (int i = 0; i < m_NoOfSections; i ++) { - m_EnterSection.DisplaySectionInformation(i + 1,NextTest()); - } - }*/ if (_SyncSystem) { //if ((DWORD)BlockInfo.CompiledLocation == 0x60A7B73B) { X86BreakPoint(__FILE__,__LINE__); } //MoveConstToVariable((DWORD)BlockInfo.CompiledLocation,&CurrentBlock,"CurrentBlock"); diff --git a/Source/Project64/N64 System/Recompiler/Code Block.h b/Source/Project64/N64 System/Recompiler/Code Block.h index 26d468ef8..95ea962b3 100644 --- a/Source/Project64/N64 System/Recompiler/Code Block.h +++ b/Source/Project64/N64 System/Recompiler/Code Block.h @@ -3,22 +3,21 @@ class CCodeBlock : { public: CCodeBlock(DWORD VAddrEnter, BYTE * RecompPos ); - + ~CCodeBlock(); + bool Compile ( void ); inline DWORD VAddrEnter ( void ) const { return m_VAddrEnter; } inline DWORD VAddrFirst ( void ) const { return m_VAddrFirst; } inline DWORD VAddrLast ( void ) const { return m_VAddrLast; } inline BYTE * CompiledLocation ( void ) const { return m_CompiledLocation; } - inline int NoOfSections ( void ) const { return m_NoOfSections; } + inline int NoOfSections ( void ) const { return m_Sections.size(); } inline const CCodeSection & EnterSection ( void ) const { return *m_EnterSection; } inline const MD5Digest & Hash ( void ) const { return m_Hash; } inline void SetVAddrFirst ( DWORD VAddr ) { m_VAddrFirst = VAddr; } inline void SetVAddrLast ( DWORD VAddr ) { m_VAddrLast = VAddr; } - inline void IncSectionCount ( void ) { m_NoOfSections += 1; } - CCodeSection * ExistingSection ( DWORD Addr ) { return m_EnterSection->ExistingSection(Addr,NextTest()); } bool SectionAccessible ( DWORD m_SectionID ) { return m_EnterSection->SectionAccessible(m_SectionID,NextTest()); } @@ -29,6 +28,10 @@ public: DWORD NextTest ( void ); private: + CCodeBlock(void); // Disable default constructor + CCodeBlock(const CCodeBlock&); // Disable copy constructor + CCodeBlock& operator=(const CCodeBlock&); // Disable assignment + bool AnalyseBlock ( void ); void CompileExitCode ( void ); @@ -43,7 +46,6 @@ private: DWORD m_VAddrFirst; // the address of the first opcode in the block DWORD m_VAddrLast; // the address of the first opcode in the block BYTE * m_CompiledLocation; // What address is this compiled at - int m_NoOfSections; // The number of sections this block uses typedef std::map SectionMap; typedef std::list SectionList; diff --git a/Source/Project64/N64 System/Recompiler/Code Section.cpp b/Source/Project64/N64 System/Recompiler/Code Section.cpp index b63e2042f..978858514 100644 --- a/Source/Project64/N64 System/Recompiler/Code Section.cpp +++ b/Source/Project64/N64 System/Recompiler/Code Section.cpp @@ -1351,7 +1351,7 @@ bool CCodeSection::GenerateX86Code ( DWORD Test ) GenerateSectionLinkage(); m_NextInstruction = END_BLOCK; } - else if (m_CompilePC == ContinueSectionPC) + else if (m_NextInstruction != END_BLOCK && m_CompilePC == ContinueSectionPC) { if (m_NextInstruction != NORMAL) {