1 //===-- CSKYMCExpr.h - CSKY specific MC expression classes -*- C++ -*----===//
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 #ifndef LLVM_LIB_TARGET_LANAI_MCTARGETDESC_LANAIMCEXPR_H
10 #define LLVM_LIB_TARGET_LANAI_MCTARGETDESC_LANAIMCEXPR_H
11 
12 #include "llvm/MC/MCExpr.h"
13 #include "llvm/MC/MCValue.h"
14 
15 namespace llvm {
16 
17 class CSKYMCExpr : public MCTargetExpr {
18 public:
19   enum VariantKind {
20     VK_CSKY_None,
21     VK_CSKY_ADDR,
22     VK_CSKY_ADDR_HI16,
23     VK_CSKY_ADDR_LO16,
24     VK_CSKY_PCREL,
25     VK_CSKY_GOT,
26     VK_CSKY_GOT_IMM18_BY4,
27     VK_CSKY_GOTPC,
28     VK_CSKY_GOTOFF,
29     VK_CSKY_PLT,
30     VK_CSKY_PLT_IMM18_BY4,
31     VK_CSKY_TLSIE,
32     VK_CSKY_TLSLE,
33     VK_CSKY_TLSGD,
34     VK_CSKY_TLSLDO,
35     VK_CSKY_TLSLDM,
36     VK_CSKY_Invalid
37   };
38 
39 private:
40   const VariantKind Kind;
41   const MCExpr *Expr;
42 
CSKYMCExpr(VariantKind Kind,const MCExpr * Expr)43   explicit CSKYMCExpr(VariantKind Kind, const MCExpr *Expr)
44       : Kind(Kind), Expr(Expr) {}
45 
46 public:
47   static const CSKYMCExpr *create(const MCExpr *Expr, VariantKind Kind,
48                                   MCContext &Ctx);
49 
50   // Returns the kind of this expression.
getKind()51   VariantKind getKind() const { return Kind; }
52 
53   // Returns the child of this expression.
getSubExpr()54   const MCExpr *getSubExpr() const { return Expr; }
55 
56   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
57 
58   bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
59                                  const MCFixup *Fixup) const override;
60   void visitUsedExpr(MCStreamer &Streamer) const override;
61 
findAssociatedFragment()62   MCFragment *findAssociatedFragment() const override {
63     return getSubExpr()->findAssociatedFragment();
64   }
65 
66   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
67 
classof(const MCExpr * E)68   static bool classof(const MCExpr *E) {
69     return E->getKind() == MCExpr::Target;
70   }
71 
72   static StringRef getVariantKindName(VariantKind Kind);
73 };
74 } // end namespace llvm
75 
76 #endif
77