P4C
The P4 Compiler
Loading...
Searching...
No Matches
parsers.h
1/*
2 * Copyright (c) 2017 VMware Inc. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef BACKENDS_GRAPHS_PARSERS_H_
19#define BACKENDS_GRAPHS_PARSERS_H_
20
21#include "frontends/common/resolveReferences/referenceMap.h"
22#include "graphs.h"
23#include "ir/ir.h"
24#include "lib/cstring.h"
25#include "lib/nullstream.h"
26#include "lib/safe_vector.h"
27
28namespace P4::graphs {
29
30class ParserGraphs : public Graphs {
31 protected:
33 const IR::ParserState *sourceState;
34 const IR::ParserState *destState;
35 cstring label;
36
37 TransitionEdge(const IR::ParserState *source, const IR::ParserState *dest, cstring label)
38 : sourceState(source), destState(dest), label(label) {}
39 };
40
41 std::map<const IR::P4Parser *, safe_vector<const TransitionEdge *>> transitions;
42 std::map<const IR::P4Parser *, safe_vector<const IR::ParserState *>> states;
43
44 public:
45 ParserGraphs(P4::ReferenceMap *refMap, std::filesystem::path graphsDir);
46
47 Graph *CreateSubGraph(Graph &currentSubgraph, const cstring &name);
48 void postorder(const IR::P4Parser *parser) override;
49 void postorder(const IR::ParserState *state) override;
50 void postorder(const IR::PathExpression *expression) override;
51 void postorder(const IR::SelectExpression *expression) override;
52
53 std::vector<Graph *> parserGraphsArray{};
54
55 private:
56 P4::ReferenceMap *refMap;
57 const cstring graphsDir;
58 std::optional<cstring> instanceName{};
59};
60
61} // namespace P4::graphs
62
63#endif /* BACKENDS_GRAPHS_PARSERS_H_ */
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition cstring.h:85
Definition graphs.h:97
Definition parsers.h:30
Graph * CreateSubGraph(Graph &currentSubgraph, const cstring &name)
We always have only one subgraph.
Definition parsers.cpp:37
Definition controls.cpp:30