• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- PPCMCExpr.h - PPC specific MC expression classes --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H
11 #define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H
12 
13 #include "llvm/MC/MCAsmLayout.h"
14 #include "llvm/MC/MCExpr.h"
15 #include "llvm/MC/MCValue.h"
16 
17 namespace llvm {
18 
19 class PPCMCExpr : public MCTargetExpr {
20 public:
21   enum VariantKind {
22     VK_PPC_None,
23     VK_PPC_LO,
24     VK_PPC_HI,
25     VK_PPC_HA,
26     VK_PPC_HIGH,
27     VK_PPC_HIGHA,
28     VK_PPC_HIGHER,
29     VK_PPC_HIGHERA,
30     VK_PPC_HIGHEST,
31     VK_PPC_HIGHESTA
32   };
33 
34 private:
35   const VariantKind Kind;
36   const MCExpr *Expr;
37   bool IsDarwin;
38 
39   int64_t evaluateAsInt64(int64_t Value) const;
40 
PPCMCExpr(VariantKind Kind,const MCExpr * Expr,bool IsDarwin)41   explicit PPCMCExpr(VariantKind Kind, const MCExpr *Expr, bool IsDarwin)
42       : Kind(Kind), Expr(Expr), IsDarwin(IsDarwin) {}
43 
44 public:
45   /// @name Construction
46   /// @{
47 
48   static const PPCMCExpr *create(VariantKind Kind, const MCExpr *Expr,
49                                  bool isDarwin, MCContext &Ctx);
50 
createLo(const MCExpr * Expr,bool isDarwin,MCContext & Ctx)51   static const PPCMCExpr *createLo(const MCExpr *Expr,
52                                    bool isDarwin, MCContext &Ctx) {
53     return create(VK_PPC_LO, Expr, isDarwin, Ctx);
54   }
55 
createHi(const MCExpr * Expr,bool isDarwin,MCContext & Ctx)56   static const PPCMCExpr *createHi(const MCExpr *Expr,
57                                    bool isDarwin, MCContext &Ctx) {
58     return create(VK_PPC_HI, Expr, isDarwin, Ctx);
59   }
60 
createHa(const MCExpr * Expr,bool isDarwin,MCContext & Ctx)61   static const PPCMCExpr *createHa(const MCExpr *Expr,
62                                    bool isDarwin, MCContext &Ctx) {
63     return create(VK_PPC_HA, Expr, isDarwin, Ctx);
64   }
65 
66   /// @}
67   /// @name Accessors
68   /// @{
69 
70   /// getOpcode - Get the kind of this expression.
getKind()71   VariantKind getKind() const { return Kind; }
72 
73   /// getSubExpr - Get the child of this expression.
getSubExpr()74   const MCExpr *getSubExpr() const { return Expr; }
75 
76   /// isDarwinSyntax - True if expression is to be printed using Darwin syntax.
isDarwinSyntax()77   bool isDarwinSyntax() const { return IsDarwin; }
78 
79 
80   /// @}
81 
82   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
83   bool evaluateAsRelocatableImpl(MCValue &Res,
84                                  const MCAsmLayout *Layout,
85                                  const MCFixup *Fixup) const override;
86   void visitUsedExpr(MCStreamer &Streamer) const override;
findAssociatedFragment()87   MCFragment *findAssociatedFragment() const override {
88     return getSubExpr()->findAssociatedFragment();
89   }
90 
91   // There are no TLS PPCMCExprs at the moment.
fixELFSymbolsInTLSFixups(MCAssembler & Asm)92   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
93 
94   bool evaluateAsConstant(int64_t &Res) const;
95 
classof(const MCExpr * E)96   static bool classof(const MCExpr *E) {
97     return E->getKind() == MCExpr::Target;
98   }
99 };
100 } // end namespace llvm
101 
102 #endif
103