Static Value-Flow Analysis
Loading...
Searching...
No Matches
GraphPrinter.h
Go to the documentation of this file.
1//===- GraphPrinter.h -- Print Generic Graph---------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2017> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23
24/*
25 * GraphPrinter.h
26 *
27 * Created on: 19.Sep.,2018
28 * Author: Yulei
29 */
30
31#ifndef INCLUDE_GRAPHS_GRAPHPRINTER_H_
32#define INCLUDE_GRAPHS_GRAPHPRINTER_H_
33
34#include <system_error>
35#include "Graphs/GraphWriter.h" // for graph write
36#include <fstream>
37
38namespace SVF
39{
40
41/*
42 * Dump and print the graph for debugging
43 */
45{
46
47public:
49 {
50 }
51
55 template<class GraphType>
57 const std::string &GraphName, const GraphType &GT, bool simple = false)
58 {
59 // Filename of the output dot file
60 std::string Filename = GraphName + ".dot";
61 std::ofstream outFile(Filename);
62 if (outFile.fail())
63 {
64 O << " error opening file for writing!\n";
65 outFile.close();
66 return;
67 }
68
69 O << "Writing '" << Filename << "'...";
70
72 outFile.close();
73 }
74
78 template<class GraphType>
79 static void PrintGraph(SVF::OutStream &O, const std::string &GraphName,
80 const GraphType &GT)
81 {
83 typedef GenericGraphTraits<GraphType> GTraits;
84
85 typedef typename GTraits::NodeRef NodeRef;
86 typedef typename GTraits::nodes_iterator node_iterator;
87 typedef typename GTraits::ChildIteratorType child_iterator;
88
89 O << "Printing VFG Graph" << "'...\n";
90 // Print each node name and its edges
91 node_iterator I = GTraits::nodes_begin(GT);
92 node_iterator E = GTraits::nodes_end(GT);
93 for (; I != E; ++I)
94 {
95 NodeRef *Node = *I;
96 O << "node :" << Node << "'\n";
97 child_iterator EI = GTraits::child_begin(Node);
98 child_iterator EE = GTraits::child_end(Node);
99 for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i)
100 {
101 O << "child :" << *EI << "'\n";
102 }
103 }
104 }
105};
106
107} // End namespace llvm
108
109
110
111#endif /* INCLUDE_GRAPHS_GRAPHPRINTER_H_ */
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType &GT, bool simple=false)
static void PrintGraph(SVF::OutStream &O, const std::string &GraphName, const GraphType &GT)
for isBitcode
Definition BasicTypes.h:68
std::ostream OutStream
Definition GeneralType.h:45
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
std::ofstream & WriteGraph(std::ofstream &O, const GraphType &G, bool ShortNames=false)