P4C
The P4 Compiler
Loading...
Searching...
No Matches
moveConstructors.h
1/*
2 * SPDX-FileCopyrightText: 2013 Barefoot Networks, Inc.
3 * Copyright 2013-present Barefoot Networks, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef FRONTENDS_P4_MOVECONSTRUCTORS_H_
9#define FRONTENDS_P4_MOVECONSTRUCTORS_H_
10
11#include "frontends/common/resolveReferences/referenceMap.h"
12#include "ir/ir.h"
13#include "ir/visitor.h"
14#include "lib/ordered_map.h"
15
16namespace P4 {
17
46class MoveConstructors : public Transform {
47 struct ConstructorMap {
48 // Maps a constructor to the temporary used to hold its value.
50
51 void clear() { tmpName.clear(); }
52 void add(const IR::ConstructorCallExpression *expression, cstring name) {
53 CHECK_NULL(expression);
54 tmpName[expression] = name;
55 }
56 bool empty() const { return tmpName.empty(); }
57 };
58
59 enum class Region { InParserStateful, InControlStateful, InBody, Outside };
60
62 ConstructorMap cmap;
63 Region convert;
64
65 public:
66 MoveConstructors();
67
68 profile_t init_apply(const IR::Node *node) override;
69 const IR::Node *preorder(IR::P4Parser *parser) override;
70 const IR::Node *preorder(IR::IndexedVector<IR::Declaration> *declarations) override;
71 const IR::Node *postorder(IR::P4Parser *parser) override;
72 const IR::Node *preorder(IR::P4Control *control) override;
73 const IR::Node *postorder(IR::P4Control *control) override;
74 const IR::Node *preorder(IR::P4Table *table) override;
75 const IR::Node *postorder(IR::ConstructorCallExpression *expression) override;
76};
77
78} // namespace P4
79
80#endif /* FRONTENDS_P4_MOVECONSTRUCTORS_H_ */
Definition indexed_vector.h:31
Definition node.h:53
Definition referenceMap.h:36
Definition visitor.h:442
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:13