refactor to use base listener for busdecoder

This commit is contained in:
Arnav Sacheti
2025-10-19 21:35:17 -07:00
parent be116def83
commit bafebf8595
10 changed files with 136 additions and 65 deletions

View File

@@ -2,17 +2,20 @@ import os
from datetime import datetime
from importlib.metadata import version
from pathlib import Path
from typing import TYPE_CHECKING, TypedDict
from typing import TYPE_CHECKING, Any, TypedDict
import jinja2 as jj
from systemrdl.node import AddrmapNode, RootNode
from systemrdl.walker import RDLSteerableWalker
from typing_extensions import Unpack
from .cpuif import BaseCpuif
from .cpuif.apb4 import APB4Cpuif
from .decoder import AddressDecode, DecodeLogicFlavor
from .decoder import DecodeLogicFlavor, DecodeLogicGenerator
from .design_state import DesignState
from .identifier_filter import kw_filter as kwf
from .listener import BusDecoderListener
from .struct_generator import StructGenerator
from .sv_int import SVInt
from .validate_design import DesignValidator
@@ -32,7 +35,6 @@ if TYPE_CHECKING:
class BusDecoderExporter:
cpuif: BaseCpuif
address_decode: type[AddressDecode]
ds: DesignState
def __init__(self, **kwargs: Unpack[ExporterKwargs]) -> None:
@@ -56,6 +58,7 @@ class BusDecoderExporter:
undefined=jj.StrictUndefined,
)
self.jj_env.filters["kwf"] = kwf
self.jj_env.filters["walk"] = self.walk
def export(self, node: RootNode | AddrmapNode, output_dir: str, **kwargs: Unpack[ExporterKwargs]) -> None:
"""
@@ -98,7 +101,6 @@ class BusDecoderExporter:
# Construct exporter components
self.cpuif = cpuif_cls(self)
self.address_decode = AddressDecode
# Validate that there are no unsupported constructs
DesignValidator(self).do_validate()
@@ -108,8 +110,9 @@ class BusDecoderExporter:
"current_date": datetime.now().strftime("%Y-%m-%d"),
"version": version("peakrdl-busdecoder"),
"cpuif": self.cpuif,
"address_decode": self.address_decode,
"DecodeLogicFlavor": DecodeLogicFlavor,
"cpuif_decode": DecodeLogicGenerator,
"cpuif_select": StructGenerator,
"cpuif_decode_flavor": DecodeLogicFlavor,
"ds": self.ds,
"SVInt": SVInt,
}
@@ -125,3 +128,9 @@ class BusDecoderExporter:
template = self.jj_env.get_template("module_tmpl.sv")
stream = template.stream(context)
stream.dump(module_file_path)
def walk(self, listener_cls: type[BusDecoderListener], **kwargs: Any) -> BusDecoderListener:
walker = RDLSteerableWalker()
listener = listener_cls(self.ds, **kwargs)
walker.walk(self.ds.top_node, listener, skip_top=True)
return str(listener)