Skip to content

Commit 16b62df

Browse files
authored
For BMV2, try to compile the program after specializing it. (#144)
1 parent 944e253 commit 16b62df

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

flay.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ int Flay::mainImpl(const CompilerResult &compilerResult) {
101101
const auto &flayOptions = FlayOptions::get();
102102

103103
// If we write to the optimized program to file, also dump the program after the midend.
104-
if (FlayOptions::get().optimizedOutputDir() != std::nullopt) {
105-
auto midendOutputFile = FlayOptions::get().optimizedOutputDir().value() / "midend.p4";
104+
auto optimizedOutputDir = flayOptions.optimizedOutputDir();
105+
if (optimizedOutputDir != std::nullopt) {
106+
if (!std::filesystem::exists(optimizedOutputDir.value())) {
107+
std::filesystem::create_directory(optimizedOutputDir.value());
108+
}
109+
auto midendOutputFile = optimizedOutputDir.value() / "midend.p4";
106110
std::ofstream output(midendOutputFile);
107111
if (!output.is_open()) {
108112
::error("Could not open file %1% for writing.", midendOutputFile.c_str());
@@ -189,6 +193,14 @@ std::optional<std::vector<AnalysisStatistics *>> optimizeProgramImpl(
189193
return std::nullopt;
190194
}
191195

196+
// If we write to the optimized program to file, also dump the program after the midend.
197+
auto optimizedOutputDir = flayOptions.optimizedOutputDir();
198+
if (optimizedOutputDir != std::nullopt) {
199+
if (!std::filesystem::exists(optimizedOutputDir.value())) {
200+
std::filesystem::create_directory(optimizedOutputDir.value());
201+
}
202+
}
203+
192204
PartialEvaluationOptions partialEvaluationOptions;
193205
IncrementalAnalysisMap incrementalAnalysisMap;
194206
auto [result, inserted] = incrementalAnalysisMap.emplace(

targets/bmv2/test/BMv2V1ModelXfail.cmake

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,19 @@ p4tools_add_xfail_reason(
9090
"Reachability mapping for node .* already exists"
9191
)
9292

93-
93+
p4tools_add_xfail_reason(
94+
"flay-bmv2-v1model"
95+
"Failed BMv2 compilation."
96+
# This test uses a feature currently unsupported in the BMv2 back-end.
97+
issue907-bmv2.p4
98+
# These tests use a table key with type 'error'
99+
issue1062-bmv2.p4
100+
# This reads stack.next
101+
issue692-bmv2.p4
102+
# These test use computations in the verify/update checksum controls - unsupported
103+
issue1765-1-bmv2.p4
104+
# This test tries to hash (via the hash extern) a value that isn't a tuple - unsupported
105+
hashing-non-tuple-bmv2.p4
106+
# Similarly, this test hashes on a bit input.
107+
issue584-1-bmv2.p4
108+
)

targets/bmv2/test/TestTemplate.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ function(p4tools_add_test_with_args)
4545
endif()
4646

4747
file(APPEND ${__testfile} "${driver} --target ${target} --arch ${arch} "
48-
"${test_args} \"$@\" --file ${p4test}\n"
48+
"${test_args} \"$@\" --file ${p4test} --optimized-output-dir ${__testfolder}\n")
49+
file(APPEND ${__testfile} "${CMAKE_BINARY_DIR}/p4c-bm2-ss --target ${target} --arch ${arch} "
50+
"${__testfolder}/optimized.final.p4 || echo \"Failed BMv2 compilation.\"\n"
4951
)
5052

5153
execute_process(COMMAND chmod +x ${__testfile})

0 commit comments

Comments
 (0)