1 //===-------- StackMapPrinter.h - Pretty-print stackmaps --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
11 #define LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
13 #include "llvm/Object/StackMapParser.h"
17 // Pretty print a stackmap to the given ostream.
18 template <typename OStreamT, typename StackMapParserT>
19 void prettyPrintStackMap(OStreamT &OS, const StackMapParserT &SMP) {
21 OS << "LLVM StackMap Version: " << SMP.getVersion()
22 << "\nNum Functions: " << SMP.getNumFunctions();
25 for (const auto &F : SMP.functions())
26 OS << "\n Function address: " << F.getFunctionAddress()
27 << ", stack size: " << F.getStackSize();
30 OS << "\nNum Constants: " << SMP.getNumConstants();
31 unsigned ConstantIndex = 0;
32 for (const auto &C : SMP.constants())
33 OS << "\n #" << ++ConstantIndex << ": " << C.getValue();
36 OS << "\nNum Records: " << SMP.getNumRecords();
37 for (const auto &R : SMP.records()) {
38 OS << "\n Record ID: " << R.getID()
39 << ", instruction offset: " << R.getInstructionOffset()
40 << "\n " << R.getNumLocations() << " locations:";
42 unsigned LocationIndex = 0;
43 for (const auto &Loc : R.locations()) {
44 OS << "\n #" << ++LocationIndex << ": ";
45 switch (Loc.getKind()) {
46 case StackMapParserT::LocationKind::Register:
47 OS << "Register R#" << Loc.getDwarfRegNum();
49 case StackMapParserT::LocationKind::Direct:
50 OS << "Direct R#" << Loc.getDwarfRegNum() << " + "
53 case StackMapParserT::LocationKind::Indirect:
54 OS << "Indirect [R#" << Loc.getDwarfRegNum() << " + "
55 << Loc.getOffset() << "]";
57 case StackMapParserT::LocationKind::Constant:
58 OS << "Constant " << Loc.getSmallConstant();
60 case StackMapParserT::LocationKind::ConstantIndex:
61 OS << "ConstantIndex #" << Loc.getConstantIndex() << " ("
62 << SMP.getConstant(Loc.getConstantIndex()).getValue() << ")";
67 OS << "\n " << R.getNumLiveOuts() << " live-outs: [ ";
68 for (const auto &LO : R.liveouts())
69 OS << "R#" << LO.getDwarfRegNum() << " ("
70 << LO.getSizeInBytes() << "-bytes) ";