MCValue.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/MC/MCValue.h - MCValue class -----------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file contains the declaration of the MCValue class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_MC_MCVALUE_H
  18. #define LLVM_MC_MCVALUE_H
  19. #include "llvm/MC/MCExpr.h"
  20. #include "llvm/Support/DataTypes.h"
  21. namespace llvm {
  22. class raw_ostream;
  23. /// This represents an "assembler immediate".
  24. ///
  25. /// In its most general form, this can hold ":Kind:(SymbolA - SymbolB +
  26. /// imm64)". Not all targets supports relocations of this general form, but we
  27. /// need to represent this anyway.
  28. ///
  29. /// In general both SymbolA and SymbolB will also have a modifier
  30. /// analogous to the top-level Kind. Current targets are not expected
  31. /// to make use of both though. The choice comes down to whether
  32. /// relocation modifiers apply to the closest symbol or the whole
  33. /// expression.
  34. ///
  35. /// Note that this class must remain a simple POD value class, because we need
  36. /// it to live in unions etc.
  37. class MCValue {
  38. const MCSymbolRefExpr *SymA = nullptr, *SymB = nullptr;
  39. int64_t Cst = 0;
  40. uint32_t RefKind = 0;
  41. public:
  42. MCValue() = default;
  43. int64_t getConstant() const { return Cst; }
  44. const MCSymbolRefExpr *getSymA() const { return SymA; }
  45. const MCSymbolRefExpr *getSymB() const { return SymB; }
  46. uint32_t getRefKind() const { return RefKind; }
  47. /// Is this an absolute (as opposed to relocatable) value.
  48. bool isAbsolute() const { return !SymA && !SymB; }
  49. /// Print the value to the stream \p OS.
  50. void print(raw_ostream &OS) const;
  51. /// Print the value to stderr.
  52. void dump() const;
  53. MCSymbolRefExpr::VariantKind getAccessVariant() const;
  54. static MCValue get(const MCSymbolRefExpr *SymA,
  55. const MCSymbolRefExpr *SymB = nullptr,
  56. int64_t Val = 0, uint32_t RefKind = 0) {
  57. MCValue R;
  58. R.Cst = Val;
  59. R.SymA = SymA;
  60. R.SymB = SymB;
  61. R.RefKind = RefKind;
  62. return R;
  63. }
  64. static MCValue get(int64_t Val) {
  65. MCValue R;
  66. R.Cst = Val;
  67. R.SymA = nullptr;
  68. R.SymB = nullptr;
  69. R.RefKind = 0;
  70. return R;
  71. }
  72. };
  73. } // end namespace llvm
  74. #endif
  75. #ifdef __GNUC__
  76. #pragma GCC diagnostic pop
  77. #endif