This commit is contained in:
Jean-Philip Desjardins 2016-12-28 11:23:32 -05:00
parent ec81047e9d
commit c7cc895c69
4 changed files with 56 additions and 84 deletions

View File

@ -2,7 +2,6 @@
#include <stddef.h>
#include "MIPSInstructionFactory.h"
#include "MIPS.h"
#include "PtrMacro.h"
#include "offsetof_def.h"
CMIPSInstructionFactory::CMIPSInstructionFactory(MIPS_REGSIZE nRegSize)
@ -15,11 +14,6 @@ CMIPSInstructionFactory::CMIPSInstructionFactory(MIPS_REGSIZE nRegSize)
}
CMIPSInstructionFactory::~CMIPSInstructionFactory()
{
}
void CMIPSInstructionFactory::SetupQuickVariables(uint32 nAddress, CMipsJitter* codeGen, CMIPS* pCtx)
{
m_pCtx = pCtx;

View File

@ -1,5 +1,4 @@
#ifndef _MIPSINSTRUCTIONFACTORY_H_
#define _MIPSINSTRUCTIONFACTORY_H_
#pragma once
#include "Types.h"
#include "MipsJitter.h"
@ -23,7 +22,7 @@ class CMIPSInstructionFactory
{
public:
CMIPSInstructionFactory(MIPS_REGSIZE);
virtual ~CMIPSInstructionFactory();
virtual ~CMIPSInstructionFactory() = default;
virtual void CompileInstruction(uint32, CMipsJitter*, CMIPS*) = 0;
protected:
@ -34,11 +33,9 @@ protected:
void Illegal();
void SetupQuickVariables(uint32, CMipsJitter*, CMIPS*);
CMipsJitter* m_codeGen;
CMIPS* m_pCtx;
uint32 m_nOpcode;
uint32 m_nAddress;
CMipsJitter* m_codeGen;
CMIPS* m_pCtx;
uint32 m_nOpcode;
uint32 m_nAddress;
MIPS_REGSIZE m_regSize;
};
#endif

View File

@ -1,5 +1,4 @@
#include "MIPSTags.h"
#include "PtrMacro.h"
#include "StdStream.h"
#include "lexical_cast_ex.h"
#include "xml/FilteringNodeIterator.h"
@ -8,23 +7,10 @@
#define TAG_ELEMENT_ATTRIBUTE_ADDRESS ("address")
#define TAG_ELEMENT_ATTRIBUTE_VALUE ("value")
using namespace Framework;
using namespace std;
CMIPSTags::CMIPSTags()
{
}
CMIPSTags::~CMIPSTags()
{
RemoveTags();
}
void CMIPSTags::InsertTag(uint32 nAddress, const char* sTag)
{
bool nErase = false;
if(sTag == NULL)
if(sTag == nullptr)
{
nErase = true;
}
@ -35,46 +21,44 @@ void CMIPSTags::InsertTag(uint32 nAddress, const char* sTag)
if(nErase)
{
TagMap::iterator itTag(m_Tags.find(nAddress));
if(itTag != m_Tags.end())
auto tagIterator = m_tags.find(nAddress);
if(tagIterator != m_tags.end())
{
m_Tags.erase(itTag);
m_tags.erase(tagIterator);
}
}
else
{
m_Tags[nAddress] = sTag;
m_tags[nAddress] = sTag;
}
}
void CMIPSTags::RemoveTags()
{
m_Tags.clear();
m_tags.clear();
}
const char* CMIPSTags::Find(uint32 nAddress)
const char* CMIPSTags::Find(uint32 nAddress) const
{
TagMap::const_iterator itTag(m_Tags.find(nAddress));
return (itTag != m_Tags.end()) ? (itTag->second.c_str()) : (NULL);
auto tagIterator = m_tags.find(nAddress);
return (tagIterator != m_tags.end()) ? (tagIterator->second.c_str()) : nullptr;
}
void CMIPSTags::Serialize(const char* sPath)
void CMIPSTags::Serialize(const char* sPath) const
{
CStdStream Stream(fopen(sPath, "wb"));
Framework::CStdStream stream(fopen(sPath, "wb"));
Stream.Write32(static_cast<uint32>(m_Tags.size()));
stream.Write32(static_cast<uint32>(m_tags.size()));
for(TagMap::const_iterator itTag(m_Tags.begin());
itTag != m_Tags.end(); itTag++)
for(const auto& tagPair : m_tags)
{
const string& sTag = itTag->second;
const auto& sTag = tagPair.second;
uint8 nLength = static_cast<uint8>(min<size_t>(sTag.length(), 255));
uint8 nLength = static_cast<uint8>(std::min<size_t>(sTag.length(), 255));
Stream.Write32(itTag->first);
Stream.Write8(nLength);
Stream.Write(sTag.c_str(), nLength);
stream.Write32(tagPair.first);
stream.Write8(nLength);
stream.Write(sTag.c_str(), nLength);
}
}
@ -82,7 +66,7 @@ void CMIPSTags::Unserialize(const char* sPath)
{
try
{
CStdStream Stream(fopen(sPath, "rb"));
Framework::CStdStream Stream(fopen(sPath, "rb"));
RemoveTags();
uint32 nCount = Stream.Read32();
@ -106,52 +90,51 @@ void CMIPSTags::Unserialize(const char* sPath)
}
}
void CMIPSTags::Serialize(Xml::CNode* parentNode, const char* sectionName)
void CMIPSTags::Serialize(Framework::Xml::CNode* parentNode, const char* sectionName) const
{
Xml::CNode* section = new Xml::CNode(sectionName, true);
Serialize(section);
parentNode->InsertNode(section);
auto section = new Framework::Xml::CNode(sectionName, true);
Serialize(section);
parentNode->InsertNode(section);
}
void CMIPSTags::Unserialize(Xml::CNode* parentNode, const char* sectionName)
void CMIPSTags::Unserialize(Framework::Xml::CNode* parentNode, const char* sectionName)
{
Xml::CNode* section = parentNode->Select(sectionName);
if(!section) return;
Unserialize(section);
auto section = parentNode->Select(sectionName);
if(!section) return;
Unserialize(section);
}
void CMIPSTags::Serialize(Xml::CNode* parentNode)
void CMIPSTags::Serialize(Framework::Xml::CNode* parentNode) const
{
for(TagMap::const_iterator itTag(m_Tags.begin());
itTag != m_Tags.end(); itTag++)
for(const auto& tagPair : m_tags)
{
Xml::CNode* node = new Xml::CNode(TAG_ELEMENT_NAME, true);
node->InsertAttribute(TAG_ELEMENT_ATTRIBUTE_ADDRESS, lexical_cast_hex<string>(itTag->first, 8).c_str());
node->InsertAttribute(TAG_ELEMENT_ATTRIBUTE_VALUE, itTag->second.c_str());
parentNode->InsertNode(node);
auto node = new Framework::Xml::CNode(TAG_ELEMENT_NAME, true);
node->InsertAttribute(TAG_ELEMENT_ATTRIBUTE_ADDRESS, lexical_cast_hex<std::string>(tagPair.first, 8).c_str());
node->InsertAttribute(TAG_ELEMENT_ATTRIBUTE_VALUE, tagPair.second.c_str());
parentNode->InsertNode(node);
}
}
void CMIPSTags::Unserialize(Xml::CNode* parentNode)
void CMIPSTags::Unserialize(Framework::Xml::CNode* parentNode)
{
for(Xml::CFilteringNodeIterator nodeIterator(parentNode, TAG_ELEMENT_NAME);
for(Framework::Xml::CFilteringNodeIterator nodeIterator(parentNode, TAG_ELEMENT_NAME);
!nodeIterator.IsEnd(); nodeIterator++)
{
Xml::CNode* node = *nodeIterator;
const char* addressText = node->GetAttribute(TAG_ELEMENT_ATTRIBUTE_ADDRESS);
const char* valueText = node->GetAttribute(TAG_ELEMENT_ATTRIBUTE_VALUE);
auto node = *nodeIterator;
auto addressText = node->GetAttribute(TAG_ELEMENT_ATTRIBUTE_ADDRESS);
auto valueText = node->GetAttribute(TAG_ELEMENT_ATTRIBUTE_VALUE);
if(!addressText || !valueText) continue;
uint32 address = lexical_cast_hex<string>(addressText);
uint32 address = lexical_cast_hex<std::string>(addressText);
InsertTag(address, valueText);
}
}
CMIPSTags::TagIterator CMIPSTags::GetTagsBegin() const
{
return m_Tags.begin();
return m_tags.begin();
}
CMIPSTags::TagIterator CMIPSTags::GetTagsEnd() const
{
return m_Tags.end();
return m_tags.end();
}

View File

@ -1,5 +1,4 @@
#ifndef _MIPSTAGS_H_
#define _MIPSTAGS_H_
#pragma once
#include "Types.h"
#include "xml/Node.h"
@ -15,23 +14,22 @@ public:
boost::signals2::signal<void ()> OnTagListChange;
CMIPSTags();
~CMIPSTags();
void InsertTag(uint32, const char*);
void RemoveTags();
const char* Find(uint32);
void Serialize(Framework::Xml::CNode*, const char*);
const char* Find(uint32) const;
void Serialize(Framework::Xml::CNode*, const char*) const;
void Unserialize(Framework::Xml::CNode*, const char*);
void Serialize(Framework::Xml::CNode*);
void Serialize(Framework::Xml::CNode*) const;
void Unserialize(Framework::Xml::CNode*);
void Serialize(const char*);
void Serialize(const char*) const;
void Unserialize(const char*);
TagIterator GetTagsBegin() const;
TagIterator GetTagsEnd() const;
private:
TagMap m_Tags;
TagMap m_tags;
};
#endif