Skip to content

Commit 20c4412

Browse files
committed
Use the same format for an initial config as you would for an update. Miscellaneous fixes.
1 parent 5d698c1 commit 20c4412

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

core/interpreter/target.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -115,30 +115,38 @@ std::optional<ControlPlaneConstraints> FlayTarget::computeControlPlaneConstraint
115115
// By default we only support P4Runtime parsing.
116116
if (options.controlPlaneApi() == "P4RUNTIME") {
117117
auto deserializedConfig =
118-
Protobuf::deserializeObjectFromFile<p4runtime::flaytests::Config>(confPath);
118+
Protobuf::deserializeObjectFromFile<p4::v1::WriteRequest>(confPath);
119119
if (!deserializedConfig.has_value()) {
120120
return std::nullopt;
121121
}
122122
SymbolSet symbolSet;
123-
if (P4Runtime::updateControlPlaneConstraints(deserializedConfig.value(),
124-
*compilerResult.getP4RuntimeApi().p4Info,
125-
constraints, symbolSet) != EXIT_SUCCESS) {
126-
return std::nullopt;
123+
for (const auto &msg : deserializedConfig.value().updates()) {
124+
if (P4Runtime::updateControlPlaneConstraintsWithEntityMessage(
125+
msg.entity(), *compilerResult.getP4RuntimeApi().p4Info, constraints,
126+
msg.type(), symbolSet) != EXIT_SUCCESS) {
127+
return std::nullopt;
128+
}
127129
}
130+
warning("Parsed %1% control plane updates for the initial configuration.",
131+
deserializedConfig.value().updates().size());
128132
return constraints;
129133
}
130134
if (options.controlPlaneApi() == "BFRUNTIME") {
131135
auto deserializedConfig =
132-
Protobuf::deserializeObjectFromFile<bfruntime::flaytests::Config>(confPath);
136+
Protobuf::deserializeObjectFromFile<bfrt_proto::WriteRequest>(confPath);
133137
if (!deserializedConfig.has_value()) {
134138
return std::nullopt;
135139
}
136140
SymbolSet symbolSet;
137-
if (BfRuntime::updateControlPlaneConstraints(deserializedConfig.value(),
138-
*compilerResult.getP4RuntimeApi().p4Info,
139-
constraints, symbolSet) != EXIT_SUCCESS) {
140-
return std::nullopt;
141+
for (const auto &msg : deserializedConfig.value().updates()) {
142+
if (BfRuntime::updateControlPlaneConstraintsWithEntityMessage(
143+
msg.entity(), *compilerResult.getP4RuntimeApi().p4Info, constraints,
144+
msg.type(), symbolSet) != EXIT_SUCCESS) {
145+
return std::nullopt;
146+
}
141147
}
148+
printInfo("Parsed %1% control plane updates for the initial configuration.",
149+
deserializedConfig.value().updates().size());
142150
return constraints;
143151
}
144152
}
@@ -151,28 +159,27 @@ std::optional<ControlPlaneConstraints> FlayTarget::computeControlPlaneConstraint
151159
MidEnd FlayTarget::mkMidEnd(const CompilerOptions &options) const {
152160
MidEnd midEnd(options);
153161
midEnd.setStopOnError(true);
154-
auto *refMap = midEnd.getRefMap();
155162
auto *typeMap = midEnd.getTypeMap();
156163
midEnd.addPasses({
157164
// Sort call arguments according to the order of the function's parameters.
158-
new P4::OrderArguments(refMap, typeMap),
165+
new P4::OrderArguments(typeMap),
159166
// Replace any slices in the left side of assignments and convert them to casts.
160-
new P4::RemoveLeftSlices(refMap, typeMap),
167+
new P4::RemoveLeftSlices(typeMap),
161168
new PassRepeated({
162169
// Local copy propagation and dead-code elimination.
163170
// Skip this if skipSideEffectOrdering is set.
164171
// TODO: Pass FlayOptions as argument here.
165172
FlayOptions::get().skipSideEffectOrdering()
166173
? nullptr
167174
: new P4::LocalCopyPropagation(
168-
refMap, typeMap, nullptr,
175+
typeMap, nullptr,
169176
[](const Visitor::Context * /*context*/, const IR::Expression * /*expr*/) {
170177
return true;
171178
}),
172179
// Simplify control flow that has constants as conditions.
173180
new P4::SimplifyControlFlow(typeMap),
174181
// Compress member access to struct expressions.
175-
new P4::ConstantFolding(refMap, typeMap),
182+
new P4::ConstantFolding(typeMap),
176183
}),
177184
});
178185
return midEnd;
@@ -186,11 +193,11 @@ PassManager FlayTarget::mkPrivateMidEnd(const CompilerOptions &options, P4::Refe
186193
midEnd.addDebugHook(options.getDebugHook(), true);
187194
midEnd.addPasses({
188195
// Replace serializable enum constants with their values.
189-
new P4::EliminateSerEnums(refMap, typeMap),
196+
new P4::EliminateSerEnums(typeMap),
190197
// Replace types introduced by 'type' with 'typedef'.
191-
new P4::EliminateNewtype(refMap, typeMap),
198+
new P4::EliminateNewtype(typeMap),
192199
// Make sure that we have no TypeDef left in the program.
193-
new P4::EliminateTypedef(refMap, typeMap),
200+
new P4::EliminateTypedef(typeMap),
194201
// Remove exit statements from the program.
195202
// TODO: We should not depend on this pass. It has bugs.
196203
new P4::RemoveExits(typeMap),
@@ -199,11 +206,11 @@ PassManager FlayTarget::mkPrivateMidEnd(const CompilerOptions &options, P4::Refe
199206
new P4::ParsersUnroll(true, refMap, typeMap),
200207
new P4::TypeChecking(refMap, typeMap, true),
201208
// Convert enums and errors to bit<32>.
202-
new P4::ConvertEnums(refMap, typeMap, new EnumOn32Bits()),
203-
new P4::ConvertErrors(refMap, typeMap, new ErrorOn32Bits()),
209+
new P4::ConvertEnums(typeMap, new EnumOn32Bits()),
210+
new P4::ConvertErrors(typeMap, new ErrorOn32Bits()),
204211
// Simplify header stack assignments with runtime indices into conditional statements.
205212
// TODO: Get rid of this pass.
206-
new P4::HSIndexSimplifier(refMap, typeMap),
213+
new P4::HSIndexSimplifier(typeMap),
207214
// Parse BMv2-specific annotations.
208215
new BMV2::ParseAnnotations(),
209216
// Convert Type_Varbits into a type that contains information about the assigned width.

targets/bmv2/test/testdata/issue2345-2.ref

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Eliminated node at line 40: return;
22
Replaced node at line 39: if (h.eth_hdr.eth_type == 1) { with 2
3-
statement_count_before:17
4-
statement_count_after:17
3+
statement_count_before:13
4+
statement_count_after:13
55
cyclomatic_complexity:1
66
num_parsers_paths:1
77
num_updates_processed:0

0 commit comments

Comments
 (0)