1 //===-- PPCMCExpr.h - PPC 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_POWERPC_MCTARGETDESC_PPCMCEXPR_H 10 #define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H 11 12 #include "llvm/MC/MCAsmLayout.h" 13 #include "llvm/MC/MCExpr.h" 14 #include "llvm/MC/MCValue.h" 15 16 namespace llvm { 17 18 class PPCMCExpr : public MCTargetExpr { 19 public: 20 enum VariantKind { 21 VK_PPC_None, 22 VK_PPC_LO, 23 VK_PPC_HI, 24 VK_PPC_HA, 25 VK_PPC_HIGH, 26 VK_PPC_HIGHA, 27 VK_PPC_HIGHER, 28 VK_PPC_HIGHERA, 29 VK_PPC_HIGHEST, 30 VK_PPC_HIGHESTA 31 }; 32 33 private: 34 const VariantKind Kind; 35 const MCExpr *Expr; 36 37 int64_t evaluateAsInt64(int64_t Value) const; 38 39 explicit PPCMCExpr(VariantKind Kind, const MCExpr *Expr) 40 : Kind(Kind), Expr(Expr) {} 41 42 public: 43 /// @name Construction 44 /// @{ 45 46 static const PPCMCExpr *create(VariantKind Kind, const MCExpr *Expr, 47 MCContext &Ctx); 48 49 static const PPCMCExpr *createLo(const MCExpr *Expr, MCContext &Ctx) { 50 return create(VK_PPC_LO, Expr, Ctx); 51 } 52 53 static const PPCMCExpr *createHi(const MCExpr *Expr, MCContext &Ctx) { 54 return create(VK_PPC_HI, Expr, Ctx); 55 } 56 57 static const PPCMCExpr *createHa(const MCExpr *Expr, MCContext &Ctx) { 58 return create(VK_PPC_HA, Expr, Ctx); 59 } 60 61 /// @} 62 /// @name Accessors 63 /// @{ 64 65 /// getOpcode - Get the kind of this expression. 66 VariantKind getKind() const { return Kind; } 67 68 /// getSubExpr - Get the child of this expression. 69 const MCExpr *getSubExpr() const { return Expr; } 70 71 /// @} 72 73 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; 74 bool evaluateAsRelocatableImpl(MCValue &Res, 75 const MCAsmLayout *Layout, 76 const MCFixup *Fixup) const override; 77 void visitUsedExpr(MCStreamer &Streamer) const override; 78 MCFragment *findAssociatedFragment() const override { 79 return getSubExpr()->findAssociatedFragment(); 80 } 81 82 // There are no TLS PPCMCExprs at the moment. 83 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {} 84 85 bool evaluateAsConstant(int64_t &Res) const; 86 87 static bool classof(const MCExpr *E) { 88 return E->getKind() == MCExpr::Target; 89 } 90 }; 91 } // end namespace llvm 92 93 #endif 94