xref: /freebsd/contrib/llvm-project/llvm/lib/Target/ARM/MCTargetDesc/ARMMCExpr.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- ARMMCExpr.h - ARM 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_ARM_MCTARGETDESC_ARMMCEXPR_H
100b57cec5SDimitry Andric #define LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMMCEXPR_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "llvm/MC/MCExpr.h"
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric namespace llvm {
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric class ARMMCExpr : public MCTargetExpr {
170b57cec5SDimitry Andric public:
180b57cec5SDimitry Andric   enum VariantKind {
190b57cec5SDimitry Andric     VK_ARM_None,
200b57cec5SDimitry Andric     VK_ARM_HI16, // The R_ARM_MOVT_ABS relocation (:upper16: in the .s file)
2106c3fb27SDimitry Andric     VK_ARM_LO16, // The R_ARM_MOVW_ABS_NC relocation (:lower16: in the .s file)
2206c3fb27SDimitry Andric 
2306c3fb27SDimitry Andric     VK_ARM_HI_8_15, // The R_ARM_THM_ALU_ABS_G3    relocation (:upper8_15: in
2406c3fb27SDimitry Andric                     // the .s file)
2506c3fb27SDimitry Andric     VK_ARM_HI_0_7,  // The R_ARM_THM_ALU_ABS_G2_NC relocation (:upper0_8: in the
2606c3fb27SDimitry Andric                     // .s file)
2706c3fb27SDimitry Andric     VK_ARM_LO_8_15, // The R_ARM_THM_ALU_ABS_G1_NC relocation (:lower8_15: in
2806c3fb27SDimitry Andric                     // the .s file)
2906c3fb27SDimitry Andric     VK_ARM_LO_0_7,  // The R_ARM_THM_ALU_ABS_G0_NC relocation (:lower0_7: in the
3006c3fb27SDimitry Andric                     // .s file)
310b57cec5SDimitry Andric   };
320b57cec5SDimitry Andric 
330b57cec5SDimitry Andric private:
340b57cec5SDimitry Andric   const VariantKind Kind;
350b57cec5SDimitry Andric   const MCExpr *Expr;
360b57cec5SDimitry Andric 
ARMMCExpr(VariantKind Kind,const MCExpr * Expr)370b57cec5SDimitry Andric   explicit ARMMCExpr(VariantKind Kind, const MCExpr *Expr)
380b57cec5SDimitry Andric       : Kind(Kind), Expr(Expr) {}
390b57cec5SDimitry Andric 
400b57cec5SDimitry Andric public:
410b57cec5SDimitry Andric   /// @name Construction
420b57cec5SDimitry Andric   /// @{
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric   static const ARMMCExpr *create(VariantKind Kind, const MCExpr *Expr,
450b57cec5SDimitry Andric                                       MCContext &Ctx);
460b57cec5SDimitry Andric 
createUpper16(const MCExpr * Expr,MCContext & Ctx)470b57cec5SDimitry Andric   static const ARMMCExpr *createUpper16(const MCExpr *Expr, MCContext &Ctx) {
480b57cec5SDimitry Andric     return create(VK_ARM_HI16, Expr, Ctx);
490b57cec5SDimitry Andric   }
500b57cec5SDimitry Andric 
createLower16(const MCExpr * Expr,MCContext & Ctx)510b57cec5SDimitry Andric   static const ARMMCExpr *createLower16(const MCExpr *Expr, MCContext &Ctx) {
520b57cec5SDimitry Andric     return create(VK_ARM_LO16, Expr, Ctx);
530b57cec5SDimitry Andric   }
540b57cec5SDimitry Andric 
createUpper8_15(const MCExpr * Expr,MCContext & Ctx)5506c3fb27SDimitry Andric   static const ARMMCExpr *createUpper8_15(const MCExpr *Expr, MCContext &Ctx) {
5606c3fb27SDimitry Andric     return create(VK_ARM_HI_8_15, Expr, Ctx);
5706c3fb27SDimitry Andric   }
5806c3fb27SDimitry Andric 
createUpper0_7(const MCExpr * Expr,MCContext & Ctx)5906c3fb27SDimitry Andric   static const ARMMCExpr *createUpper0_7(const MCExpr *Expr, MCContext &Ctx) {
6006c3fb27SDimitry Andric     return create(VK_ARM_HI_0_7, Expr, Ctx);
6106c3fb27SDimitry Andric   }
6206c3fb27SDimitry Andric 
createLower8_15(const MCExpr * Expr,MCContext & Ctx)6306c3fb27SDimitry Andric   static const ARMMCExpr *createLower8_15(const MCExpr *Expr, MCContext &Ctx) {
6406c3fb27SDimitry Andric     return create(VK_ARM_LO_8_15, Expr, Ctx);
6506c3fb27SDimitry Andric   }
6606c3fb27SDimitry Andric 
createLower0_7(const MCExpr * Expr,MCContext & Ctx)6706c3fb27SDimitry Andric   static const ARMMCExpr *createLower0_7(const MCExpr *Expr, MCContext &Ctx) {
6806c3fb27SDimitry Andric     return create(VK_ARM_LO_0_7, Expr, Ctx);
6906c3fb27SDimitry Andric   }
7006c3fb27SDimitry Andric 
710b57cec5SDimitry Andric   /// @}
720b57cec5SDimitry Andric   /// @name Accessors
730b57cec5SDimitry Andric   /// @{
740b57cec5SDimitry Andric 
750b57cec5SDimitry Andric   /// getOpcode - Get the kind of this expression.
getKind()760b57cec5SDimitry Andric   VariantKind getKind() const { return Kind; }
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric   /// getSubExpr - Get the child of this expression.
getSubExpr()790b57cec5SDimitry Andric   const MCExpr *getSubExpr() const { return Expr; }
800b57cec5SDimitry Andric 
810b57cec5SDimitry Andric   /// @}
820b57cec5SDimitry Andric 
830b57cec5SDimitry Andric   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
evaluateAsRelocatableImpl(MCValue & Res,const MCAssembler * Asm,const MCFixup * Fixup)84*0fca6ea1SDimitry Andric   bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
850b57cec5SDimitry Andric                                  const MCFixup *Fixup) const override {
860b57cec5SDimitry Andric     return false;
870b57cec5SDimitry Andric   }
880b57cec5SDimitry Andric   void visitUsedExpr(MCStreamer &Streamer) const override;
findAssociatedFragment()890b57cec5SDimitry Andric   MCFragment *findAssociatedFragment() const override {
900b57cec5SDimitry Andric     return getSubExpr()->findAssociatedFragment();
910b57cec5SDimitry Andric   }
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric   // There are no TLS ARMMCExprs at the moment.
fixELFSymbolsInTLSFixups(MCAssembler & Asm)940b57cec5SDimitry Andric   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
950b57cec5SDimitry Andric 
classof(const MCExpr * E)960b57cec5SDimitry Andric   static bool classof(const MCExpr *E) {
970b57cec5SDimitry Andric     return E->getKind() == MCExpr::Target;
980b57cec5SDimitry Andric   }
990b57cec5SDimitry Andric };
1000b57cec5SDimitry Andric } // end namespace llvm
1010b57cec5SDimitry Andric 
1020b57cec5SDimitry Andric #endif
103