44import os
55import sys
66
7- from collections import defaultdict
87from dataclasses import dataclass
98from enum import StrEnum
109from pathlib import Path
1110from pprint import pformat
1211from typing import Dict , List , Optional , Type
1312
14- from amaranth import Value , ValueCastable , Module , Signal , ClockSignal , ResetSignal , ClockDomain
15- from amaranth .lib import io , meta , wiring
16- from amaranth .lib .wiring import In , Out
13+ from amaranth import Module , ClockSignal , ResetSignal , ClockDomain
14+ from amaranth .lib import io , wiring
1715from amaranth .back import rtlil # type: ignore[reportAttributeAccessIssue]
1816from amaranth .hdl ._ir import PortDirection
1917from amaranth .lib .cdc import FFSynchronizer
@@ -46,6 +44,7 @@ class SimModel:
4644 capabilities: List of capabilities of the model.
4745 """
4846 name : str
47+ namespace : str
4948 signature : Type [wiring .Signature ]
5049 capabilities : Optional [List [SimModelCapability ]] = None
5150
@@ -103,9 +102,6 @@ class BasicCxxBuilder(BaseModel):
103102 def model_post_init (self , * args , ** kwargs ):
104103 self ._table = { getattr (m .signature ,'__chipflow_uid__' ): m for m in self .models }
105104
106- def uid_to_c (self , uid : str ) -> str :
107- return uid .replace ('.' ,'__' )
108-
109105 def instantiate_model (self , interface : str , sim_interface : SimInterface , interface_desc : Interface , ports : Dict [str , io .SimulationPort ]) -> str :
110106 uid = sim_interface ['uid' ]
111107 parameters = sim_interface ['parameters' ]
@@ -120,11 +116,10 @@ def instantiate_model(self, interface: str, sim_interface: SimInterface, interfa
120116 sig_names = [ path for path , _ , _ in members ]
121117 port_names = { n : interface_desc [n ].port_name for n in interface_desc .keys ()}
122118
123- identifier_uid = self .uid_to_c (uid )
124119 names = [f"\\ io${ port_names [str (n )]} ${ d } " for n ,d in sig_names ]
125120 params = [f"top.{ cxxrtlmangle (n )} " for n in names ]
126121
127- cpp_class = model .name
122+ cpp_class = f" { model .namespace } :: { model . name } "
128123 if len (parameters ):
129124 template_params = []
130125 for p ,v in parameters :
@@ -146,11 +141,11 @@ def find_builder(builders: List[BasicCxxBuilder], sim_interface: SimInterface):
146141
147142_COMMON_BUILDER = BasicCxxBuilder (
148143 models = [
149- SimModel ('spi_model ' , SPISignature ),
150- SimModel ('spiflash_model ' , QSPIFlashSignature , [SimModelCapability .LOAD_DATA ]),
151- SimModel ('uart_model ' , UARTSignature ),
152- SimModel ('i2c_model ' , I2CSignature ),
153- SimModel ('gpio_model ' , GPIOSignature ),
144+ SimModel ('spi' , 'chipflow::models ' , SPISignature ),
145+ SimModel ('spiflash' , 'chipflow::models ' , QSPIFlashSignature , [SimModelCapability .LOAD_DATA ]),
146+ SimModel ('uart' , 'chipflow::models ' , UARTSignature ),
147+ SimModel ('i2c' , 'chipflow::models ' , I2CSignature ),
148+ SimModel ('gpio' , 'chipflow::models ' , GPIOSignature ),
154149 ],
155150 cpp_files = [ Path ('{COMMON_DIR}' , 'models.cc' ) ],
156151 hpp_files = [ Path ('models.h' ) ],
0 commit comments