LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ARMMCExpr.cpp
Go to the documentation of this file.
1 //===-- ARMMCExpr.cpp - ARM 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 #define DEBUG_TYPE "armmcexpr"
11 #include "ARMMCExpr.h"
12 #include "llvm/MC/MCAssembler.h"
13 #include "llvm/MC/MCContext.h"
14 using namespace llvm;
15 
16 const ARMMCExpr*
18  MCContext &Ctx) {
19  return new (Ctx) ARMMCExpr(Kind, Expr);
20 }
21 
23  switch (Kind) {
24  default: llvm_unreachable("Invalid kind!");
25  case VK_ARM_HI16: OS << ":upper16:"; break;
26  case VK_ARM_LO16: OS << ":lower16:"; break;
27  }
28 
29  const MCExpr *Expr = getSubExpr();
30  if (Expr->getKind() != MCExpr::SymbolRef)
31  OS << '(';
32  Expr->print(OS);
33  if (Expr->getKind() != MCExpr::SymbolRef)
34  OS << ')';
35 }
36 
37 bool
39  const MCAsmLayout *Layout) const {
40  return false;
41 }
42 
43 // FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
44 // that method should be made public?
45 static void AddValueSymbols_(const MCExpr *Value, MCAssembler *Asm) {
46  switch (Value->getKind()) {
47  case MCExpr::Target:
48  llvm_unreachable("Can't handle nested target expr!");
49 
50  case MCExpr::Constant:
51  break;
52 
53  case MCExpr::Binary: {
54  const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
55  AddValueSymbols_(BE->getLHS(), Asm);
56  AddValueSymbols_(BE->getRHS(), Asm);
57  break;
58  }
59 
60  case MCExpr::SymbolRef:
61  Asm->getOrCreateSymbolData(cast<MCSymbolRefExpr>(Value)->getSymbol());
62  break;
63 
64  case MCExpr::Unary:
65  AddValueSymbols_(cast<MCUnaryExpr>(Value)->getSubExpr(), Asm);
66  break;
67  }
68 }
69 
72 }
ExprKind getKind() const
Definition: MCExpr.h:61
#define llvm_unreachable(msg)
const MCExpr * getSubExpr() const
getSubExpr - Get the child of this expression.
Definition: ARMMCExpr.h:55
void PrintImpl(raw_ostream &OS) const
Definition: ARMMCExpr.cpp:22
Unary expressions.
Definition: MCExpr.h:37
static void AddValueSymbols_(const MCExpr *Value, MCAssembler *Asm)
Definition: ARMMCExpr.cpp:45
const MCExpr * getLHS() const
getLHS - Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:477
bool EvaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout) const
Definition: ARMMCExpr.cpp:38
MCBinaryExpr - Binary assembler expressions.
Definition: MCExpr.h:356
static const ARMMCExpr * Create(VariantKind Kind, const MCExpr *Expr, MCContext &Ctx)
Definition: ARMMCExpr.cpp:17
MCSymbolData & getOrCreateSymbolData(const MCSymbol &Symbol, bool *Created=0)
Definition: MCAssembler.h:1151
const MCExpr * getRHS() const
getRHS - Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:480
void print(raw_ostream &OS) const
Definition: MCExpr.cpp:31
References to labels and assigned expressions.
Definition: MCExpr.h:36
LLVM Value Representation.
Definition: Value.h:66
Constant expressions.
Definition: MCExpr.h:35
Binary expressions.
Definition: MCExpr.h:34
void AddValueSymbols(MCAssembler *) const
Definition: ARMMCExpr.cpp:70
Target specific expression.
Definition: MCExpr.h:38