LLVM  3.7.0
SparcMCExpr.cpp
Go to the documentation of this file.
1 //===-- SparcMCExpr.cpp - Sparc specific MC expression classes --------===//
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 // This file contains the implementation of the assembly expression modifiers
11 // accepted by the Sparc architecture (e.g. "%hi", "%lo", ...).
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "SparcMCExpr.h"
16 #include "llvm/MC/MCAssembler.h"
17 #include "llvm/MC/MCContext.h"
19 #include "llvm/MC/MCSymbolELF.h"
20 #include "llvm/Object/ELF.h"
21 
22 
23 using namespace llvm;
24 
25 #define DEBUG_TYPE "sparcmcexpr"
26 
27 const SparcMCExpr*
29  MCContext &Ctx) {
30  return new (Ctx) SparcMCExpr(Kind, Expr);
31 }
32 
33 void SparcMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
34 
35  bool closeParen = printVariantKind(OS, Kind);
36 
37  const MCExpr *Expr = getSubExpr();
38  Expr->print(OS, MAI);
39 
40  if (closeParen)
41  OS << ')';
42 }
43 
45 {
46  bool closeParen = true;
47  switch (Kind) {
48  case VK_Sparc_None: closeParen = false; break;
49  case VK_Sparc_LO: OS << "%lo("; break;
50  case VK_Sparc_HI: OS << "%hi("; break;
51  case VK_Sparc_H44: OS << "%h44("; break;
52  case VK_Sparc_M44: OS << "%m44("; break;
53  case VK_Sparc_L44: OS << "%l44("; break;
54  case VK_Sparc_HH: OS << "%hh("; break;
55  case VK_Sparc_HM: OS << "%hm("; break;
56  // FIXME: use %pc22/%pc10, if system assembler supports them.
57  case VK_Sparc_PC22: OS << "%hi("; break;
58  case VK_Sparc_PC10: OS << "%lo("; break;
59  // FIXME: use %got22/%got10, if system assembler supports them.
60  case VK_Sparc_GOT22: OS << "%hi("; break;
61  case VK_Sparc_GOT10: OS << "%lo("; break;
62  case VK_Sparc_WPLT30: closeParen = false; break;
63  case VK_Sparc_R_DISP32: OS << "%r_disp32("; break;
64  case VK_Sparc_TLS_GD_HI22: OS << "%tgd_hi22("; break;
65  case VK_Sparc_TLS_GD_LO10: OS << "%tgd_lo10("; break;
66  case VK_Sparc_TLS_GD_ADD: OS << "%tgd_add("; break;
67  case VK_Sparc_TLS_GD_CALL: OS << "%tgd_call("; break;
68  case VK_Sparc_TLS_LDM_HI22: OS << "%tldm_hi22("; break;
69  case VK_Sparc_TLS_LDM_LO10: OS << "%tldm_lo10("; break;
70  case VK_Sparc_TLS_LDM_ADD: OS << "%tldm_add("; break;
71  case VK_Sparc_TLS_LDM_CALL: OS << "%tldm_call("; break;
72  case VK_Sparc_TLS_LDO_HIX22: OS << "%tldo_hix22("; break;
73  case VK_Sparc_TLS_LDO_LOX10: OS << "%tldo_lox10("; break;
74  case VK_Sparc_TLS_LDO_ADD: OS << "%tldo_add("; break;
75  case VK_Sparc_TLS_IE_HI22: OS << "%tie_hi22("; break;
76  case VK_Sparc_TLS_IE_LO10: OS << "%tie_lo10("; break;
77  case VK_Sparc_TLS_IE_LD: OS << "%tie_ld("; break;
78  case VK_Sparc_TLS_IE_LDX: OS << "%tie_ldx("; break;
79  case VK_Sparc_TLS_IE_ADD: OS << "%tie_add("; break;
80  case VK_Sparc_TLS_LE_HIX22: OS << "%tle_hix22("; break;
81  case VK_Sparc_TLS_LE_LOX10: OS << "%tle_lox10("; break;
82  }
83  return closeParen;
84 }
85 
87 {
89  .Case("lo", VK_Sparc_LO)
90  .Case("hi", VK_Sparc_HI)
91  .Case("h44", VK_Sparc_H44)
92  .Case("m44", VK_Sparc_M44)
93  .Case("l44", VK_Sparc_L44)
94  .Case("hh", VK_Sparc_HH)
95  .Case("hm", VK_Sparc_HM)
96  .Case("pc22", VK_Sparc_PC22)
97  .Case("pc10", VK_Sparc_PC10)
98  .Case("got22", VK_Sparc_GOT22)
99  .Case("got10", VK_Sparc_GOT10)
100  .Case("r_disp32", VK_Sparc_R_DISP32)
101  .Case("tgd_hi22", VK_Sparc_TLS_GD_HI22)
102  .Case("tgd_lo10", VK_Sparc_TLS_GD_LO10)
103  .Case("tgd_add", VK_Sparc_TLS_GD_ADD)
104  .Case("tgd_call", VK_Sparc_TLS_GD_CALL)
105  .Case("tldm_hi22", VK_Sparc_TLS_LDM_HI22)
106  .Case("tldm_lo10", VK_Sparc_TLS_LDM_LO10)
107  .Case("tldm_add", VK_Sparc_TLS_LDM_ADD)
108  .Case("tldm_call", VK_Sparc_TLS_LDM_CALL)
109  .Case("tldo_hix22", VK_Sparc_TLS_LDO_HIX22)
110  .Case("tldo_lox10", VK_Sparc_TLS_LDO_LOX10)
111  .Case("tldo_add", VK_Sparc_TLS_LDO_ADD)
112  .Case("tie_hi22", VK_Sparc_TLS_IE_HI22)
113  .Case("tie_lo10", VK_Sparc_TLS_IE_LO10)
114  .Case("tie_ld", VK_Sparc_TLS_IE_LD)
115  .Case("tie_ldx", VK_Sparc_TLS_IE_LDX)
116  .Case("tie_add", VK_Sparc_TLS_IE_ADD)
117  .Case("tle_hix22", VK_Sparc_TLS_LE_HIX22)
118  .Case("tle_lox10", VK_Sparc_TLS_LE_LOX10)
120 }
121 
123  switch (Kind) {
124  default: llvm_unreachable("Unhandled SparcMCExpr::VariantKind");
130  case VK_Sparc_HH: return Sparc::fixup_sparc_hh;
131  case VK_Sparc_HM: return Sparc::fixup_sparc_hm;
155  }
156 }
157 
158 bool
160  const MCAsmLayout *Layout,
161  const MCFixup *Fixup) const {
162  return getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup);
163 }
164 
166  switch (Expr->getKind()) {
167  case MCExpr::Target:
168  llvm_unreachable("Can't handle nested target expr!");
169  break;
170 
171  case MCExpr::Constant:
172  break;
173 
174  case MCExpr::Binary: {
175  const MCBinaryExpr *BE = cast<MCBinaryExpr>(Expr);
178  break;
179  }
180 
181  case MCExpr::SymbolRef: {
182  const MCSymbolRefExpr &SymRef = *cast<MCSymbolRefExpr>(Expr);
183  cast<MCSymbolELF>(SymRef.getSymbol()).setType(ELF::STT_TLS);
184  break;
185  }
186 
187  case MCExpr::Unary:
188  fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
189  break;
190  }
191 
192 }
193 
195  switch(getKind()) {
196  default: return;
199  case VK_Sparc_TLS_GD_ADD:
210  case VK_Sparc_TLS_IE_LD:
211  case VK_Sparc_TLS_IE_LDX:
212  case VK_Sparc_TLS_IE_ADD:
214  case VK_Sparc_TLS_LE_LOX10: break;
215  }
217 }
218 
219 void SparcMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
220  Streamer.visitUsedExpr(*getSubExpr());
221 }
fixup_sparc_got22 - 22-bit fixup corresponding to got22(foo)
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm)
const MCSymbol & getSymbol() const
Definition: MCExpr.h:328
This represents an "assembler immediate".
Definition: MCValue.h:44
const MCExpr * getSubExpr() const
getSubExpr - Get the child of this expression.
Definition: SparcMCExpr.h:82
static bool printVariantKind(raw_ostream &OS, VariantKind Kind)
Definition: SparcMCExpr.cpp:44
ExprKind getKind() const
Definition: MCExpr.h:69
fixup_sparc_m44 - 10-bit fixup corresponding to m44(foo)
StringSwitch & Case(const char(&S)[N], const T &Value)
Definition: StringSwitch.h:55
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:62
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:29
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
fixup_sparc_got10 - 10-bit fixup corresponding to got10(foo)
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:159
Context object for machine code objects.
Definition: MCContext.h:48
fixup_sparc_hm - 10-bit fixup corresponding to hm(foo)
Unary expressions.
Definition: MCExpr.h:39
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:58
Sparc::Fixups getFixupKind() const
getFixupKind - Get the fixup kind of this expression.
Definition: SparcMCExpr.h:85
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:531
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
Definition: MCExpr.cpp:33
Streaming machine code generation interface.
Definition: MCStreamer.h:157
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
fixup_sparc_hh - 22-bit fixup corresponding to hh(foo)
VariantKind getKind() const
getOpcode - Get the kind of this expression.
Definition: SparcMCExpr.h:79
static VariantKind parseVariantKind(StringRef name)
Definition: SparcMCExpr.cpp:86
fixup_sparc_l44 - 12-bit fixup corresponding to l44(foo)
Binary assembler expressions.
Definition: MCExpr.h:405
PowerPC TLS Dynamic Call Fixup
fixup_sparc_lo10 - 10-bit fixup corresponding to lo(foo)
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: SparcMCExpr.cpp:33
R Default(const T &Value) const
Definition: StringSwitch.h:111
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
Definition: MCExpr.cpp:595
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:613
fixup_sparc_pc22 - 22-bit fixup corresponding to pc22(foo)
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:534
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
References to labels and assigned expressions.
Definition: MCExpr.h:38
void visitUsedExpr(MCStreamer &Streamer) const override
static const SparcMCExpr * create(VariantKind Kind, const MCExpr *Expr, MCContext &Ctx)
Definition: SparcMCExpr.cpp:28
const ARM::ArchExtKind Kind
static const char * name
Constant expressions.
Definition: MCExpr.h:37
Binary expressions.
Definition: MCExpr.h:36
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
Target specific expression.
Definition: MCExpr.h:40
fixups for Thread Local Storage
fixup_sparc_hi22 - 22-bit fixup corresponding to hi(foo) for sethi
fixup_sparc_h44 - 22-bit fixup corresponding to h44(foo)
fixup_sparc_pc10 - 10-bit fixup corresponding to pc10(foo)