1 //===- LinkerScript.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_LINKERSCRIPT_H_
10 #define MCLD_LINKERSCRIPT_H_
11 
12 #include "mcld/ADT/HashTable.h"
13 #include "mcld/ADT/StringEntry.h"
14 #include "mcld/ADT/StringHash.h"
15 #include "mcld/MC/SearchDirs.h"
16 #include "mcld/Object/SectionMap.h"
17 #include "mcld/Script/AssertCmd.h"
18 #include "mcld/Script/Assignment.h"
19 
20 #include <llvm/ADT/StringRef.h>
21 #include <llvm/ADT/SmallVector.h>
22 
23 #include <string>
24 #include <vector>
25 
26 namespace mcld {
27 
28 class LDSymbol;
29 
30 /** \class LinkerScript
31  *
32  */
33 class LinkerScript {
34  public:
35   typedef HashTable<StringEntry<llvm::StringRef>,
36                     hash::StringHash<hash::DJB>,
37                     StringEntryFactory<llvm::StringRef> > SymbolRenameMap;
38 
39   typedef HashTable<StringEntry<uint64_t>,
40                     hash::StringHash<hash::DJB>,
41                     StringEntryFactory<uint64_t> > AddressMap;
42 
43   typedef std::vector<std::pair<LDSymbol*, Assignment> > Assignments;
44 
45   typedef std::vector<AssertCmd> Assertions;
46 
47   typedef llvm::SmallVector<std::string, 8> DefSyms;
48 
49  public:
50   LinkerScript();
51 
52   ~LinkerScript();
53 
renameMap()54   const SymbolRenameMap& renameMap() const { return m_SymbolRenames; }
renameMap()55   SymbolRenameMap& renameMap() { return m_SymbolRenames; }
56 
addressMap()57   const AddressMap& addressMap() const { return m_AddressMap; }
addressMap()58   AddressMap& addressMap() { return m_AddressMap; }
59 
sectionMap()60   const SectionMap& sectionMap() const { return m_SectionMap; }
sectionMap()61   SectionMap& sectionMap() { return m_SectionMap; }
62 
assignments()63   const Assignments& assignments() const { return m_Assignments; }
assignments()64   Assignments& assignments() { return m_Assignments; }
65 
assertions()66   const Assertions& assertions() const { return m_Assertions; }
assertions()67   Assertions& assertions() { return m_Assertions; }
68 
defsyms()69   const DefSyms& defsyms() const { return m_DefSyms; }
defsyms()70   DefSyms& defsyms() { return m_DefSyms; }
71 
72   /// search directory
directories()73   const SearchDirs& directories() const { return m_SearchDirs; }
directories()74   SearchDirs& directories() { return m_SearchDirs; }
75 
76   /// sysroot
77   const sys::fs::Path& sysroot() const;
78 
79   void setSysroot(const sys::fs::Path& pPath);
80 
81   bool hasSysroot() const;
82 
83   /// entry point
84   const std::string& entry() const;
85 
86   void setEntry(const std::string& pEntry);
87 
88   bool hasEntry() const;
89 
90   /// output filename
91   const std::string& outputFile() const;
92 
93   void setOutputFile(const std::string& pOutputFile);
94 
95   bool hasOutputFile() const;
96 
97  private:
98   SymbolRenameMap m_SymbolRenames;
99   AddressMap m_AddressMap;
100   SectionMap m_SectionMap;
101   Assignments m_Assignments;
102   Assertions m_Assertions;
103   DefSyms m_DefSyms;
104   SearchDirs m_SearchDirs;
105   std::string m_Entry;
106   std::string m_OutputFile;
107 };
108 
109 }  // namespace mcld
110 
111 #endif  // MCLD_LINKERSCRIPT_H_
112