Skip to content

Commit d7c635e

Browse files
authored
Move some P4Tool compiler passes to the midend folder. (#3726)
1 parent 11d830a commit d7c635e

34 files changed

+255
-284
lines changed

backends/p4tools/common/CMakeLists.txt

+1-6
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,18 @@ set(
3838
options.cpp
3939
version.cpp
4040

41-
compiler/boolean_keys.cpp
4241
compiler/compiler_target.cpp
43-
compiler/convert_errors.cpp
42+
compiler/convert_hs_index.cpp
4443
compiler/convert_varbits.cpp
45-
compiler/copy_headers.cpp
46-
compiler/hs_index_simplify.cpp
4744
compiler/midend.cpp
4845
compiler/reachability.cpp
4946

5047
core/target.cpp
5148
core/z3_solver.cpp
5249

53-
lib/coverage.cpp
5450
lib/format_int.cpp
5551
lib/formulae.cpp
5652
lib/model.cpp
57-
lib/saturation_elim.cpp
5853
lib/symbolic_env.cpp
5954
lib/taint.cpp
6055
lib/timer.cpp

backends/p4tools/common/compiler/boolean_keys.h

-23
This file was deleted.

backends/p4tools/common/compiler/compiler_target.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "backends/p4tools/common/compiler/configuration.h"
99
#include "backends/p4tools/common/compiler/context.h"
10-
#include "backends/p4tools/common/compiler/hs_index_simplify.h"
10+
#include "backends/p4tools/common/compiler/convert_hs_index.h"
1111
#include "backends/p4tools/common/compiler/midend.h"
1212
#include "frontends/common/applyOptionsPragmas.h"
1313
#include "frontends/common/options.h"

backends/p4tools/common/compiler/convert_errors.h

-76
This file was deleted.

backends/p4tools/common/compiler/hs_index_simplify.cpp backends/p4tools/common/compiler/convert_hs_index.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "backends/p4tools/common/compiler/hs_index_simplify.h"
1+
#include "backends/p4tools/common/compiler/convert_hs_index.h"
22

33
#include <string>
44

backends/p4tools/common/compiler/hs_index_simplify.h backends/p4tools/common/compiler/convert_hs_index.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef BACKENDS_P4TOOLS_COMMON_COMPILER_HS_INDEX_SIMPLIFY_H_
2-
#define BACKENDS_P4TOOLS_COMMON_COMPILER_HS_INDEX_SIMPLIFY_H_
1+
#ifndef BACKENDS_P4TOOLS_COMMON_COMPILER_CONVERT_HS_INDEX_H_
2+
#define BACKENDS_P4TOOLS_COMMON_COMPILER_CONVERT_HS_INDEX_H_
33

44
#include <stddef.h>
55

@@ -22,4 +22,4 @@ class HSIndexToMember : public Transform {
2222

2323
} // namespace P4Tools
2424

25-
#endif /* BACKENDS_P4TOOLS_COMMON_COMPILER_HS_INDEX_SIMPLIFY_H_ */
25+
#endif /* BACKENDS_P4TOOLS_COMMON_COMPILER_CONVERT_HS_INDEX_H_ */

backends/p4tools/common/compiler/midend.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include "backends/p4tools/common/compiler/midend.h"
22

3-
#include "backends/p4tools/common/compiler/boolean_keys.h"
4-
#include "backends/p4tools/common/compiler/convert_errors.h"
53
#include "backends/p4tools/common/compiler/convert_varbits.h"
6-
#include "backends/p4tools/common/compiler/copy_headers.h"
74
#include "frontends/common/constantFolding.h"
85
#include "frontends/common/options.h"
96
#include "frontends/common/parser_options.h"
@@ -13,8 +10,11 @@
1310
#include "frontends/p4/simplify.h"
1411
#include "frontends/p4/typeChecking/typeChecker.h"
1512
#include "frontends/p4/typeMap.h"
13+
#include "midend/booleanKeys.h"
1614
#include "midend/complexComparison.h"
1715
#include "midend/convertEnums.h"
16+
#include "midend/convertErrors.h"
17+
#include "midend/copyHeaders.h"
1818
#include "midend/eliminateNewtype.h"
1919
#include "midend/eliminateSerEnums.h"
2020
#include "midend/eliminateSwitch.h"
@@ -49,7 +49,7 @@ Visitor* MidEnd::mkConvertEnums() {
4949
}
5050

5151
Visitor* MidEnd::mkConvertErrors() {
52-
return new ConvertErrors(&refMap, &typeMap, mkConvertErrorPolicy());
52+
return new P4::ConvertErrors(&refMap, &typeMap, mkConvertErrorPolicy());
5353
}
5454

5555
Visitor* MidEnd::mkConvertKeys() {
@@ -67,9 +67,9 @@ P4::ChooseEnumRepresentation* MidEnd::mkConvertEnumsPolicy() {
6767
return new EnumOn32Bits();
6868
}
6969

70-
ChooseErrorRepresentation* MidEnd::mkConvertErrorPolicy() {
70+
P4::ChooseErrorRepresentation* MidEnd::mkConvertErrorPolicy() {
7171
/// Implements the default enum-conversion policy, which converts all enums to bit<32>.
72-
class ErrorOn32Bits : public ChooseErrorRepresentation {
72+
class ErrorOn32Bits : public P4::ChooseErrorRepresentation {
7373
bool convert(const IR::Type_Error* /*type*/) const override { return true; }
7474

7575
unsigned errorSize(unsigned) const override { return 32; }
@@ -120,7 +120,7 @@ void MidEnd::addDefaultPasses() {
120120
// Expand comparisons on structs and headers into comparisons on fields.
121121
new P4::SimplifyComparisons(&refMap, &typeMap),
122122
// Expand header and struct assignments into sequences of field assignments.
123-
new CopyHeaders(&refMap, &typeMap),
123+
new P4::CopyHeaders(&refMap, &typeMap),
124124
// Flatten nested list expressions.
125125
new P4::SimplifySelectList(&refMap, &typeMap),
126126
// Convert booleans in selects into bit<1>.
@@ -158,7 +158,7 @@ void MidEnd::addDefaultPasses() {
158158
// Convert Type_Varbits into a type that contains information about the assigned width.
159159
new ConvertVarbits(&refMap, &typeMap),
160160
// Cast all boolean table keys with a bit<1>.
161-
new CastBooleanTableKeys(),
161+
new P4::CastBooleanTableKeys(),
162162
});
163163
}
164164

backends/p4tools/common/compiler/midend.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#ifndef BACKENDS_P4TOOLS_COMMON_COMPILER_MIDEND_H_
22
#define BACKENDS_P4TOOLS_COMMON_COMPILER_MIDEND_H_
33

4-
#include "backends/p4tools/common/compiler/convert_errors.h"
54
#include "frontends/common/options.h"
65
#include "frontends/common/resolveReferences/referenceMap.h"
76
#include "frontends/p4/typeMap.h"
87
#include "ir/ir.h"
98
#include "ir/pass_manager.h"
109
#include "ir/visitor.h"
1110
#include "midend/convertEnums.h"
11+
#include "midend/convertErrors.h"
1212

1313
namespace P4Tools {
1414

@@ -45,7 +45,7 @@ class MidEnd : public PassManager {
4545

4646
/// Provides a target-specific policy for converting P4 error to bit<n>. The default
4747
/// implementation converts all errors to bit<32>.
48-
virtual ChooseErrorRepresentation* mkConvertErrorPolicy();
48+
virtual P4::ChooseErrorRepresentation* mkConvertErrorPolicy();
4949

5050
/// Provides a target-specific policy for determining when to do local copy propagation.
5151
/// Implementations should return @false if local copy propagation should not be performed on

backends/p4tools/modules/testgen/core/exploration_strategy/exploration_strategy.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#include "ir/ir.h"
1818
#include "ir/irutils.h"
1919
#include "lib/error.h"
20+
#include "midend/coverage.h"
2021
#include "p4tools/common/core/solver.h"
21-
#include "p4tools/common/lib/coverage.h"
2222
#include "p4tools/common/lib/formulae.h"
2323

2424
#include "backends/p4tools/modules/testgen/core/program_info.h"
@@ -109,7 +109,7 @@ ExplorationStrategy::ExplorationStrategy(AbstractSolver& solver, const ProgramIn
109109
executionState = new ExecutionState(programInfo.program);
110110
}
111111

112-
const Coverage::CoverageSet& ExplorationStrategy::getVisitedStatements() {
112+
const P4::Coverage::CoverageSet& ExplorationStrategy::getVisitedStatements() {
113113
return visitedStatements;
114114
}
115115

backends/p4tools/modules/testgen/core/exploration_strategy/exploration_strategy.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <boost/optional/optional.hpp>
1010

1111
#include "backends/p4tools/common/core/solver.h"
12-
#include "backends/p4tools/common/lib/coverage.h"
12+
#include "midend/coverage.h"
1313

1414
#include "backends/p4tools/modules/testgen/core/program_info.h"
1515
#include "backends/p4tools/modules/testgen/core/small_step/small_step.h"
@@ -56,7 +56,7 @@ class ExplorationStrategy {
5656
void printCurrentTraceAndBranches(std::ostream& out);
5757

5858
/// Getter to access visitedStatements
59-
const Coverage::CoverageSet& getVisitedStatements();
59+
const P4::Coverage::CoverageSet& getVisitedStatements();
6060

6161
protected:
6262
/// Target-specific information about the P4 program.
@@ -81,10 +81,10 @@ class ExplorationStrategy {
8181
ExecutionState* executionState = nullptr;
8282

8383
/// Set of all stetements, to be retrieved from programInfo.
84-
const Coverage::CoverageSet& allStatements;
84+
const P4::Coverage::CoverageSet& allStatements;
8585

8686
/// Set of all statements executed in any testcase that has been outputted.
87-
Coverage::CoverageSet visitedStatements;
87+
P4::Coverage::CoverageSet visitedStatements;
8888

8989
private:
9090
SmallStepEvaluator evaluator;

backends/p4tools/modules/testgen/core/exploration_strategy/inc_max_coverage_stack.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
#include <boost/none.hpp>
99

10-
#include "backends/p4tools/common/lib/coverage.h"
1110
#include "gsl/gsl-lite.hpp"
1211
#include "ir/ir.h"
1312
#include "lib/error.h"
13+
#include "midend/coverage.h"
1414
#include "p4tools/common/core/solver.h"
1515
#include "p4tools/common/lib/formulae.h"
1616

backends/p4tools/modules/testgen/core/exploration_strategy/rnd_access_max_coverage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
#include <boost/none.hpp>
99

10-
#include "backends/p4tools/common/lib/coverage.h"
1110
#include "backends/p4tools/common/lib/util.h"
1211
#include "gsl/gsl-lite.hpp"
1312
#include "ir/ir.h"
1413
#include "lib/error.h"
14+
#include "midend/coverage.h"
1515
#include "p4tools/common/core/solver.h"
1616
#include "p4tools/common/lib/formulae.h"
1717

backends/p4tools/modules/testgen/core/program_info.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include "frontends/p4/typeMap.h"
88
#include "ir/id.h"
99
#include "lib/exceptions.h"
10+
#include "midend/coverage.h"
1011
#include "p4tools/common/compiler/reachability.h"
11-
#include "p4tools/common/lib/coverage.h"
1212

1313
#include "backends/p4tools/modules/testgen/core/arch_spec.h"
1414
#include "backends/p4tools/modules/testgen/lib/concolic.h"
@@ -34,7 +34,7 @@ ProgramInfo::ProgramInfo(const IR::P4Program* program)
3434
program->apply(dcgCreator);
3535
dcg = currentDCG;
3636
}
37-
program->apply(Coverage::CollectStatements(allStatements));
37+
program->apply(P4::Coverage::CollectStatements(allStatements));
3838
}
3939

4040
/* =============================================================================================
@@ -60,7 +60,7 @@ const IR::Type_Declaration* ProgramInfo::resolveProgramType(const IR::Type_Name*
6060
* Getters
6161
* ============================================================================================= */
6262

63-
const Coverage::CoverageSet& ProgramInfo::getAllStatements() const { return allStatements; }
63+
const P4::Coverage::CoverageSet& ProgramInfo::getAllStatements() const { return allStatements; }
6464

6565
const ConcolicMethodImpls* ProgramInfo::getConcolicMethodImpls() const {
6666
return &concolicMethodImpls;

backends/p4tools/modules/testgen/core/program_info.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
#include <boost/optional/optional.hpp>
99

1010
#include "backends/p4tools/common/compiler/reachability.h"
11-
#include "backends/p4tools/common/lib/coverage.h"
1211
#include "ir/declaration.h"
1312
#include "ir/ir.h"
1413
#include "lib/castable.h"
1514
#include "lib/cstring.h"
15+
#include "midend/coverage.h"
1616
#include "p4tools/common/lib/formulae.h"
1717

1818
#include "backends/p4tools/modules/testgen/core/arch_spec.h"
@@ -37,7 +37,7 @@ class ProgramInfo : public ICastable {
3737
ConcolicMethodImpls concolicMethodImpls;
3838

3939
/// Set of all statements in the input P4 program.
40-
Coverage::CoverageSet allStatements;
40+
P4::Coverage::CoverageSet allStatements;
4141

4242
std::vector<Continuation::Command> pipelineSequence;
4343

@@ -84,7 +84,7 @@ class ProgramInfo : public ICastable {
8484
bool forceTaint) const = 0;
8585

8686
/// Getter to access allStatements.
87-
const Coverage::CoverageSet& getAllStatements() const;
87+
const P4::Coverage::CoverageSet& getAllStatements() const;
8888

8989
/// @returns the list of implemented concolic methods for this particular program.
9090
const ConcolicMethodImpls* getConcolicMethodImpls() const;

backends/p4tools/modules/testgen/core/small_step/abstract_stepper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <boost/optional/optional.hpp>
99
#include <boost/variant/variant.hpp>
1010

11-
#include "backends/p4tools/common/compiler/hs_index_simplify.h"
11+
#include "backends/p4tools/common/compiler/convert_hs_index.h"
1212
#include "backends/p4tools/common/lib/formulae.h"
1313
#include "backends/p4tools/common/lib/model.h"
1414
#include "backends/p4tools/common/lib/symbolic_env.h"

backends/p4tools/modules/testgen/core/small_step/cmd_stepper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <boost/variant/get.hpp>
1212
#include <boost/variant/variant.hpp>
1313

14-
#include "backends/p4tools/common/compiler/hs_index_simplify.h"
14+
#include "backends/p4tools/common/compiler/convert_hs_index.h"
1515
#include "backends/p4tools/common/lib/symbolic_env.h"
1616
#include "backends/p4tools/common/lib/trace_events.h"
1717
#include "backends/p4tools/common/lib/util.h"

0 commit comments

Comments
 (0)