blob: 8bb4791d13dd103a60624b49158c0c8348e36352 [file] [log] [blame]
Ulrich Weigand41789de2013-05-23 22:26:41 +00001//===-- 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 Kramera7c40ef2014-08-13 16:26:38 +000010#ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H
11#define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H
Ulrich Weigand41789de2013-05-23 22:26:41 +000012
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000013#include "llvm/MC/MCAsmLayout.h"
Ulrich Weigand41789de2013-05-23 22:26:41 +000014#include "llvm/MC/MCExpr.h"
15#include "llvm/MC/MCValue.h"
Ulrich Weigand41789de2013-05-23 22:26:41 +000016
17namespace llvm {
18
19class PPCMCExpr : public MCTargetExpr {
20public:
21 enum VariantKind {
22 VK_PPC_None,
Ulrich Weigandd51c09f2013-06-21 14:42:20 +000023 VK_PPC_LO,
Ulrich Weigande67c5652013-06-21 14:42:49 +000024 VK_PPC_HI,
Ulrich Weigande9126f52013-06-21 14:43:42 +000025 VK_PPC_HA,
Sean Fertile80b8f822018-06-15 19:47:11 +000026 VK_PPC_HIGH,
27 VK_PPC_HIGHA,
Ulrich Weigande9126f52013-06-21 14:43:42 +000028 VK_PPC_HIGHER,
29 VK_PPC_HIGHERA,
30 VK_PPC_HIGHEST,
31 VK_PPC_HIGHESTA
Ulrich Weigand41789de2013-05-23 22:26:41 +000032 };
33
34private:
35 const VariantKind Kind;
36 const MCExpr *Expr;
Ulrich Weigand266db7f2013-07-08 20:20:51 +000037 bool IsDarwin;
Ulrich Weigand41789de2013-05-23 22:26:41 +000038
Jim Grosbach13760bd2015-05-30 01:25:56 +000039 int64_t evaluateAsInt64(int64_t Value) const;
Joerg Sonnenbergerbfef1dd2014-08-10 12:41:50 +000040
David Blaikie9f380a32015-03-16 18:06:57 +000041 explicit PPCMCExpr(VariantKind Kind, const MCExpr *Expr, bool IsDarwin)
42 : Kind(Kind), Expr(Expr), IsDarwin(IsDarwin) {}
Ulrich Weigand41789de2013-05-23 22:26:41 +000043
44public:
45 /// @name Construction
46 /// @{
47
Jim Grosbach13760bd2015-05-30 01:25:56 +000048 static const PPCMCExpr *create(VariantKind Kind, const MCExpr *Expr,
Ulrich Weigand266db7f2013-07-08 20:20:51 +000049 bool isDarwin, MCContext &Ctx);
Ulrich Weigand41789de2013-05-23 22:26:41 +000050
Jim Grosbach13760bd2015-05-30 01:25:56 +000051 static const PPCMCExpr *createLo(const MCExpr *Expr,
Ulrich Weigand266db7f2013-07-08 20:20:51 +000052 bool isDarwin, MCContext &Ctx) {
Jim Grosbach13760bd2015-05-30 01:25:56 +000053 return create(VK_PPC_LO, Expr, isDarwin, Ctx);
Ulrich Weigand41789de2013-05-23 22:26:41 +000054 }
55
Jim Grosbach13760bd2015-05-30 01:25:56 +000056 static const PPCMCExpr *createHi(const MCExpr *Expr,
Ulrich Weigand266db7f2013-07-08 20:20:51 +000057 bool isDarwin, MCContext &Ctx) {
Jim Grosbach13760bd2015-05-30 01:25:56 +000058 return create(VK_PPC_HI, Expr, isDarwin, Ctx);
Ulrich Weigande67c5652013-06-21 14:42:49 +000059 }
60
Jim Grosbach13760bd2015-05-30 01:25:56 +000061 static const PPCMCExpr *createHa(const MCExpr *Expr,
Ulrich Weigand266db7f2013-07-08 20:20:51 +000062 bool isDarwin, MCContext &Ctx) {
Jim Grosbach13760bd2015-05-30 01:25:56 +000063 return create(VK_PPC_HA, Expr, isDarwin, Ctx);
Ulrich Weigand41789de2013-05-23 22:26:41 +000064 }
65
66 /// @}
67 /// @name Accessors
68 /// @{
69
70 /// getOpcode - Get the kind of this expression.
71 VariantKind getKind() const { return Kind; }
72
73 /// getSubExpr - Get the child of this expression.
74 const MCExpr *getSubExpr() const { return Expr; }
75
Ulrich Weigand96e65782013-06-20 16:23:52 +000076 /// isDarwinSyntax - True if expression is to be printed using Darwin syntax.
Ulrich Weigand266db7f2013-07-08 20:20:51 +000077 bool isDarwinSyntax() const { return IsDarwin; }
Ulrich Weigand96e65782013-06-20 16:23:52 +000078
79
Ulrich Weigand41789de2013-05-23 22:26:41 +000080 /// @}
81
Matt Arsenault8b643552015-06-09 00:31:39 +000082 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
Jim Grosbach13760bd2015-05-30 01:25:56 +000083 bool evaluateAsRelocatableImpl(MCValue &Res,
Joerg Sonnenberger752b91b2014-08-10 11:35:12 +000084 const MCAsmLayout *Layout,
85 const MCFixup *Fixup) const override;
Rafael Espindolae2c66242014-06-25 15:45:33 +000086 void visitUsedExpr(MCStreamer &Streamer) const override;
Rafael Espindolae3a20f52015-10-05 12:07:05 +000087 MCFragment *findAssociatedFragment() const override {
88 return getSubExpr()->findAssociatedFragment();
Ulrich Weigand41789de2013-05-23 22:26:41 +000089 }
90
91 // There are no TLS PPCMCExprs at the moment.
Craig Topper0d3fa922014-04-29 07:57:37 +000092 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
Ulrich Weigand41789de2013-05-23 22:26:41 +000093
Jim Grosbach13760bd2015-05-30 01:25:56 +000094 bool evaluateAsConstant(int64_t &Res) const;
Joerg Sonnenbergerbfef1dd2014-08-10 12:41:50 +000095
Ulrich Weigand41789de2013-05-23 22:26:41 +000096 static bool classof(const MCExpr *E) {
97 return E->getKind() == MCExpr::Target;
98 }
99};
100} // end namespace llvm
101
102#endif