Deleted Added
full compact
MCExpr.h (208954) MCExpr.h (218893)
1//===- MCExpr.h - Assembly Level Expressions --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_MC_MCEXPR_H
11#define LLVM_MC_MCEXPR_H
12
1//===- MCExpr.h - Assembly Level Expressions --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_MC_MCEXPR_H
11#define LLVM_MC_MCEXPR_H
12
13#include "llvm/ADT/DenseMap.h"
13#include "llvm/Support/Casting.h"
14#include "llvm/Support/Casting.h"
14#include "llvm/System/DataTypes.h"
15#include "llvm/Support/DataTypes.h"
15
16namespace llvm {
17class MCAsmInfo;
18class MCAsmLayout;
16
17namespace llvm {
18class MCAsmInfo;
19class MCAsmLayout;
20class MCAssembler;
19class MCContext;
21class MCContext;
22class MCSectionData;
20class MCSymbol;
21class MCValue;
22class raw_ostream;
23class StringRef;
23class MCSymbol;
24class MCValue;
25class raw_ostream;
26class StringRef;
27typedef DenseMap<const MCSectionData*, uint64_t> SectionAddrMap;
24
25/// MCExpr - Base class for the full range of assembler expressions which are
26/// needed for parsing.
27class MCExpr {
28public:
29 enum ExprKind {
30 Binary, ///< Binary expressions.
31 Constant, ///< Constant expressions.
32 SymbolRef, ///< References to labels and assigned expressions.
33 Unary, ///< Unary expressions.
34 Target ///< Target specific expression.
35 };
36
37private:
38 ExprKind Kind;
39
40 MCExpr(const MCExpr&); // DO NOT IMPLEMENT
41 void operator=(const MCExpr&); // DO NOT IMPLEMENT
42
28
29/// MCExpr - Base class for the full range of assembler expressions which are
30/// needed for parsing.
31class MCExpr {
32public:
33 enum ExprKind {
34 Binary, ///< Binary expressions.
35 Constant, ///< Constant expressions.
36 SymbolRef, ///< References to labels and assigned expressions.
37 Unary, ///< Unary expressions.
38 Target ///< Target specific expression.
39 };
40
41private:
42 ExprKind Kind;
43
44 MCExpr(const MCExpr&); // DO NOT IMPLEMENT
45 void operator=(const MCExpr&); // DO NOT IMPLEMENT
46
47 bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
48 const MCAsmLayout *Layout,
49 const SectionAddrMap *Addrs) const;
43protected:
44 explicit MCExpr(ExprKind _Kind) : Kind(_Kind) {}
45
50protected:
51 explicit MCExpr(ExprKind _Kind) : Kind(_Kind) {}
52
53 bool EvaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
54 const MCAsmLayout *Layout,
55 const SectionAddrMap *Addrs,
56 bool InSet) const;
46public:
47 /// @name Accessors
48 /// @{
49
50 ExprKind getKind() const { return Kind; }
51
52 /// @}
53 /// @name Utility Methods

--- 8 unchanged lines hidden (view full) ---

62
63 /// EvaluateAsAbsolute - Try to evaluate the expression to an absolute value.
64 ///
65 /// @param Res - The absolute value, if evaluation succeeds.
66 /// @param Layout - The assembler layout object to use for evaluating symbol
67 /// values. If not given, then only non-symbolic expressions will be
68 /// evaluated.
69 /// @result - True on success.
57public:
58 /// @name Accessors
59 /// @{
60
61 ExprKind getKind() const { return Kind; }
62
63 /// @}
64 /// @name Utility Methods

--- 8 unchanged lines hidden (view full) ---

73
74 /// EvaluateAsAbsolute - Try to evaluate the expression to an absolute value.
75 ///
76 /// @param Res - The absolute value, if evaluation succeeds.
77 /// @param Layout - The assembler layout object to use for evaluating symbol
78 /// values. If not given, then only non-symbolic expressions will be
79 /// evaluated.
80 /// @result - True on success.
70 bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout = 0) const;
81 bool EvaluateAsAbsolute(int64_t &Res) const;
82 bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const;
83 bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout) const;
84 bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout,
85 const SectionAddrMap &Addrs) const;
71
72 /// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable
73 /// value, i.e. an expression of the fixed form (a - b + constant).
74 ///
75 /// @param Res - The relocatable value, if evaluation succeeds.
76 /// @param Layout - The assembler layout object to use for evaluating values.
77 /// @result - True on success.
86
87 /// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable
88 /// value, i.e. an expression of the fixed form (a - b + constant).
89 ///
90 /// @param Res - The relocatable value, if evaluation succeeds.
91 /// @param Layout - The assembler layout object to use for evaluating values.
92 /// @result - True on success.
78 bool EvaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout = 0) const;
93 bool EvaluateAsRelocatable(MCValue &Res, const MCAsmLayout &Layout) const;
79
80 /// @}
81
82 static bool classof(const MCExpr *) { return true; }
83};
84
85inline raw_ostream &operator<<(raw_ostream &OS, const MCExpr &E) {
86 E.print(OS);

--- 40 unchanged lines hidden (view full) ---

127 VK_Invalid,
128
129 VK_GOT,
130 VK_GOTOFF,
131 VK_GOTPCREL,
132 VK_GOTTPOFF,
133 VK_INDNTPOFF,
134 VK_NTPOFF,
94
95 /// @}
96
97 static bool classof(const MCExpr *) { return true; }
98};
99
100inline raw_ostream &operator<<(raw_ostream &OS, const MCExpr &E) {
101 E.print(OS);

--- 40 unchanged lines hidden (view full) ---

142 VK_Invalid,
143
144 VK_GOT,
145 VK_GOTOFF,
146 VK_GOTPCREL,
147 VK_GOTTPOFF,
148 VK_INDNTPOFF,
149 VK_NTPOFF,
150 VK_GOTNTPOFF,
135 VK_PLT,
136 VK_TLSGD,
151 VK_PLT,
152 VK_TLSGD,
153 VK_TLSLD,
154 VK_TLSLDM,
137 VK_TPOFF,
155 VK_TPOFF,
138 VK_ARM_HI16, // The R_ARM_MOVT_ABS relocation (:upper16: in the asm file)
139 VK_ARM_LO16, // The R_ARM_MOVW_ABS_NC relocation (:lower16: in the asm file)
140 VK_TLVP // Mach-O thread local variable relocation
156 VK_DTPOFF,
157 VK_TLVP, // Mach-O thread local variable relocation
158 // FIXME: We'd really like to use the generic Kinds listed above for these.
159 VK_ARM_PLT, // ARM-style PLT references. i.e., (PLT) instead of @PLT
160 VK_ARM_TLSGD, // ditto for TLSGD, GOT, GOTOFF, TPOFF and GOTTPOFF
161 VK_ARM_GOT,
162 VK_ARM_GOTOFF,
163 VK_ARM_TPOFF,
164 VK_ARM_GOTTPOFF,
165
166 VK_PPC_TOC,
167 VK_PPC_HA16, // ha16(symbol)
168 VK_PPC_LO16 // lo16(symbol)
141 };
142
143private:
144 /// The symbol being referenced.
145 const MCSymbol *Symbol;
146
147 /// The symbol reference modifier.
148 const VariantKind Kind;

