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