Skip to content

Commit d29d920

Browse files
authored
Do not gen empty param sv (#498)
1 parent aeab8ed commit d29d920

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

lib/src/synthesizers/systemverilog.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class SystemVerilogSynthesizer extends Synthesizer {
102102
final connectionsStr = connections.join(',');
103103

104104
var parameterString = '';
105-
if (parameters != null) {
105+
if (parameters != null && parameters.isNotEmpty) {
106106
final parameterContents =
107107
parameters.entries.map((e) => '.${e.key}(${e.value})').join(',');
108108
parameterString = '#($parameterContents)';
@@ -485,7 +485,7 @@ class _SystemVerilogSynthesisResult extends SynthesisResult {
485485
String? _verilogParameters(Module module) {
486486
if (module is SystemVerilog) {
487487
final defParams = module.definitionParameters;
488-
if (defParams == null) {
488+
if (defParams == null || defParams.isEmpty) {
489489
return null;
490490
}
491491

test/sv_param_passthrough_test.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,35 @@ class LeafNodeExternal extends ModWithParamPassthrough {
114114
String? definitionVerilog(String definitionType) => '';
115115
}
116116

117+
class TopForEmptyParams extends ModWithParamPassthrough {
118+
Logic get b => output('b');
119+
TopForEmptyParams(Logic a,
120+
{super.definitionName = 'top_for_empty',
121+
super.instantiationParameters = const {},
122+
super.name = 'top'})
123+
: super([]) {
124+
a = addInput('a', a, width: 8);
125+
addOutput('b', width: 8);
126+
b <= LeafNodeExternalEmptyParams(a).b;
127+
}
128+
}
129+
130+
class LeafNodeExternalEmptyParams extends ModWithParamPassthrough {
131+
Logic get b => output('b');
132+
LeafNodeExternalEmptyParams(Logic a,
133+
{super.definitionName = 'leaf_node',
134+
super.instantiationParameters = const {},
135+
super.name = 'leaf'})
136+
: super([]) {
137+
a = addInput('a', a, width: 8);
138+
addOutput('b', width: 8);
139+
}
140+
141+
// leaf node should not generate any SV, like external
142+
@override
143+
String? definitionVerilog(String definitionType) => '';
144+
}
145+
117146
void main() {
118147
test('passthrough params custom system verilog', () async {
119148
final mod = Top(Logic(width: 8));
@@ -128,4 +157,12 @@ void main() {
128157
'test/sv_param_passthrough.sv', // include external SV
129158
]);
130159
});
160+
161+
test('empty params does include param # in generated system verilog',
162+
() async {
163+
final mod = TopForEmptyParams(Logic(width: 8));
164+
await mod.build();
165+
final sv = mod.generateSynth();
166+
expect(sv.contains('#'), isFalse);
167+
});
131168
}

0 commit comments

Comments
 (0)