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

Fix #163 - invalid generated SystemVerilog for bit slicing on expressions #164

Merged
merged 1 commit into from
Sep 27, 2022
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
5 changes: 4 additions & 1 deletion lib/src/modules/bus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class BusSubset extends Module with InlineSystemVerilog {
'Index out of bounds, indices $startIndex and $endIndex must be less than width-1');
}

_original = Module.unpreferredName('original_' + bus.name);
// original name can't be unpreferred because you cannot do a bit slice on expressions
// in SystemVerilog, and other expressions could have been in-lined
_original = 'original_' + bus.name;

_subset =
Module.unpreferredName('subset_${endIndex}_${startIndex}_' + bus.name);

Expand Down
19 changes: 18 additions & 1 deletion test/bus_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class BusTestModule extends Module {
var aBJoined = addOutput('a_b_joined', width: a.width + b.width);
var aPlusB = addOutput('a_plus_b', width: a.width);
var a1 = addOutput('a1');
var expressionBitSelect = addOutput('expression_bit_select', width: 4);

aBar <= ~a;
aAndB <= a & b;
Expand All @@ -52,6 +53,8 @@ class BusTestModule extends Module {
aBJoined <= [b, a].swizzle();
a1 <= a[1];
aPlusB <= a + b;
expressionBitSelect <=
[aBJoined, aShrunk, aRange, aRSliced, aPlusB].swizzle().slice(3, 0);
}
}

Expand Down Expand Up @@ -148,7 +151,8 @@ void main() {
'a_reversed': 8,
'a_range': 3,
'a_b_joined': 16,
'a_plus_b': 8
'a_plus_b': 8,
'expression_bit_select': 4,
};
test('NotGate bus', () async {
var gtm = BusTestModule(Logic(width: 8), Logic(width: 8));
Expand Down Expand Up @@ -291,5 +295,18 @@ void main() {
signalToWidthMap: signalToWidthMap);
expect(simResult, equals(true));
});

test('expression bit select', () async {
var gtm = BusTestModule(Logic(width: 8), Logic(width: 8));
await gtm.build();
var vectors = [
Vector({'a': 1, 'b': 1}, {'expression_bit_select': 2}),
];
await SimCompare.checkFunctionalVector(gtm, vectors);
var simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap, dontDeleteTmpFiles: true);
expect(simResult, equals(true));
});
});
}