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"
14 #include "llvm/Support/ScopedPrinter.h"
18 // Pretty print a stackmap to the given ostream.
19 template <typename StackMapParserT
>
20 void prettyPrintStackMap(ScopedPrinter
&W
, const StackMapParserT
&SMP
) {
22 W
.printNumber("LLVM StackMap Version", SMP
.getVersion());
23 W
.printNumber("Num Functions", SMP
.getNumFunctions());
26 for (const auto &F
: SMP
.functions())
27 W
.startLine() << " Function address: " << F
.getFunctionAddress()
28 << ", stack size: " << F
.getStackSize()
29 << ", callsite record count: " << F
.getRecordCount() << "\n";
32 W
.printNumber("Num Constants", SMP
.getNumConstants());
33 unsigned ConstantIndex
= 0;
34 for (const auto &C
: SMP
.constants())
35 W
.startLine() << " #" << ++ConstantIndex
<< ": " << C
.getValue() << "\n";
38 W
.printNumber("Num Records", SMP
.getNumRecords());
39 for (const auto &R
: SMP
.records()) {
40 W
.startLine() << " Record ID: " << R
.getID()
41 << ", instruction offset: " << R
.getInstructionOffset()
43 W
.startLine() << " " << R
.getNumLocations() << " locations:\n";
45 unsigned LocationIndex
= 0;
46 for (const auto &Loc
: R
.locations()) {
47 raw_ostream
&OS
= W
.startLine();
48 OS
<< " #" << ++LocationIndex
<< ": ";
49 switch (Loc
.getKind()) {
50 case StackMapParserT::LocationKind::Register
:
51 OS
<< "Register R#" << Loc
.getDwarfRegNum() << "\n";
53 case StackMapParserT::LocationKind::Direct
:
54 OS
<< "Direct R#" << Loc
.getDwarfRegNum() << " + " << Loc
.getOffset()
57 case StackMapParserT::LocationKind::Indirect
:
58 OS
<< "Indirect [R#" << Loc
.getDwarfRegNum() << " + " << Loc
.getOffset()
61 case StackMapParserT::LocationKind::Constant
:
62 OS
<< "Constant " << Loc
.getSmallConstant() << "\n";
64 case StackMapParserT::LocationKind::ConstantIndex
:
65 OS
<< "ConstantIndex #" << Loc
.getConstantIndex() << " ("
66 << SMP
.getConstant(Loc
.getConstantIndex()).getValue() << ")\n";
71 raw_ostream
&OS
= W
.startLine();
72 OS
<< " " << R
.getNumLiveOuts() << " live-outs: [ ";
73 for (const auto &LO
: R
.liveouts())
74 OS
<< "R#" << LO
.getDwarfRegNum() << " ("
75 << LO
.getSizeInBytes() << "-bytes) ";