]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-readobj/StackMapPrinter.h
MFHead@r345275
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-readobj / StackMapPrinter.h
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 #include "llvm/Support/ScopedPrinter.h"
15
16 namespace llvm {
17
18 // Pretty print a stackmap to the given ostream.
19 template <typename StackMapParserT>
20 void prettyPrintStackMap(ScopedPrinter &W, const StackMapParserT &SMP) {
21
22   W.printNumber("LLVM StackMap Version",  SMP.getVersion());
23   W.printNumber("Num Functions", SMP.getNumFunctions());
24
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";
30
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";
36
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";
44
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;
68       }
69     }
70
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";
77   }
78 }
79
80 }
81
82 #endif