summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp')
-rw-r--r--llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp b/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp
index 7366ff0cf30..ff921713302 100644
--- a/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp
+++ b/llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp
@@ -71,6 +71,30 @@ std::vector<uint64_t> GraphResult::flattenAddress(uint64_t Address) const {
return Addresses;
}
+void printPairToDOT(const FileAnalysis &Analysis, raw_ostream &OS,
+ uint64_t From, uint64_t To) {
+ OS << " \"" << format_hex(From, 2) << ": ";
+ Analysis.printInstruction(Analysis.getInstructionOrDie(From), OS);
+ OS << "\" -> \"" << format_hex(To, 2) << ": ";
+ Analysis.printInstruction(Analysis.getInstructionOrDie(To), OS);
+ OS << "\"\n";
+}
+
+void GraphResult::printToDOT(const FileAnalysis &Analysis,
+ raw_ostream &OS) const {
+ std::map<uint64_t, uint64_t> SortedIntermediateNodes(
+ IntermediateNodes.begin(), IntermediateNodes.end());
+ OS << "digraph graph_" << format_hex(BaseAddress, 2) << " {\n";
+ for (const auto &KV : SortedIntermediateNodes)
+ printPairToDOT(Analysis, OS, KV.first, KV.second);
+
+ for (auto &BranchNode : ConditionalBranchNodes) {
+ for (auto &V : {BranchNode.Target, BranchNode.Fallthrough})
+ printPairToDOT(Analysis, OS, BranchNode.Address, V);
+ }
+ OS << "}\n";
+}
+
GraphResult GraphBuilder::buildFlowGraph(const FileAnalysis &Analysis,
uint64_t Address) {
GraphResult Result;
OpenPOWER on IntegriCloud