MCValue.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //===- lib/MC/MCValue.cpp - MCValue implementation ------------------------===//
  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. #include "llvm/MC/MCValue.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. 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. MCSymbolRefExpr::VariantKind Kind = A->getKind();
  47. if (Kind == MCSymbolRefExpr::VK_WEAKREF)
  48. return MCSymbolRefExpr::VK_None;
  49. return Kind;
  50. }