@@ -44,7 +44,8 @@ namespace P4 {
44
44
*
45
45
* Further, struct initialization is converted to assignment on struct fields
46
46
*
47
- * Note, header assignments are not converted in this pass.
47
+ * header assignments and tuple assignments are optionally converted in this pass, based
48
+ * on constructor argument
48
49
*
49
50
* @pre none
50
51
* @post
@@ -62,13 +63,22 @@ class DoCopyStructures : public Transform {
62
63
63
64
// / Do not only copy normal structures but also perform copy assignments for headers.
64
65
bool copyHeaders;
66
+ // / Also split up assignments of tuples
67
+ bool copyTuples;
65
68
66
69
public:
67
- explicit DoCopyStructures (TypeMap *typeMap, bool errorOnMethodCall, bool copyHeaders = false )
68
- : typeMap(typeMap), errorOnMethodCall(errorOnMethodCall), copyHeaders(copyHeaders) {
70
+ explicit DoCopyStructures (TypeMap *typeMap, bool errorOnMethodCall, bool copyHeaders = false ,
71
+ bool copyTuples = true )
72
+ : typeMap(typeMap),
73
+ errorOnMethodCall(errorOnMethodCall),
74
+ copyHeaders(copyHeaders),
75
+ copyTuples(copyTuples) {
69
76
CHECK_NULL (typeMap);
70
77
setName (" DoCopyStructures" );
71
78
}
79
+ // FIXME -- this should be a preorder so we can deal with nested structs directly,
80
+ // but that fails because we depend on the typeMap which will be out of date after
81
+ // expanding outer copies. So we need to repeat this pass in a loop
72
82
const IR::Node *postorder (IR::AssignmentStatement *statement) override ;
73
83
};
74
84
@@ -117,14 +127,13 @@ class RemoveAliases : public Transform {
117
127
class CopyStructures : public PassRepeated {
118
128
public:
119
129
explicit CopyStructures (TypeMap *typeMap, bool errorOnMethodCall = true ,
120
- bool copyHeaders = false , TypeChecking *typeChecking = nullptr ) {
130
+ bool copyHeaders = false , bool copyTuples = false ,
131
+ TypeChecking *typeChecking = nullptr ) {
121
132
CHECK_NULL (typeMap);
122
133
setName (" CopyStructures" );
123
134
if (typeChecking == nullptr ) typeChecking = new TypeChecking (nullptr , typeMap);
124
- passes.emplace_back (typeChecking);
125
- passes.emplace_back (new RemoveAliases (typeMap));
126
- passes.emplace_back (typeChecking);
127
- passes.emplace_back (new DoCopyStructures (typeMap, errorOnMethodCall, copyHeaders));
135
+ addPasses ({typeChecking, new RemoveAliases (typeMap), typeChecking,
136
+ new DoCopyStructures (typeMap, errorOnMethodCall, copyHeaders, copyTuples)});
128
137
}
129
138
};
130
139
0 commit comments