@@ -122,15 +122,13 @@ class TrafficTestModule extends Module {
122
122
TrafficPresence .isEastActive (traffic): LightStates .northSlowing,
123
123
}, actions: [
124
124
northLight < LightColor .green.value,
125
- eastLight < LightColor .red.value,
126
125
]),
127
126
State (
128
127
LightStates .northSlowing,
129
128
events: {},
130
129
defaultNextState: LightStates .eastFlowing,
131
130
actions: [
132
131
northLight < LightColor .yellow.value,
133
- eastLight < LightColor .red.value,
134
132
],
135
133
),
136
134
State (
@@ -139,7 +137,6 @@ class TrafficTestModule extends Module {
139
137
TrafficPresence .isNorthActive (traffic): LightStates .eastSlowing,
140
138
},
141
139
actions: [
142
- northLight < LightColor .red.value,
143
140
eastLight < LightColor .green.value,
144
141
],
145
142
),
@@ -148,7 +145,6 @@ class TrafficTestModule extends Module {
148
145
events: {},
149
146
defaultNextState: LightStates .northFlowing,
150
147
actions: [
151
- northLight < LightColor .red.value,
152
148
eastLight < LightColor .yellow.value,
153
149
],
154
150
),
@@ -159,6 +155,11 @@ class TrafficTestModule extends Module {
159
155
reset,
160
156
LightStates .northFlowing,
161
157
states,
158
+ setupActions: [
159
+ // by default, lights should be red
160
+ northLight < LightColor .red.value,
161
+ eastLight < LightColor .red.value,
162
+ ],
162
163
);
163
164
164
165
if (! kIsWeb) {
@@ -179,23 +180,49 @@ void main() {
179
180
});
180
181
181
182
test ('zero-out receivers in default case' , () async {
182
- final pipem = TestModule (Logic (), Logic (), Logic ());
183
- await pipem .build ();
183
+ final mod = TestModule (Logic (), Logic (), Logic ());
184
+ await mod .build ();
184
185
185
- final sv = pipem .generateSynth ();
186
+ final sv = mod .generateSynth ();
186
187
187
188
expect (sv, contains ("b = 1'h0;" ));
188
189
});
189
190
190
191
test ('conditional type is used' , () async {
191
- final pipem = TestModule (Logic (), Logic (), Logic ());
192
- await pipem .build ();
192
+ final mod = TestModule (Logic (), Logic (), Logic ());
193
+ await mod .build ();
193
194
194
- final sv = pipem .generateSynth ();
195
+ final sv = mod .generateSynth ();
195
196
196
197
expect (sv, contains ('priority case' ));
197
198
});
198
199
200
+ test ('label name included in generated SV' , () async {
201
+ final mod = TestModule (Logic (), Logic (), Logic ());
202
+ await mod.build ();
203
+
204
+ final sv = mod.generateSynth ();
205
+
206
+ expect (sv, contains ('MyStates_state1 : begin' ));
207
+ });
208
+
209
+ test ('state value lookup is correct' , () async {
210
+ final mod = DefaultStateFsmMod (Logic ());
211
+ await mod.build ();
212
+
213
+ expect (mod._fsm.stateWidth, 2 );
214
+
215
+ expect (mod._fsm.stateIndexLookup.length, MyStates .values.length);
216
+ expect (
217
+ MyStates .values.every ((e) => mod._fsm.stateIndexLookup.containsKey (e)),
218
+ isTrue);
219
+ for (var i = 0 ; i < MyStates .values.length; i++ ) {
220
+ final stateEnum = MyStates .values[i];
221
+ expect (mod._fsm.getStateIndex (stateEnum), i);
222
+ expect (mod._fsm.stateIndexLookup[stateEnum], i);
223
+ }
224
+ });
225
+
199
226
group ('fsm validation' , () {
200
227
test ('duplicate state identifiers throws exception' , () {
201
228
expect (
@@ -231,42 +258,42 @@ void main() {
231
258
232
259
group ('simcompare' , () {
233
260
test ('simple fsm' , () async {
234
- final pipem = TestModule (Logic (), Logic (), Logic ());
261
+ final mod = TestModule (Logic (), Logic (), Logic ());
235
262
236
- await pipem .build ();
263
+ await mod .build ();
237
264
238
265
final vectors = [
239
266
Vector ({'reset' : 1 , 'a' : 0 , 'c' : 0 }, {}),
240
267
Vector ({'reset' : 0 }, {'b' : 0 }),
241
268
Vector ({}, {'b' : 1 }),
242
269
Vector ({'c' : 1 }, {'b' : 0 }),
243
270
];
244
- await SimCompare .checkFunctionalVector (pipem , vectors);
245
- SimCompare .checkIverilogVector (pipem , vectors);
271
+ await SimCompare .checkFunctionalVector (mod , vectors);
272
+ SimCompare .checkIverilogVector (mod , vectors);
246
273
247
274
verifyMermaidStateDiagram (_simpleFSMPath);
248
275
});
249
276
250
277
test ('simple fsm async reset' , () async {
251
- final pipem =
278
+ final mod =
252
279
TestModule (Logic (), Logic (), Logic (), testingAsyncReset: true );
253
280
254
- await pipem .build ();
281
+ await mod .build ();
255
282
256
283
final vectors = [
257
284
Vector ({'reset' : 0 , 'a' : 0 , 'c' : 0 }, {}),
258
285
Vector ({'reset' : 1 }, {'b' : 0 }),
259
286
];
260
- await SimCompare .checkFunctionalVector (pipem , vectors);
261
- SimCompare .checkIverilogVector (pipem , vectors);
287
+ await SimCompare .checkFunctionalVector (mod , vectors);
288
+ SimCompare .checkIverilogVector (mod , vectors);
262
289
263
290
verifyMermaidStateDiagram (_simpleFSMPath);
264
291
});
265
292
266
293
test ('default next state fsm' , () async {
267
- final pipem = DefaultStateFsmMod (Logic ());
294
+ final mod = DefaultStateFsmMod (Logic ());
268
295
269
- await pipem .build ();
296
+ await mod .build ();
270
297
271
298
final vectors = [
272
299
Vector ({'reset' : 1 }, {}),
@@ -275,12 +302,12 @@ void main() {
275
302
Vector ({'reset' : 0 }, {'b' : 4 }),
276
303
Vector ({'reset' : 0 }, {'b' : 4 }),
277
304
];
278
- await SimCompare .checkFunctionalVector (pipem , vectors);
279
- SimCompare .checkIverilogVector (pipem , vectors);
305
+ await SimCompare .checkFunctionalVector (mod , vectors);
306
+ SimCompare .checkIverilogVector (mod , vectors);
280
307
281
308
if (! kIsWeb) {
282
309
const fsmPath = '$_tmpDir /default_next_state_fsm.md' ;
283
- pipem ._fsm.generateDiagram (outputPath: fsmPath);
310
+ mod ._fsm.generateDiagram (outputPath: fsmPath);
284
311
285
312
final mermaid = File (fsmPath).readAsStringSync ();
286
313
expect (mermaid, contains ('state2' ));
@@ -293,8 +320,8 @@ void main() {
293
320
});
294
321
295
322
test ('traffic light fsm' , () async {
296
- final pipem = TrafficTestModule (Logic (width: 2 ), Logic ());
297
- await pipem .build ();
323
+ final mod = TrafficTestModule (Logic (width: 2 ), Logic ());
324
+ await mod .build ();
298
325
299
326
final vectors = [
300
327
Vector ({'reset' : 1 , 'traffic' : 00 }, {}),
@@ -315,8 +342,8 @@ void main() {
315
342
'eastLight' : LightColor .green.value
316
343
})
317
344
];
318
- await SimCompare .checkFunctionalVector (pipem , vectors);
319
- SimCompare .checkIverilogVector (pipem , vectors);
345
+ await SimCompare .checkFunctionalVector (mod , vectors);
346
+ SimCompare .checkIverilogVector (mod , vectors);
320
347
321
348
verifyMermaidStateDiagram (_trafficFSMPath);
322
349
});
0 commit comments