10b57cec5SDimitry Andric //===-- PPCMCExpr.h - PPC specific MC expression classes --------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H 100b57cec5SDimitry Andric #define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #include "llvm/MC/MCExpr.h" 130b57cec5SDimitry Andric #include "llvm/MC/MCValue.h" 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric namespace llvm { 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric class PPCMCExpr : public MCTargetExpr { 180b57cec5SDimitry Andric public: 190b57cec5SDimitry Andric enum VariantKind { 200b57cec5SDimitry Andric VK_PPC_None, 210b57cec5SDimitry Andric VK_PPC_LO, 220b57cec5SDimitry Andric VK_PPC_HI, 230b57cec5SDimitry Andric VK_PPC_HA, 240b57cec5SDimitry Andric VK_PPC_HIGH, 250b57cec5SDimitry Andric VK_PPC_HIGHA, 260b57cec5SDimitry Andric VK_PPC_HIGHER, 270b57cec5SDimitry Andric VK_PPC_HIGHERA, 280b57cec5SDimitry Andric VK_PPC_HIGHEST, 290b57cec5SDimitry Andric VK_PPC_HIGHESTA 300b57cec5SDimitry Andric }; 310b57cec5SDimitry Andric 320b57cec5SDimitry Andric private: 330b57cec5SDimitry Andric const VariantKind Kind; 340b57cec5SDimitry Andric const MCExpr *Expr; 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric int64_t evaluateAsInt64(int64_t Value) const; 370b57cec5SDimitry Andric 385ffd83dbSDimitry Andric explicit PPCMCExpr(VariantKind Kind, const MCExpr *Expr) 395ffd83dbSDimitry Andric : Kind(Kind), Expr(Expr) {} 400b57cec5SDimitry Andric 410b57cec5SDimitry Andric public: 420b57cec5SDimitry Andric /// @name Construction 430b57cec5SDimitry Andric /// @{ 440b57cec5SDimitry Andric 450b57cec5SDimitry Andric static const PPCMCExpr *create(VariantKind Kind, const MCExpr *Expr, 465ffd83dbSDimitry Andric MCContext &Ctx); 470b57cec5SDimitry Andric 485ffd83dbSDimitry Andric static const PPCMCExpr *createLo(const MCExpr *Expr, MCContext &Ctx) { 495ffd83dbSDimitry Andric return create(VK_PPC_LO, Expr, Ctx); 500b57cec5SDimitry Andric } 510b57cec5SDimitry Andric 525ffd83dbSDimitry Andric static const PPCMCExpr *createHi(const MCExpr *Expr, MCContext &Ctx) { 535ffd83dbSDimitry Andric return create(VK_PPC_HI, Expr, Ctx); 540b57cec5SDimitry Andric } 550b57cec5SDimitry Andric 565ffd83dbSDimitry Andric static const PPCMCExpr *createHa(const MCExpr *Expr, MCContext &Ctx) { 575ffd83dbSDimitry Andric return create(VK_PPC_HA, Expr, Ctx); 580b57cec5SDimitry Andric } 590b57cec5SDimitry Andric 600b57cec5SDimitry Andric /// @} 610b57cec5SDimitry Andric /// @name Accessors 620b57cec5SDimitry Andric /// @{ 630b57cec5SDimitry Andric 640b57cec5SDimitry Andric /// getOpcode - Get the kind of this expression. 650b57cec5SDimitry Andric VariantKind getKind() const { return Kind; } 660b57cec5SDimitry Andric 670b57cec5SDimitry Andric /// getSubExpr - Get the child of this expression. 680b57cec5SDimitry Andric const MCExpr *getSubExpr() const { return Expr; } 690b57cec5SDimitry Andric 700b57cec5SDimitry Andric /// @} 710b57cec5SDimitry Andric 720b57cec5SDimitry Andric void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; 73*0fca6ea1SDimitry Andric bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, 740b57cec5SDimitry Andric const MCFixup *Fixup) const override; 750b57cec5SDimitry Andric void visitUsedExpr(MCStreamer &Streamer) const override; 760b57cec5SDimitry Andric MCFragment *findAssociatedFragment() const override { 770b57cec5SDimitry Andric return getSubExpr()->findAssociatedFragment(); 780b57cec5SDimitry Andric } 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric // There are no TLS PPCMCExprs at the moment. 810b57cec5SDimitry Andric void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {} 820b57cec5SDimitry Andric 830b57cec5SDimitry Andric bool evaluateAsConstant(int64_t &Res) const; 840b57cec5SDimitry Andric 850b57cec5SDimitry Andric static bool classof(const MCExpr *E) { 860b57cec5SDimitry Andric return E->getKind() == MCExpr::Target; 870b57cec5SDimitry Andric } 880b57cec5SDimitry Andric }; 890b57cec5SDimitry Andric } // end namespace llvm 900b57cec5SDimitry Andric 910b57cec5SDimitry Andric #endif 92