Skip to content

Commit b02beda

Browse files
authored
More module and signal naming improvements (#440)
1 parent b9e35a6 commit b02beda

File tree

8 files changed

+131
-5
lines changed

8 files changed

+131
-5
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The [ROHD Forum](https://intel.github.io/rohd-website/forum/rohd-forum/) is a pe
4242

4343
You must have [Dart](https://dart.dev/) installed on your system to use ROHD. You can find detailed instructions for how to install Dart here: <https://dart.dev/get-dart>
4444

45-
To run the complete ROHD test suite for development, you need to install [Icarus Verilog](http://iverilog.icarus.com/). It is used to compare SystemVerilog functionality with the ROHD simulator functionality. Installation instructions are available here: <https://iverilog.fandom.com/wiki/Installation_Guide>
45+
To run the complete ROHD test suite for development, you need to install [Icarus Verilog](https://steveicarus.github.io/iverilog/). It is used to compare SystemVerilog functionality with the ROHD simulator functionality. Installation instructions are available here: <https://iverilog.fandom.com/wiki/Installation_Guide>
4646

4747
### Setup Recommendations
4848

lib/src/module.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ abstract class Module {
3838
/// An internal list of internal-signals.
3939
///
4040
/// Used for waveform dump efficiency.
41-
final Set<Logic> _internalSignals = HashSet<Logic>();
41+
final Set<Logic> _internalSignals = {};
4242

4343
/// An internal list of inputs to this [Module].
4444
final Map<String, Logic> _inputs = {};

lib/src/signals/port.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class Port extends Logic {
2121
: super(
2222
name: name,
2323
width: width,
24+
25+
// make port names mergeable so we don't duplicate the ports
26+
// when calling connectIO
27+
naming: Naming.mergeable,
2428
) {
2529
if (!Sanitizer.isSanitary(name)) {
2630
throw InvalidPortNameException(name);

lib/src/synthesizers/synthesis_result.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ abstract class SynthesisResult {
4040

4141
@override
4242
bool operator ==(Object other) =>
43-
other is SynthesisResult && matchesImplementation(other);
43+
other is SynthesisResult &&
44+
matchesImplementation(other) &&
45+
// if they are both reserved defs but different def names, not equal
46+
!((module.reserveDefinitionName && other.module.reserveDefinitionName) &&
47+
module.definitionName != other.module.definitionName);
4448

4549
@override
4650
int get hashCode => matchHashCode;

test/counter_wintf_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ void main() {
106106
await moduleTest(mod);
107107
});
108108
});
109+
109110
test('resetFlipflop from root w/o resetVal', () async {
110111
final mod = Counter(CounterInterface(8), useBuiltInSequentialReset: true);
111112
await moduleTest(mod);
@@ -133,4 +134,12 @@ void main() {
133134
final simResult = SimCompare.iverilogVector(mod, vectors);
134135
expect(simResult, equals(true));
135136
});
137+
138+
test('interface ports dont get doubled up', () async {
139+
final mod = Counter(CounterInterface(8));
140+
await mod.build();
141+
final sv = mod.generateSynth();
142+
143+
expect(!sv.contains('en_0'), true);
144+
});
136145
}

test/module_merging_test.dart

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright (C) 2023 Intel Corporation
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
//
4+
// module_merging_test.dart
5+
// Unit tests for deduplication of module definitions in generated verilog
6+
//
7+
// 2023 November 28
8+
// Author: Max Korbel <[email protected]>
9+
10+
import 'package:rohd/rohd.dart';
11+
import 'package:test/test.dart';
12+
13+
class ComplicatedLeaf extends Module {
14+
Logic get d => output('d');
15+
ComplicatedLeaf(
16+
Logic clk,
17+
Logic reset, {
18+
required Logic a,
19+
required Logic b,
20+
required Logic c,
21+
}) {
22+
clk = addInput('clk', clk);
23+
reset = addInput('reset', reset);
24+
a = addInput('a', a);
25+
b = addInput('b', b);
26+
c = addInput('c', c);
27+
28+
final internal1 = Logic(name: 'internal1');
29+
final internal2 = Logic(name: 'internal2');
30+
31+
addOutput('d');
32+
33+
Combinational.ssa((s) => [
34+
s(internal1) < internal2,
35+
If(a, then: [
36+
internal1.incr(s: s),
37+
]),
38+
If(b, then: [
39+
internal1.decr(s: s),
40+
]),
41+
If(c, then: [
42+
s(internal1) < 0,
43+
])
44+
]);
45+
46+
Sequential(clk, reset: reset, [
47+
internal2 < internal1,
48+
]);
49+
}
50+
}
51+
52+
class TrunkWithLeaves extends Module {
53+
TrunkWithLeaves(
54+
Logic clk,
55+
Logic reset,
56+
) {
57+
clk = addInput('clk', clk);
58+
reset = addInput('reset', reset);
59+
60+
final abc = [Logic(name: 'a'), Logic(name: 'b'), Logic(name: 'c')];
61+
for (var i = 0; i < 50; i++) {
62+
ComplicatedLeaf(
63+
clk,
64+
reset,
65+
a: abc[i % 3],
66+
b: abc[(i + 1) % 3],
67+
c: abc[(i + 2) % 3],
68+
);
69+
}
70+
}
71+
}
72+
73+
class SpecificallyDefinedNameModule extends Module {
74+
SpecificallyDefinedNameModule(Logic a, {required super.definitionName})
75+
: super(reserveDefinitionName: true) {
76+
a = addInput('a', a);
77+
addOutput('b') <= ~a;
78+
}
79+
}
80+
81+
class ParentOfDifferentModuleDefNames extends Module {
82+
ParentOfDifferentModuleDefNames(Logic a) {
83+
a = addInput('a', a);
84+
SpecificallyDefinedNameModule(a, definitionName: 'def1');
85+
SpecificallyDefinedNameModule(a, definitionName: 'def2');
86+
}
87+
}
88+
89+
void main() async {
90+
test('complex trunk with leaves doesnt duplicate identical modules',
91+
() async {
92+
final dut = TrunkWithLeaves(Logic(), Logic());
93+
await dut.build();
94+
final sv = dut.generateSynth();
95+
96+
expect('module ComplicatedLeaf'.allMatches(sv).length, 1);
97+
});
98+
99+
test('different reserved definition name modules stay separate', () async {
100+
final dut = ParentOfDifferentModuleDefNames(Logic());
101+
await dut.build();
102+
final sv = dut.generateSynth();
103+
104+
expect(sv, contains('module def1'));
105+
expect(sv, contains('module def2'));
106+
});
107+
}

test/tree_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ void main() {
5353
List<Logic>.generate(16, (index) => Logic(width: 8)),
5454
(a, b) => mux(a > b, a, b));
5555
await mod.build();
56-
// File('tmp_tree.sv').writeAsStringSync(mod.generateSynth());
5756

5857
final vectors = [
5958
Vector({

tool/gh_actions/generate_documentation.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ set -euo pipefail
1414
# See script "check_documentation.sh" for a note on processing "dart doc" output.
1515

1616
# The documentation will be placed in the "doc/api" folder.
17-
output=$(dart doc --validate-links 2>&1 | tee)
17+
18+
# Disabling --validate-links due to https://github.com/dart-lang/dartdoc/issues/3584
19+
# output=$(dart doc --validate-links 2>&1 | tee)
20+
output=$(dart doc 2>&1 | tee)
1821

1922
echo "${output}"
2023

0 commit comments

Comments
 (0)