-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parser graph generation support for graphs backend #969
Changes from 3 commits
098e404
f2a7618
3f84ad8
c9975c6
3b75ee2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,8 @@ See the License for the specific language governing permissions and | |
limitations under the License. | ||
*/ | ||
|
||
#ifndef _BACKENDS_GRAPHS_CONTROLS_H_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a little confusing to call this file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is the common header file for both control.cpp and parser.cpp. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you refactor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to refactor the classes and created a Graphs base class. |
||
#define _BACKENDS_GRAPHS_CONTROLS_H_ | ||
#ifndef _BACKENDS_GRAPHS_GRAPHS_H_ | ||
#define _BACKENDS_GRAPHS_GRAPHS_H_ | ||
|
||
#include "config.h" | ||
|
||
|
@@ -149,6 +149,78 @@ class ControlGraphs : public Inspector { | |
boost::optional<cstring> instanceName{}; | ||
}; | ||
|
||
|
||
class ParserGraphs : public Inspector { | ||
public: | ||
enum class VertexType { | ||
HEADER, | ||
PARSER, | ||
DEFAULT, | ||
STATEMENTS | ||
}; | ||
struct Vertex { | ||
cstring name; | ||
VertexType type; | ||
}; | ||
class GraphAttributeSetter; | ||
// The boost graph support for graphviz subgraphs is not very intuitive. In | ||
// particular the write_graphviz code assumes the existence of a lot of | ||
// properties. See | ||
// https://stackoverflow.com/questions/29312444/how-to-write-graphviz-subgraphs-with-boostwrite-graphviz | ||
// for more information. | ||
using GraphvizAttributes = std::map<cstring, cstring>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems you pasted a lot of code from |
||
using vertexProperties = | ||
boost::property<boost::vertex_attribute_t, GraphvizAttributes, | ||
Vertex>; | ||
using edgeProperties = | ||
boost::property<boost::edge_attribute_t, GraphvizAttributes, | ||
boost::property<boost::edge_name_t, cstring, | ||
boost::property<boost::edge_index_t, int> > >; | ||
using graphProperties = | ||
boost::property<boost::graph_name_t, cstring, | ||
boost::property<boost::graph_graph_attribute_t, GraphvizAttributes, | ||
boost::property<boost::graph_vertex_attribute_t, GraphvizAttributes, | ||
boost::property<boost::graph_edge_attribute_t, GraphvizAttributes> > > >; | ||
using Graph_ = boost::adjacency_list<boost::setS, boost::vecS, boost::directedS, | ||
vertexProperties, edgeProperties, | ||
graphProperties>; | ||
using Graph = boost::subgraph<Graph_>; | ||
using vertex_t = boost::graph_traits<Graph>::vertex_descriptor; | ||
|
||
using Parents = std::vector<std::pair<vertex_t, EdgeTypeIface *> >; | ||
|
||
ParserGraphs(P4::ReferenceMap *refMap, P4::TypeMap *typeMap, const cstring &graphsDir); | ||
|
||
vertex_t add_vertex(const cstring &name, VertexType type); | ||
vertex_t add_and_connect_vertex(const cstring &name, VertexType type); | ||
void add_edge(const vertex_t &from, const vertex_t &to, const cstring &name); | ||
|
||
bool preorder(const IR::PackageBlock *block) override; | ||
bool preorder(const IR::ParserBlock *block) override; | ||
bool preorder(const IR::P4Parser *pars) override; | ||
bool preorder(const IR::ParserState *state) override; | ||
|
||
void writeGraphToFile(const Graph &g, const cstring &name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as underlined in my comment above, duplicating this method in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now the code duplication is minimized. |
||
|
||
cstring stringRepr(mpz_class value, unsigned bytes); | ||
void convertSimpleKey(const IR::Expression* keySet, | ||
mpz_class& value, mpz_class& mask); | ||
unsigned combine(const IR::Expression* keySet, | ||
const IR::ListExpression* select, | ||
mpz_class& value, mpz_class& mask); | ||
|
||
private: | ||
P4::ReferenceMap *refMap; P4::TypeMap *typeMap; | ||
const cstring graphsDir; | ||
Graph *g{nullptr}; | ||
vertex_t begin_v{}; | ||
vertex_t end_v{}; | ||
vertex_t accept_v{}; | ||
Parents parents{}; | ||
Parents defParents{}; | ||
boost::optional<cstring> instanceName{}; | ||
}; | ||
|
||
} // namespace graphs | ||
|
||
#endif // _BACKENDS_GRAPHS_CONTROLS_H_ | ||
#endif // _BACKENDS_GRAPHS_GRAPHS_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not used in this file, so I'm not sure why it is defined here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be removed. Remnant code from my initial experimentation with code.