33 void postorder(
const IR::P4Parser *parser)
override {
36 graphs::ParserGraphs::postorder(parser);
38 std::vector<graphs::Graphs::Graph *> emptyControl;
40 std::filesystem::path filePath =
"";
41 std::filesystem::path empty_path =
"";
42 graphs::Graph_visitor gvs(empty_path,
true,
false,
false, filePath);
43 gvs.process(emptyControl, parserGraphsArray);
45 parserGraphsArray.clear();
49 void end_apply()
override {
50 for (
auto &kv : transitions) {
51 for (
auto *t : kv.second) {
52 auto *src = t->sourceState;
53 auto *dst = t->destState;
55 preds[dst->name].insert(src->name);
56 succs[src->name].insert(dst->name);
61 bool is_descendant_impl(cstring a, cstring b, std::set<cstring> &visited)
const {
62 if (!a || !b || a == b)
return false;
64 auto inserted = visited.insert(b);
65 if (inserted.second ==
false)
68 if (!succs.count(b))
return false;
70 if (succs.at(b).count(a))
return true;
72 for (
auto succ : succs.at(b))
73 if (is_descendant_impl(a, succ, visited))
return true;
80 : graphs::ParserGraphs(refMap,
""), dumpDot(dumpDot) {}
84 std::set<cstring> visited;
85 return is_descendant_impl(a, b, visited);
91 const IR::ParserState *get_state(
const IR::P4Parser *parser, cstring state)
const {
92 for (
auto s : states.at(parser)) {
93 if (s->name == state)
return s;
99 const IR::P4Parser *
get_parser(
const IR::ParserState *state)
const {
100 for (
auto &kv : states) {
101 for (
auto s : kv.second)
102 if (s->name == state->name)
return kv.first;
108 ordered_set<const IR::ParserState *> get_all_descendants(
const IR::ParserState *state)
const {
109 ordered_set<const IR::ParserState *> rv;
113 for (
auto s : states.at(parser)) {
120 ordered_set<const IR::ParserState *> get_all_ancestors(
const IR::ParserState *state)
const {
121 ordered_set<const IR::ParserState *> rv;
125 for (
auto s : states.at(parser)) {
132 boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> create_boost_graph(
133 const IR::P4Parser *parser, std::map<int, cstring> &id_to_state)
const;
136 const IR::P4Parser *parser)
const;
138 std::set<std::set<cstring>> compute_loops(
const IR::P4Parser *parser)
const;
140 bool has_loops(
const IR::P4Parser *parser)
const {
141 auto loops = compute_loops(parser);
142 return !loops.empty();
145 std::vector<cstring> topological_sort(
const IR::P4Parser *parser)
const;
147 std::map<cstring, ordered_set<cstring>> preds, succs;
bool is_descendant(cstring a, cstring b) const
Is "a" a descendant of "b"?
Definition parser_graph.h:83
bool is_ancestor(cstring a, cstring b) const
Is "a" an ancestor of "b"?
Definition parser_graph.h:89
const IR::P4Parser * get_parser(const IR::ParserState *state) const
a kludge due to base class's lack of state -> parser reverse map
Definition parser_graph.h:99