xref: /aosp_15_r20/external/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- PPCMCExpr.h - PPC specific MC expression classes --------*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker 
10*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H
11*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H
12*9880d681SAndroid Build Coastguard Worker 
13*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCAsmLayout.h"
14*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCExpr.h"
15*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCValue.h"
16*9880d681SAndroid Build Coastguard Worker 
17*9880d681SAndroid Build Coastguard Worker namespace llvm {
18*9880d681SAndroid Build Coastguard Worker 
19*9880d681SAndroid Build Coastguard Worker class PPCMCExpr : public MCTargetExpr {
20*9880d681SAndroid Build Coastguard Worker public:
21*9880d681SAndroid Build Coastguard Worker   enum VariantKind {
22*9880d681SAndroid Build Coastguard Worker     VK_PPC_None,
23*9880d681SAndroid Build Coastguard Worker     VK_PPC_LO,
24*9880d681SAndroid Build Coastguard Worker     VK_PPC_HI,
25*9880d681SAndroid Build Coastguard Worker     VK_PPC_HA,
26*9880d681SAndroid Build Coastguard Worker     VK_PPC_HIGHER,
27*9880d681SAndroid Build Coastguard Worker     VK_PPC_HIGHERA,
28*9880d681SAndroid Build Coastguard Worker     VK_PPC_HIGHEST,
29*9880d681SAndroid Build Coastguard Worker     VK_PPC_HIGHESTA
30*9880d681SAndroid Build Coastguard Worker   };
31*9880d681SAndroid Build Coastguard Worker 
32*9880d681SAndroid Build Coastguard Worker private:
33*9880d681SAndroid Build Coastguard Worker   const VariantKind Kind;
34*9880d681SAndroid Build Coastguard Worker   const MCExpr *Expr;
35*9880d681SAndroid Build Coastguard Worker   bool IsDarwin;
36*9880d681SAndroid Build Coastguard Worker 
37*9880d681SAndroid Build Coastguard Worker   int64_t evaluateAsInt64(int64_t Value) const;
38*9880d681SAndroid Build Coastguard Worker 
PPCMCExpr(VariantKind Kind,const MCExpr * Expr,bool IsDarwin)39*9880d681SAndroid Build Coastguard Worker   explicit PPCMCExpr(VariantKind Kind, const MCExpr *Expr, bool IsDarwin)
40*9880d681SAndroid Build Coastguard Worker       : Kind(Kind), Expr(Expr), IsDarwin(IsDarwin) {}
41*9880d681SAndroid Build Coastguard Worker 
42*9880d681SAndroid Build Coastguard Worker public:
43*9880d681SAndroid Build Coastguard Worker   /// @name Construction
44*9880d681SAndroid Build Coastguard Worker   /// @{
45*9880d681SAndroid Build Coastguard Worker 
46*9880d681SAndroid Build Coastguard Worker   static const PPCMCExpr *create(VariantKind Kind, const MCExpr *Expr,
47*9880d681SAndroid Build Coastguard Worker                                  bool isDarwin, MCContext &Ctx);
48*9880d681SAndroid Build Coastguard Worker 
createLo(const MCExpr * Expr,bool isDarwin,MCContext & Ctx)49*9880d681SAndroid Build Coastguard Worker   static const PPCMCExpr *createLo(const MCExpr *Expr,
50*9880d681SAndroid Build Coastguard Worker                                    bool isDarwin, MCContext &Ctx) {
51*9880d681SAndroid Build Coastguard Worker     return create(VK_PPC_LO, Expr, isDarwin, Ctx);
52*9880d681SAndroid Build Coastguard Worker   }
53*9880d681SAndroid Build Coastguard Worker 
createHi(const MCExpr * Expr,bool isDarwin,MCContext & Ctx)54*9880d681SAndroid Build Coastguard Worker   static const PPCMCExpr *createHi(const MCExpr *Expr,
55*9880d681SAndroid Build Coastguard Worker                                    bool isDarwin, MCContext &Ctx) {
56*9880d681SAndroid Build Coastguard Worker     return create(VK_PPC_HI, Expr, isDarwin, Ctx);
57*9880d681SAndroid Build Coastguard Worker   }
58*9880d681SAndroid Build Coastguard Worker 
createHa(const MCExpr * Expr,bool isDarwin,MCContext & Ctx)59*9880d681SAndroid Build Coastguard Worker   static const PPCMCExpr *createHa(const MCExpr *Expr,
60*9880d681SAndroid Build Coastguard Worker                                    bool isDarwin, MCContext &Ctx) {
61*9880d681SAndroid Build Coastguard Worker     return create(VK_PPC_HA, Expr, isDarwin, Ctx);
62*9880d681SAndroid Build Coastguard Worker   }
63*9880d681SAndroid Build Coastguard Worker 
64*9880d681SAndroid Build Coastguard Worker   /// @}
65*9880d681SAndroid Build Coastguard Worker   /// @name Accessors
66*9880d681SAndroid Build Coastguard Worker   /// @{
67*9880d681SAndroid Build Coastguard Worker 
68*9880d681SAndroid Build Coastguard Worker   /// getOpcode - Get the kind of this expression.
getKind()69*9880d681SAndroid Build Coastguard Worker   VariantKind getKind() const { return Kind; }
70*9880d681SAndroid Build Coastguard Worker 
71*9880d681SAndroid Build Coastguard Worker   /// getSubExpr - Get the child of this expression.
getSubExpr()72*9880d681SAndroid Build Coastguard Worker   const MCExpr *getSubExpr() const { return Expr; }
73*9880d681SAndroid Build Coastguard Worker 
74*9880d681SAndroid Build Coastguard Worker   /// isDarwinSyntax - True if expression is to be printed using Darwin syntax.
isDarwinSyntax()75*9880d681SAndroid Build Coastguard Worker   bool isDarwinSyntax() const { return IsDarwin; }
76*9880d681SAndroid Build Coastguard Worker 
77*9880d681SAndroid Build Coastguard Worker 
78*9880d681SAndroid Build Coastguard Worker   /// @}
79*9880d681SAndroid Build Coastguard Worker 
80*9880d681SAndroid Build Coastguard Worker   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
81*9880d681SAndroid Build Coastguard Worker   bool evaluateAsRelocatableImpl(MCValue &Res,
82*9880d681SAndroid Build Coastguard Worker                                  const MCAsmLayout *Layout,
83*9880d681SAndroid Build Coastguard Worker                                  const MCFixup *Fixup) const override;
84*9880d681SAndroid Build Coastguard Worker   void visitUsedExpr(MCStreamer &Streamer) const override;
findAssociatedFragment()85*9880d681SAndroid Build Coastguard Worker   MCFragment *findAssociatedFragment() const override {
86*9880d681SAndroid Build Coastguard Worker     return getSubExpr()->findAssociatedFragment();
87*9880d681SAndroid Build Coastguard Worker   }
88*9880d681SAndroid Build Coastguard Worker 
89*9880d681SAndroid Build Coastguard Worker   // There are no TLS PPCMCExprs at the moment.
fixELFSymbolsInTLSFixups(MCAssembler & Asm)90*9880d681SAndroid Build Coastguard Worker   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
91*9880d681SAndroid Build Coastguard Worker 
92*9880d681SAndroid Build Coastguard Worker   bool evaluateAsConstant(int64_t &Res) const;
93*9880d681SAndroid Build Coastguard Worker 
classof(const MCExpr * E)94*9880d681SAndroid Build Coastguard Worker   static bool classof(const MCExpr *E) {
95*9880d681SAndroid Build Coastguard Worker     return E->getKind() == MCExpr::Target;
96*9880d681SAndroid Build Coastguard Worker   }
97*9880d681SAndroid Build Coastguard Worker };
98*9880d681SAndroid Build Coastguard Worker } // end namespace llvm
99*9880d681SAndroid Build Coastguard Worker 
100*9880d681SAndroid Build Coastguard Worker #endif
101