blob: 449e2c34f74df0e2524654c7dde2e08c93ab0a44 [file] [log] [blame]
Ulrich Weigand41789de2013-05-23 22:26:41 +00001//===-- PPCMCExpr.h - PPC specific MC expression classes --------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Weigand41789de2013-05-23 22:26:41 +00006//
7//===----------------------------------------------------------------------===//
8
Benjamin Kramera7c40ef2014-08-13 16:26:38 +00009#ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H
10#define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H
Ulrich Weigand41789de2013-05-23 22:26:41 +000011
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000012#include "llvm/MC/MCAsmLayout.h"
Ulrich Weigand41789de2013-05-23 22:26:41 +000013#include "llvm/MC/MCExpr.h"
14#include "llvm/MC/MCValue.h"
Ulrich Weigand41789de2013-05-23 22:26:41 +000015
16namespace llvm {
17
18class PPCMCExpr : public MCTargetExpr {
19public:
20 enum VariantKind {
21 VK_PPC_None,
Ulrich Weigandd51c09f2013-06-21 14:42:20 +000022 VK_PPC_LO,
Ulrich Weigande67c5652013-06-21 14:42:49 +000023 VK_PPC_HI,
Ulrich Weigande9126f52013-06-21 14:43:42 +000024 VK_PPC_HA,
Sean Fertile80b8f822018-06-15 19:47:11 +000025 VK_PPC_HIGH,
26 VK_PPC_HIGHA,
Ulrich Weigande9126f52013-06-21 14:43:42 +000027 VK_PPC_HIGHER,
28 VK_PPC_HIGHERA,
29 VK_PPC_HIGHEST,
30 VK_PPC_HIGHESTA
Ulrich Weigand41789de2013-05-23 22:26:41 +000031 };
32
33private:
34 const VariantKind Kind;
35 const MCExpr *Expr;
Ulrich Weigand266db7f2013-07-08 20:20:51 +000036 bool IsDarwin;
Ulrich Weigand41789de2013-05-23 22:26:41 +000037
Jim Grosbach13760bd2015-05-30 01:25:56 +000038 int64_t evaluateAsInt64(int64_t Value) const;
Joerg Sonnenbergerbfef1dd2014-08-10 12:41:50 +000039
David Blaikie9f380a32015-03-16 18:06:57 +000040 explicit PPCMCExpr(VariantKind Kind, const MCExpr *Expr, bool IsDarwin)
41 : Kind(Kind), Expr(Expr), IsDarwin(IsDarwin) {}
Ulrich Weigand41789de2013-05-23 22:26:41 +000042
43public:
44 /// @name Construction
45 /// @{
46
Jim Grosbach13760bd2015-05-30 01:25:56 +000047 static const PPCMCExpr *create(VariantKind Kind, const MCExpr *Expr,
Ulrich Weigand266db7f2013-07-08 20:20:51 +000048 bool isDarwin, MCContext &Ctx);
Ulrich Weigand41789de2013-05-23 22:26:41 +000049
Jim Grosbach13760bd2015-05-30 01:25:56 +000050 static const PPCMCExpr *createLo(const MCExpr *Expr,
Ulrich Weigand266db7f2013-07-08 20:20:51 +000051 bool isDarwin, MCContext &Ctx) {
Jim Grosbach13760bd2015-05-30 01:25:56 +000052 return create(VK_PPC_LO, Expr, isDarwin, Ctx);
Ulrich Weigand41789de2013-05-23 22:26:41 +000053 }
54
Jim Grosbach13760bd2015-05-30 01:25:56 +000055 static const PPCMCExpr *createHi(const MCExpr *Expr,
Ulrich Weigand266db7f2013-07-08 20:20:51 +000056 bool isDarwin, MCContext &Ctx) {
Jim Grosbach13760bd2015-05-30 01:25:56 +000057 return create(VK_PPC_HI, Expr, isDarwin, Ctx);
Ulrich Weigande67c5652013-06-21 14:42:49 +000058 }
59
Jim Grosbach13760bd2015-05-30 01:25:56 +000060 static const PPCMCExpr *createHa(const MCExpr *Expr,
Ulrich Weigand266db7f2013-07-08 20:20:51 +000061 bool isDarwin, MCContext &Ctx) {
Jim Grosbach13760bd2015-05-30 01:25:56 +000062 return create(VK_PPC_HA, Expr, isDarwin, Ctx);
Ulrich Weigand41789de2013-05-23 22:26:41 +000063 }
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 Weigand96e65782013-06-20 16:23:52 +000075 /// isDarwinSyntax - True if expression is to be printed using Darwin syntax.
Ulrich Weigand266db7f2013-07-08 20:20:51 +000076 bool isDarwinSyntax() const { return IsDarwin; }
Ulrich Weigand96e65782013-06-20 16:23:52 +000077
78
Ulrich Weigand41789de2013-05-23 22:26:41 +000079 /// @}
80
Matt Arsenault8b643552015-06-09 00:31:39 +000081 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
Jim Grosbach13760bd2015-05-30 01:25:56 +000082 bool evaluateAsRelocatableImpl(MCValue &Res,
Joerg Sonnenberger752b91b2014-08-10 11:35:12 +000083 const MCAsmLayout *Layout,
84 const MCFixup *Fixup) const override;
Rafael Espindolae2c66242014-06-25 15:45:33 +000085 void visitUsedExpr(MCStreamer &Streamer) const override;
Rafael Espindolae3a20f52015-10-05 12:07:05 +000086 MCFragment *findAssociatedFragment() const override {
87 return getSubExpr()->findAssociatedFragment();
Ulrich Weigand41789de2013-05-23 22:26:41 +000088 }
89
90 // There are no TLS PPCMCExprs at the moment.
Craig Topper0d3fa922014-04-29 07:57:37 +000091 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
Ulrich Weigand41789de2013-05-23 22:26:41 +000092
Jim Grosbach13760bd2015-05-30 01:25:56 +000093 bool evaluateAsConstant(int64_t &Res) const;
Joerg Sonnenbergerbfef1dd2014-08-10 12:41:50 +000094
Ulrich Weigand41789de2013-05-23 22:26:41 +000095 static bool classof(const MCExpr *E) {
96 return E->getKind() == MCExpr::Target;
97 }
98};
99} // end namespace llvm
100
101#endif