MCValue.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include <cassert>
  22. namespace llvm {
  23. class raw_ostream;
  24. /// This represents an "assembler immediate".
  25. ///
  26. /// In its most general form, this can hold ":Kind:(SymbolA - SymbolB +
  27. /// imm64)". Not all targets supports relocations of this general form, but we
  28. /// need to represent this anyway.
  29. ///
  30. /// In general both SymbolA and SymbolB will also have a modifier
  31. /// analogous to the top-level Kind. Current targets are not expected
  32. /// to make use of both though. The choice comes down to whether
  33. /// relocation modifiers apply to the closest symbol or the whole
  34. /// expression.
  35. ///
  36. /// Note that this class must remain a simple POD value class, because we need
  37. /// it to live in unions etc.
  38. class MCValue {
  39. const MCSymbolRefExpr *SymA = nullptr, *SymB = nullptr;
  40. int64_t Cst = 0;
  41. uint32_t RefKind = 0;
  42. public:
  43. MCValue() = default;
  44. int64_t getConstant() const { return Cst; }
  45. const MCSymbolRefExpr *getSymA() const { return SymA; }
  46. const MCSymbolRefExpr *getSymB() const { return SymB; }
  47. uint32_t getRefKind() const { return RefKind; }
  48. /// Is this an absolute (as opposed to relocatable) value.
  49. bool isAbsolute() const { return !SymA && !SymB; }
  50. /// Print the value to the stream \p OS.
  51. void print(raw_ostream &OS) const;
  52. /// Print the value to stderr.
  53. void dump() const;
  54. MCSymbolRefExpr::VariantKind getAccessVariant() const;
  55. static MCValue get(const MCSymbolRefExpr *SymA,
  56. const MCSymbolRefExpr *SymB = nullptr,
  57. int64_t Val = 0, uint32_t RefKind = 0) {
  58. MCValue R;
  59. R.Cst = Val;
  60. R.SymA = SymA;
  61. R.SymB = SymB;
  62. R.RefKind = RefKind;
  63. return R;
  64. }
  65. static MCValue get(int64_t Val) {
  66. MCValue R;
  67. R.Cst = Val;
  68. R.SymA = nullptr;
  69. R.SymB = nullptr;
  70. R.RefKind = 0;
  71. return R;
  72. }
  73. };
  74. } // end namespace llvm
  75. #endif
  76. #ifdef __GNUC__
  77. #pragma GCC diagnostic pop
  78. #endif