• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- ScriptFile.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_SCRIPT_SCRIPTFILE_H
10 #define MCLD_SCRIPT_SCRIPTFILE_H
11 
12 #include <mcld/Script/Assignment.h>
13 #include <mcld/Script/OutputSectDesc.h>
14 #include <mcld/Script/InputSectDesc.h>
15 #include <vector>
16 #include <string>
17 
18 namespace mcld
19 {
20 
21 class ScriptCommand;
22 class Input;
23 class InputTree;
24 class InputBuilder;
25 class GroupReader;
26 class LinkerConfig;
27 class RpnExpr;
28 class StringList;
29 class Module;
30 
31 /** \class ScriptFile
32  *  \brief This class defines the interfaces to a linker script file.
33  */
34 
35 class ScriptFile
36 {
37 public:
38   enum Kind {
39     LDScript,      // -T
40     Expression,    // --defsym
41     VersionScript, // --version-script
42     DynamicList,   // --dynamic-list
43     Unknown
44   };
45 
46   typedef std::vector<ScriptCommand*> CommandQueue;
47   typedef CommandQueue::const_iterator const_iterator;
48   typedef CommandQueue::iterator iterator;
49   typedef CommandQueue::const_reference const_reference;
50   typedef CommandQueue::reference reference;
51 
52 public:
53   ScriptFile(Kind pKind, Input& pInput, InputBuilder& pBuilder);
54   ~ScriptFile();
55 
begin()56   const_iterator  begin() const { return m_CommandQueue.begin(); }
begin()57   iterator        begin()       { return m_CommandQueue.begin(); }
end()58   const_iterator  end()   const { return m_CommandQueue.end(); }
end()59   iterator        end()         { return m_CommandQueue.end(); }
60 
front()61   const_reference front() const { return m_CommandQueue.front(); }
front()62   reference       front()       { return m_CommandQueue.front(); }
back()63   const_reference back()  const { return m_CommandQueue.back(); }
back()64   reference       back()        { return m_CommandQueue.back(); }
65 
input()66   const Input& input() const { return m_Input; }
input()67   Input&       input()       { return m_Input; }
68 
size()69   size_t size() const { return m_CommandQueue.size(); }
70 
getKind()71   Kind getKind() const { return m_Kind; }
72 
inputs()73   const InputTree& inputs() const { return *m_pInputTree; }
inputs()74   InputTree&       inputs()       { return *m_pInputTree; }
75 
name()76   const std::string& name() const { return m_Name; }
name()77   std::string&       name()       { return m_Name; }
78 
79   void dump() const;
80   void activate(Module& pModule);
81 
82   /// ENTRY(symbol)
83   void addEntryPoint(const std::string& pSymbol);
84 
85   /// OUTPUT_FORMAT(bfdname)
86   /// OUTPUT_FORMAT(default, big, little)
87   void addOutputFormatCmd(const std::string& pFormat);
88   void addOutputFormatCmd(const std::string& pDefault,
89                           const std::string& pBig,
90                           const std::string& pLittle);
91 
92   /// GROUP(file, file, ...)
93   /// GROUP(file file ...)
94   void addGroupCmd(StringList& pStringList,
95                    GroupReader& pGroupReader,
96                    const LinkerConfig& pConfig);
97 
98   /// OUTPUT(filename)
99   void addOutputCmd(const std::string& pFileName);
100 
101   /// SEARCH_DIR(path)
102   void addSearchDirCmd(const std::string& pPath);
103 
104   /// OUTPUT_ARCH(bfdarch)
105   void addOutputArchCmd(const std::string& pArch);
106 
107   /// ASSERT(exp, message)
108   void addAssertCmd(RpnExpr& pRpnExpr, const std::string& pMessage);
109 
110   /// assignment
111   void addAssignment(const std::string& pSymbol,
112                      RpnExpr& pRpnExpr,
113                      Assignment::Type pType = Assignment::DEFAULT);
114 
115   bool hasSectionsCmd() const;
116 
117   void enterSectionsCmd();
118 
119   void leaveSectionsCmd();
120 
121   void enterOutputSectDesc(const std::string& pName,
122                            const OutputSectDesc::Prolog& pProlog);
123 
124   void leaveOutputSectDesc(const OutputSectDesc::Epilog& pEpilog);
125 
126   void addInputSectDesc(InputSectDesc::KeepPolicy pPolicy,
127                         const InputSectDesc::Spec& pSpec);
128 
129   RpnExpr* createRpnExpr();
getCurrentRpnExpr()130   const RpnExpr* getCurrentRpnExpr() const { return m_pRpnExpr; }
getCurrentRpnExpr()131   RpnExpr*       getCurrentRpnExpr()       { return m_pRpnExpr; }
132 
133   StringList* createStringList();
getCurrentStringList()134   const StringList* getCurrentStringList() const { return m_pStringList; }
getCurrentStringList()135   StringList*       getCurrentStringList()       { return m_pStringList; }
136 
137   void setAsNeeded(bool pEnable = true);
asNeeded()138   bool asNeeded() const { return m_bAsNeeded; }
139 
140   static const std::string& createParserStr(const char* pText, size_t pLength);
141 
142   static void clearParserStrPool();
143 
144 private:
145   Kind m_Kind;
146   Input& m_Input;
147   std::string m_Name;
148   InputTree* m_pInputTree;
149   InputBuilder& m_Builder;
150   CommandQueue m_CommandQueue;
151   bool m_bHasSectionsCmd;
152   bool m_bInSectionsCmd;
153   bool m_bInOutputSectDesc;
154   RpnExpr* m_pRpnExpr;
155   StringList* m_pStringList;
156   bool m_bAsNeeded;
157 };
158 
159 } // namespace of mcld
160 
161 #endif
162 
163