Skip to content

Commit 17af6ad

Browse files
committed
Remove duplicate functions between utils.py and platform/utils.py
- Remove top_components() and get_software_builds() from platform/utils.py - Update all imports to use chipflow_lib.utils instead - Keep only platform-specific compute_invert_mask() in platform/utils.py - Consolidates utility functions in a single location - Addresses duplication issue between chipflow_lib/utils.py and chipflow_lib/platform/utils.py
1 parent 6297f44 commit 17af6ad

File tree

5 files changed

+8
-64
lines changed

5 files changed

+8
-64
lines changed

chipflow_lib/platform/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
# Base classes and utilities
3434
from .base import StepBase, setup_amaranth_tools
35-
from .utils import top_components, get_software_builds
35+
from ..utils import top_components, get_software_builds
3636

3737
__all__ = [
3838
# Steps (primarily accessed via chipflow_lib.steps.*)

chipflow_lib/platform/silicon_step.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from halo import Halo
2121

2222
from .base import StepBase, _wire_up_ports
23-
from .utils import top_components
23+
from ..utils import top_components
2424
from .silicon import SiliconPlatform
2525
from ..utils import ChipFlowError
2626

chipflow_lib/platform/sim_step.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
from amaranth import Module
1414

1515
from .base import StepBase, _wire_up_ports
16-
from .utils import top_components
1716
from .sim import VARIABLES, TASKS, DOIT_CONFIG, SimPlatform
18-
from ..utils import ChipFlowError, ensure_chipflow_root
17+
from ..utils import ChipFlowError, ensure_chipflow_root, top_components
1918

2019

2120
EXE = ".exe" if os.name == "nt" else ""

chipflow_lib/platform/software_step.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
from .base import StepBase
1010
from .software import SoftwarePlatform
11-
from .utils import top_components
12-
from ..utils import ChipFlowError
11+
from ..utils import top_components, ChipFlowError
1312

1413
logger = logging.getLogger(__name__)
1514

chipflow_lib/platform/utils.py

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
# SPDX-License-Identifier: BSD-2-Clause
22
"""
3-
Platform utilities for ChipFlow.
3+
Platform-specific utilities for ChipFlow.
4+
5+
This module contains utilities specific to platform operations.
6+
For general utilities, see chipflow_lib.utils.
47
"""
58

69
import logging
7-
import pydantic
8-
9-
from pprint import pformat
10-
from typing import Dict, TYPE_CHECKING
11-
12-
from amaranth import Module
13-
from amaranth.lib import wiring
14-
15-
from ..utils import ChipFlowError, get_cls_by_reference
16-
from .io.signatures import DATA_SCHEMA, SoftwareBuild
17-
18-
if TYPE_CHECKING:
19-
from ..config import Config
2010

2111
logger = logging.getLogger(__name__)
2212

@@ -32,47 +22,3 @@ def compute_invert_mask(invert_list):
3222
Integer mask where set bits indicate positions to invert
3323
"""
3424
return sum(inv << bit for bit, inv in enumerate(invert_list))
35-
36-
37-
def top_components(config: 'Config') -> Dict[str, wiring.Component]:
38-
"""
39-
Return the top level components for the design, as configured in ``chipflow.toml``
40-
"""
41-
component_configs = {}
42-
result = {}
43-
44-
# First pass: collect component configs
45-
for name, conf in config.chipflow.top.items():
46-
if '.' in name:
47-
assert isinstance(conf, dict)
48-
param = name.split('.')[1]
49-
logger.debug(f"Config {param} = {conf} found for {name}")
50-
component_configs[param] = conf
51-
if name.startswith('_'):
52-
raise ChipFlowError(f"Top components cannot start with '_' character, these are reserved for internal use: {name}")
53-
54-
# Second pass: instantiate components
55-
for name, ref in config.chipflow.top.items():
56-
if '.' not in name: # Skip component configs, only process actual components
57-
cls = get_cls_by_reference(ref, context=f"top component: {name}")
58-
if name in component_configs:
59-
result[name] = cls(component_configs[name])
60-
else:
61-
result[name] = cls()
62-
logger.debug(f"Top members for {name}:\n{pformat(result[name].metadata.origin.signature.members)}")
63-
64-
return result
65-
66-
67-
def get_software_builds(m: Module, component: str):
68-
"""
69-
Extract software build information from a module's component metadata.
70-
"""
71-
builds = {}
72-
iface = getattr(m.submodules, component).metadata.as_json()
73-
for interface, interface_desc in iface['interface']['members'].items():
74-
annotations = interface_desc['annotations']
75-
if DATA_SCHEMA in annotations \
76-
and annotations[DATA_SCHEMA]['data']['type'] == "SoftwareBuild":
77-
builds[interface] = pydantic.TypeAdapter(SoftwareBuild).validate_python(annotations[DATA_SCHEMA]['data'])
78-
return builds

0 commit comments

Comments
 (0)