PPCMCExpr.h revision d2849572463da994c685b3bd7a60d5a7566c01e3
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
10#ifndef PPCMCEXPR_H
11#define PPCMCEXPR_H
12
13#include "llvm/MC/MCExpr.h"
14#include "llvm/MC/MCValue.h"
15#include "llvm/MC/MCAsmLayout.h"
16
17namespace llvm {
18
19class PPCMCExpr : public MCTargetExpr {
20public:
21  enum VariantKind {
22    VK_PPC_None,
23    VK_PPC_LO,
24    VK_PPC_HI,
25    VK_PPC_HA
26  };
27
28private:
29  const VariantKind Kind;
30  const MCExpr *Expr;
31  const int AssemblerDialect;
32
33  explicit PPCMCExpr(VariantKind _Kind, const MCExpr *_Expr,
34                     int _AssemblerDialect)
35    : Kind(_Kind), Expr(_Expr), AssemblerDialect(_AssemblerDialect) {}
36
37public:
38  /// @name Construction
39  /// @{
40
41  static const PPCMCExpr *Create(VariantKind Kind, const MCExpr *Expr,
42                                      MCContext &Ctx);
43
44  static const PPCMCExpr *CreateLo(const MCExpr *Expr, MCContext &Ctx) {
45    return Create(VK_PPC_LO, Expr, Ctx);
46  }
47
48  static const PPCMCExpr *CreateHi(const MCExpr *Expr, MCContext &Ctx) {
49    return Create(VK_PPC_HI, Expr, Ctx);
50  }
51
52  static const PPCMCExpr *CreateHa(const MCExpr *Expr, MCContext &Ctx) {
53    return Create(VK_PPC_HA, Expr, Ctx);
54  }
55
56  /// @}
57  /// @name Accessors
58  /// @{
59
60  /// getOpcode - Get the kind of this expression.
61  VariantKind getKind() const { return Kind; }
62
63  /// getSubExpr - Get the child of this expression.
64  const MCExpr *getSubExpr() const { return Expr; }
65
66  /// isDarwinSyntax - True if expression is to be printed using Darwin syntax.
67  bool isDarwinSyntax() const { return AssemblerDialect == 1; }
68
69
70  /// @}
71
72  void PrintImpl(raw_ostream &OS) const;
73  bool EvaluateAsRelocatableImpl(MCValue &Res,
74                                 const MCAsmLayout *Layout) const;
75  void AddValueSymbols(MCAssembler *) const;
76  const MCSection *FindAssociatedSection() const {
77    return getSubExpr()->FindAssociatedSection();
78  }
79
80  // There are no TLS PPCMCExprs at the moment.
81  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {}
82
83  static bool classof(const MCExpr *E) {
84    return E->getKind() == MCExpr::Target;
85  }
86};
87} // end namespace llvm
88
89#endif
90