1 //===-- LanaiMCExpr.cpp - Lanai 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 "LanaiMCExpr.h"
11 #include "llvm/MC/MCAssembler.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCStreamer.h"
14 using namespace llvm;
15
16 #define DEBUG_TYPE "lanaimcexpr"
17
create(VariantKind Kind,const MCExpr * Expr,MCContext & Ctx)18 const LanaiMCExpr *LanaiMCExpr::create(VariantKind Kind, const MCExpr *Expr,
19 MCContext &Ctx) {
20 return new (Ctx) LanaiMCExpr(Kind, Expr);
21 }
22
printImpl(raw_ostream & OS,const MCAsmInfo * MAI) const23 void LanaiMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
24 if (Kind == VK_Lanai_None) {
25 Expr->print(OS, MAI);
26 return;
27 }
28
29 switch (Kind) {
30 default:
31 llvm_unreachable("Invalid kind!");
32 case VK_Lanai_ABS_HI:
33 OS << "hi";
34 break;
35 case VK_Lanai_ABS_LO:
36 OS << "lo";
37 break;
38 }
39
40 OS << '(';
41 const MCExpr *Expr = getSubExpr();
42 Expr->print(OS, MAI);
43 OS << ')';
44 }
45
visitUsedExpr(MCStreamer & Streamer) const46 void LanaiMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
47 Streamer.visitUsedExpr(*getSubExpr());
48 }
49
evaluateAsRelocatableImpl(MCValue & Res,const MCAsmLayout * Layout,const MCFixup * Fixup) const50 bool LanaiMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
51 const MCAsmLayout *Layout,
52 const MCFixup *Fixup) const {
53 if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup))
54 return false;
55
56 Res =
57 MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), getKind());
58
59 return true;
60 }
61