P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
graph_visitor.h
1
17#include <boost/graph/adjacency_list.hpp>
18#include <boost/graph/copy.hpp>
19
20#include "graphs.h"
21#include "lib/json.h"
22
23#ifndef BACKENDS_GRAPHS_GRAPH_VISITOR_H_
24#define BACKENDS_GRAPHS_GRAPH_VISITOR_H_
25
26namespace graphs {
27
32class Graph_visitor : public Graphs {
33 private:
35 enum class PrevType { Control, Parser };
36
38 struct fullGraphOpts {
39 Graph fg; // fullGraph
40
41 /* variables needed for subgraph connection*/
42 unsigned long node_i = 0; // node indexer
43 unsigned cluster_i = 0; // cluster indexer
44 };
45
47 struct edge_name_copier {
52 edge_name_copier(const Graph &from, Graph &to) : from(from), to(to) {}
53 const Graph &from;
54 Graph &to;
55
56 void operator()(Graph::edge_descriptor input, Graph::edge_descriptor output) const {
57 auto label = boost::get(boost::edge_name, from, input);
58
59 boost::put(boost::edge_name, to, output, label);
60 }
61 };
62
63 public:
70 Graph_visitor(const cstring &graphsDir, const bool graphs, const bool fullGraph,
71 const bool jsonOut, const cstring &filename)
72 : graphsDir(graphsDir),
74 fullGraph(fullGraph),
75 jsonOut(jsonOut),
76 filename(filename) {}
82 const char *getType(const VertexType &v_type);
88 const char *getPrevType(const PrevType &prev_type);
101 void process(std::vector<Graph *> &controlGraphsArray, std::vector<Graph *> &parserGraphsArray);
107 void writeGraphToFile(const Graph &g, const cstring &name);
108
109 private:
116 void forLoopJson(std::vector<Graph *> &graphsArray, PrevType prev_type);
124 void forLoopFullGraph(std::vector<Graph *> &graphsArray, fullGraphOpts *opts,
125 PrevType prev_type);
126
127 Util::JsonObject *json = nullptr; // stores json that will be outputted
128 Util::JsonArray *programBlocks = nullptr; // stores objects in top level array "nodes"
129 const cstring graphsDir;
130 // options
131 const bool graphs; // output boost graphs to files
132 const bool fullGraph; // merge boost graphs into one CFG, and output to file
133 const bool jsonOut; // iterate over boost graphs, and create json representation of these
134 // graphs
135 const cstring filename;
136};
137
138} // namespace graphs
139
140#endif /* BACKENDS_GRAPHS_GRAPH_VISITOR_H_ */
Definition json.h:111
Definition json.h:158
Definition cstring.h:72
Definition graph_visitor.h:32
Graph_visitor(const cstring &graphsDir, const bool graphs, const bool fullGraph, const bool jsonOut, const cstring &filename)
Definition graph_visitor.h:70
const char * getType(const VertexType &v_type)
Maps VertexType to string.
Definition graph_visitor.cpp:37
const char * getPrevType(const PrevType &prev_type)
Maps PrevType to string.
Definition graph_visitor.cpp:70
void writeGraphToFile(const Graph &g, const cstring &name)
Writes boost graph "g" in dot format to file given by "name".
Definition graph_visitor.cpp:25
void process(std::vector< Graph * > &controlGraphsArray, std::vector< Graph * > &parserGraphsArray)
main function
Definition graph_visitor.cpp:172
Definition graphs.h:94
Definition controls.cpp:29