blob: 69b55ca6f7cd35e53feca8287530d27d0aed9233 [file] [log] [blame]
Alex Bradbury9d3f1252017-09-28 08:26:24 +00001//===-- 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
20namespace llvm {
21
22class StringRef;
23class RISCVMCExpr : public MCTargetExpr {
24public:
25 enum VariantKind {
26 VK_RISCV_None,
27 VK_RISCV_LO,
28 VK_RISCV_HI,
29 VK_RISCV_PCREL_HI,
30 VK_RISCV_Invalid
31 };
32
33private:
34 const MCExpr *Expr;
35 const VariantKind Kind;
36
37 int64_t evaluateAsInt64(int64_t Value) const;
38
39 explicit RISCVMCExpr(const MCExpr *Expr, VariantKind Kind)
40 : Expr(Expr), Kind(Kind) {}
41
42public:
43 static const RISCVMCExpr *create(const MCExpr *Expr, VariantKind Kind,
44 MCContext &Ctx);
45
46 VariantKind getKind() const { return Kind; }
47
48 const MCExpr *getSubExpr() const { return Expr; }
49
50 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
51 bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
52 const MCFixup *Fixup) const override;
53 void visitUsedExpr(MCStreamer &Streamer) const override;
54 MCFragment *findAssociatedFragment() const override {
55 return getSubExpr()->findAssociatedFragment();
56 }
57
58 // There are no TLS RISCVMCExprs at the moment.
59 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
60
61 bool evaluateAsConstant(int64_t &Res) const;
62
63 static bool classof(const MCExpr *E) {
64 return E->getKind() == MCExpr::Target;
65 }
66
67 static bool classof(const RISCVMCExpr *) { return true; }
68
69 static VariantKind getVariantKindForName(StringRef name);
70 static StringRef getVariantKindName(VariantKind Kind);
71};
72
73} // end namespace llvm.
74
75#endif