Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/src/connection_extractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,22 @@ class _ConnectionSliceTracking {
final List<int> dstDimensionAccess;

/// The module of the [src].
BridgeModule get srcModule => src.parentModule! as BridgeModule;
BridgeModule get srcModule => (src is Const && src.parentModule == null)
? throw RohdBridgeException('Const has no parent module pre-build.')
: src.parentModule! as BridgeModule;

/// The module of the [dst].
BridgeModule get dstModule => dst.parentModule! as BridgeModule;

/// Converts the [src] to a [PortReference].
Reference toSrcRef() => src is Const
? ConstReference(src.value, module: srcModule)
? ConstReference(
src.value,

// use the `dstModule` since we haven't necessarily built yet and the
// source is a `Const`, not a port
module: dstModule,
)
: PortReference.fromPort(src).slice(srcHighIndex, srcLowIndex);

/// Converts the [dst] to a [PortReference].
Expand Down
32 changes: 32 additions & 0 deletions test/connection_extractor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1111,4 +1111,36 @@ void main() {
.value,
LogicValue.ofString('11'));
});

test('connection extraction with consts pre-build', () {
final top = BridgeModule('top');
final subMod = BridgeModule('subMod');
final myDst = subMod.createPort('myDst', PortDirection.input, width: 8);
top.addSubModule(subMod);

myDst.slice(4, 3).tieOff(value: 3);
top.pullUpPort(myDst.slice(6, 5));

final extractor = ConnectionExtractor([top, subMod]);

final connections = extractor.connections;
expect(connections.whereType<TieOffConnection>().length, 2);

expect(connections.whereType<TieOffConnection>().first.src.module, subMod);

expect(
connections
.whereType<TieOffConnection>()
.firstWhere((e) => e.dst.toString().contains('myDst[3]'))
.src
.value,
LogicValue.ofString('11'));
expect(
connections
.whereType<TieOffConnection>()
.firstWhere((e) => e.dst.toString().contains('myDst[4]'))
.src
.value,
LogicValue.ofString('11'));
});
}