LLVM  14.0.0git
LanaiMCExpr.cpp
Go to the documentation of this file.
1 //===-- LanaiMCExpr.cpp - Lanai specific MC expression classes ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "LanaiMCExpr.h"
10 #include "llvm/MC/MCAssembler.h"
11 #include "llvm/MC/MCContext.h"
12 #include "llvm/MC/MCStreamer.h"
13 using namespace llvm;
14 
15 #define DEBUG_TYPE "lanaimcexpr"
16 
18  MCContext &Ctx) {
19  return new (Ctx) LanaiMCExpr(Kind, Expr);
20 }
21 
22 void LanaiMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
23  if (Kind == VK_Lanai_None) {
24  Expr->print(OS, MAI);
25  return;
26  }
27 
28  switch (Kind) {
29  default:
30  llvm_unreachable("Invalid kind!");
31  case VK_Lanai_ABS_HI:
32  OS << "hi";
33  break;
34  case VK_Lanai_ABS_LO:
35  OS << "lo";
36  break;
37  }
38 
39  OS << '(';
40  const MCExpr *Expr = getSubExpr();
41  Expr->print(OS, MAI);
42  OS << ')';
43 }
44 
45 void LanaiMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
46  Streamer.visitUsedExpr(*getSubExpr());
47 }
48 
50  const MCAsmLayout *Layout,
51  const MCFixup *Fixup) const {
52  if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup))
53  return false;
54 
55  Res =
56  MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), getKind());
57 
58  return true;
59 }
llvm::LanaiMCExpr::printImpl
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: LanaiMCExpr.cpp:22
llvm::MCStreamer::visitUsedExpr
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:1059
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::LanaiMCExpr::getSubExpr
const MCExpr * getSubExpr() const
Definition: LanaiMCExpr.h:36
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::LanaiMCExpr
Definition: LanaiMCExpr.h:17
MCAssembler.h
llvm::MCExpr::evaluateAsRelocatable
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:745
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:197
llvm::LanaiMCExpr::evaluateAsRelocatableImpl
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: LanaiMCExpr.cpp:49
llvm::LanaiMCExpr::create
static const LanaiMCExpr * create(VariantKind Kind, const MCExpr *Expr, MCContext &Ctx)
Definition: LanaiMCExpr.cpp:17
MCContext.h
llvm::LanaiMCExpr::VK_Lanai_ABS_HI
@ VK_Lanai_ABS_HI
Definition: LanaiMCExpr.h:19
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MCValue::getConstant
int64_t getConstant() const
Definition: MCValue.h:44
llvm::MCValue::getSymA
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:45
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::LanaiMCExpr::getKind
VariantKind getKind() const
Definition: LanaiMCExpr.h:33
llvm::MCValue::get
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=nullptr, int64_t Val=0, uint32_t RefKind=0)
Definition: MCValue.h:60
Fixup
PowerPC TLS Dynamic Call Fixup
Definition: PPCTLSDynamicCall.cpp:235
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::LanaiMCExpr::VariantKind
VariantKind
Definition: LanaiMCExpr.h:19
llvm::LanaiMCExpr::visitUsedExpr
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: LanaiMCExpr.cpp:45
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
llvm::LanaiMCExpr::VK_Lanai_None
@ VK_Lanai_None
Definition: LanaiMCExpr.h:19
llvm::MCExpr::print
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:42
MCStreamer.h
LanaiMCExpr.h
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::MCValue::getSymB
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:46
llvm::LanaiMCExpr::VK_Lanai_ABS_LO
@ VK_Lanai_ABS_LO
Definition: LanaiMCExpr.h:19