66import yaml
77
88__all__ = [
9- < << << << HEAD
10- << < << << HEAD
119 'ParsedProtoVLSIR' ,
1210 'generate_raw_netlist_dict_from_module' ,
1311 'generate_raw_yaml_from_module'
14- == == == =
15- "ParsedProtoVLSIR" ,
16- "parse_module_to_proto_dict" ,
17- "generate_raw_netlist_from_module" ,
18- "generate_raw_yaml_from_module" ,
19- > >> >> >> 75 a4e37 ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
20- == == == =
21- "ParsedProtoVLSIR" ,
22- "generate_raw_netlist_dict_from_module" ,
23- "generate_raw_yaml_from_module" ,
24- > >> >> >> a705eac ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
2512]
2613
2714ParsedProtoVLSIR = dict
2815
2916
30- < << << << HEAD
31- < << << << HEAD
32- == == == =
33- >> >> >> > a705eac ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
3417def _parse_module_to_proto_dict (module : h .module ) -> ParsedProtoVLSIR :
35- == == == =
36- def parse_module_to_proto_dict (module : h .module ) -> ParsedProtoVLSIR :
37- > >> >> >> 75 a4e37 ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
3818 """
3919 Parse a hdl21 module object into a dictionary with the same structure as the proto VLSIR format.
4020 """
@@ -92,40 +72,16 @@ def _parse_connections(proto_dict: ParsedProtoVLSIR) -> dict:
9272 target_signal = connection ["target" ][0 ]["sig" ]
9373 connection_key = f"{ instance_name } ,{ portname } "
9474 # Find the target instance and port
95- < << << << HEAD
96- < << << << HEAD
9775 target_instance_port = _find_target_instance_port (proto_dict , target_signal , instance_name )
98- == == == =
99- target_instance_port = find_target_instance_port (
100- proto_dict , target_signal , instance_name
101- )
102- >> >> >> > 75 a4e37 ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
103- == == == =
104- target_instance_port = _find_target_instance_port (
105- proto_dict , target_signal , instance_name
106- )
107- >> >> >> > a705eac ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
10876 if target_instance_port :
10977 connections [connection_key ] = target_instance_port
11078
11179 return connections
11280
11381
114- < << << << HEAD
115- < << << << HEAD
11682def _find_target_instance_port (proto_dict : ParsedProtoVLSIR ,
11783 target_signal ,
11884 current_instance_name ):
119- == == == =
120- def find_target_instance_port (
121- proto_dict : ParsedProtoVLSIR , target_signal , current_instance_name
122- ):
123- > >> >> >> 75 a4e37 ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
124- == == == =
125- def _find_target_instance_port (
126- proto_dict : ParsedProtoVLSIR , target_signal , current_instance_name
127- ):
128- > >> >> >> a705eac ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
12985 """
13086 Find the target instance and port of the target signal in the proto_dict.
13187 """
@@ -158,23 +114,10 @@ def _generate_top_level_connections(proto_dict: ParsedProtoVLSIR):
158114 top_level_connections = {}
159115
160116 # Iterate over the top-level module ports
161- << << << < HEAD
162- < << << << HEAD
163117 for module in proto_dict .get ('modules' , []):
164118 for port in module .get ('ports' , []):
165119 port_signal = port ['signal' ]
166- == == == =
167- for module in proto_dict .get ("modules" , []):
168- for port in module .get ("ports" , []):
169- port_signal = port ["signal" ]
170- > >> >> >> a705eac ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
171120 connection = _find_port_connection (proto_dict , port_signal )
172- == == == =
173- for module in proto_dict .get ("modules" , []):
174- for port in module .get ("ports" , []):
175- port_signal = port ["signal" ]
176- connection = find_port_connection (proto_dict , port_signal )
177- > >> >> >> 75 a4e37 ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
178121 if connection :
179122 top_level_connections [port_signal ] = connection
180123
@@ -205,8 +148,7 @@ def _extract_instance_parameters(proto_dict: ParsedProtoVLSIR):
205148 for instance in module .get ("instances" , []):
206149 instance_name = instance ["name" ]
207150 instance_info = {
208- << << << < HEAD
209- << < << << HEAD
151+
210152 'component' : _extract_component_name (instance ),
211153 'info' : {},
212154 'settings' : {}
@@ -217,30 +159,6 @@ def _extract_instance_parameters(proto_dict: ParsedProtoVLSIR):
217159 param_name = parameter ['name' ]
218160 param_value = _extract_parameter_value (parameter ['value' ])
219161 instance_info ['settings' ][param_name ] = param_value
220- == == == =
221- "component" : extract_component_name (instance ),
222- "info" : {},
223- "settings" : {},
224- }
225-
226- # Extract parameters into the settings
227- for parameter in instance .get ("parameters" , []):
228- param_name = parameter ["name" ]
229- param_value = extract_parameter_value (parameter ["value" ])
230- instance_info ["settings" ][param_name ] = param_value
231- > >> >> >> 75 a4e37 ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
232- == == == =
233- "component" : _extract_component_name (instance ),
234- "info" : {},
235- "settings" : {},
236- }
237-
238- # Extract parameters into the settings
239- for parameter in instance .get ("parameters" , []):
240- param_name = parameter ["name" ]
241- param_value = _extract_parameter_value (parameter ["value" ])
242- instance_info ["settings" ][param_name ] = param_value
243- > >> >> >> a705eac ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
244162
245163 # Extract connections and add to settings
246164 instance_info ["settings" ]["ports" ] = {}
@@ -260,24 +178,10 @@ def _extract_component_name(instance):
260178 """
261179 external_modules = instance .get ("module" , [])
262180 if external_modules :
263- << << << < HEAD
264- < << << << HEAD
265181 domain = external_modules [0 ].get ('external' , [{}])[0 ].get ('domain' , '' )
266182 name = external_modules [0 ].get ('external' , [{}])[0 ].get ('name' , '' )
267183 return f"{ name } "
268184 return 'unknown_component'
269- == == == =
270- domain = external_modules [0 ].get ("external" , [{}])[0 ].get ("domain" , "" )
271- name = external_modules [0 ].get ("external" , [{}])[0 ].get ("name" , "" )
272- return f"{ domain } _{ name } "
273- return "unknown_component"
274- >> >> >> > 75 a4e37 ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
275- == == == =
276- domain = external_modules [0 ].get ("external" , [{}])[0 ].get ("domain" , "" )
277- name = external_modules [0 ].get ("external" , [{}])[0 ].get ("name" , "" )
278- return f"{ name } "
279- return "unknown_component"
280- >> >> >> > a705eac ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
281185
282186
283187def _extract_parameter_value (value ):
@@ -304,31 +208,13 @@ def _generate_raw_netlist_dict_from_proto_dict(proto_dict: ParsedProtoVLSIR):
304208 raw_netlist_dict ["name" ] = proto_dict ["modules" ][0 ].get ("name" , "" )
305209
306210 # Generate instances information
307- < << << << HEAD
308- < << << << HEAD
309211 raw_netlist_dict ['instances' ] = _extract_instance_parameters (proto_dict )
310- == == == =
311- raw_netlist_dict ["instances" ] = _extract_instance_parameters (proto_dict )
312- >> >> >> > a705eac ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
313212
314213 # Generate connections
315214 raw_netlist_dict ["connections" ] = _parse_connections (proto_dict )
316215
317216 # Generate top-level connections
318- << << << < HEAD
319217 raw_netlist_dict ['ports' ] = _generate_top_level_connections (proto_dict )
320- == == == =
321- raw_netlist_dict ["instances" ] = extract_instance_parameters (proto_dict )
322-
323- # Generate connections
324- raw_netlist_dict ["connections" ] = parse_connections (proto_dict )
325-
326- # Generate top-level connections
327- raw_netlist_dict ["ports" ] = generate_top_level_connections (proto_dict )
328- >> >> >> > 75 a4e37 ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
329- == == == =
330- raw_netlist_dict ["ports" ] = _generate_top_level_connections (proto_dict )
331- >> >> >> > a705eac ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
332218
333219 return raw_netlist_dict
334220
@@ -347,9 +233,6 @@ def generate_raw_yaml_from_module(module: h.module):
347233 Generate a raw netlist yaml from a hdl21 module object which could be manually edited for specific instances
348234 related to the corresponding SPICE.
349235 """
350- << << << < HEAD
236+
351237 raw_netlist = generate_raw_netlist_dict_from_module (module )
352- == == == =
353- raw_netlist = generate_raw_netlist_from_module (module )
354- >> >> >> > 75 a4e37 ([pre - commit .ci ] auto fixes from pre - commit .com hooks )
355238 return yaml .dump (raw_netlist , default_flow_style = False )
0 commit comments