Skip to content

Commit

Permalink
Fix bug in internal array discovery (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorbel1 authored Jun 24, 2024
1 parent ddbd2d1 commit e465234
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/src/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,12 @@ abstract class Module {
!isInput(signal) &&
!isInOut(signal) &&
subModule == null) {
// handle expanding the search for arrays
if (signal.isArrayMember) {
await _traceInputForModuleContents(signal.parentStructure!,
dontAddSignal: dontAddSignal);
}

_addInternalSignal(signal);
}

Expand Down Expand Up @@ -514,6 +520,12 @@ abstract class Module {
!isOutput(signal) &&
!isInOut(signal) &&
subModule == null) {
// handle expanding the search for arrays
if (signal.isArrayMember) {
await _traceOutputForModuleContents(signal.parentStructure!,
dontAddSignal: dontAddSignal);
}

_addInternalSignal(signal);
for (final dstConnection in signal.dstConnections) {
await _traceInputForModuleContents(dstConnection);
Expand Down
6 changes: 4 additions & 2 deletions lib/src/synthesizers/systemverilog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,10 @@ class _SynthModuleDefinition {
for (var i = 0; i < logicsToTraverse.length; i++) {
final receiver = logicsToTraverse[i];

assert(receiver.parentModule != null,
'Any signal traced by this should have been detected by build.');
assert(
receiver.parentModule != null,
'Any signal traced by this should have been detected by build,'
' but $receiver was not.');

if (receiver.parentModule != module &&
!module.subModules.contains(receiver.parentModule)) {
Expand Down
39 changes: 39 additions & 0 deletions test/module_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// 2023 September 11
// Author: Max Korbel <[email protected]>

import 'package:collection/collection.dart';
import 'package:rohd/rohd.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -61,6 +62,33 @@ class MultipleLocation extends Module {
}
}

class ArrayConcatMod extends Module {
ArrayConcatMod() {
final a = addInput('a', Logic());
final en = addInput('en', Logic());
final b = addOutput('b');

final aBar = Logic(name: 'a_bar');
final orOut = Logic(name: 'or_out');

final t0 = Logic(name: 't0');
final t2 = Logic(name: 't2');
final t3 = Logic(name: 't3');
final aConcat = LogicArray([4], 1, name: 'a_concat');

aConcat.elements[3] <= t3;
aConcat.elements[2] <= t2;
aConcat.elements[1] <= a;
aConcat.elements[0] <= t0;

aBar <= ~aConcat.elements[1];

orOut <= aBar | en;

b <= aConcat.elements[1] & orOut;
}
}

void main() {
test('tryInput, exists', () {
final mod = ModuleWithMaybePorts(addIn: true);
Expand Down Expand Up @@ -101,4 +129,15 @@ void main() {
final mod = MultipleLocation();
expect(mod.build, throwsA(isA<PortRulesViolationException>()));
});

test('array concat per element builds and finds sigs', () async {
final mod = ArrayConcatMod();
await mod.build();

expect(
mod.internalSignals.firstWhereOrNull((e) => e.name == 't0'), isNotNull);

final sv = mod.generateSynth();
expect(sv, contains('assign a_concat[0] = t0;'));
});
}

0 comments on commit e465234

Please sign in to comment.