[PowerPC] Minor cleanup in PPCELFObjectWriter::getRelocTypeInner
[oota-llvm.git] / lib / Target / PowerPC / MCTargetDesc / PPCMCExpr.h
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
17 namespace llvm {
18
19 class PPCMCExpr : public MCTargetExpr {
20 public:
21   enum VariantKind {
22     VK_PPC_None,
23     VK_PPC_HA16,
24     VK_PPC_LO16
25   };
26
27 private:
28   const VariantKind Kind;
29   const MCExpr *Expr;
30   const int AssemblerDialect;
31
32   explicit PPCMCExpr(VariantKind _Kind, const MCExpr *_Expr,
33                      int _AssemblerDialect)
34     : Kind(_Kind), Expr(_Expr), AssemblerDialect(_AssemblerDialect) {}
35
36 public:
37   /// @name Construction
38   /// @{
39
40   static const PPCMCExpr *Create(VariantKind Kind, const MCExpr *Expr,
41                                       MCContext &Ctx);
42
43   static const PPCMCExpr *CreateHa16(const MCExpr *Expr, MCContext &Ctx) {
44     return Create(VK_PPC_HA16, Expr, Ctx);
45   }
46
47   static const PPCMCExpr *CreateLo16(const MCExpr *Expr, MCContext &Ctx) {
48     return Create(VK_PPC_LO16, Expr, Ctx);
49   }
50
51   /// @}
52   /// @name Accessors
53   /// @{
54
55   /// getOpcode - Get the kind of this expression.
56   VariantKind getKind() const { return Kind; }
57
58   /// getSubExpr - Get the child of this expression.
59   const MCExpr *getSubExpr() const { return Expr; }
60
61   /// isDarwinSyntax - True if expression is to be printed using Darwin syntax.
62   bool isDarwinSyntax() const { return AssemblerDialect == 1; }
63
64
65   /// @}
66
67   void PrintImpl(raw_ostream &OS) const;
68   bool EvaluateAsRelocatableImpl(MCValue &Res,
69                                  const MCAsmLayout *Layout) const;
70   void AddValueSymbols(MCAssembler *) const;
71   const MCSection *FindAssociatedSection() const {
72     return getSubExpr()->FindAssociatedSection();
73   }
74
75   // There are no TLS PPCMCExprs at the moment.
76   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {}
77
78   static bool classof(const MCExpr *E) {
79     return E->getKind() == MCExpr::Target;
80   }
81 };
82 } // end namespace llvm
83
84 #endif