Skip to content
Snippets Groups Projects

Implemented "Modify Word Length"

Merged Arvid Westerlund requested to merge 29-modify-word-length into develop
All threads resolved!
2 files
+ 37
26
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 12
13
@@ -35,15 +35,6 @@ class Port(ABC):
"""Return a list of all connected signals."""
raise NotImplementedError
@abstractmethod
def signal(self, i: int = 0) -> Signal:
"""Return the connected signal at index i.
Keyword argumens:
i: integer index of the signal requsted.
"""
raise NotImplementedError
@property
@abstractmethod
def connected_ports(self) -> List["Port"]:
@@ -119,24 +110,32 @@ class InputPort(AbstractPort):
"""
_source_signal: Optional[Signal]
_value_length: Optional[int]
def __init__(self, port_id: PortIndex, operation: Operation):
super().__init__(port_id, operation)
self._source_signal = None
self._value_length = None
@property
def signals(self) -> List[Signal]:
return [] if self._source_signal is None else [self._source_signal]
def signal(self, i: int = 0) -> Signal:
assert 0 <= i < self.signal_count(), "Signal index out of bound."
assert self._source_signal is not None, "No Signal connect to InputPort."
return self._source_signal
@property
def value_length(self) -> Optional[int]:
return self._value_length
@property
def connected_ports(self) -> List[Port]:
return [] if self._source_signal is None or self._source_signal.source is None \
else [self._source_signal.source]
@value_length.setter
def value_length(self, bits: Optional[int]) -> None:
assert isinstance(bits, int) or bits is None, "Value length on input port has to be of type Int or NoneType."
assert bits is None or bits >= 0, "Value length on input port has to be a non-negative integer or None."
self._value_length = bits
def signal_count(self) -> int:
return 0 if self._source_signal is None else 1
Loading