xref: /freebsd/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
1 //====- SparcMCExpr.h - Sparc 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 // This file describes Sparc-specific MCExprs, used for modifiers like
10 // "%hi" or "%lo" etc.,
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_SPARC_MCTARGETDESC_SPARCMCEXPR_H
15 #define LLVM_LIB_TARGET_SPARC_MCTARGETDESC_SPARCMCEXPR_H
16 
17 #include "SparcFixupKinds.h"
18 #include "llvm/MC/MCExpr.h"
19 
20 namespace llvm {
21 
22 class StringRef;
23 class SparcMCExpr : public MCTargetExpr {
24 public:
25   enum VariantKind {
26     VK_Sparc_None,
27     VK_Sparc_LO,
28     VK_Sparc_HI,
29     VK_Sparc_H44,
30     VK_Sparc_M44,
31     VK_Sparc_L44,
32     VK_Sparc_HH,
33     VK_Sparc_HM,
34     VK_Sparc_LM,
35     VK_Sparc_PC22,
36     VK_Sparc_PC10,
37     VK_Sparc_GOT22,
38     VK_Sparc_GOT10,
39     VK_Sparc_GOT13,
40     VK_Sparc_13,
41     VK_Sparc_WPLT30,
42     VK_Sparc_WDISP30,
43     VK_Sparc_R_DISP32,
44     VK_Sparc_TLS_GD_HI22,
45     VK_Sparc_TLS_GD_LO10,
46     VK_Sparc_TLS_GD_ADD,
47     VK_Sparc_TLS_GD_CALL,
48     VK_Sparc_TLS_LDM_HI22,
49     VK_Sparc_TLS_LDM_LO10,
50     VK_Sparc_TLS_LDM_ADD,
51     VK_Sparc_TLS_LDM_CALL,
52     VK_Sparc_TLS_LDO_HIX22,
53     VK_Sparc_TLS_LDO_LOX10,
54     VK_Sparc_TLS_LDO_ADD,
55     VK_Sparc_TLS_IE_HI22,
56     VK_Sparc_TLS_IE_LO10,
57     VK_Sparc_TLS_IE_LD,
58     VK_Sparc_TLS_IE_LDX,
59     VK_Sparc_TLS_IE_ADD,
60     VK_Sparc_TLS_LE_HIX22,
61     VK_Sparc_TLS_LE_LOX10
62   };
63 
64 private:
65   const VariantKind Kind;
66   const MCExpr *Expr;
67 
68   explicit SparcMCExpr(VariantKind Kind, const MCExpr *Expr)
69       : Kind(Kind), Expr(Expr) {}
70 
71 public:
72   /// @name Construction
73   /// @{
74 
75   static const SparcMCExpr *create(VariantKind Kind, const MCExpr *Expr,
76                                  MCContext &Ctx);
77   /// @}
78   /// @name Accessors
79   /// @{
80 
81   /// getOpcode - Get the kind of this expression.
82   VariantKind getKind() const { return Kind; }
83 
84   /// getSubExpr - Get the child of this expression.
85   const MCExpr *getSubExpr() const { return Expr; }
86 
87   /// getFixupKind - Get the fixup kind of this expression.
88   Sparc::Fixups getFixupKind() const { return getFixupKind(Kind); }
89 
90   /// @}
91   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
92   bool evaluateAsRelocatableImpl(MCValue &Res,
93                                  const MCAsmLayout *Layout,
94                                  const MCFixup *Fixup) const override;
95   void visitUsedExpr(MCStreamer &Streamer) const override;
96   MCFragment *findAssociatedFragment() const override {
97     return getSubExpr()->findAssociatedFragment();
98   }
99 
100   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
101 
102   static bool classof(const MCExpr *E) {
103     return E->getKind() == MCExpr::Target;
104   }
105 
106   static bool classof(const SparcMCExpr *) { return true; }
107 
108   static VariantKind parseVariantKind(StringRef name);
109   static bool printVariantKind(raw_ostream &OS, VariantKind Kind);
110   static Sparc::Fixups getFixupKind(VariantKind Kind);
111 };
112 
113 } // end namespace llvm.
114 
115 #endif
116