Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 1 | //===- Module.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 | // Module contains the intermediate representation (LDIR) of MCLinker. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 13 | #ifndef MCLD_MODULE_H_ |
| 14 | #define MCLD_MODULE_H_ |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 15 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 16 | #include "mcld/InputTree.h" |
| 17 | #include "mcld/LD/NamePool.h" |
| 18 | #include "mcld/LD/SectionSymbolSet.h" |
| 19 | #include "mcld/MC/SymbolCategory.h" |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 20 | |
Stephen Hines | 87f3465 | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 21 | #include <vector> |
| 22 | #include <string> |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 23 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 24 | namespace mcld { |
| 25 | |
Stephen Hines | 87f3465 | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 26 | class Input; |
| 27 | class LinkerScript; |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 28 | class LDSection; |
| 29 | class LDSymbol; |
| 30 | |
| 31 | /** \class Module |
| 32 | * \brief Module provides the intermediate representation for linking. |
| 33 | */ |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 34 | class Module { |
| 35 | public: |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 36 | typedef std::vector<Input*> ObjectList; |
| 37 | typedef ObjectList::iterator obj_iterator; |
| 38 | typedef ObjectList::const_iterator const_obj_iterator; |
| 39 | |
| 40 | typedef std::vector<Input*> LibraryList; |
| 41 | typedef LibraryList::iterator lib_iterator; |
| 42 | typedef LibraryList::const_iterator const_lib_iterator; |
| 43 | |
| 44 | typedef InputTree::iterator input_iterator; |
| 45 | typedef InputTree::const_iterator const_input_iterator; |
| 46 | |
| 47 | typedef std::vector<LDSection*> SectionTable; |
| 48 | typedef SectionTable::iterator iterator; |
| 49 | typedef SectionTable::const_iterator const_iterator; |
| 50 | |
| 51 | typedef SymbolCategory SymbolTable; |
| 52 | typedef SymbolTable::iterator sym_iterator; |
| 53 | typedef SymbolTable::const_iterator const_sym_iterator; |
| 54 | |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 55 | typedef std::vector<const ResolveInfo*> AliasList; |
| 56 | typedef AliasList::iterator alias_iterator; |
| 57 | typedef AliasList::const_iterator const_alias_iterator; |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 58 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 59 | public: |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 60 | explicit Module(LinkerScript& pScript); |
| 61 | |
| 62 | Module(const std::string& pName, LinkerScript& pScript); |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 63 | |
| 64 | ~Module(); |
| 65 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 66 | const std::string& name() const { return m_Name; } |
| 67 | |
| 68 | void setName(const std::string& pName) { m_Name = pName; } |
| 69 | |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 70 | const LinkerScript& getScript() const { return m_Script; } |
| 71 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 72 | LinkerScript& getScript() { return m_Script; } |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 73 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 74 | // ----- link-in objects ----- // |
| 75 | const ObjectList& getObjectList() const { return m_ObjectList; } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 76 | ObjectList& getObjectList() { return m_ObjectList; } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 77 | |
| 78 | const_obj_iterator obj_begin() const { return m_ObjectList.begin(); } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 79 | obj_iterator obj_begin() { return m_ObjectList.begin(); } |
| 80 | const_obj_iterator obj_end() const { return m_ObjectList.end(); } |
| 81 | obj_iterator obj_end() { return m_ObjectList.end(); } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 82 | |
| 83 | // ----- link-in libraries ----- // |
| 84 | const LibraryList& getLibraryList() const { return m_LibraryList; } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 85 | LibraryList& getLibraryList() { return m_LibraryList; } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 86 | |
| 87 | const_lib_iterator lib_begin() const { return m_LibraryList.begin(); } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 88 | lib_iterator lib_begin() { return m_LibraryList.begin(); } |
| 89 | const_lib_iterator lib_end() const { return m_LibraryList.end(); } |
| 90 | lib_iterator lib_end() { return m_LibraryList.end(); } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 91 | |
| 92 | // ----- link-in inputs ----- // |
| 93 | const InputTree& getInputTree() const { return m_MainTree; } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 94 | InputTree& getInputTree() { return m_MainTree; } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 95 | |
| 96 | const_input_iterator input_begin() const { return m_MainTree.begin(); } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 97 | input_iterator input_begin() { return m_MainTree.begin(); } |
| 98 | const_input_iterator input_end() const { return m_MainTree.end(); } |
| 99 | input_iterator input_end() { return m_MainTree.end(); } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 100 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 101 | /// @} |
| 102 | /// @name Section Accessors |
| 103 | /// @{ |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 104 | |
| 105 | // ----- sections ----- // |
| 106 | const SectionTable& getSectionTable() const { return m_SectionTable; } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 107 | SectionTable& getSectionTable() { return m_SectionTable; } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 108 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 109 | iterator begin() { return m_SectionTable.begin(); } |
| 110 | const_iterator begin() const { return m_SectionTable.begin(); } |
| 111 | iterator end() { return m_SectionTable.end(); } |
| 112 | const_iterator end() const { return m_SectionTable.end(); } |
| 113 | LDSection* front() { return m_SectionTable.front(); } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 114 | const LDSection* front() const { return m_SectionTable.front(); } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 115 | LDSection* back() { return m_SectionTable.back(); } |
| 116 | const LDSection* back() const { return m_SectionTable.back(); } |
| 117 | size_t size() const { return m_SectionTable.size(); } |
| 118 | bool empty() const { return m_SectionTable.empty(); } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 119 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 120 | LDSection* getSection(const std::string& pName); |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 121 | const LDSection* getSection(const std::string& pName) const; |
| 122 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 123 | /// @} |
| 124 | /// @name Symbol Accessors |
| 125 | /// @{ |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 126 | |
| 127 | // ----- symbols ----- // |
| 128 | const SymbolTable& getSymbolTable() const { return m_SymbolTable; } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 129 | SymbolTable& getSymbolTable() { return m_SymbolTable; } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 130 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 131 | sym_iterator sym_begin() { return m_SymbolTable.begin(); } |
| 132 | const_sym_iterator sym_begin() const { return m_SymbolTable.begin(); } |
| 133 | sym_iterator sym_end() { return m_SymbolTable.end(); } |
| 134 | const_sym_iterator sym_end() const { return m_SymbolTable.end(); } |
| 135 | size_t sym_size() const { return m_SymbolTable.numOfSymbols(); } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 136 | |
| 137 | // ----- section symbols ----- // |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 138 | const LDSymbol* getSectionSymbol(const LDSection& pSection) const { |
| 139 | return m_SectSymbolSet.get(pSection); |
| 140 | } |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 141 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 142 | LDSymbol* getSectionSymbol(const LDSection& pSection) { |
| 143 | return m_SectSymbolSet.get(pSection); |
| 144 | } |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 145 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 146 | const SectionSymbolSet& getSectionSymbolSet() const { |
| 147 | return m_SectSymbolSet; |
| 148 | } |
| 149 | SectionSymbolSet& getSectionSymbolSet() { return m_SectSymbolSet; } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 150 | |
| 151 | // ----- names ----- // |
| 152 | const NamePool& getNamePool() const { return m_NamePool; } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 153 | NamePool& getNamePool() { return m_NamePool; } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 154 | |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 155 | // ----- Aliases ----- // |
| 156 | // create an alias list for pSym, the aliases of pSym |
| 157 | // can be added into the list by calling addAlias |
| 158 | void CreateAliasList(const ResolveInfo& pSym); |
| 159 | |
| 160 | // add pAlias into the newly created alias list |
| 161 | void addAlias(const ResolveInfo& pAlias); |
| 162 | AliasList* getAliasList(const ResolveInfo& pSym); |
| 163 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 164 | private: |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 165 | std::string m_Name; |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 166 | LinkerScript& m_Script; |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 167 | ObjectList m_ObjectList; |
| 168 | LibraryList m_LibraryList; |
| 169 | InputTree m_MainTree; |
| 170 | SectionTable m_SectionTable; |
| 171 | SymbolTable m_SymbolTable; |
| 172 | NamePool m_NamePool; |
| 173 | SectionSymbolSet m_SectSymbolSet; |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 174 | std::vector<AliasList*> m_AliasLists; |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 175 | }; |
| 176 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 177 | } // namespace mcld |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 178 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 179 | #endif // MCLD_MODULE_H_ |