• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- RISCVMCExpr.h - RISCV specific MC expression classes ----*- C++ -*-===//
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 // This file describes RISCV-specific MCExprs, used for modifiers like
11 // "%hi" or "%lo" etc.,
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVMCEXPR_H
16 #define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVMCEXPR_H
17 
18 #include "llvm/MC/MCExpr.h"
19 
20 namespace llvm {
21 
22 class StringRef;
23 class MCOperand;
24 class RISCVMCExpr : public MCTargetExpr {
25 public:
26   enum VariantKind {
27     VK_RISCV_None,
28     VK_RISCV_LO,
29     VK_RISCV_HI,
30     VK_RISCV_PCREL_LO,
31     VK_RISCV_PCREL_HI,
32     VK_RISCV_CALL,
33     VK_RISCV_Invalid
34   };
35 
36 private:
37   const MCExpr *Expr;
38   const VariantKind Kind;
39 
40   int64_t evaluateAsInt64(int64_t Value) const;
41 
RISCVMCExpr(const MCExpr * Expr,VariantKind Kind)42   explicit RISCVMCExpr(const MCExpr *Expr, VariantKind Kind)
43       : Expr(Expr), Kind(Kind) {}
44 
45 public:
46   static const RISCVMCExpr *create(const MCExpr *Expr, VariantKind Kind,
47                                    MCContext &Ctx);
48 
getKind()49   VariantKind getKind() const { return Kind; }
50 
getSubExpr()51   const MCExpr *getSubExpr() const { return Expr; }
52 
53   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
54   bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
55                                  const MCFixup *Fixup) const override;
56   void visitUsedExpr(MCStreamer &Streamer) const override;
findAssociatedFragment()57   MCFragment *findAssociatedFragment() const override {
58     return getSubExpr()->findAssociatedFragment();
59   }
60 
61   // There are no TLS RISCVMCExprs at the moment.
fixELFSymbolsInTLSFixups(MCAssembler & Asm)62   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
63 
64   bool evaluateAsConstant(int64_t &Res) const;
65 
classof(const MCExpr * E)66   static bool classof(const MCExpr *E) {
67     return E->getKind() == MCExpr::Target;
68   }
69 
classof(const RISCVMCExpr *)70   static bool classof(const RISCVMCExpr *) { return true; }
71 
72   static VariantKind getVariantKindForName(StringRef name);
73   static StringRef getVariantKindName(VariantKind Kind);
74 };
75 
76 } // end namespace llvm.
77 
78 #endif
79