fix (#13)
* fix * fix pyrefly * remove tests * Update tests/unit/test_exporter.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/peakrdl_busdecoder/listener.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/unit/test_exporter.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix iter --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -104,5 +104,5 @@ python-version = "3.10"
|
|||||||
# Default behavior: check bodies of untyped defs & infer return types.
|
# Default behavior: check bodies of untyped defs & infer return types.
|
||||||
untyped-def-behavior = "check-and-infer-return-type"
|
untyped-def-behavior = "check-and-infer-return-type"
|
||||||
|
|
||||||
project-includes = ["**/*"]
|
project-includes = ["src/**/*"]
|
||||||
project-excludes = ["**/__pycache__", "**/*venv/**/*"]
|
project-excludes = ["**/__pycache__", "**/*venv/**/*"]
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from textwrap import indent
|
from textwrap import indent
|
||||||
from types import EllipsisType
|
from types import EllipsisType
|
||||||
|
|
||||||
@@ -50,7 +48,7 @@ class IfBody(Body):
|
|||||||
|
|
||||||
# --- Context manager for a branch ---
|
# --- Context manager for a branch ---
|
||||||
class _BranchCtx:
|
class _BranchCtx:
|
||||||
def __init__(self, outer: IfBody, condition: SupportsStr | None) -> None:
|
def __init__(self, outer: "IfBody", condition: SupportsStr | None) -> None:
|
||||||
self._outer = outer
|
self._outer = outer
|
||||||
# route through __getitem__ to reuse validation logic
|
# route through __getitem__ to reuse validation logic
|
||||||
self._body = outer[Ellipsis if condition is None else condition]
|
self._body = outer[Ellipsis if condition is None else condition]
|
||||||
@@ -66,7 +64,7 @@ class IfBody(Body):
|
|||||||
) -> bool:
|
) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def cm(self, condition: SupportsStr | None) -> IfBody._BranchCtx:
|
def cm(self, condition: SupportsStr | None) -> "IfBody._BranchCtx":
|
||||||
"""Use with: with ifb.cm('cond') as b: ... ; use None for else."""
|
"""Use with: with ifb.cm('cond') as b: ... ; use None for else."""
|
||||||
return IfBody._BranchCtx(self, condition)
|
return IfBody._BranchCtx(self, condition)
|
||||||
|
|
||||||
|
|||||||
@@ -36,18 +36,17 @@ class FaninGenerator(BusDecoderListener):
|
|||||||
)
|
)
|
||||||
self._stack.append(fb)
|
self._stack.append(fb)
|
||||||
|
|
||||||
if action == WalkerAction.Continue:
|
ifb = IfBody()
|
||||||
ifb = IfBody()
|
with ifb.cm(
|
||||||
with ifb.cm(
|
f"cpuif_rd_sel.{get_indexed_path(self._cpuif.exp.ds.top_node, node)} || cpuif_wr_sel.{get_indexed_path(self._cpuif.exp.ds.top_node, node)}"
|
||||||
f"cpuif_rd_sel.{get_indexed_path(self._cpuif.exp.ds.top_node, node)} || cpuif_wr_sel.{get_indexed_path(self._cpuif.exp.ds.top_node, node)}"
|
) as b:
|
||||||
) as b:
|
b += self._cpuif.fanin(node)
|
||||||
b += self._cpuif.fanin(node)
|
self._stack[-1] += ifb
|
||||||
self._stack[-1] += ifb
|
|
||||||
|
|
||||||
ifb = IfBody()
|
ifb = IfBody()
|
||||||
with ifb.cm(f"cpuif_rd_sel.{get_indexed_path(self._cpuif.exp.ds.top_node, node)}") as b:
|
with ifb.cm(f"cpuif_rd_sel.{get_indexed_path(self._cpuif.exp.ds.top_node, node)}") as b:
|
||||||
b += self._cpuif.readback(node)
|
b += self._cpuif.readback(node)
|
||||||
self._stack[-1] += ifb
|
self._stack[-1] += ifb
|
||||||
|
|
||||||
return action
|
return action
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ class FanoutGenerator(BusDecoderListener):
|
|||||||
)
|
)
|
||||||
self._stack.append(fb)
|
self._stack.append(fb)
|
||||||
|
|
||||||
if action == WalkerAction.Continue:
|
self._stack[-1] += self._cpuif.fanout(node)
|
||||||
self._stack[-1] += self._cpuif.fanout(node)
|
|
||||||
|
|
||||||
return action
|
return action
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,9 @@ class BusDecoderListener(RDLListener):
|
|||||||
|
|
||||||
# Check if this node only contains external addressable children
|
# Check if this node only contains external addressable children
|
||||||
if node != self._ds.top_node and not isinstance(node, RegNode):
|
if node != self._ds.top_node and not isinstance(node, RegNode):
|
||||||
if any(isinstance(c, AddressableNode) for c in node.children()) and \
|
if any(isinstance(c, AddressableNode) for c in node.children()) and all(
|
||||||
all(c.external for c in node.children() if isinstance(c, AddressableNode)):
|
c.external for c in node.children() if isinstance(c, AddressableNode)
|
||||||
|
):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
@@ -29,23 +30,14 @@ class BusDecoderListener(RDLListener):
|
|||||||
def enter_AddressableComponent(self, node: AddressableNode) -> WalkerAction | None:
|
def enter_AddressableComponent(self, node: AddressableNode) -> WalkerAction | None:
|
||||||
if node.array_dimensions:
|
if node.array_dimensions:
|
||||||
assert node.array_stride is not None, "Array stride should be defined for arrayed components"
|
assert node.array_stride is not None, "Array stride should be defined for arrayed components"
|
||||||
# Calculate stride for each dimension
|
|
||||||
# For multi-dimensional arrays like [2][3], array_stride gives the stride of the
|
|
||||||
# rightmost (fastest-changing) dimension. We need to calculate strides for all dimensions.
|
|
||||||
# Example: for [2][3] with 4-byte elements:
|
|
||||||
# - i1 (rightmost/fastest): stride = 4 (from array_stride)
|
|
||||||
# - i0 (leftmost/slowest): stride = 3 * 4 = 12
|
|
||||||
strides = []
|
|
||||||
current_stride = node.array_stride
|
current_stride = node.array_stride
|
||||||
strides.append(current_stride)
|
self._array_stride_stack.append(current_stride)
|
||||||
|
|
||||||
# Work backwards from rightmost to leftmost dimension (fastest to slowest changing)
|
# Work backwards from rightmost to leftmost dimension (fastest to slowest changing)
|
||||||
# Each dimension's stride is the product of its size and the previous dimension's stride
|
# Each dimension's stride is the product of its size and the previous dimension's stride
|
||||||
for i in range(len(node.array_dimensions) - 1, 0, -1):
|
for dim in node.array_dimensions[-1:0:-1]:
|
||||||
current_stride = current_stride * node.array_dimensions[i]
|
current_stride = current_stride * dim
|
||||||
strides.insert(0, current_stride)
|
self._array_stride_stack.appendleft(current_stride)
|
||||||
|
|
||||||
self._array_stride_stack.extend(strides)
|
|
||||||
|
|
||||||
self._depth += 1
|
self._depth += 1
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Pytest fixtures for unit tests."""
|
"""Pytest fixtures for unit tests."""
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Tests for body classes used in code generation."""
|
"""Tests for body classes used in code generation."""
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
"""Integration tests for the BusDecoderExporter."""
|
"""Integration tests for the BusDecoderExporter."""
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -321,7 +320,6 @@ class TestAPB4Interface:
|
|||||||
|
|
||||||
module_file = tmp_path / "test_block.sv"
|
module_file = tmp_path / "test_block.sv"
|
||||||
module_content = module_file.read_text()
|
module_content = module_file.read_text()
|
||||||
|
|
||||||
# For a [2][3] array where each register is 4 bytes:
|
# For a [2][3] array where each register is 4 bytes:
|
||||||
# i0 (leftmost/slowest) should have stride = 3 * 4 = 12 (0xc)
|
# i0 (leftmost/slowest) should have stride = 3 * 4 = 12 (0xc)
|
||||||
# i1 (rightmost/fastest) should have stride = 4 (0x4)
|
# i1 (rightmost/fastest) should have stride = 4 (0x4)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Tests for code generation classes."""
|
"""Tests for code generation classes."""
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Tests for utility functions."""
|
"""Tests for utility functions."""
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from systemrdl import RDLCompiler
|
from systemrdl import RDLCompiler
|
||||||
|
|||||||
Reference in New Issue
Block a user