[llvm-objcopy] [COFF] Fix warnings abuilt missing field initialization. NFC.
[llvm-complete.git] / tools / llvm-readobj / StackMapPrinter.h
blob77a054b178a523dca428885bcf68ded05f3d7258
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 //===----------------------------------------------------------------------===//
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"
16 namespace llvm {
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());
25 // Functions:
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";
31 // Constants:
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";
37 // Records:
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()
42 << "\n";
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";
52 break;
53 case StackMapParserT::LocationKind::Direct:
54 OS << "Direct R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset()
55 << "\n";
56 break;
57 case StackMapParserT::LocationKind::Indirect:
58 OS << "Indirect [R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset()
59 << "]\n";
60 break;
61 case StackMapParserT::LocationKind::Constant:
62 OS << "Constant " << Loc.getSmallConstant() << "\n";
63 break;
64 case StackMapParserT::LocationKind::ConstantIndex:
65 OS << "ConstantIndex #" << Loc.getConstantIndex() << " ("
66 << SMP.getConstant(Loc.getConstantIndex()).getValue() << ")\n";
67 break;
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) ";
76 OS << "]\n";
82 #endif