• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- Operand.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_OPERAND_H
10 #define MCLD_SCRIPT_OPERAND_H
11 
12 #include <mcld/Script/ExprToken.h>
13 #include <mcld/Object/SectionMap.h>
14 #include <mcld/Support/Allocators.h>
15 #include <mcld/Config/Config.h>
16 #include <llvm/Support/DataTypes.h>
17 #include <string>
18 #include <cassert>
19 
20 namespace mcld
21 {
22 
23 /** \class Operand
24  *  \brief This class defines the interfaces to an operand token.
25  */
26 
27 class Operand : public ExprToken
28 {
29 public:
30   enum Type {
31     SYMBOL,
32     INTEGER,
33     SECTION,
34     SECTION_DESC,
35     FRAGMENT
36   };
37 
38 protected:
39   Operand(Type pType);
40   virtual ~Operand();
41 
42 public:
type()43   Type type() const { return m_Type; }
44 
isDot()45   virtual bool isDot() const { return false; }
46 
47   virtual uint64_t value() const = 0;
48 
classof(const ExprToken * pToken)49   static bool classof(const ExprToken* pToken)
50   {
51     return pToken->kind() == ExprToken::OPERAND;
52   }
53 
54 private:
55   Type m_Type;
56 };
57 
58 /** \class SymOperand
59  *  \brief This class defines the interfaces to a symbol operand.
60  */
61 
62 class SymOperand : public Operand
63 {
64 private:
65   friend class Chunk<SymOperand, MCLD_SYMBOLS_PER_INPUT>;
66   SymOperand();
67   SymOperand(const std::string& pName);
68 
69 public:
70   void dump() const;
71 
name()72   const std::string& name() const { return m_Name; }
73 
74   bool isDot() const;
75 
value()76   uint64_t value() const { return m_Value; }
77 
setValue(uint64_t pValue)78   void setValue(uint64_t pValue) { m_Value = pValue; }
79 
classof(const Operand * pOperand)80   static bool classof(const Operand* pOperand)
81   {
82     return pOperand->type() == Operand::SYMBOL;
83   }
84 
85   /* factory method */
86   static SymOperand* create(const std::string& pName);
87   static void destroy(SymOperand*& pOperand);
88   static void clear();
89 
90 private:
91   std::string m_Name;
92   uint64_t m_Value;
93 };
94 
95 /** \class IntOperand
96  *  \brief This class defines the interfaces to an integer operand.
97  */
98 
99 class IntOperand : public Operand
100 {
101 private:
102   friend class Chunk<IntOperand, MCLD_SYMBOLS_PER_INPUT>;
103   IntOperand();
104   IntOperand(uint64_t pValue);
105 
106 public:
107   void dump() const;
108 
value()109   uint64_t value() const { return m_Value; }
110 
setValue(uint64_t pValue)111   void setValue(uint64_t pValue) { m_Value = pValue; }
112 
classof(const Operand * pOperand)113   static bool classof(const Operand* pOperand)
114   {
115     return pOperand->type() == Operand::INTEGER;
116   }
117 
118   /* factory method */
119   static IntOperand* create(uint64_t pValue);
120   static void destroy(IntOperand*& pOperand);
121   static void clear();
122 
123 private:
124   uint64_t m_Value;
125 };
126 
127 /** \class SectOperand
128  *  \brief This class defines the interfaces to an section name operand.
129  */
130 class LDSection;
131 
132 class SectOperand : public Operand
133 {
134 private:
135   friend class Chunk<SectOperand, MCLD_SECTIONS_PER_INPUT>;
136   SectOperand();
137   SectOperand(const std::string& pName);
138 
139 public:
140   void dump() const;
141 
name()142   const std::string& name() const { return m_Name; }
143 
value()144   uint64_t value() const
145   {
146     assert(0);
147     return 0;
148   }
149 
classof(const Operand * pOperand)150   static bool classof(const Operand* pOperand)
151   {
152     return pOperand->type() == Operand::SECTION;
153   }
154 
155   /* factory method */
156   static SectOperand* create(const std::string& pName);
157   static void destroy(SectOperand*& pOperand);
158   static void clear();
159 
160 private:
161   std::string m_Name;
162 };
163 
164 /** \class SectDescOperand
165  *  \brief This class defines the interfaces to an section name operand.
166  */
167 
168 class SectDescOperand : public Operand
169 {
170 private:
171   friend class Chunk<SectDescOperand, MCLD_SECTIONS_PER_INPUT>;
172   SectDescOperand();
173   SectDescOperand(const SectionMap::Output* pOutputDesc);
174 
175 public:
176   void dump() const;
177 
outputDesc()178   const SectionMap::Output* outputDesc() const { return m_pOutputDesc; }
179 
value()180   uint64_t value() const
181   {
182     assert(0);
183     return 0;
184   }
185 
classof(const Operand * pOperand)186   static bool classof(const Operand* pOperand)
187   {
188     return pOperand->type() == Operand::SECTION_DESC;
189   }
190 
191   /* factory method */
192   static SectDescOperand* create(const SectionMap::Output* pOutputDesc);
193   static void destroy(SectDescOperand*& pOperand);
194   static void clear();
195 
196 private:
197   const SectionMap::Output* m_pOutputDesc;
198 };
199 
200 /** \class FragOperand
201  *  \brief This class defines the interfaces to a fragment operand.
202  */
203 
204 class Fragment;
205 
206 class FragOperand : public Operand
207 {
208 private:
209   friend class Chunk<FragOperand, MCLD_SYMBOLS_PER_INPUT>;
210   FragOperand();
211   FragOperand(Fragment& pFragment);
212 
213 public:
214   void dump() const;
215 
frag()216   const Fragment* frag() const { return m_pFragment; }
frag()217   Fragment*       frag()       { return m_pFragment; }
218 
219   uint64_t value() const;
220 
classof(const Operand * pOperand)221   static bool classof(const Operand* pOperand)
222   {
223     return pOperand->type() == Operand::FRAGMENT;
224   }
225 
226   /* factory method */
227   static FragOperand* create(Fragment& pFragment);
228   static void destroy(FragOperand*& pOperand);
229   static void clear();
230 
231 private:
232   Fragment* m_pFragment;
233 };
234 
235 } // namespace of mcld
236 
237 #endif
238 
239