P4C
The P4 Compiler
Loading...
Searching...
No Matches
graph_visitor.h
1
17#include <string>
18
19#include <boost/graph/adjacency_list.hpp>
20#include <boost/graph/copy.hpp>
21
22#include "graphs.h"
23#include "lib/json.h"
24
25#ifndef BACKENDS_GRAPHS_GRAPH_VISITOR_H_
26#define BACKENDS_GRAPHS_GRAPH_VISITOR_H_
27
28namespace P4::graphs {
29
32class Graph_visitor : public Graphs {
33 private:
35 enum class PrevType { Control, Parser };
36
38 struct fullGraphOpts {
39 Graph fg; // fullGraph
40
42 unsigned long node_i = 0; // node indexer
43 unsigned cluster_i = 0; // cluster indexer
44 };
45
47 struct edge_name_copier {
50 edge_name_copier(const Graph &from, Graph &to) : from(from), to(to) {}
51 const Graph &from;
52 Graph &to;
53
54 void operator()(Graph::edge_descriptor input, Graph::edge_descriptor output) const {
55 auto label = boost::get(boost::edge_name, from, input);
56
57 boost::put(boost::edge_name, to, output, label);
58 }
59 };
60
61 public:
66 Graph_visitor(std::filesystem::path graphsDir, const bool graphs, const bool fullGraph,
67 const bool jsonOut, std::filesystem::path filename)
68 : graphsDir(std::move(graphsDir)),
69 graphs(graphs),
70 fullGraph(fullGraph),
71 jsonOut(jsonOut),
72 filename(std::move(filename)) {}
76 const char *getType(const VertexType &v_type);
77
81 const char *getPrevType(const PrevType &prev_type);
92 void process(std::vector<Graph *> &controlGraphsArray, std::vector<Graph *> &parserGraphsArray);
97 void writeGraphToFile(const Graph &g, const std::string &name);
98
99 private:
104 void forLoopJson(std::vector<Graph *> &graphsArray, PrevType prev_type);
105
112 void forLoopFullGraph(std::vector<Graph *> &graphsArray, fullGraphOpts *opts,
113 PrevType prev_type);
114
115 Util::JsonObject *json = nullptr; // stores json that will be outputted
116 Util::JsonArray *programBlocks = nullptr; // stores objects in top level array "nodes"
117 std::filesystem::path graphsDir;
119 const bool graphs; // output boost graphs to files
120 const bool fullGraph; // merge boost graphs into one CFG, and output to file
121 const bool jsonOut; // iterate over boost graphs, and create json representation of these
122 // graphs
123 const std::filesystem::path filename;
124};
125
126} // namespace P4::graphs
127
128#endif /* BACKENDS_GRAPHS_GRAPH_VISITOR_H_ */
Definition json.h:115
Definition json.h:164
Definition graph_visitor.h:32
void process(std::vector< Graph * > &controlGraphsArray, std::vector< Graph * > &parserGraphsArray)
Definition graph_visitor.cpp:171
void writeGraphToFile(const Graph &g, const std::string &name)
Definition graph_visitor.cpp:24
const char * getType(const VertexType &v_type)
Maps VertexType to string.
Definition graph_visitor.cpp:36
const char * getPrevType(const PrevType &prev_type)
Maps PrevType to string.
Definition graph_visitor.cpp:69
Graph_visitor(std::filesystem::path graphsDir, const bool graphs, const bool fullGraph, const bool jsonOut, std::filesystem::path filename)
Definition graph_visitor.h:66
Definition graphs.h:97
Definition controls.cpp:30
STL namespace.