Skip to content

Commit 529c4df

Browse files
committed
Move port list generation out of Jinja template. #125, #153
1 parent 1926aff commit 529c4df

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

src/peakrdl_regblock/exporter.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ def export(self, node: Union[RootNode, AddrmapNode], output_dir:str, **kwargs: A
175175
context = {
176176
"cpuif": self.cpuif,
177177
"hwif": self.hwif,
178+
"module_has_parameters": self.module_has_parameters,
179+
"get_module_parameter_list": self.get_module_parameter_list,
180+
"get_module_port_list": self.get_module_port_list,
178181
"write_buffering": self.write_buffering,
179182
"read_buffering": self.read_buffering,
180183
"get_resetsignal": self.dereferencer.get_resetsignal,
@@ -206,6 +209,47 @@ def export(self, node: Union[RootNode, AddrmapNode], output_dir:str, **kwargs: A
206209
if hwif_report_file:
207210
hwif_report_file.close()
208211

212+
def module_has_parameters(self) -> bool:
213+
return bool(self.cpuif.parameters)
214+
215+
def get_module_parameter_list(self) -> str:
216+
return ",\n".join(self.cpuif.parameters)
217+
218+
def get_module_port_list(self) -> str:
219+
groups = []
220+
221+
# Main clock & reset
222+
clkrst = [
223+
"input wire clk",
224+
f"input wire {self.dereferencer.default_resetsignal_name}"
225+
]
226+
groups.append(",\n".join(clkrst))
227+
228+
# Signals that were declared outside of the hierarchy of the addrmap
229+
# being exported
230+
out_of_hier_signals = []
231+
for signal in self.ds.out_of_hier_signals.values():
232+
if signal.width == 1:
233+
out_of_hier_signals.append(f"input wire {kwf(signal.inst_name)}")
234+
else:
235+
out_of_hier_signals.append(f"input wire [{signal.width - 1}:0] {kwf(signal.inst_name)}")
236+
if out_of_hier_signals:
237+
groups.append(",\n".join(out_of_hier_signals))
238+
239+
# Parity check error output
240+
if self.ds.has_paritycheck:
241+
groups.append("output logic parity_error")
242+
243+
# CPU interface ports
244+
groups.append(self.cpuif.port_declaration)
245+
246+
if self.hwif.has_input_struct or self.hwif.has_output_struct:
247+
groups.append(self.hwif.port_declaration)
248+
249+
return ",\n\n".join(groups)
250+
251+
252+
209253

210254
class DesignState:
211255
"""

src/peakrdl_regblock/hwif/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ def port_declaration(self) -> str:
108108
Returns the declaration string for all I/O ports in the hwif group
109109
"""
110110

111-
# Assume get_package_declaration() is always called prior to this
112-
assert self.has_input_struct is not None
113-
assert self.has_output_struct is not None
114-
115111
lines = []
116112
if self.has_input_struct:
117113
type_name = f"{self.top_node.inst_name}__in_t"

src/peakrdl_regblock/module_tmpl.sv

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,10 @@
22
// https://github.com/SystemRDL/PeakRDL-regblock
33

44
module {{ds.module_name}}
5-
{%- if cpuif.parameters %} #(
6-
{{",\n ".join(cpuif.parameters)}}
5+
{%- if module_has_parameters() %} #(
6+
{{get_module_parameter_list()|indent(8)}}
77
) {%- endif %} (
8-
input wire clk,
9-
input wire {{default_resetsignal_name}},
10-
11-
{%- for signal in ds.out_of_hier_signals.values() %}
12-
{%- if signal.width == 1 %}
13-
input wire {{kwf(signal.inst_name)}},
14-
{%- else %}
15-
input wire [{{signal.width-1}}:0] {{kwf(signal.inst_name)}},
16-
{%- endif %}
17-
{%- endfor %}
18-
19-
{%- if ds.has_paritycheck %}
20-
21-
output logic parity_error,
22-
{%- endif %}
23-
24-
{{cpuif.port_declaration|indent(8)}}
25-
{%- if hwif.has_input_struct or hwif.has_output_struct %},{% endif %}
26-
27-
{{hwif.port_declaration|indent(8)}}
8+
{{get_module_port_list()|indent(8)}}
289
);
2910

3011
//--------------------------------------------------------------------------

0 commit comments

Comments
 (0)