|
9 | 9 |
|
10 | 10 | import abc |
11 | 11 | from collections import defaultdict |
12 | | -from typing import TYPE_CHECKING, Dict, List, Set |
| 12 | +from typing import TYPE_CHECKING, Dict, Generic, List, Set, TypeVar |
13 | 13 |
|
14 | 14 | import pydantic |
15 | 15 | from amaranth.lib import wiring, io |
|
24 | 24 | if TYPE_CHECKING: |
25 | 25 | from ..config_models import Config, Process |
26 | 26 |
|
| 27 | +# Type variable for pin types (int for linear allocation, GAPin for grid arrays, etc.) |
| 28 | +PinType = TypeVar('PinType') |
27 | 29 |
|
28 | | -class BasePackageDef(pydantic.BaseModel, abc.ABC): |
| 30 | + |
| 31 | +class BasePackageDef(pydantic.BaseModel, Generic[PinType], abc.ABC): |
29 | 32 | """ |
30 | 33 | Abstract base class for the definition of a package. |
31 | 34 |
|
@@ -166,7 +169,7 @@ def allocate_pins(self, config: 'Config', process: 'Process', lockfile: LockFile |
166 | 169 | return LockFile(package=package, process=process, metadata=self._interfaces, port_map=portmap) |
167 | 170 |
|
168 | 171 | @abc.abstractmethod |
169 | | - def _allocate(self, available, width: int): |
| 172 | + def _allocate(self, available: Set[PinType], width: int) -> List[PinType]: |
170 | 173 | """ |
171 | 174 | Allocate pins from available set. |
172 | 175 |
|
@@ -206,7 +209,7 @@ def _sortpins(self, pins: Pins) -> PinList: |
206 | 209 | return sorted(list(pins)) |
207 | 210 |
|
208 | 211 |
|
209 | | -class LinearAllocPackageDef(BasePackageDef): |
| 212 | +class LinearAllocPackageDef(BasePackageDef[int]): |
210 | 213 | """ |
211 | 214 | Base class for package types with linear pin/pad allocation. |
212 | 215 |
|
|
0 commit comments