1//===-- PPCMCExpr.h - PPC specific MC expression classes --------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H
10#define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H
11
12#include "llvm/MC/MCExpr.h"
13#include "llvm/MC/MCValue.h"
14
15namespace llvm {
16
17class PPCMCExpr : public MCTargetExpr {
18public:
19 enum VariantKind {
20 VK_PPC_None,
21 VK_PPC_LO,
22 VK_PPC_HI,
23 VK_PPC_HA,
24 VK_PPC_HIGH,
25 VK_PPC_HIGHA,
26 VK_PPC_HIGHER,
27 VK_PPC_HIGHERA,
28 VK_PPC_HIGHEST,
29 VK_PPC_HIGHESTA
30 };
31
32private:
33 const VariantKind Kind;
34 const MCExpr *Expr;
35
36 int64_t evaluateAsInt64(int64_t Value) const;
37
38 explicit PPCMCExpr(VariantKind Kind, const MCExpr *Expr)
39 : Kind(Kind), Expr(Expr) {}
40
41public:
42 /// @name Construction
43 /// @{
44
45 static const PPCMCExpr *create(VariantKind Kind, const MCExpr *Expr,
46 MCContext &Ctx);
47
48 static const PPCMCExpr *createLo(const MCExpr *Expr, MCContext &Ctx) {
49 return create(Kind: VK_PPC_LO, Expr, Ctx);
50 }
51
52 static const PPCMCExpr *createHi(const MCExpr *Expr, MCContext &Ctx) {
53 return create(Kind: VK_PPC_HI, Expr, Ctx);
54 }
55
56 static const PPCMCExpr *createHa(const MCExpr *Expr, MCContext &Ctx) {
57 return create(Kind: VK_PPC_HA, Expr, Ctx);
58 }
59
60 /// @}
61 /// @name Accessors
62 /// @{
63
64 /// getOpcode - Get the kind of this expression.
65 VariantKind getKind() const { return Kind; }
66
67 /// getSubExpr - Get the child of this expression.
68 const MCExpr *getSubExpr() const { return Expr; }
69
70 /// @}
71
72 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
73 bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
74 const MCFixup *Fixup) const override;
75 void visitUsedExpr(MCStreamer &Streamer) const override;
76 MCFragment *findAssociatedFragment() const override {
77 return getSubExpr()->findAssociatedFragment();
78 }
79
80 // There are no TLS PPCMCExprs at the moment.
81 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
82
83 bool evaluateAsConstant(int64_t &Res) const;
84
85 static bool classof(const MCExpr *E) {
86 return E->getKind() == MCExpr::Target;
87 }
88};
89} // end namespace llvm
90
91#endif
92