2012-12-19 09:30:18 +00:00
|
|
|
#pragma once
|
2015-12-19 23:57:27 +00:00
|
|
|
#include <Common/md5.h>
|
2016-01-13 11:15:30 +00:00
|
|
|
#include <Project64-core/N64System/Recompiler/CodeSection.h>
|
2022-10-10 00:22:17 +00:00
|
|
|
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
|
2012-12-19 09:30:18 +00:00
|
|
|
|
2022-09-12 13:14:42 +00:00
|
|
|
#if !defined(_MSC_VER) && !defined(_Printf_format_string_)
|
|
|
|
#define _Printf_format_string_
|
|
|
|
#endif
|
|
|
|
|
2022-05-01 22:06:50 +00:00
|
|
|
class CMipsMemoryVM;
|
|
|
|
|
2016-06-28 11:22:30 +00:00
|
|
|
class CCodeBlock
|
2010-05-30 01:54:42 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-05-01 22:06:50 +00:00
|
|
|
CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * CompiledLocation);
|
2015-11-08 21:00:16 +00:00
|
|
|
~CCodeBlock();
|
2012-10-14 06:33:51 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
bool Compile();
|
2010-05-30 01:54:42 +00:00
|
|
|
|
2022-10-10 00:22:17 +00:00
|
|
|
uint32_t VAddrEnter() const
|
|
|
|
{
|
|
|
|
return m_VAddrEnter;
|
|
|
|
}
|
|
|
|
uint32_t VAddrFirst() const
|
|
|
|
{
|
|
|
|
return m_VAddrFirst;
|
|
|
|
}
|
|
|
|
uint32_t VAddrLast() const
|
|
|
|
{
|
|
|
|
return m_VAddrLast;
|
|
|
|
}
|
|
|
|
uint8_t * CompiledLocation() const
|
|
|
|
{
|
|
|
|
return m_CompiledLocation;
|
|
|
|
}
|
|
|
|
uint8_t * CompiledLocationEnd() const
|
|
|
|
{
|
|
|
|
return m_CompiledLocationEnd;
|
|
|
|
}
|
|
|
|
int32_t NoOfSections() const
|
|
|
|
{
|
|
|
|
return (int32_t)m_Sections.size() - 1;
|
|
|
|
}
|
|
|
|
const CCodeSection & EnterSection() const
|
|
|
|
{
|
|
|
|
return *m_EnterSection;
|
|
|
|
}
|
|
|
|
const MD5Digest & Hash() const
|
|
|
|
{
|
|
|
|
return m_Hash;
|
|
|
|
}
|
|
|
|
CRecompilerOps *& RecompilerOps()
|
|
|
|
{
|
|
|
|
return m_RecompilerOps;
|
|
|
|
}
|
|
|
|
const std::string & CodeLog() const
|
|
|
|
{
|
|
|
|
return m_CodeLog;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetVAddrFirst(uint32_t VAddr)
|
|
|
|
{
|
|
|
|
m_VAddrFirst = VAddr;
|
|
|
|
}
|
|
|
|
void SetVAddrLast(uint32_t VAddr)
|
|
|
|
{
|
|
|
|
m_VAddrLast = VAddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCodeSection * ExistingSection(uint32_t Addr)
|
|
|
|
{
|
|
|
|
return m_EnterSection->ExistingSection(Addr, NextTest());
|
|
|
|
}
|
|
|
|
bool SectionAccessible(uint32_t m_SectionID)
|
|
|
|
{
|
|
|
|
return m_EnterSection->SectionAccessible(m_SectionID, NextTest());
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t MemContents(int32_t i) const
|
|
|
|
{
|
|
|
|
return m_MemContents[i];
|
|
|
|
}
|
|
|
|
uint64_t * MemLocation(int32_t i) const
|
|
|
|
{
|
|
|
|
return m_MemLocation[i];
|
|
|
|
}
|
2015-04-28 22:19:02 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
uint32_t NextTest();
|
2012-09-24 22:07:51 +00:00
|
|
|
|
2022-08-08 10:52:51 +00:00
|
|
|
void Log(_Printf_format_string_ const char * Text, ...);
|
|
|
|
|
2010-05-30 01:54:42 +00:00
|
|
|
private:
|
2021-04-13 00:07:11 +00:00
|
|
|
CCodeBlock();
|
2022-10-10 00:22:17 +00:00
|
|
|
CCodeBlock(const CCodeBlock &);
|
|
|
|
CCodeBlock & operator=(const CCodeBlock &);
|
2012-10-14 06:33:51 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
bool AnalyseBlock();
|
2010-05-30 01:54:42 +00:00
|
|
|
|
2016-07-06 20:14:12 +00:00
|
|
|
bool CreateBlockLinkage(CCodeSection * EnterSection);
|
|
|
|
void DetermineLoops();
|
|
|
|
void LogSectionInfo();
|
2022-10-10 00:22:17 +00:00
|
|
|
bool SetSection(CCodeSection *& Section, CCodeSection * CurrentSection, uint32_t TargetPC, bool LinkAllowed, uint32_t CurrentPC);
|
2022-05-01 22:06:50 +00:00
|
|
|
bool AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t & ContinuePC, bool & LikelyBranch, bool & IncludeDelaySlot, bool & EndBlock, bool & PermLoop);
|
2012-10-14 01:05:52 +00:00
|
|
|
|
2022-05-01 22:06:50 +00:00
|
|
|
uint32_t m_VAddrEnter;
|
2022-10-24 01:43:48 +00:00
|
|
|
uint32_t m_VAddrFirst;
|
|
|
|
uint32_t m_VAddrLast;
|
|
|
|
uint8_t * m_CompiledLocation;
|
|
|
|
uint8_t * m_CompiledLocationEnd;
|
2012-10-14 01:05:52 +00:00
|
|
|
|
2016-07-06 20:14:12 +00:00
|
|
|
typedef std::map<uint32_t, CCodeSection *> SectionMap;
|
2022-05-01 22:06:50 +00:00
|
|
|
typedef std::list<CCodeSection *> SectionList;
|
2015-11-08 21:00:16 +00:00
|
|
|
|
2022-05-01 22:06:50 +00:00
|
|
|
CMipsMemoryVM & m_MMU;
|
|
|
|
SectionMap m_SectionMap;
|
|
|
|
SectionList m_Sections;
|
|
|
|
CCodeSection * m_EnterSection;
|
|
|
|
int32_t m_Test;
|
|
|
|
MD5Digest m_Hash;
|
|
|
|
uint64_t m_MemContents[2];
|
|
|
|
uint64_t * m_MemLocation[2];
|
2016-07-03 05:22:14 +00:00
|
|
|
CRecompilerOps * m_RecompilerOps;
|
2022-08-08 10:52:51 +00:00
|
|
|
std::string m_CodeLog;
|
2010-05-30 01:54:42 +00:00
|
|
|
};
|