Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not generate SystemVerilog parameter syntax when there are 0 parameters #498

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/src/synthesizers/systemverilog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)';
Expand Down Expand Up @@ -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;
}

Expand Down
37 changes: 37 additions & 0 deletions test/sv_param_passthrough_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
});
}
Loading