Home | History | Annotate | Line # | Download | only in MCTargetDesc
      1 //===- MipsMCExpr.h - Mips 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_MIPS_MCTARGETDESC_MIPSMCEXPR_H
     10 #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCEXPR_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 MipsMCExpr : public MCTargetExpr {
     19 public:
     20   enum MipsExprKind {
     21     MEK_None,
     22     MEK_CALL_HI16,
     23     MEK_CALL_LO16,
     24     MEK_DTPREL,
     25     MEK_DTPREL_HI,
     26     MEK_DTPREL_LO,
     27     MEK_GOT,
     28     MEK_GOTTPREL,
     29     MEK_GOT_CALL,
     30     MEK_GOT_DISP,
     31     MEK_GOT_HI16,
     32     MEK_GOT_LO16,
     33     MEK_GOT_OFST,
     34     MEK_GOT_PAGE,
     35     MEK_GPREL,
     36     MEK_HI,
     37     MEK_HIGHER,
     38     MEK_HIGHEST,
     39     MEK_LO,
     40     MEK_NEG,
     41     MEK_PCREL_HI16,
     42     MEK_PCREL_LO16,
     43     MEK_TLSGD,
     44     MEK_TLSLDM,
     45     MEK_TPREL_HI,
     46     MEK_TPREL_LO,
     47     MEK_Special,
     48   };
     49 
     50 private:
     51   const MipsExprKind Kind;
     52   const MCExpr *Expr;
     53 
     54   explicit MipsMCExpr(MipsExprKind Kind, const MCExpr *Expr)
     55       : Kind(Kind), Expr(Expr) {}
     56 
     57 public:
     58   static const MipsMCExpr *create(MipsExprKind Kind, const MCExpr *Expr,
     59                                   MCContext &Ctx);
     60   static const MipsMCExpr *createGpOff(MipsExprKind Kind, const MCExpr *Expr,
     61                                        MCContext &Ctx);
     62 
     63   /// Get the kind of this expression.
     64   MipsExprKind getKind() const { return Kind; }
     65 
     66   /// Get the child of this expression.
     67   const MCExpr *getSubExpr() const { return Expr; }
     68 
     69   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
     70   bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
     71                                  const MCFixup *Fixup) const override;
     72   void visitUsedExpr(MCStreamer &Streamer) const override;
     73 
     74   MCFragment *findAssociatedFragment() const override {
     75     return getSubExpr()->findAssociatedFragment();
     76   }
     77 
     78   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
     79 
     80   static bool classof(const MCExpr *E) {
     81     return E->getKind() == MCExpr::Target;
     82   }
     83 
     84   bool isGpOff(MipsExprKind &Kind) const;
     85   bool isGpOff() const {
     86     MipsExprKind Kind;
     87     return isGpOff(Kind);
     88   }
     89 };
     90 
     91 } // end namespace llvm
     92 
     93 #endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCEXPR_H
     94