Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 1 | //===-- PPCMCExpr.h - PPC specific MC expression classes --------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 9 | #ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H |
| 10 | #define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 11 | |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCAsmLayout.h" |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCExpr.h" |
| 14 | #include "llvm/MC/MCValue.h" |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 15 | |
| 16 | namespace llvm { |
| 17 | |
| 18 | class PPCMCExpr : public MCTargetExpr { |
| 19 | public: |
| 20 | enum VariantKind { |
| 21 | VK_PPC_None, |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 22 | VK_PPC_LO, |
Ulrich Weigand | e67c565 | 2013-06-21 14:42:49 +0000 | [diff] [blame] | 23 | VK_PPC_HI, |
Ulrich Weigand | e9126f5 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 24 | VK_PPC_HA, |
Sean Fertile | 80b8f82 | 2018-06-15 19:47:11 +0000 | [diff] [blame] | 25 | VK_PPC_HIGH, |
| 26 | VK_PPC_HIGHA, |
Ulrich Weigand | e9126f5 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 27 | VK_PPC_HIGHER, |
| 28 | VK_PPC_HIGHERA, |
| 29 | VK_PPC_HIGHEST, |
| 30 | VK_PPC_HIGHESTA |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | private: |
| 34 | const VariantKind Kind; |
| 35 | const MCExpr *Expr; |
Ulrich Weigand | 266db7f | 2013-07-08 20:20:51 +0000 | [diff] [blame] | 36 | bool IsDarwin; |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 37 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 38 | int64_t evaluateAsInt64(int64_t Value) const; |
Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 39 | |
David Blaikie | 9f380a3 | 2015-03-16 18:06:57 +0000 | [diff] [blame] | 40 | explicit PPCMCExpr(VariantKind Kind, const MCExpr *Expr, 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 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 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 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 50 | static const PPCMCExpr *createLo(const MCExpr *Expr, |
Ulrich Weigand | 266db7f | 2013-07-08 20:20:51 +0000 | [diff] [blame] | 51 | bool isDarwin, MCContext &Ctx) { |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 52 | return create(VK_PPC_LO, Expr, isDarwin, Ctx); |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 55 | static const PPCMCExpr *createHi(const MCExpr *Expr, |
Ulrich Weigand | 266db7f | 2013-07-08 20:20:51 +0000 | [diff] [blame] | 56 | bool isDarwin, MCContext &Ctx) { |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 57 | return create(VK_PPC_HI, Expr, isDarwin, Ctx); |
Ulrich Weigand | e67c565 | 2013-06-21 14:42:49 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 60 | static const PPCMCExpr *createHa(const MCExpr *Expr, |
Ulrich Weigand | 266db7f | 2013-07-08 20:20:51 +0000 | [diff] [blame] | 61 | bool isDarwin, MCContext &Ctx) { |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 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 | |
Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 81 | void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +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; |
Rafael Espindola | e3a20f5 | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 86 | MCFragment *findAssociatedFragment() const override { |
| 87 | return getSubExpr()->findAssociatedFragment(); |
Ulrich Weigand | 41789de | 2013-05-23 22:26:41 +0000 | [diff] [blame] | 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 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 93 | bool evaluateAsConstant(int64_t &Res) const; |
Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 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 |