LLVM  3.7.0
MipsMCExpr.cpp
Go to the documentation of this file.
1 //===-- MipsMCExpr.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 #include "MipsMCExpr.h"
11 #include "llvm/MC/MCAsmInfo.h"
12 #include "llvm/MC/MCAssembler.h"
13 #include "llvm/MC/MCContext.h"
15 
16 using namespace llvm;
17 
18 #define DEBUG_TYPE "mipsmcexpr"
19 
21  const MCBinaryExpr *BE) {
22  switch (VK) {
27  break;
28  default:
29  return false;
30  }
31 
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()))
36  return false;
37  BE = cast<MCBinaryExpr>(BE->getLHS());
38  }
39  return (isa<MCSymbolRefExpr>(BE->getLHS())
40  && isa<MCSymbolRefExpr>(BE->getRHS()));
41 }
42 
43 const MipsMCExpr*
45  MCContext &Ctx) {
46  VariantKind Kind;
47  switch (VK) {
49  Kind = VK_Mips_LO;
50  break;
52  Kind = VK_Mips_HI;
53  break;
55  Kind = VK_Mips_HIGHER;
56  break;
58  Kind = VK_Mips_HIGHEST;
59  break;
60  default:
61  llvm_unreachable("Invalid kind!");
62  }
63 
64  return new (Ctx) MipsMCExpr(Kind, Expr);
65 }
66 
67 void MipsMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
68  switch (Kind) {
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;
74  }
75 
76  OS << '(';
77  Expr->print(OS, MAI);
78  OS << ')';
79 }
80 
81 bool
83  const MCAsmLayout *Layout,
84  const MCFixup *Fixup) const {
85  return getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup);
86 }
87 
88 void MipsMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
89  Streamer.visitUsedExpr(*getSubExpr());
90 }
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: MipsMCExpr.cpp:82
const MCExpr * getSubExpr() const
getSubExpr - Get the child of this expression.
Definition: MipsMCExpr.h:47
This represents an "assembler immediate".
Definition: MCValue.h:44
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:62
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:29
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
Context object for machine code objects.
Definition: MCContext.h:48
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: MipsMCExpr.cpp:88
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:58
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:531
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
Definition: MCExpr.cpp:33
Streaming machine code generation interface.
Definition: MCStreamer.h:157
static bool isSupportedBinaryExpr(MCSymbolRefExpr::VariantKind VK, const MCBinaryExpr *BE)
Definition: MipsMCExpr.cpp:20
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: MipsMCExpr.cpp:67
Binary assembler expressions.
Definition: MCExpr.h:405
static const MipsMCExpr * create(MCSymbolRefExpr::VariantKind VK, const MCExpr *Expr, MCContext &Ctx)
Definition: MipsMCExpr.cpp:44
PowerPC TLS Dynamic Call Fixup
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
Definition: MCExpr.cpp:595
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:613
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:534
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38