directDriverSignalPath method
Returns the directly connected port that drives wireName in scopePath.
A driver is either an output port of an instance in the scope or an input port on the scope itself. Returns null for missing, ambiguous, or inout connections so cross-probing never guesses at connectivity.
Implementation
String? directDriverSignalPath(String wireName, String scopePath) {
LayoutNode? scope;
for (final node in nodeMap.values) {
if (node.occurrence.path() == scopePath) {
scope = node;
break;
}
}
if (scope == null) {
return null;
}
final matchingEdges = scope.hyperedges
?.where((hyperedge) => hyperedge.name == wireName)
.toList();
if (matchingEdges == null || matchingEdges.length != 1) {
return null;
}
final drivers = <String>{};
for (final (nodeId, portIndex) in matchingEdges.single.sources) {
final node = nodeMap[nodeId];
if (node == null || portIndex < 0 || portIndex >= node.elkPorts.length) {
continue;
}
final port = node.elkPorts[portIndex];
final isScopeInput =
node == scope && port.direction == PortDirection.input;
final isChildOutput =
node.parent == scope && port.direction == PortDirection.output;
if (isScopeInput || isChildOutput) {
drivers.add('${node.occurrence.path()}/${port.hwMeta.name}');
}
}
return drivers.length == 1 ? drivers.single : null;
}