MCValue.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //===- lib/MC/MCValue.cpp - MCValue implementation ------------------------===//
  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. #include "llvm/MC/MCValue.h"
  9. #include "llvm/Config/llvm-config.h"
  10. #include "llvm/MC/MCExpr.h"
  11. #include "llvm/Support/Debug.h"
  12. #include "llvm/Support/ErrorHandling.h"
  13. #include "llvm/Support/raw_ostream.h"
  14. using namespace llvm;
  15. void MCValue::print(raw_ostream &OS) const {
  16. if (isAbsolute()) {
  17. OS << getConstant();
  18. return;
  19. }
  20. // FIXME: prints as a number, which isn't ideal. But the meaning will be
  21. // target-specific anyway.
  22. if (getRefKind())
  23. OS << ':' << getRefKind() << ':';
  24. OS << *getSymA();
  25. if (getSymB()) {
  26. OS << " - ";
  27. OS << *getSymB();
  28. }
  29. if (getConstant())
  30. OS << " + " << getConstant();
  31. }
  32. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  33. LLVM_DUMP_METHOD void MCValue::dump() const {
  34. print(dbgs());
  35. }
  36. #endif
  37. MCSymbolRefExpr::VariantKind MCValue::getAccessVariant() const {
  38. const MCSymbolRefExpr *B = getSymB();
  39. if (B) {
  40. if (B->getKind() != MCSymbolRefExpr::VK_None)
  41. llvm_unreachable("unsupported");
  42. }
  43. const MCSymbolRefExpr *A = getSymA();
  44. if (!A)
  45. return MCSymbolRefExpr::VK_None;
  46. return A->getKind();
  47. }