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 #include "ARMMCExpr.h"
11 #include "llvm/MC/MCAssembler.h"
12 #include "llvm/MC/MCContext.h"
13 using namespace llvm;
14 
15 #define DEBUG_TYPE "armmcexpr"
16 
17 const ARMMCExpr*
Create(VariantKind Kind,const MCExpr * Expr,MCContext & Ctx)18 ARMMCExpr::Create(VariantKind Kind, const MCExpr *Expr,
19                        MCContext &Ctx) {
20   return new (Ctx) ARMMCExpr(Kind, Expr);
21 }
22 
PrintImpl(raw_ostream & OS) const23 void ARMMCExpr::PrintImpl(raw_ostream &OS) const {
24   switch (Kind) {
25   default: llvm_unreachable("Invalid kind!");
26   case VK_ARM_HI16: OS << ":upper16:"; break;
27   case VK_ARM_LO16: OS << ":lower16:"; break;
28   }
29 
30   const MCExpr *Expr = getSubExpr();
31   if (Expr->getKind() != MCExpr::SymbolRef)
32     OS << '(';
33   Expr->print(OS);
34   if (Expr->getKind() != MCExpr::SymbolRef)
35     OS << ')';
36 }
37 
visitUsedExpr(MCStreamer & Streamer) const38 void ARMMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
39   Streamer.visitUsedExpr(*getSubExpr());
40 }
41