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