1 //===-- MipsMCExpr.cpp - Mips 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 "mipsmcexpr"
11 #include "MipsMCExpr.h"
12 #include "llvm/MC/MCAsmInfo.h"
13 #include "llvm/MC/MCAssembler.h"
14 #include "llvm/MC/MCContext.h"
19 MipsMCExpr::Create(VariantKind Kind, const MCExpr *Expr,
21 return new (Ctx) MipsMCExpr(Kind, Expr);
24 void MipsMCExpr::PrintImpl(raw_ostream &OS) const {
26 default: llvm_unreachable("Invalid kind!");
27 case VK_Mips_ABS_LO: OS << "%lo"; break;
28 case VK_Mips_ABS_HI: OS << "%hi"; break;
37 MipsMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
38 const MCAsmLayout *Layout) const {
39 return getSubExpr()->EvaluateAsRelocatable(Res, Layout);
42 // FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
43 // that method should be made public?
44 static void AddValueSymbolsImpl(const MCExpr *Value, MCAssembler *Asm) {
45 switch (Value->getKind()) {
47 llvm_unreachable("Can't handle nested target expr!");
49 case MCExpr::Constant:
52 case MCExpr::Binary: {
53 const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
54 AddValueSymbolsImpl(BE->getLHS(), Asm);
55 AddValueSymbolsImpl(BE->getRHS(), Asm);
59 case MCExpr::SymbolRef:
60 Asm->getOrCreateSymbolData(cast<MCSymbolRefExpr>(Value)->getSymbol());
64 AddValueSymbolsImpl(cast<MCUnaryExpr>(Value)->getSubExpr(), Asm);
69 void MipsMCExpr::AddValueSymbols(MCAssembler *Asm) const {
70 AddValueSymbolsImpl(getSubExpr(), Asm);