P4C
The P4 Compiler
Loading...
Searching...
No Matches
moveConstructors.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef FRONTENDS_P4_MOVECONSTRUCTORS_H_
18#define FRONTENDS_P4_MOVECONSTRUCTORS_H_
19
20#include "frontends/common/resolveReferences/referenceMap.h"
21#include "ir/ir.h"
22#include "ir/visitor.h"
23#include "lib/ordered_map.h"
24
25namespace P4 {
26
56 struct ConstructorMap {
57 // Maps a constructor to the temporary used to hold its value.
59
60 void clear() { tmpName.clear(); }
61 void add(const IR::ConstructorCallExpression *expression, cstring name) {
62 CHECK_NULL(expression);
63 tmpName[expression] = name;
64 }
65 bool empty() const { return tmpName.empty(); }
66 };
67
68 enum class Region { InParserStateful, InControlStateful, InBody, Outside };
69
71 ConstructorMap cmap;
72 Region convert;
73
74 public:
76
77 profile_t init_apply(const IR::Node *node) override;
78 const IR::Node *preorder(IR::P4Parser *parser) override;
79 const IR::Node *preorder(IR::IndexedVector<IR::Declaration> *declarations) override;
80 const IR::Node *postorder(IR::P4Parser *parser) override;
81 const IR::Node *preorder(IR::P4Control *control) override;
82 const IR::Node *postorder(IR::P4Control *control) override;
83 const IR::Node *preorder(IR::P4Table *table) override;
84 const IR::Node *postorder(IR::ConstructorCallExpression *expression) override;
85};
86
87} // namespace P4
88
89#endif /* FRONTENDS_P4_MOVECONSTRUCTORS_H_ */
Definition node.h:52
Definition node.h:94
Definition referenceMap.h:36
Definition moveConstructors.h:55
Definition visitor.h:424
Definition visitor.h:78
Definition cstring.h:85
Definition ordered_map.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24