--- 8 unchanged lines hidden (view full) ---

157 static const MCSymbolRefExpr *Create(const MCSymbol *Symbol, MCContext &Ctx) {
158 return MCSymbolRefExpr::Create(Symbol, VK_None, Ctx);
159 }
160
161 static const MCSymbolRefExpr *Create(const MCSymbol *Symbol, VariantKind Kind,
162 MCContext &Ctx);
163 static const MCSymbolRefExpr *Create(StringRef Name, VariantKind Kind,
164 MCContext &Ctx);
169 };
170
171private:
172 /// The symbol being referenced.
173 const MCSymbol *Symbol;
174
175 /// The symbol reference modifier.
176 const VariantKind Kind;

--- 8 unchanged lines hidden (view full) ---

185 static const MCSymbolRefExpr *Create(const MCSymbol *Symbol, MCContext &Ctx) {
186 return MCSymbolRefExpr::Create(Symbol, VK_None, Ctx);
187 }
188
189 static const MCSymbolRefExpr *Create(const MCSymbol *Symbol, VariantKind Kind,
190 MCContext &Ctx);
191 static const MCSymbolRefExpr *Create(StringRef Name, VariantKind Kind,
192 MCContext &Ctx);
165
193
166 /// @}
167 /// @name Accessors
168 /// @{
169
170 const MCSymbol &getSymbol() const { return *Symbol; }
171
172 VariantKind getKind() const { return Kind; }
173

--- 212 unchanged lines hidden (view full) ---

386protected:
387 MCTargetExpr() : MCExpr(Target) {}
388 virtual ~MCTargetExpr() {}
389public:
390
391 virtual void PrintImpl(raw_ostream &OS) const = 0;
392 virtual bool EvaluateAsRelocatableImpl(MCValue &Res,
393 const MCAsmLayout *Layout) const = 0;
194 /// @}
195 /// @name Accessors
196 /// @{
197
198 const MCSymbol &getSymbol() const { return *Symbol; }
199
200 VariantKind getKind() const { return Kind; }
201

--- 212 unchanged lines hidden (view full) ---

414protected:
415 MCTargetExpr() : MCExpr(Target) {}
416 virtual ~MCTargetExpr() {}
417public:
418
419 virtual void PrintImpl(raw_ostream &OS) const = 0;
420 virtual bool EvaluateAsRelocatableImpl(MCValue &Res,
421 const MCAsmLayout *Layout) const = 0;
422 virtual void AddValueSymbols(MCAssembler *) const = 0;
394
423
395
396 static bool classof(const MCExpr *E) {
397 return E->getKind() == MCExpr::Target;
398 }
399 static bool classof(const MCTargetExpr *) { return true; }
400};
401
402} // end namespace llvm
403
404#endif
424 static bool classof(const MCExpr *E) {
425 return E->getKind() == MCExpr::Target;
426 }
427 static bool classof(const MCTargetExpr *) { return true; }
428};
429
430} // end namespace llvm
431
432#endif