• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- Nios2MCExpr.cpp - Nios2 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 "Nios2.h"
11 
12 #include "Nios2MCExpr.h"
13 #include "llvm/MC/MCAsmInfo.h"
14 #include "llvm/MC/MCAssembler.h"
15 #include "llvm/MC/MCContext.h"
16 #include "llvm/MC/MCObjectStreamer.h"
17 #include "llvm/MC/MCSymbolELF.h"
18 
19 using namespace llvm;
20 
21 #define DEBUG_TYPE "nios2mcexpr"
22 
create(Nios2MCExpr::Nios2ExprKind Kind,const MCExpr * Expr,MCContext & Ctx)23 const Nios2MCExpr *Nios2MCExpr::create(Nios2MCExpr::Nios2ExprKind Kind,
24                                        const MCExpr *Expr, MCContext &Ctx) {
25   return new (Ctx) Nios2MCExpr(Kind, Expr);
26 }
27 
create(const MCSymbol * Symbol,Nios2MCExpr::Nios2ExprKind Kind,MCContext & Ctx)28 const Nios2MCExpr *Nios2MCExpr::create(const MCSymbol *Symbol,
29                                        Nios2MCExpr::Nios2ExprKind Kind,
30                                        MCContext &Ctx) {
31   const MCSymbolRefExpr *MCSym =
32       MCSymbolRefExpr::create(Symbol, MCSymbolRefExpr::VK_None, Ctx);
33   return new (Ctx) Nios2MCExpr(Kind, MCSym);
34 }
35 
printImpl(raw_ostream & OS,const MCAsmInfo * MAI) const36 void Nios2MCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
37 
38   switch (Kind) {
39   case CEK_None:
40   case CEK_Special:
41     llvm_unreachable("CEK_None and CEK_Special are invalid");
42     break;
43   case CEK_ABS_HI:
44     OS << "%hiadj";
45     break;
46   case CEK_ABS_LO:
47     OS << "%lo";
48     break;
49   }
50 
51   OS << '(';
52   Expr->print(OS, MAI, true);
53   OS << ')';
54 }
55 
evaluateAsRelocatableImpl(MCValue & Res,const MCAsmLayout * Layout,const MCFixup * Fixup) const56 bool Nios2MCExpr::evaluateAsRelocatableImpl(MCValue &Res,
57                                             const MCAsmLayout *Layout,
58                                             const MCFixup *Fixup) const {
59   return getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup);
60 }
61 
visitUsedExpr(MCStreamer & Streamer) const62 void Nios2MCExpr::visitUsedExpr(MCStreamer &Streamer) const {
63   Streamer.visitUsedExpr(*getSubExpr());
64 }
65 
fixELFSymbolsInTLSFixups(MCAssembler & Asm) const66 void Nios2MCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
67   switch (getKind()) {
68   case CEK_None:
69   case CEK_Special:
70     llvm_unreachable("CEK_None and CEK_Special are invalid");
71     break;
72   case CEK_ABS_HI:
73   case CEK_ABS_LO:
74     break;
75   }
76 }
77