Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 10 | #ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H |
| 11 | #define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 12 | |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCAsmLayout.h" |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCExpr.h" |
| 15 | #include "llvm/MC/MCValue.h" |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 16 | |
| 17 | namespace llvm { |
| 18 | |
| 19 | class PPCMCExpr : public MCTargetExpr { |
| 20 | public: |
| 21 | enum VariantKind { |
| 22 | VK_PPC_None, |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 23 | VK_PPC_LO, |
Ulrich Weigand | e67c565 | 2013-06-21 14:42:49 +0000 | [diff] [blame] | 24 | VK_PPC_HI, |
Ulrich Weigand | e9126f5 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 25 | VK_PPC_HA, |
| 26 | VK_PPC_HIGHER, |
| 27 | VK_PPC_HIGHERA, |
| 28 | VK_PPC_HIGHEST, |
| 29 | VK_PPC_HIGHESTA |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | private: |
| 33 | const VariantKind Kind; |
| 34 | const MCExpr *Expr; |
Ulrich Weigand | 266db7f | 2013-07-08 20:20:51 +0000 | [diff] [blame] | 35 | bool IsDarwin; |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 36 | |
Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 37 | int64_t EvaluateAsInt64(int64_t Value) const; |
| 38 | |
Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 39 | explicit PPCMCExpr(VariantKind _Kind, const MCExpr *_Expr, |
Ulrich Weigand | 266db7f | 2013-07-08 20:20:51 +0000 | [diff] [blame] | 40 | bool _IsDarwin) |
| 41 | : Kind(_Kind), Expr(_Expr), IsDarwin(_IsDarwin) {} |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 42 | |
| 43 | public: |
| 44 | /// @name Construction |
| 45 | /// @{ |
| 46 | |
| 47 | static const PPCMCExpr *Create(VariantKind Kind, const MCExpr *Expr, |
Ulrich Weigand | 266db7f | 2013-07-08 20:20:51 +0000 | [diff] [blame] | 48 | bool isDarwin, MCContext &Ctx); |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 49 | |
Ulrich Weigand | 266db7f | 2013-07-08 20:20:51 +0000 | [diff] [blame] | 50 | static const PPCMCExpr *CreateLo(const MCExpr *Expr, |
| 51 | bool isDarwin, MCContext &Ctx) { |
| 52 | return Create(VK_PPC_LO, Expr, isDarwin, Ctx); |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Ulrich Weigand | 266db7f | 2013-07-08 20:20:51 +0000 | [diff] [blame] | 55 | static const PPCMCExpr *CreateHi(const MCExpr *Expr, |
| 56 | bool isDarwin, MCContext &Ctx) { |
| 57 | return Create(VK_PPC_HI, Expr, isDarwin, Ctx); |
Ulrich Weigand | e67c565 | 2013-06-21 14:42:49 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Ulrich Weigand | 266db7f | 2013-07-08 20:20:51 +0000 | [diff] [blame] | 60 | static const PPCMCExpr *CreateHa(const MCExpr *Expr, |
| 61 | bool isDarwin, MCContext &Ctx) { |
| 62 | return Create(VK_PPC_HA, Expr, isDarwin, Ctx); |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /// @} |
| 66 | /// @name Accessors |
| 67 | /// @{ |
| 68 | |
| 69 | /// getOpcode - Get the kind of this expression. |
| 70 | VariantKind getKind() const { return Kind; } |
| 71 | |
| 72 | /// getSubExpr - Get the child of this expression. |
| 73 | const MCExpr *getSubExpr() const { return Expr; } |
| 74 | |
Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 75 | /// isDarwinSyntax - True if expression is to be printed using Darwin syntax. |
Ulrich Weigand | 266db7f | 2013-07-08 20:20:51 +0000 | [diff] [blame] | 76 | bool isDarwinSyntax() const { return IsDarwin; } |
Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 77 | |
| 78 | |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 79 | /// @} |
| 80 | |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 81 | void PrintImpl(raw_ostream &OS) const override; |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 82 | bool EvaluateAsRelocatableImpl(MCValue &Res, |
Joerg Sonnenberger | 752b91b | 2014-08-10 11:35:12 +0000 | [diff] [blame] | 83 | const MCAsmLayout *Layout, |
| 84 | const MCFixup *Fixup) const override; |
Rafael Espindola | e2c6624 | 2014-06-25 15:45:33 +0000 | [diff] [blame] | 85 | void visitUsedExpr(MCStreamer &Streamer) const override; |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 86 | const MCSection *FindAssociatedSection() const override { |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 87 | return getSubExpr()->FindAssociatedSection(); |
| 88 | } |
| 89 | |
| 90 | // There are no TLS PPCMCExprs at the moment. |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 91 | void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {} |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 92 | |
Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 93 | bool EvaluateAsConstant(int64_t &Res) const; |
| 94 | |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 95 | static bool classof(const MCExpr *E) { |
| 96 | return E->getKind() == MCExpr::Target; |
| 97 | } |
| 98 | }; |
| 99 | } // end namespace llvm |
| 100 | |
| 101 | #endif |