gets method
- PortReference other, {
- SameModuleConnectionType? sameModuleConnectionType,
inherited
Connects this port to be driven by other.
This establishes a connection where the signal from other drives this
port. The connection respects the hierarchical nature of the modules and
handles directionality of ports appropriately.
When connecting two ports on the same module where the connection type is
ambiguous (at least one port is PortDirection.inOut and neither is
PortDirection.input), a sameModuleConnectionType must be provided to
disambiguate.
Implementation
void gets(PortReference other,
{SameModuleConnectionType? sameModuleConnectionType}) {
final relativeLocation = _relativeLocationOf(other);
if (relativeLocation == _RelativePortLocation.sameModule &&
(other is InterfacePortReference || this is InterfacePortReference)) {
throw RohdBridgeException(
'Connections involving interface ports on the same module'
' ${module.name} should be done using port maps.');
}
if (relativeLocation == _RelativePortLocation.sameLevel &&
direction == other.direction &&
(direction != PortDirection.inOut)) {
throw RohdBridgeException(
'Cannot connect two ports with the same direction'
' on sibling modules.');
}
if (relativeLocation == _RelativePortLocation.thisAboveOther &&
direction == PortDirection.input &&
other.direction == PortDirection.input) {
throw RohdBridgeException(
'A submodule (${other.module}) input ($other) cannot drive a parent '
'module ($module) input ($this).');
}
if (relativeLocation == _RelativePortLocation.otherAboveThis &&
direction == PortDirection.output &&
other.direction == PortDirection.output) {
throw RohdBridgeException(
'A parent module (${other.module}) output ($other) cannot drive a '
'submodule ($module) output ($this).');
}
if (direction == PortDirection.output &&
other.direction == PortDirection.input &&
relativeLocation != _RelativePortLocation.sameModule) {
throw RohdBridgeException(
'Cannot use an input $other from ${other.module}'
' to drive $this, an output of $module.');
}
if (relativeLocation == _RelativePortLocation.sameModule &&
direction == PortDirection.input &&
other.direction == PortDirection.input) {
throw RohdBridgeException(
'An input port $other on module ${other.module} cannot drive an'
' input $this on the same module');
}
if (relativeLocation == _RelativePortLocation.otherAboveThis &&
direction == PortDirection.input &&
other.direction == PortDirection.output) {
throw RohdBridgeException(
'A parent module (${other.module}) output ($other) cannot drive a '
'submodule ($module) input ($this).');
}
if (relativeLocation == _RelativePortLocation.thisAboveOther &&
direction == PortDirection.input &&
other.direction == PortDirection.output) {
throw RohdBridgeException(
'A submodule (${other.module}) output ($other) cannot drive a '
'parent module ($module) input ($this).');
}
if (relativeLocation != _RelativePortLocation.sameModule &&
sameModuleConnectionType != null) {
throw RohdBridgeException(
'SameModuleConnectionType should only be provided when connecting'
' ports on the same module, but $this is on $module'
' and $other is on ${other.module}.');
}
// Same-module connection type validation
var resolvedConnectionType = sameModuleConnectionType;
if (relativeLocation == _RelativePortLocation.sameModule &&
other is! InterfacePortReference &&
this is! InterfacePortReference) {
resolvedConnectionType =
_validateSameModuleConnectionType(other, sameModuleConnectionType);
}
getsInternal(other, sameModuleConnectionType: resolvedConnectionType);
}