1 //===- MCLDInput.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 // 10 // Input class inherits MCLDFile, which is used to represent a input file 11 // 12 //===----------------------------------------------------------------------===// 13 #ifndef MCLD_INPUT_H 14 #define MCLD_INPUT_H 15 #ifdef ENABLE_UNITTEST 16 #include <gtest.h> 17 #endif 18 19 #include <mcld/Support/Path.h> 20 21 namespace mcld { 22 23 class MemoryArea; 24 class AttributeProxy; 25 class Attribute; 26 class InputFactory; 27 class LDContext; 28 29 /** \class Input 30 * \brief Input provides the information of a input file. 31 */ 32 class Input 33 { 34 friend class InputFactory; 35 public: 36 enum Type { 37 Unknown, 38 Object, 39 Exec, 40 DynObj, 41 CoreFile, 42 Script, 43 Archive, 44 External 45 }; 46 47 public: 48 explicit Input(llvm::StringRef pName); 49 50 Input(llvm::StringRef pName, 51 const AttributeProxy& pAttr); 52 53 Input(llvm::StringRef pName, 54 const sys::fs::Path& pPath, 55 unsigned int pType = Unknown, 56 off_t pFileOffset = 0); 57 58 Input(llvm::StringRef pName, 59 const sys::fs::Path& pPath, 60 const AttributeProxy& pAttr, 61 unsigned int pType = Unknown, 62 off_t pFileOffset = 0); 63 64 ~Input(); 65 66 const std::string& name() const 67 { return m_Name; } 68 69 void setName(const std::string& pName) 70 { m_Name = pName; } 71 72 const sys::fs::Path& path() const 73 { return m_Path; } 74 75 void setPath(const sys::fs::Path& pPath) 76 { m_Path = pPath; } 77 78 void setType(unsigned int pType) 79 { m_Type = pType; } 80 81 unsigned int type() const 82 { return m_Type; } 83 84 bool isRecognized() const 85 { return (m_Type != Unknown); } 86 87 bool hasAttribute() const 88 { return (NULL != m_pAttr); } 89 90 const Attribute* attribute() const 91 { return m_pAttr; } 92 93 bool isNeeded() const 94 { return m_bNeeded; } 95 96 void setNeeded() 97 { m_bNeeded = true; } 98 99 off_t fileOffset() const 100 { return m_fileOffset; } 101 102 void setFileOffset(off_t pFileOffset) 103 { m_fileOffset = pFileOffset; } 104 105 // ----- memory area ----- // 106 void setMemArea(MemoryArea* pMemArea) 107 { m_pMemArea = pMemArea; } 108 109 bool hasMemArea() const 110 { return (NULL != m_pMemArea); } 111 112 const MemoryArea* memArea() const { return m_pMemArea; } 113 MemoryArea* memArea() { return m_pMemArea; } 114 115 // ----- context ----- // 116 void setContext(LDContext* pContext) 117 { m_pContext = pContext; } 118 119 bool hasContext() const 120 { return (NULL != m_pContext); } 121 122 const LDContext* context() const { return m_pContext; } 123 LDContext* context() { return m_pContext; } 124 125 private: 126 unsigned int m_Type; 127 std::string m_Name; 128 sys::fs::Path m_Path; 129 Attribute *m_pAttr; 130 bool m_bNeeded; 131 off_t m_fileOffset; 132 MemoryArea* m_pMemArea; 133 LDContext* m_pContext; 134 }; 135 136 } // namespace of mcld 137 138 #endif 139 140