diff --git a/lib/src/synthesizers/systemverilog.dart b/lib/src/synthesizers/systemverilog.dart index 47a065b8c..7395b5520 100644 --- a/lib/src/synthesizers/systemverilog.dart +++ b/lib/src/synthesizers/systemverilog.dart @@ -102,7 +102,7 @@ class SystemVerilogSynthesizer extends Synthesizer { final connectionsStr = connections.join(','); var parameterString = ''; - if (parameters != null) { + if (parameters != null && parameters.isNotEmpty) { final parameterContents = parameters.entries.map((e) => '.${e.key}(${e.value})').join(','); parameterString = '#($parameterContents)'; @@ -485,7 +485,7 @@ class _SystemVerilogSynthesisResult extends SynthesisResult { String? _verilogParameters(Module module) { if (module is SystemVerilog) { final defParams = module.definitionParameters; - if (defParams == null) { + if (defParams == null || defParams.isEmpty) { return null; } diff --git a/test/sv_param_passthrough_test.dart b/test/sv_param_passthrough_test.dart index a92b000bc..e7b0876dd 100644 --- a/test/sv_param_passthrough_test.dart +++ b/test/sv_param_passthrough_test.dart @@ -114,6 +114,35 @@ class LeafNodeExternal extends ModWithParamPassthrough { String? definitionVerilog(String definitionType) => ''; } +class TopForEmptyParams extends ModWithParamPassthrough { + Logic get b => output('b'); + TopForEmptyParams(Logic a, + {super.definitionName = 'top_for_empty', + super.instantiationParameters = const {}, + super.name = 'top'}) + : super([]) { + a = addInput('a', a, width: 8); + addOutput('b', width: 8); + b <= LeafNodeExternalEmptyParams(a).b; + } +} + +class LeafNodeExternalEmptyParams extends ModWithParamPassthrough { + Logic get b => output('b'); + LeafNodeExternalEmptyParams(Logic a, + {super.definitionName = 'leaf_node', + super.instantiationParameters = const {}, + super.name = 'leaf'}) + : super([]) { + a = addInput('a', a, width: 8); + addOutput('b', width: 8); + } + + // leaf node should not generate any SV, like external + @override + String? definitionVerilog(String definitionType) => ''; +} + void main() { test('passthrough params custom system verilog', () async { final mod = Top(Logic(width: 8)); @@ -128,4 +157,12 @@ void main() { 'test/sv_param_passthrough.sv', // include external SV ]); }); + + test('empty params does include param # in generated system verilog', + () async { + final mod = TopForEmptyParams(Logic(width: 8)); + await mod.build(); + final sv = mod.generateSynth(); + expect(sv.contains('#'), isFalse); + }); }