1 //===- TestLinker.h -------------------------------------------------------===// 2 // 3 // The MCLinker Project 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #ifndef MCLD_TEST_LINKER_H 10 #define MCLD_TEST_LINKER_H 11 12 #include <gtest.h> 13 14 #include <string> 15 #include <list> 16 17 #include <mcld/MC/MCLDDriver.h> 18 #include <mcld/MC/MCLinker.h> 19 #include <mcld/LD/DiagnosticPrinter.h> 20 #include <mcld/LD/DiagnosticLineInfo.h> 21 #include <mcld/Support/TargetRegistry.h> 22 #include <mcld/Support/Path.h> 23 24 namespace mcld { 25 26 class MCLDInfo; 27 class TargetLDBackend; 28 class RegionFactory; 29 30 namespace test 31 { 32 33 class TestLinker 34 { 35 public: 36 TestLinker(); 37 38 ~TestLinker(); 39 40 bool initialize(const std::string &pTriple); 41 config()42 MCLDInfo* config() { 43 assert(NULL != m_pInfo); 44 return m_pInfo; 45 } 46 config()47 const MCLDInfo* config() const { 48 assert(NULL != m_pInfo); 49 return m_pInfo; 50 } 51 52 // ----- search directories ----- // 53 void addSearchDir(const std::string &pPath); 54 55 void setSysRoot(const mcld::sys::fs::Path &pPath); 56 57 // ----- input operators ----- // 58 void addObject(const std::string &pPath); 59 addObject(const mcld::sys::fs::Path & pPath)60 void addObject(const mcld::sys::fs::Path &pPath) 61 { addObject(pPath.native()); } 62 63 void addObject(void* pMemBuffer, size_t pSize); 64 65 void addObject(int pFileHandler); 66 67 void addNameSpec(const std::string &pNameSpec); 68 69 bool setOutput(const std::string &pPath); 70 71 bool setOutput(int pFileHandler); 72 73 bool setOutput(const sys::fs::Path &pPath); 74 75 /// getDriver getDriver()76 MCLDDriver* getDriver() { 77 assert(NULL != m_pDriver); 78 return m_pDriver; 79 } 80 81 /// getDriver getDriver()82 const MCLDDriver* getDriver() const { 83 assert(NULL != m_pDriver); 84 return m_pDriver; 85 } 86 87 /// getLinker getLinker()88 MCLinker* getLinker() { 89 assert(NULL != m_pDriver); 90 return m_pDriver->getLinker(); 91 } 92 93 /// getLinker getLinker()94 const MCLinker* getLinker() const { 95 assert(NULL != m_pDriver); 96 return m_pDriver->getLinker(); 97 } 98 99 private: 100 void advanceRoot(); 101 102 private: 103 const mcld::Target* m_pTarget; 104 mcld::MCLDDriver *m_pDriver; 105 mcld::MCLDInfo* m_pInfo; 106 mcld::DiagnosticLineInfo* m_pDiagLineInfo; 107 mcld::DiagnosticPrinter* m_pDiagPrinter; 108 mcld::TargetLDBackend* m_pBackend; 109 mcld::InputTree::iterator m_Root; 110 mcld::RegionFactory* m_pRegionFactory; 111 mcld::MemoryAreaFactory* m_pMemAreaFactory; 112 113 std::list<mcld::FileHandle*> m_FileHandleList; 114 std::list<mcld::MemoryArea*> m_MemAreaList; 115 116 }; 117 118 } // namespace of test 119 } // namespace of mcld 120 #endif 121 122