Home | History | Annotate | Download | only in llvm-readobj
      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()
     27        << ", stack size: " << F.getStackSize();
     28 
     29   // Constants:
     30   OS << "\nNum Constants: " << SMP.getNumConstants();
     31   unsigned ConstantIndex = 0;
     32   for (const auto &C : SMP.constants())
     33     OS << "\n  #" << ++ConstantIndex << ": " << C.getValue();
     34 
     35   // Records:
     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:";
     41 
     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();
     48         break;
     49       case StackMapParserT::LocationKind::Direct:
     50         OS << "Direct R#" << Loc.getDwarfRegNum() << " + "
     51            << Loc.getOffset();
     52         break;
     53       case StackMapParserT::LocationKind::Indirect:
     54         OS << "Indirect [R#" << Loc.getDwarfRegNum() << " + "
     55            << Loc.getOffset() << "]";
     56         break;
     57       case StackMapParserT::LocationKind::Constant:
     58         OS << "Constant " << Loc.getSmallConstant();
     59         break;
     60       case StackMapParserT::LocationKind::ConstantIndex:
     61         OS << "ConstantIndex #" << Loc.getConstantIndex() << " ("
     62            << SMP.getConstant(Loc.getConstantIndex()).getValue() << ")";
     63         break;
     64       }
     65     }
     66 
     67     OS << "\n    " << R.getNumLiveOuts() << " live-outs: [ ";
     68     for (const auto &LO : R.liveouts())
     69       OS << "R#" << LO.getDwarfRegNum() << " ("
     70          << LO.getSizeInBytes() << "-bytes) ";
     71     OS << "]\n";
     72   }
     73 
     74  OS << "\n";
     75 
     76 }
     77 
     78 }
     79 
     80 #endif
     81