PPCMCExpr.h 2.5 KB

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