1 //===-- ARMMCExpr.cpp - ARM specific MC expression classes ----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #define DEBUG_TYPE "armmcexpr"
11 #include "ARMMCExpr.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCAssembler.h"
17 ARMMCExpr::Create(VariantKind Kind
, const MCExpr
*Expr
,
19 return new (Ctx
) ARMMCExpr(Kind
, Expr
);
22 void ARMMCExpr::PrintImpl(raw_ostream
&OS
) const {
24 default: assert(0 && "Invalid kind!");
25 case VK_ARM_HI16
: OS
<< ":upper16:"; break;
26 case VK_ARM_LO16
: OS
<< ":lower16:"; break;
29 const MCExpr
*Expr
= getSubExpr();
30 if (Expr
->getKind() != MCExpr::SymbolRef
)
33 if (Expr
->getKind() != MCExpr::SymbolRef
)
38 ARMMCExpr::EvaluateAsRelocatableImpl(MCValue
&Res
,
39 const MCAsmLayout
*Layout
) const {
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()) {
48 assert(0 && "Can't handle nested target expr!");
51 case MCExpr::Constant
:
54 case MCExpr::Binary
: {
55 const MCBinaryExpr
*BE
= cast
<MCBinaryExpr
>(Value
);
56 AddValueSymbols_(BE
->getLHS(), Asm
);
57 AddValueSymbols_(BE
->getRHS(), Asm
);
61 case MCExpr::SymbolRef
:
62 Asm
->getOrCreateSymbolData(cast
<MCSymbolRefExpr
>(Value
)->getSymbol());
66 AddValueSymbols_(cast
<MCUnaryExpr
>(Value
)->getSubExpr(), Asm
);
71 void ARMMCExpr::AddValueSymbols(MCAssembler
*Asm
) const {
72 AddValueSymbols_(getSubExpr(), Asm
);