1 //===-- ARMMCExpr.h - ARM 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_ARM_MCTARGETDESC_ARMMCEXPR_H 10 #define LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMMCEXPR_H 11 12 #include "llvm/MC/MCExpr.h" 13 14 namespace llvm { 15 16 class ARMMCExpr : public MCTargetExpr { 17 public: 18 enum VariantKind { 19 VK_ARM_None, 20 VK_ARM_HI16, // The R_ARM_MOVT_ABS relocation (:upper16: in the .s file) 21 VK_ARM_LO16, // The R_ARM_MOVW_ABS_NC relocation (:lower16: in the .s file) 22 23 VK_ARM_HI_8_15, // The R_ARM_THM_ALU_ABS_G3 relocation (:upper8_15: in 24 // the .s file) 25 VK_ARM_HI_0_7, // The R_ARM_THM_ALU_ABS_G2_NC relocation (:upper0_8: in the 26 // .s file) 27 VK_ARM_LO_8_15, // The R_ARM_THM_ALU_ABS_G1_NC relocation (:lower8_15: in 28 // the .s file) 29 VK_ARM_LO_0_7, // The R_ARM_THM_ALU_ABS_G0_NC relocation (:lower0_7: in the 30 // .s file) 31 }; 32 33 private: 34 const VariantKind Kind; 35 const MCExpr *Expr; 36 37 explicit ARMMCExpr(VariantKind Kind, const MCExpr *Expr) 38 : Kind(Kind), Expr(Expr) {} 39 40 public: 41 /// @name Construction 42 /// @{ 43 44 static const ARMMCExpr *create(VariantKind Kind, const MCExpr *Expr, 45 MCContext &Ctx); 46 47 static const ARMMCExpr *createUpper16(const MCExpr *Expr, MCContext &Ctx) { 48 return create(VK_ARM_HI16, Expr, Ctx); 49 } 50 51 static const ARMMCExpr *createLower16(const MCExpr *Expr, MCContext &Ctx) { 52 return create(VK_ARM_LO16, Expr, Ctx); 53 } 54 55 static const ARMMCExpr *createUpper8_15(const MCExpr *Expr, MCContext &Ctx) { 56 return create(VK_ARM_HI_8_15, Expr, Ctx); 57 } 58 59 static const ARMMCExpr *createUpper0_7(const MCExpr *Expr, MCContext &Ctx) { 60 return create(VK_ARM_HI_0_7, Expr, Ctx); 61 } 62 63 static const ARMMCExpr *createLower8_15(const MCExpr *Expr, MCContext &Ctx) { 64 return create(VK_ARM_LO_8_15, Expr, Ctx); 65 } 66 67 static const ARMMCExpr *createLower0_7(const MCExpr *Expr, MCContext &Ctx) { 68 return create(VK_ARM_LO_0_7, Expr, Ctx); 69 } 70 71 /// @} 72 /// @name Accessors 73 /// @{ 74 75 /// getOpcode - Get the kind of this expression. 76 VariantKind getKind() const { return Kind; } 77 78 /// getSubExpr - Get the child of this expression. 79 const MCExpr *getSubExpr() const { return Expr; } 80 81 /// @} 82 83 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; 84 bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, 85 const MCFixup *Fixup) const override { 86 return false; 87 } 88 void visitUsedExpr(MCStreamer &Streamer) const override; 89 MCFragment *findAssociatedFragment() const override { 90 return getSubExpr()->findAssociatedFragment(); 91 } 92 93 // There are no TLS ARMMCExprs at the moment. 94 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {} 95 96 static bool classof(const MCExpr *E) { 97 return E->getKind() == MCExpr::Target; 98 } 99 }; 100 } // end namespace llvm 101 102 #endif 103