1 //===-- MipsMCSymbolRefExpr.cpp - Mips 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 "mipsmcsymbolrefexpr" 11 #include "MipsMCSymbolRefExpr.h" 12 #include "llvm/MC/MCAssembler.h" 13 #include "llvm/MC/MCContext.h" 14 #include "llvm/MC/MCSymbol.h" 15 using namespace llvm; 16 17 const MipsMCSymbolRefExpr* 18 MipsMCSymbolRefExpr::Create(VariantKind Kind, const MCSymbol *Symbol, 19 int Offset, MCContext &Ctx) { 20 return new (Ctx) MipsMCSymbolRefExpr(Kind, Symbol, Offset); 21 } 22 23 void MipsMCSymbolRefExpr::PrintImpl(raw_ostream &OS) const { 24 switch (Kind) { 25 default: assert(0 && "Invalid kind!"); 26 case VK_Mips_None: break; 27 case VK_Mips_GPREL: OS << "%gp_rel("; break; 28 case VK_Mips_GOT_CALL: OS << "%call16("; break; 29 case VK_Mips_GOT: OS << "%got("; break; 30 case VK_Mips_ABS_HI: OS << "%hi("; break; 31 case VK_Mips_ABS_LO: OS << "%lo("; break; 32 case VK_Mips_TLSGD: OS << "%tlsgd("; break; 33 case VK_Mips_GOTTPREL: OS << "%gottprel("; break; 34 case VK_Mips_TPREL_HI: OS << "%tprel_hi("; break; 35 case VK_Mips_TPREL_LO: OS << "%tprel_lo("; break; 36 case VK_Mips_GPOFF_HI: OS << "%hi(%neg(%gp_rel("; break; 37 case VK_Mips_GPOFF_LO: OS << "%lo(%neg(%gp_rel("; break; 38 case VK_Mips_GOT_DISP: OS << "%got_disp("; break; 39 case VK_Mips_GOT_PAGE: OS << "%got_page("; break; 40 case VK_Mips_GOT_OFST: OS << "%got_ofst("; break; 41 } 42 43 OS << *Symbol; 44 45 if (Offset) { 46 if (Offset > 0) 47 OS << '+'; 48 OS << Offset; 49 } 50 51 if (Kind == VK_Mips_GPOFF_HI || Kind == VK_Mips_GPOFF_LO) 52 OS << ")))"; 53 else if (Kind != VK_Mips_None) 54 OS << ')'; 55 } 56 57 bool 58 MipsMCSymbolRefExpr::EvaluateAsRelocatableImpl(MCValue &Res, 59 const MCAsmLayout *Layout) const { 60 return false; 61 } 62 63 void MipsMCSymbolRefExpr::AddValueSymbols(MCAssembler *Asm) const { 64 Asm->getOrCreateSymbolData(*Symbol); 65 } 66 67 const MCSection *MipsMCSymbolRefExpr::FindAssociatedSection() const { 68 return Symbol->isDefined() ? &Symbol->getSection() : NULL; 69 } 70 71