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* 17 ARMMCExpr::Create(VariantKind Kind, const MCExpr *Expr, 18 MCContext &Ctx) { 19 return new (Ctx) ARMMCExpr(Kind, Expr); 20 } 21 22 void ARMMCExpr::PrintImpl(raw_ostream &OS) const { 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 38 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? 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 70 void ARMMCExpr::AddValueSymbols(MCAssembler *Asm) const { 71 AddValueSymbols_(getSubExpr(), Asm); 72 } 73