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 #include "MipsMCExpr.h"
11 #include "llvm/MC/MCAsmInfo.h"
12 #include "llvm/MC/MCAssembler.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/MC/MCObjectStreamer.h"
18 #define DEBUG_TYPE "mipsmcexpr"
20 bool MipsMCExpr::isSupportedBinaryExpr(MCSymbolRefExpr::VariantKind VK,
21 const MCBinaryExpr *BE) {
23 case MCSymbolRefExpr::VK_Mips_ABS_LO:
24 case MCSymbolRefExpr::VK_Mips_ABS_HI:
25 case MCSymbolRefExpr::VK_Mips_HIGHER:
26 case MCSymbolRefExpr::VK_Mips_HIGHEST:
32 // We support expressions of the form "(sym1 binop1 sym2) binop2 const",
33 // where "binop2 const" is optional.
34 if (isa<MCBinaryExpr>(BE->getLHS())) {
35 if (!isa<MCConstantExpr>(BE->getRHS()))
37 BE = cast<MCBinaryExpr>(BE->getLHS());
39 return (isa<MCSymbolRefExpr>(BE->getLHS())
40 && isa<MCSymbolRefExpr>(BE->getRHS()));
44 MipsMCExpr::Create(MCSymbolRefExpr::VariantKind VK, const MCExpr *Expr,
48 case MCSymbolRefExpr::VK_Mips_ABS_LO:
51 case MCSymbolRefExpr::VK_Mips_ABS_HI:
54 case MCSymbolRefExpr::VK_Mips_HIGHER:
55 Kind = VK_Mips_HIGHER;
57 case MCSymbolRefExpr::VK_Mips_HIGHEST:
58 Kind = VK_Mips_HIGHEST;
61 llvm_unreachable("Invalid kind!");
64 return new (Ctx) MipsMCExpr(Kind, Expr);
67 void MipsMCExpr::PrintImpl(raw_ostream &OS) const {
69 default: llvm_unreachable("Invalid kind!");
70 case VK_Mips_LO: OS << "%lo"; break;
71 case VK_Mips_HI: OS << "%hi"; break;
72 case VK_Mips_HIGHER: OS << "%higher"; break;
73 case VK_Mips_HIGHEST: OS << "%highest"; break;
82 MipsMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
83 const MCAsmLayout *Layout) const {
84 return getSubExpr()->EvaluateAsRelocatable(Res, Layout);
87 void MipsMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
88 Streamer.visitUsedExpr(*getSubExpr());