@@ -16,7 +16,9 @@ limitations under the License.
16
16
17
17
#include " midend.h"
18
18
#include " lower.h"
19
+ #if 0
19
20
#include "inlining.h"
21
+ #endif
20
22
#include " frontends/common/constantFolding.h"
21
23
#include " frontends/common/resolveReferences/resolveReferences.h"
22
24
#include " frontends/p4/evaluator/evaluator.h"
@@ -84,11 +86,26 @@ class EnumOn32Bits : public P4::ChooseEnumRepresentation {
84
86
{ return 32 ; }
85
87
};
86
88
89
+ class SkipControls : public P4 ::ActionSynthesisPolicy {
90
+ const std::set<cstring> *skip;
91
+
92
+ public:
93
+ SkipControls (const std::set<cstring> *skip) : skip(skip) { CHECK_NULL (skip); }
94
+ bool convert (const IR::P4Control* control) const {
95
+ if (skip->find (control->name ) != skip->end ())
96
+ return false ;
97
+ return true ;
98
+ }
99
+ };
87
100
88
- void MidEnd::setup_for_P4_16 (CompilerOptions&) {
89
- // we may come through this path even if the program is actually a P4 v1.0 program
101
+ MidEnd::MidEnd (CompilerOptions& options) {
102
+ bool isv1 = options.isv1 ();
103
+ setName (" MidEnd" );
104
+ refMap.setIsV1 (isv1); // must be done BEFORE creating passes
90
105
auto evaluator = new P4::EvaluatorPass (&refMap, &typeMap);
91
106
auto convertEnums = new P4::ConvertEnums (&refMap, &typeMap, new EnumOn32Bits ());
107
+ auto v1controls = new std::set<cstring>();
108
+
92
109
addPasses ({
93
110
convertEnums,
94
111
new VisitFunctor ([this , convertEnums]() { enumMap = convertEnums->getEnumMapping (); }),
@@ -97,11 +114,29 @@ void MidEnd::setup_for_P4_16(CompilerOptions&) {
97
114
new P4::RemoveAllUnusedDeclarations (&refMap),
98
115
new P4::ClearTypeMap (&typeMap),
99
116
evaluator,
100
- new VisitFunctor ([evaluator](const IR::Node *root) -> const IR::Node * {
117
+ new VisitFunctor ([this ,v1controls, evaluator](const IR::Node *root) -> const IR::Node* {
101
118
auto toplevel = evaluator->getToplevelBlock ();
102
- if (toplevel->getMain () == nullptr )
119
+ auto main = toplevel->getMain ();
120
+ if (main == nullptr )
103
121
// nothing further to do
104
122
return nullptr ;
123
+ // We save the names of some control blocks for special processing later
124
+ if (main->getConstructorParameters ()->size () != 6 )
125
+ ::error (" %1%: Expected 6 arguments for main package" , main);
126
+ auto verify = main->getParameterValue (P4V1::V1Model::instance.sw .verify .name );
127
+ auto update = main->getParameterValue (P4V1::V1Model::instance.sw .update .name );
128
+ auto deparser = main->getParameterValue (P4V1::V1Model::instance.sw .deparser .name );
129
+ if (verify == nullptr || update == nullptr || deparser == nullptr ||
130
+ !verify->is <IR::ControlBlock>() || !update->is <IR::ControlBlock>() ||
131
+ !deparser->is <IR::ControlBlock>()) {
132
+ ::error (" %1%: main package does not match the expected model %2%" ,
133
+ main, P4V1::V1Model::instance.file.toString());
134
+ return nullptr ;
135
+ }
136
+ updateControlBlockName = update->to <IR::ControlBlock>()->container ->name ;
137
+ v1controls->emplace (verify->to <IR::ControlBlock>()->container ->name );
138
+ v1controls->emplace (updateControlBlockName);
139
+ v1controls->emplace (deparser->to <IR::ControlBlock>()->container ->name );
105
140
return root; }),
106
141
new P4::Inline (&refMap, &typeMap, evaluator),
107
142
new P4::InlineActions (&refMap, &typeMap),
@@ -130,33 +165,16 @@ void MidEnd::setup_for_P4_16(CompilerOptions&) {
130
165
" meters" , " size" , " support_timeout" }),
131
166
new P4::SimplifyControlFlow (&refMap, &typeMap),
132
167
new P4::CompileTimeOperations (),
133
- new P4::SynthesizeActions (&refMap, &typeMap),
168
+ new P4::SynthesizeActions (&refMap, &typeMap, new SkipControls (v1controls) ),
134
169
new P4::MoveActionsToTables (&refMap, &typeMap),
135
- });
136
- }
137
-
138
-
139
- MidEnd::MidEnd (CompilerOptions& options) {
140
- bool isv1 = options.isv1 ();
141
- setName (" MidEnd" );
142
- refMap.setIsV1 (isv1); // must be done BEFORE creating passes
143
- #if 0
144
- if (isv1)
145
- // TODO: This path should be eventually deprecated
146
- setup_for_P4_14(options);
147
- else
148
- #endif
149
- setup_for_P4_16 (options);
150
-
151
- // BMv2-specific passes
152
- auto evaluator = new P4::EvaluatorPass (&refMap, &typeMap);
153
- addPasses ({
170
+ // Proper back-end
154
171
new P4::TypeChecking (&refMap, &typeMap),
155
172
new P4::SimplifyControlFlow (&refMap, &typeMap),
156
173
new P4::RemoveLeftSlices (&refMap, &typeMap),
157
174
new P4::TypeChecking (&refMap, &typeMap),
158
175
new LowerExpressions (&typeMap),
159
176
new P4::ConstantFolding (&refMap, &typeMap, false ),
177
+ new FixupChecksum (&updateControlBlockName),
160
178
evaluator,
161
179
new VisitFunctor ([this , evaluator]() { toplevel = evaluator->getToplevelBlock (); })
162
180
});
0 commit comments