P4C
The P4 Compiler
Loading...
Searching...
No Matches
copyStructures.h
1/*
2 * Copyright 2016 VMware, Inc.
3 * SPDX-FileCopyrightText: 2016 VMware, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef MIDEND_COPYSTRUCTURES_H_
9#define MIDEND_COPYSTRUCTURES_H_
10
11#include "frontends/p4/typeChecking/typeChecker.h"
12#include "ir/ir.h"
13
14namespace P4 {
15
47class DoCopyStructures : public Transform {
48 TypeMap *typeMap;
53 bool errorOnMethodCall;
54
56 bool copyHeaders;
58 bool copyTuples;
59
60 public:
61 explicit DoCopyStructures(TypeMap *typeMap, bool errorOnMethodCall, bool copyHeaders = false,
62 bool copyTuples = true)
63 : typeMap(typeMap),
64 errorOnMethodCall(errorOnMethodCall),
65 copyHeaders(copyHeaders),
66 copyTuples(copyTuples) {
67 CHECK_NULL(typeMap);
68 setName("DoCopyStructures");
69 }
70 // FIXME -- this should be a preorder so we can deal with nested structs directly,
71 // but that fails because we depend on the typeMap which will be out of date after
72 // expanding outer copies. So we need to repeat this pass in a loop
73 const IR::Node *postorder(IR::AssignmentStatement *statement) override;
74};
75
95class RemoveAliases : public Transform {
97 TypeMap *typeMap;
98
100
101 public:
102 explicit RemoveAliases(TypeMap *typeMap) : typeMap(typeMap) {
103 CHECK_NULL(typeMap);
104 setName("RemoveAliases");
105 }
106 Visitor::profile_t init_apply(const IR::Node *node) override {
107 auto rv = Transform::init_apply(node);
108 node->apply(nameGen);
109
110 return rv;
111 }
112
113 const IR::Node *postorder(IR::AssignmentStatement *statement) override;
114 const IR::Node *postorder(IR::P4Parser *parser) override;
115 const IR::Node *postorder(IR::P4Control *control) override;
116};
117
118class CopyStructures : public PassRepeated {
119 public:
120 explicit CopyStructures(TypeMap *typeMap, bool errorOnMethodCall = true,
121 bool copyHeaders = false, bool copyTuples = false,
122 TypeChecking *typeChecking = nullptr) {
123 CHECK_NULL(typeMap);
124 setName("CopyStructures");
125 if (typeChecking == nullptr) typeChecking = new TypeChecking(nullptr, typeMap);
126 addPasses({typeChecking, new RemoveAliases(typeMap), typeChecking,
127 new DoCopyStructures(typeMap, errorOnMethodCall, copyHeaders, copyTuples)});
128 }
129};
130
131} // namespace P4
132
133#endif /* MIDEND_COPYSTRUCTURES_H_ */
Definition copyStructures.h:47
Definition indexed_vector.h:31
Definition node.h:53
Definition referenceMap.h:36
Definition copyStructures.h:95
Definition visitor.h:442
Definition typeChecker.h:55
Definition typeMap.h:32
Definition visitor.h:78
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13