Skip to content

Commit a23c3af

Browse files
authored
Update to upstream changes. (#17)
1 parent 6877eda commit a23c3af

File tree

20 files changed

+47
-121
lines changed

20 files changed

+47
-121
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ foreach(ext ${rtsmith_targets})
4848
set(include_statements_var
4949
"${include_statements_var}#include \"backends/p4tools/modules/p4rtsmith/targets/${ext}/register.h\"\n"
5050
)
51-
set(compiler_targets_var "${compiler_targets_var} ${ext}_registerCompilerTarget();\n")
5251
set(rtsmith_targets_var "${rtsmith_targets_var} ${ext}_registerRtSmithTarget();\n")
5352
endif()
5453
endif()

core/target.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "backends/p4tools/modules/p4rtsmith/core/target.h"
22

33
#include <string>
4-
#include <utility>
54

65
#include "backends/p4tools/common/compiler/compiler_target.h"
76
#include "backends/p4tools/common/core/target.h"
87
#include "backends/p4tools/modules/p4rtsmith/core/program_info.h"
8+
#include "backends/p4tools/modules/p4rtsmith/toolname.h"
99
#include "ir/declaration.h"
1010
#include "ir/ir.h"
1111
#include "ir/node.h"
@@ -14,8 +14,8 @@
1414

1515
namespace P4Tools::RTSmith {
1616

17-
RtSmithTarget::RtSmithTarget(std::string deviceName, std::string archName)
18-
: Target("rtsmith", std::move(deviceName), std::move(archName)) {}
17+
RtSmithTarget::RtSmithTarget(const std::string &deviceName, const std::string &archName)
18+
: CompilerTarget(TOOL_NAME, deviceName, archName) {}
1919

2020
const ProgramInfo *RtSmithTarget::produceProgramInfoImpl(
2121
const CompilerResult &compilerResult) const {
@@ -41,7 +41,7 @@ P4RuntimeFuzzer &RtSmithTarget::getFuzzer(const ProgramInfo &programInfo) {
4141
return get().getFuzzerImpl(programInfo);
4242
}
4343

44-
const RtSmithTarget &RtSmithTarget::get() { return Target::get<RtSmithTarget>("rtsmith"); }
44+
const RtSmithTarget &RtSmithTarget::get() { return Target::get<RtSmithTarget>(TOOL_NAME); }
4545

4646
const ProgramInfo *RtSmithTarget::produceProgramInfo(const CompilerResult &compilerResult) {
4747
return get().produceProgramInfoImpl(compilerResult);

core/target.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
#include <string>
55

66
#include "backends/p4tools/common/compiler/compiler_target.h"
7-
#include "backends/p4tools/common/core/target.h"
87
#include "backends/p4tools/modules/p4rtsmith/core/fuzzer.h"
98
#include "backends/p4tools/modules/p4rtsmith/core/program_info.h"
109
#include "ir/ir.h"
1110

1211
namespace P4Tools::RTSmith {
1312

14-
class RtSmithTarget : public Target {
13+
class RtSmithTarget : public CompilerTarget {
1514
public:
1615
/// @returns the singleton instance for the current target.
1716
static const RtSmithTarget &get();
@@ -37,7 +36,7 @@ class RtSmithTarget : public Target {
3736
/// @see @getStepper.
3837
[[nodiscard]] virtual P4RuntimeFuzzer &getFuzzerImpl(const ProgramInfo &programInfo) const = 0;
3938

40-
explicit RtSmithTarget(std::string deviceName, std::string archName);
39+
explicit RtSmithTarget(const std::string &deviceName, const std::string &archName);
4140

4241
private:
4342
};

main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "backends/p4tools/common/lib/logging.h"
1010
#include "backends/p4tools/modules/p4rtsmith/rtsmith.h"
11+
#include "backends/p4tools/modules/p4rtsmith/toolname.h"
1112
#include "lib/crash.h"
1213
#include "lib/exceptions.h"
1314

@@ -22,7 +23,7 @@ int main(int argc, char **argv) {
2223
int result = EXIT_SUCCESS;
2324
try {
2425
Util::ScopedTimer timer("P4RuntimeSmith Main");
25-
result = P4Tools::RTSmith::RtSmith().main(args);
26+
result = P4Tools::RTSmith::RtSmith().main(P4Tools::RTSmith::TOOL_NAME, args);
2627
} catch (const Util::CompilerBug &e) {
2728
std::cerr << "Internal error: " << e.what() << '\n';
2829
std::cerr << "Please submit a bug report with your code." << '\n';

options.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "backends/p4tools/modules/p4rtsmith/options.h"
22

33
#include "backends/p4tools/common/options.h"
4+
#include "backends/p4tools/modules/p4rtsmith/toolname.h"
45
#include "lib/cstring.h"
56
#include "lib/exceptions.h"
67

@@ -16,7 +17,8 @@ const char *RtSmithOptions::getIncludePath() {
1617
}
1718

1819
RtSmithOptions::RtSmithOptions()
19-
: AbstractP4cToolOptions("Remove control-plane dead code from a P4 program.") {
20+
: AbstractP4cToolOptions(RTSmith::TOOL_NAME,
21+
"Remove control-plane dead code from a P4 program.") {
2022
registerOption(
2123
"--print-to-stdout", nullptr,
2224
[this](const char *) {

register.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
namespace P4Tools::RTSmith {
77

8-
inline void registerCompilerTargets() {
9-
@compiler_targets_var@}
10-
118
inline void registerRtSmithTargets() {
129
@rtsmith_targets_var@}
1310

rtsmith.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "backends/p4tools/modules/p4rtsmith/core/target.h"
1111
#include "backends/p4tools/modules/p4rtsmith/core/util.h"
1212
#include "backends/p4tools/modules/p4rtsmith/register.h"
13+
#include "backends/p4tools/modules/p4rtsmith/toolname.h"
1314
#include "control-plane/p4RuntimeSerializer.h"
1415
#include "lib/error.h"
1516
#include "lib/nullstream.h"
@@ -19,7 +20,7 @@ namespace P4Tools::RTSmith {
1920
void RtSmith::registerTarget() {
2021
// Register all available compiler targets.
2122
// These are discovered by CMAKE, which fills out the register.h.in file.
22-
registerCompilerTargets();
23+
registerRtSmithTargets();
2324
}
2425

2526
int RtSmith::mainImpl(const CompilerResult &compilerResult) {
@@ -104,9 +105,6 @@ int RtSmith::mainImpl(const CompilerResult &compilerResult) {
104105
std::optional<RtSmithResult> generateConfigImpl(
105106
std::optional<std::reference_wrapper<const std::string>> program,
106107
const CompilerOptions &compilerOptions, const RtSmithOptions & /*rtSmithOptions*/) {
107-
// Register supported compiler targets.
108-
registerCompilerTargets();
109-
110108
// Register supported P4RTSmith targets.
111109
registerRtSmithTargets();
112110

@@ -121,12 +119,14 @@ std::optional<RtSmithResult> generateConfigImpl(
121119
if (program.has_value()) {
122120
// Run the compiler to get an IR and invoke the tool.
123121
ASSIGN_OR_RETURN(compilerResult,
124-
P4Tools::CompilerTarget::runCompiler(program.value().get()), std::nullopt);
122+
P4Tools::CompilerTarget::runCompiler(TOOL_NAME, program.value().get()),
123+
std::nullopt);
125124
} else {
126125
RETURN_IF_FALSE_WITH_MESSAGE(!compilerOptions.file.isNullOrEmpty(), std::nullopt,
127126
::error("Expected a file input."));
128127
// Run the compiler to get an IR and invoke the tool.
129-
ASSIGN_OR_RETURN(compilerResult, P4Tools::CompilerTarget::runCompiler(), std::nullopt);
128+
ASSIGN_OR_RETURN(compilerResult, P4Tools::CompilerTarget::runCompiler(TOOL_NAME),
129+
std::nullopt);
130130
}
131131

132132
const auto *programInfo = RtSmithTarget::produceProgramInfo(compilerResult.value());

targets/bmv2/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ set(RTSMITH_SOURCES
55
${CMAKE_CURRENT_SOURCE_DIR}/fuzzer.cpp
66
${CMAKE_CURRENT_SOURCE_DIR}/program_info.cpp
77
${CMAKE_CURRENT_SOURCE_DIR}/target.cpp
8-
${CMAKE_CURRENT_SOURCE_DIR}/v1model.cpp
98
PARENT_SCOPE
109
)
1110

targets/bmv2/register.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22
#define BACKENDS_P4TOOLS_MODULES_P4RTSMITH_TARGETS_BMV2_REGISTER_H_
33

44
#include "backends/p4tools/modules/p4rtsmith/targets/bmv2/target.h"
5-
#include "backends/p4tools/modules/p4rtsmith/targets/bmv2/v1model.h"
65

76
namespace P4Tools::RTSmith {
87

9-
/// Register the V1Model compiler target with the tools framework.
10-
inline void bmv2_registerCompilerTarget() { V1Model::Bmv2V1ModelCompilerTarget::make(); }
11-
128
/// Register the V1Model RtSmith target with the P4RuntimeSmith framework.
139
inline void bmv2_registerRtSmithTarget() { V1Model::Bmv2V1ModelRtSmithTarget::make(); }
1410

targets/bmv2/target.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ void Bmv2V1ModelRtSmithTarget::make() {
1919
}
2020
}
2121

22+
MidEnd Bmv2V1ModelRtSmithTarget::mkMidEnd(const CompilerOptions &options) const {
23+
MidEnd midEnd(options);
24+
// Currently a no-op because we have all the necessary information from the front-end.
25+
midEnd.addPasses({});
26+
return midEnd;
27+
}
28+
2229
const ProgramInfo *Bmv2V1ModelRtSmithTarget::produceProgramInfoImpl(
2330
const CompilerResult &compilerResult, const IR::Declaration_Instance * /*mainDecl*/) const {
2431
return new Bmv2V1ModelProgramInfo(compilerResult);

0 commit comments

Comments
 (0)