• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- Operator.cpp -------------------------------------------------------===//
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 #include <mcld/Script/Operator.h>
10 #include <mcld/Script/NullaryOp.h>
11 #include <mcld/Script/UnaryOp.h>
12 #include <mcld/Script/BinaryOp.h>
13 #include <mcld/Script/TernaryOp.h>
14 #include <mcld/Script/Operand.h>
15 #include <mcld/Support/raw_ostream.h>
16 
17 using namespace mcld;
18 //===----------------------------------------------------------------------===//
19 // Operator
20 //===----------------------------------------------------------------------===//
21 const char* Operator::OpNames[] = {
22   "+",
23   "-",
24   "!",
25   "~",
26   "*",
27   "/",
28   "%",
29   "+",
30   "-",
31   "<<",
32   ">>",
33   "<",
34   "<=",
35   ">",
36   ">=",
37   "==",
38   "!=",
39   "&",
40   "^",
41   "|",
42   "&&",
43   "||",
44   "?:",
45   "=",
46   "+=",
47   "-=",
48   "*=",
49   "/=",
50   "&=",
51   "|=",
52   "<<=",
53   ">>=",
54   "ABSOLUTE",
55   "ADDR",
56   "ALIGN",
57   "ALIGNOF",
58   "BLOCK",
59   "DATA_SEGMENT_ALIGN",
60   "DATA_SEGMENT_END",
61   "DATA_SEGMENT_RELRO_END",
62   "DEFINED",
63   "LENGTH",
64   "LOADADDR",
65   "MAX",
66   "MIN",
67   "NEXT",
68   "ORIGIN",
69   "SEGMENT_START",
70   "SIZEOF",
71   "SIZEOF_HEADERS",
72   "MAXPAGESIZE",
73   "COMMONPAGESIZE"
74 };
75 
Operator(Arity pArity,Type pType)76 Operator::Operator(Arity pArity,
77                    Type pType)
78   : ExprToken(ExprToken::OPERATOR),
79     m_Arity(pArity),
80     m_Type(pType)
81 {
82   m_pIntOperand = IntOperand::create(0);
83 }
84 
~Operator()85 Operator::~Operator()
86 {
87 }
88 
dump() const89 void Operator::dump() const
90 {
91   mcld::outs() << OpNames[type()];
92 }
93 
94 /* Nullary operator */
95 template<>
create()96 Operator& Operator::create<Operator::SIZEOF_HEADERS>()
97 {
98   static NullaryOp<Operator::SIZEOF_HEADERS> op;
99   return op;
100 }
101 
102 template<>
create()103 Operator& Operator::create<Operator::MAXPAGESIZE>()
104 {
105   static NullaryOp<Operator::MAXPAGESIZE> op;
106   return op;
107 }
108 
109 template<>
create()110 Operator& Operator::create<Operator::COMMONPAGESIZE>()
111 {
112   static NullaryOp<Operator::COMMONPAGESIZE> op;
113   return op;
114 }
115 
116 /* Unary operator */
117 template<>
create()118 Operator& Operator::create<Operator::UNARY_PLUS>()
119 {
120   static UnaryOp<Operator::UNARY_PLUS> op;
121   return op;
122 }
123 
124 template<>
create()125 Operator& Operator::create<Operator::UNARY_MINUS>()
126 {
127   static UnaryOp<Operator::UNARY_MINUS> op;
128   return op;
129 }
130 
131 template<>
create()132 Operator& Operator::create<Operator::LOGICAL_NOT>()
133 {
134   static UnaryOp<Operator::LOGICAL_NOT> op;
135   return op;
136 }
137 
138 template<>
create()139 Operator& Operator::create<Operator::BITWISE_NOT>()
140 {
141   static UnaryOp<Operator::BITWISE_NOT> op;
142   return op;
143 }
144 
145 template<>
create()146 Operator& Operator::create<Operator::ABSOLUTE>()
147 {
148   static UnaryOp<Operator::ABSOLUTE> op;
149   return op;
150 }
151 
152 template<>
create()153 Operator& Operator::create<Operator::ADDR>()
154 {
155   static UnaryOp<Operator::ADDR> op;
156   return op;
157 }
158 
159 template<>
create()160 Operator& Operator::create<Operator::ALIGNOF>()
161 {
162   static UnaryOp<Operator::ALIGNOF> op;
163   return op;
164 }
165 
166 template<>
create()167 Operator& Operator::create<Operator::DATA_SEGMENT_END>()
168 {
169   static UnaryOp<Operator::DATA_SEGMENT_END> op;
170   return op;
171 }
172 
173 template<>
create()174 Operator& Operator::create<Operator::DEFINED>()
175 {
176   static UnaryOp<Operator::DEFINED> op;
177   return op;
178 }
179 
180 template<>
create()181 Operator& Operator::create<Operator::LENGTH>()
182 {
183   static UnaryOp<Operator::LENGTH> op;
184   return op;
185 }
186 
187 template<>
create()188 Operator& Operator::create<Operator::LOADADDR>()
189 {
190   static UnaryOp<Operator::LOADADDR> op;
191   return op;
192 }
193 
194 template<>
create()195 Operator& Operator::create<Operator::NEXT>()
196 {
197   static UnaryOp<Operator::NEXT> op;
198   return op;
199 }
200 
201 template<>
create()202 Operator& Operator::create<Operator::ORIGIN>()
203 {
204   static UnaryOp<Operator::ORIGIN> op;
205   return op;
206 }
207 
208 template<>
create()209 Operator& Operator::create<Operator::SIZEOF>()
210 {
211   static UnaryOp<Operator::SIZEOF> op;
212   return op;
213 }
214 
215 /* Binary operator */
216 template<>
create()217 Operator& Operator::create<Operator::MUL>()
218 {
219   static BinaryOp<Operator::MUL> op;
220   return op;
221 }
222 
223 template<>
create()224 Operator& Operator::create<Operator::DIV>()
225 {
226   static BinaryOp<Operator::DIV> op;
227   return op;
228 }
229 
230 template<>
create()231 Operator& Operator::create<Operator::MOD>()
232 {
233   static BinaryOp<Operator::MOD> op;
234   return op;
235 }
236 
237 template<>
create()238 Operator& Operator::create<Operator::ADD>()
239 {
240   static BinaryOp<Operator::ADD> op;
241   return op;
242 }
243 
244 template<>
create()245 Operator& Operator::create<Operator::SUB>()
246 {
247   static BinaryOp<Operator::SUB> op;
248   return op;
249 }
250 
251 template<>
create()252 Operator& Operator::create<Operator::LSHIFT>()
253 {
254   static BinaryOp<Operator::LSHIFT> op;
255   return op;
256 }
257 
258 template<>
create()259 Operator& Operator::create<Operator::RSHIFT>()
260 {
261   static BinaryOp<Operator::RSHIFT> op;
262   return op;
263 }
264 
265 template<>
create()266 Operator& Operator::create<Operator::LT>()
267 {
268   static BinaryOp<Operator::LT> op;
269   return op;
270 }
271 
272 template<>
create()273 Operator& Operator::create<Operator::LE>()
274 {
275   static BinaryOp<Operator::LE> op;
276   return op;
277 }
278 
279 template<>
create()280 Operator& Operator::create<Operator::GT>()
281 {
282   static BinaryOp<Operator::GT> op;
283   return op;
284 }
285 
286 template<>
create()287 Operator& Operator::create<Operator::GE>()
288 {
289   static BinaryOp<Operator::GE> op;
290   return op;
291 }
292 
293 template<>
create()294 Operator& Operator::create<Operator::EQ>()
295 {
296   static BinaryOp<Operator::EQ> op;
297   return op;
298 }
299 
300 template<>
create()301 Operator& Operator::create<Operator::NE>()
302 {
303   static BinaryOp<Operator::NE> op;
304   return op;
305 }
306 
307 template<>
create()308 Operator& Operator::create<Operator::BITWISE_AND>()
309 {
310   static BinaryOp<Operator::BITWISE_AND> op;
311   return op;
312 }
313 
314 template<>
create()315 Operator& Operator::create<Operator::BITWISE_XOR>()
316 {
317   static BinaryOp<Operator::BITWISE_XOR> op;
318   return op;
319 }
320 
321 template<>
create()322 Operator& Operator::create<Operator::BITWISE_OR>()
323 {
324   static BinaryOp<Operator::BITWISE_OR> op;
325   return op;
326 }
327 
328 template<>
create()329 Operator& Operator::create<Operator::LOGICAL_AND>()
330 {
331   static BinaryOp<Operator::LOGICAL_AND> op;
332   return op;
333 }
334 
335 template<>
create()336 Operator& Operator::create<Operator::LOGICAL_OR>()
337 {
338   static BinaryOp<Operator::LOGICAL_OR> op;
339   return op;
340 }
341 
342 template<>
create()343 Operator& Operator::create<Operator::ALIGN>()
344 {
345   static BinaryOp<Operator::ALIGN> op;
346   return op;
347 }
348 
349 template<>
create()350 Operator& Operator::create<Operator::DATA_SEGMENT_RELRO_END>()
351 {
352   static BinaryOp<Operator::DATA_SEGMENT_RELRO_END> op;
353   return op;
354 }
355 
356 template<>
create()357 Operator& Operator::create<Operator::MAX>()
358 {
359   static BinaryOp<Operator::MAX> op;
360   return op;
361 }
362 
363 template<>
create()364 Operator& Operator::create<Operator::MIN>()
365 {
366   static BinaryOp<Operator::MIN> op;
367   return op;
368 }
369 
370 template<>
create()371 Operator& Operator::create<Operator::SEGMENT_START>()
372 {
373   static BinaryOp<Operator::SEGMENT_START> op;
374   return op;
375 }
376 
377 /* Ternary operator */
378 template<>
create()379 Operator& Operator::create<Operator::TERNARY_IF>()
380 {
381   static TernaryOp<Operator::TERNARY_IF> op;
382   return op;
383 }
384 
385 template<>
create()386 Operator& Operator::create<Operator::DATA_SEGMENT_ALIGN>()
387 {
388   static TernaryOp<Operator::DATA_SEGMENT_ALIGN> op;
389   return op;
390 }
391