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/path.h"
27#include "lib/safe_vector.h"
28
29namespace graphs {
30
31class ParserGraphs : public Graphs {
32 protected:
34 const IR::ParserState *sourceState;
35 const IR::ParserState *destState;
36 cstring label;
37
38 TransitionEdge(const IR::ParserState *source, const IR::ParserState *dest, cstring label)
39 : sourceState(source), destState(dest), label(label) {}
40 };
41
42 std::map<const IR::P4Parser *, safe_vector<const TransitionEdge *>> transitions;
43 std::map<const IR::P4Parser *, safe_vector<const IR::ParserState *>> states;
44
45 public:
46 ParserGraphs(P4::ReferenceMap *refMap, const cstring &graphsDir);
47
48 Graph *CreateSubGraph(Graph &currentSubgraph, const cstring &name);
49 void postorder(const IR::P4Parser *parser) override;
50 void postorder(const IR::ParserState *state) override;
51 void postorder(const IR::PathExpression *expression) override;
52 void postorder(const IR::SelectExpression *expression) override;
53
54 std::vector<Graph *> parserGraphsArray{};
55
56 private:
57 P4::ReferenceMap *refMap;
58 const cstring graphsDir;
59 std::optional<cstring> instanceName{};
60};
61
62} // namespace graphs
63
64#endif /* BACKENDS_GRAPHS_PARSERS_H_ */
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition cstring.h:72
Definition graphs.h:94
Definition parsers.h:31
Definition controls.cpp:29