Permalink
Browse files

Use smart pointers for assembler file objects

  • Loading branch information...
sp1187 committed Jun 22, 2018
1 parent 85f44a8 commit bb06fb0fb0855b38b1bdc99b300567d7fd45b744
@@ -264,12 +264,11 @@ void MipsElfFile::save()
DirectiveLoadMipsElf::DirectiveLoadMipsElf(const std::wstring& fileName)
{
file = new MipsElfFile();
file = std::make_shared<MipsElfFile>();
this->inputName = getFullPathName(fileName);
if (file->load(this->inputName,this->inputName) == false)
{
delete file;
file = nullptr;
return;
}
@@ -279,13 +278,12 @@ DirectiveLoadMipsElf::DirectiveLoadMipsElf(const std::wstring& fileName)
DirectiveLoadMipsElf::DirectiveLoadMipsElf(const std::wstring& inputName, const std::wstring& outputName)
{
file = new MipsElfFile();
file = std::make_shared<MipsElfFile>();
this->inputName = getFullPathName(inputName);
this->outputName = getFullPathName(outputName);
if (file->load(this->inputName,this->outputName) == false)
{
delete file;
file = nullptr;
return;
}
@@ -48,7 +48,7 @@ class DirectiveLoadMipsElf: public CAssemblerCommand
virtual void writeTempData(TempData& tempData) const;
virtual void writeSymData(SymbolData& symData) const;
private:
MipsElfFile* file;
std::shared_ptr<MipsElfFile> file;
std::wstring inputName;
std::wstring outputName;
};
@@ -19,7 +19,7 @@ void CDirectiveFile::initOpen(const std::wstring& fileName, int64_t memory)
type = Type::Open;
std::wstring fullName = getFullPathName(fileName);
file = new GenericAssemblerFile(fullName,memory,false);
file = std::make_shared<GenericAssemblerFile>(fullName,memory,false);
g_fileManager->addFile(file);
updateSection(++Global.Section);
@@ -30,7 +30,7 @@ void CDirectiveFile::initCreate(const std::wstring& fileName, int64_t memory)
type = Type::Create;
std::wstring fullName = getFullPathName(fileName);
file = new GenericAssemblerFile(fullName,memory,true);
file = std::make_shared<GenericAssemblerFile>(fullName,memory,true);
g_fileManager->addFile(file);
updateSection(++Global.Section);
@@ -42,7 +42,7 @@ void CDirectiveFile::initCopy(const std::wstring& inputName, const std::wstring&
std::wstring fullInputName = getFullPathName(inputName);
std::wstring fullOutputName = getFullPathName(outputName);
file = new GenericAssemblerFile(fullOutputName,fullInputName,memory);
file = std::make_shared<GenericAssemblerFile>(fullOutputName,fullInputName,memory);
g_fileManager->addFile(file);
updateSection(++Global.Section);
@@ -431,13 +431,13 @@ CDirectiveHeaderSize::CDirectiveHeaderSize(Expression expression)
void CDirectiveHeaderSize::exec() const
{
AssemblerFile* openFile = g_fileManager->getOpenFile();
std::shared_ptr<AssemblerFile> openFile = g_fileManager->getOpenFile();
if (!openFile->hasFixedVirtualAddress())
{
Logger::printError(Logger::Error,L"Header size not applicable for this file");
return;
}
GenericAssemblerFile* file = static_cast<GenericAssemblerFile*>(openFile);
std::shared_ptr<GenericAssemblerFile> file = std::static_pointer_cast<GenericAssemblerFile>(openFile);
int64_t physicalAddress = file->getPhysicalAddress();
file->setHeaderSize(headerSize);
file->seekPhysical(physicalAddress);
@@ -23,8 +23,8 @@ class CDirectiveFile: public CAssemblerCommand
private:
Type type;
int64_t virtualAddress;
GenericAssemblerFile* file;
AssemblerFile* closeFile;
std::shared_ptr<GenericAssemblerFile> file;
std::shared_ptr<AssemblerFile> closeFile;
};
class CDirectivePosition: public CAssemblerCommand
@@ -38,7 +38,7 @@ struct ArmipsArguments
std::wstring symFileName;
// memory mode
AssemblerFile* memoryFile;
std::shared_ptr<AssemblerFile> memoryFile;
std::wstring content;
ArmipsArguments()
@@ -26,7 +26,7 @@ typedef struct {
bool relativeInclude;
int validationPasses;
bool memoryMode;
AssemblerFile* memoryFile;
std::shared_ptr<AssemblerFile> memoryFile;
bool multiThreading;
} tGlobal;
@@ -71,7 +71,7 @@ ExpressionValue expFuncEndianness(const std::wstring& funcName, const std::vecto
ExpressionValue expFuncOutputName(const std::wstring& funcName, const std::vector<ExpressionValue>& parameters)
{
AssemblerFile* file = g_fileManager->getOpenFile();
std::shared_ptr<AssemblerFile> file = g_fileManager->getOpenFile();
if (file == nullptr)
{
Logger::queueError(Logger::Error,L"outputName: no file opened");
@@ -243,7 +243,7 @@ bool FileManager::checkActiveFile()
return true;
}
bool FileManager::openFile(AssemblerFile* file, bool onlyCheck)
bool FileManager::openFile(std::shared_ptr<AssemblerFile> file, bool onlyCheck)
{
if (activeFile != nullptr)
{
@@ -255,7 +255,7 @@ bool FileManager::openFile(AssemblerFile* file, bool onlyCheck)
return activeFile->open(onlyCheck);
}
void FileManager::addFile(AssemblerFile* file)
void FileManager::addFile(std::shared_ptr<AssemblerFile> file)
{
files.push_back(file);
}
@@ -65,8 +65,8 @@ class FileManager
FileManager();
~FileManager();
void reset();
bool openFile(AssemblerFile* file, bool onlyCheck);
void addFile(AssemblerFile* file);
bool openFile(std::shared_ptr<AssemblerFile> file, bool onlyCheck);
void addFile(std::shared_ptr<AssemblerFile> file);
bool hasOpenFile() { return activeFile != nullptr; };
void closeFile();
bool write(void* data, size_t length);
@@ -80,13 +80,13 @@ class FileManager
bool seekVirtual(int64_t virtualAddress);
bool seekPhysical(int64_t physicalAddress);
bool advanceMemory(size_t bytes);
AssemblerFile* getOpenFile() { return activeFile; };
std::shared_ptr<AssemblerFile> getOpenFile() { return activeFile; };
void setEndianness(Endianness endianness) { this->endianness = endianness; };
Endianness getEndianness() { return endianness; }
private:
bool checkActiveFile();
std::vector<AssemblerFile*> files;
AssemblerFile* activeFile;
std::vector<std::shared_ptr<AssemblerFile>> files;
std::shared_ptr<AssemblerFile> activeFile;
Endianness endianness;
Endianness ownEndianness;
};

0 comments on commit bb06fb0

Please sign in to comment.