• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/MCContext.h"
13 #include "llvm/MC/MCAssembler.h"
14 using namespace llvm;
15 
16 const ARMMCExpr*
Create(VariantKind Kind,const MCExpr * Expr,MCContext & Ctx)17 ARMMCExpr::Create(VariantKind Kind, const MCExpr *Expr,
18                        MCContext &Ctx) {
19   return new (Ctx) ARMMCExpr(Kind, Expr);
20 }
21 
PrintImpl(raw_ostream & OS) const22 void ARMMCExpr::PrintImpl(raw_ostream &OS) const {
23   switch (Kind) {
24   default: assert(0 && "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
EvaluateAsRelocatableImpl(MCValue & Res,const MCAsmLayout * Layout) const38 ARMMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
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?
AddValueSymbols_(const MCExpr * Value,MCAssembler * Asm)45 static void AddValueSymbols_(const MCExpr *Value, MCAssembler *Asm) {
46   switch (Value->getKind()) {
47   case MCExpr::Target:
48     assert(0 && "Can't handle nested target expr!");
49     break;
50 
51   case MCExpr::Constant:
52     break;
53 
54   case MCExpr::Binary: {
55     const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
56     AddValueSymbols_(BE->getLHS(), Asm);
57     AddValueSymbols_(BE->getRHS(), Asm);
58     break;
59   }
60 
61   case MCExpr::SymbolRef:
62     Asm->getOrCreateSymbolData(cast<MCSymbolRefExpr>(Value)->getSymbol());
63     break;
64 
65   case MCExpr::Unary:
66     AddValueSymbols_(cast<MCUnaryExpr>(Value)->getSubExpr(), Asm);
67     break;
68   }
69 }
70 
AddValueSymbols(MCAssembler * Asm) const71 void ARMMCExpr::AddValueSymbols(MCAssembler *Asm) const {
72   AddValueSymbols_(getSubExpr(), Asm);
73 }
74