summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-readobj/StackMapPrinter.h
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2015-06-26 23:56:53 +0000
committerLang Hames <lhames@gmail.com>2015-06-26 23:56:53 +0000
commit0000afd88cc35d6febd25c72f484b22378897737 (patch)
treea5e8e0565506a1dcdd44174363cf95ef815a8fb7 /llvm/tools/llvm-readobj/StackMapPrinter.h
parent605e1f6b6cb8bba842a08ef5d59eee3e42f5a834 (diff)
downloadbcm5719-llvm-0000afd88cc35d6febd25c72f484b22378897737.tar.gz
bcm5719-llvm-0000afd88cc35d6febd25c72f484b22378897737.zip
[StackMaps] Add a lightweight parser for stackmap version 1 sections.
The parser provides a convenient interface for reading llvm stackmap v1 sections in object files. This patch also includes a new option for llvm-readobj, '-stackmap', which uses the parser to pretty-print stackmap sections for debugging/testing purposes. llvm-svn: 240860
Diffstat (limited to 'llvm/tools/llvm-readobj/StackMapPrinter.h')
-rw-r--r--llvm/tools/llvm-readobj/StackMapPrinter.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/llvm/tools/llvm-readobj/StackMapPrinter.h b/llvm/tools/llvm-readobj/StackMapPrinter.h
new file mode 100644
index 00000000000..92645bcf917
--- /dev/null
+++ b/llvm/tools/llvm-readobj/StackMapPrinter.h
@@ -0,0 +1,80 @@
+//===-------- StackMapPrinter.h - Pretty-print stackmaps --------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
+#define LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
+
+#include "llvm/Object/StackMapParser.h"
+
+namespace llvm {
+
+// Pretty print a stackmap to the given ostream.
+template <typename OStreamT, typename StackMapParserT>
+void prettyPrintStackMap(OStreamT &OS, const StackMapParserT &SMP) {
+
+ OS << "LLVM StackMap Version: " << SMP.getVersion()
+ << "\nNum Functions: " << SMP.getNumFunctions();
+
+ // Functions:
+ for (const auto &F : SMP.functions())
+ OS << "\n Function address: " << F.getFunctionAddress()
+ << ", stack size: " << F.getStackSize();
+
+ // Constants:
+ OS << "\nNum Constants: " << SMP.getNumConstants();
+ unsigned ConstantIndex = 0;
+ for (const auto &C : SMP.constants())
+ OS << "\n #" << ++ConstantIndex << ": " << C.getValue();
+
+ // Records:
+ OS << "\nNum Records: " << SMP.getNumRecords();
+ for (const auto &R : SMP.records()) {
+ OS << "\n Record ID: " << R.getID()
+ << ", instruction offset: " << R.getInstructionOffset()
+ << "\n " << R.getNumLocations() << " locations:";
+
+ unsigned LocationIndex = 0;
+ for (const auto &Loc : R.locations()) {
+ OS << "\n #" << ++LocationIndex << ": ";
+ switch (Loc.getKind()) {
+ case StackMapParserT::LocationKind::Register:
+ OS << "Register R#" << Loc.getDwarfRegNum();
+ break;
+ case StackMapParserT::LocationKind::Direct:
+ OS << "Direct R#" << Loc.getDwarfRegNum() << " + "
+ << Loc.getOffset();
+ break;
+ case StackMapParserT::LocationKind::Indirect:
+ OS << "Indirect [R#" << Loc.getDwarfRegNum() << " + "
+ << Loc.getOffset() << "]";
+ break;
+ case StackMapParserT::LocationKind::Constant:
+ OS << "Constant " << Loc.getSmallConstant();
+ break;
+ case StackMapParserT::LocationKind::ConstantIndex:
+ OS << "ConstantIndex #" << Loc.getConstantIndex() << " ("
+ << SMP.getConstant(Loc.getConstantIndex()).getValue() << ")";
+ break;
+ }
+ }
+
+ OS << "\n " << R.getNumLiveOuts() << " live-outs: [ ";
+ for (const auto &LO : R.liveouts())
+ OS << "R#" << LO.getDwarfRegNum() << " ("
+ << LO.getSizeInBytes() << "-bytes) ";
+ OS << "]\n";
+ }
+
+ OS << "\n";
+
+}
+
+}
+
+#endif
OpenPOWER on IntegriCloud