1 #include "ObjectFile.h" 2 #include <algorithm> 3 #include <assert.h> 4 #include <stdexcept> 5 6 using namespace Jitter; 7 CObjectFile(CPU_ARCH cpuArch)8CObjectFile::CObjectFile(CPU_ARCH cpuArch) 9 : m_cpuArch(cpuArch) 10 { 11 12 } 13 ~CObjectFile()14CObjectFile::~CObjectFile() 15 { 16 17 } 18 AddInternalSymbol(const INTERNAL_SYMBOL & internalSymbol)19unsigned int CObjectFile::AddInternalSymbol(const INTERNAL_SYMBOL& internalSymbol) 20 { 21 { 22 auto symbolIterator = std::find_if(std::begin(m_internalSymbols), std::end(m_internalSymbols), 23 [&] (const INTERNAL_SYMBOL& symbol) 24 { 25 return symbol.name == internalSymbol.name; 26 } 27 ); 28 if(symbolIterator != std::end(m_internalSymbols)) 29 { 30 throw std::runtime_error("Symbol already exists."); 31 } 32 } 33 m_internalSymbols.push_back(internalSymbol); 34 return m_internalSymbols.size() - 1; 35 } 36 AddExternalSymbol(const EXTERNAL_SYMBOL & externalSymbol)37unsigned int CObjectFile::AddExternalSymbol(const EXTERNAL_SYMBOL& externalSymbol) 38 { 39 assert(std::find_if(std::begin(m_externalSymbols), std::end(m_externalSymbols), [&] (const EXTERNAL_SYMBOL& symbol) { return symbol.name == externalSymbol.name; }) == std::end(m_externalSymbols)); 40 m_externalSymbols.push_back(externalSymbol); 41 return m_externalSymbols.size() - 1; 42 } 43 AddExternalSymbol(const std::string & name,uintptr_t value)44unsigned int CObjectFile::AddExternalSymbol(const std::string& name, uintptr_t value) 45 { 46 EXTERNAL_SYMBOL symbol = { name, value }; 47 return AddExternalSymbol(symbol); 48 } 49 GetExternalSymbolIndexByValue(uintptr_t value) const50unsigned int CObjectFile::GetExternalSymbolIndexByValue(uintptr_t value) const 51 { 52 auto externalSymbolIterator = std::find_if(std::begin(m_externalSymbols), std::end(m_externalSymbols), 53 [&] (const EXTERNAL_SYMBOL& externalSymbol) 54 { 55 return externalSymbol.value == value; 56 } 57 ); 58 if(externalSymbolIterator == std::end(m_externalSymbols)) 59 { 60 throw std::runtime_error("Symbol not found."); 61 } 62 return externalSymbolIterator - std::begin(m_externalSymbols); 63 } 64