StackMapPrinter.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //===-------- StackMapPrinter.h - Pretty-print stackmaps --------*- C++ -*-===//
  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. #ifndef LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
  10. #define LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
  11. #include "llvm/Object/StackMapParser.h"
  12. namespace llvm {
  13. // Pretty print a stackmap to the given ostream.
  14. template <typename OStreamT, typename StackMapParserT>
  15. void prettyPrintStackMap(OStreamT &OS, const StackMapParserT &SMP) {
  16. OS << "LLVM StackMap Version: " << SMP.getVersion()
  17. << "\nNum Functions: " << SMP.getNumFunctions();
  18. // Functions:
  19. for (const auto &F : SMP.functions())
  20. OS << "\n Function address: " << F.getFunctionAddress()
  21. << ", stack size: " << F.getStackSize();
  22. // Constants:
  23. OS << "\nNum Constants: " << SMP.getNumConstants();
  24. unsigned ConstantIndex = 0;
  25. for (const auto &C : SMP.constants())
  26. OS << "\n #" << ++ConstantIndex << ": " << C.getValue();
  27. // Records:
  28. OS << "\nNum Records: " << SMP.getNumRecords();
  29. for (const auto &R : SMP.records()) {
  30. OS << "\n Record ID: " << R.getID()
  31. << ", instruction offset: " << R.getInstructionOffset()
  32. << "\n " << R.getNumLocations() << " locations:";
  33. unsigned LocationIndex = 0;
  34. for (const auto &Loc : R.locations()) {
  35. OS << "\n #" << ++LocationIndex << ": ";
  36. switch (Loc.getKind()) {
  37. case StackMapParserT::LocationKind::Register:
  38. OS << "Register R#" << Loc.getDwarfRegNum();
  39. break;
  40. case StackMapParserT::LocationKind::Direct:
  41. OS << "Direct R#" << Loc.getDwarfRegNum() << " + "
  42. << Loc.getOffset();
  43. break;
  44. case StackMapParserT::LocationKind::Indirect:
  45. OS << "Indirect [R#" << Loc.getDwarfRegNum() << " + "
  46. << Loc.getOffset() << "]";
  47. break;
  48. case StackMapParserT::LocationKind::Constant:
  49. OS << "Constant " << Loc.getSmallConstant();
  50. break;
  51. case StackMapParserT::LocationKind::ConstantIndex:
  52. OS << "ConstantIndex #" << Loc.getConstantIndex() << " ("
  53. << SMP.getConstant(Loc.getConstantIndex()).getValue() << ")";
  54. break;
  55. }
  56. }
  57. OS << "\n " << R.getNumLiveOuts() << " live-outs: [ ";
  58. for (const auto &LO : R.liveouts())
  59. OS << "R#" << LO.getDwarfRegNum() << " ("
  60. << LO.getSizeInBytes() << "-bytes) ";
  61. OS << "]\n";
  62. }
  63. OS << "\n";
  64. }
  65. }
  66. #endif