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
21 bool errorOnMethodCall = true;
22
24 bool copyHeaders = false;
30 bool expandUnions = false;
32 bool copyTuples = false;
33};
34
66class DoCopyStructures : public Transform {
68 TypeMap *typeMap;
69
72
73 public:
74 explicit DoCopyStructures(TypeMap *typeMap, CopyStructuresConfig config)
75 : typeMap(typeMap), config(config) {
76 CHECK_NULL(typeMap);
77 setName("DoCopyStructures");
78 }
79 explicit DoCopyStructures(TypeMap *typeMap, bool errorOnMethodCall, bool copyHeaders = false,
80 bool copyTuples = true)
81 : DoCopyStructures(typeMap, {.errorOnMethodCall = errorOnMethodCall,
82 .copyHeaders = copyHeaders,
83 .copyTuples = copyTuples}) {}
84 // FIXME -- this should be a preorder so we can deal with nested structs directly,
85 // but that fails because we depend on the typeMap which will be out of date after
86 // expanding outer copies. So we need to repeat this pass in a loop
87 const IR::Node *postorder(IR::AssignmentStatement *statement) override;
88};
89
109class RemoveAliases : public Transform {
110 MinimalNameGenerator nameGen;
111 TypeMap *typeMap;
112
114
115 public:
116 explicit RemoveAliases(TypeMap *typeMap) : typeMap(typeMap) {
117 CHECK_NULL(typeMap);
118 setName("RemoveAliases");
119 }
120 Visitor::profile_t init_apply(const IR::Node *node) override {
121 auto rv = Transform::init_apply(node);
122 node->apply(nameGen);
123
124 return rv;
125 }
126
127 const IR::Node *postorder(IR::AssignmentStatement *statement) override;
128 const IR::Node *postorder(IR::P4Parser *parser) override;
129 const IR::Node *postorder(IR::P4Control *control) override;
130};
131
132class CopyStructures : public PassRepeated {
133 public:
134 explicit CopyStructures(TypeMap *typeMap, CopyStructuresConfig config,
135 TypeChecking *typeChecking = nullptr) {
136 CHECK_NULL(typeMap);
137 setName("CopyStructures");
138 if (typeChecking == nullptr) typeChecking = new TypeChecking(nullptr, typeMap);
139 addPasses({typeChecking, new RemoveAliases(typeMap), typeChecking,
140 new DoCopyStructures(typeMap, config)});
141 }
142 explicit CopyStructures(TypeMap *typeMap, bool errorOnMethodCall = true,
143 bool copyHeaders = false, bool copyTuples = false,
144 TypeChecking *typeChecking = nullptr)
145 : CopyStructures(typeMap,
146 {.errorOnMethodCall = errorOnMethodCall,
147 .copyHeaders = copyHeaders,
148 .copyTuples = copyTuples},
149 typeChecking) {}
150};
151
152} // namespace P4
153
154#endif /* MIDEND_COPYSTRUCTURES_H_ */
Definition copyStructures.h:66
Definition indexed_vector.h:31
Definition node.h:44
Definition referenceMap.h:27
Definition copyStructures.h:109
Definition visitor.h:433
Definition typeChecker.h:46
Definition typeMap.h:32
Definition visitor.h:69
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
bool copyHeaders
Do not only copy normal structures but also perform copy assignments for headers.
Definition copyStructures.h:24
bool errorOnMethodCall
Definition copyStructures.h:21
bool expandUnions
Definition copyStructures.h:30
bool copyTuples
Also split up assignments of tuples.
Definition copyStructures.h:32
Definition copyStructures.h:16