-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sort ports and internal signals, fix #395
- Loading branch information
Showing
2 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
// sv_gen_test.dart | ||
// Tests for SystemVerilog generation. | ||
// | ||
// 2023 October 4 | ||
// Author: Max Korbel <[email protected]> | ||
|
||
import 'package:collection/collection.dart'; | ||
import 'package:rohd/rohd.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
class AlphabeticalModule extends Module { | ||
AlphabeticalModule() { | ||
final l = addInput('l', Logic()); | ||
final a = addInput('a', Logic()); | ||
final w = addInput('w', Logic()); | ||
|
||
final o = Logic(name: 'o'); | ||
final c = Logic(name: 'c'); | ||
final y = Logic(name: 'y'); | ||
|
||
c <= l & w; | ||
o <= a | l; | ||
y <= w ^ l; | ||
|
||
addOutput('m'); | ||
addOutput('x') <= c + o + y; | ||
addOutput('b'); | ||
} | ||
} | ||
|
||
void main() { | ||
test('input, output, and internal signals are sorted', () async { | ||
final mod = AlphabeticalModule(); | ||
await mod.build(); | ||
final sv = mod.generateSynth(); | ||
|
||
void checkSignalDeclarationOrder(List<String> signalNames) { | ||
final expected = signalNames.map((e) => 'logic $e'); | ||
final indices = expected.map(sv.indexOf); | ||
expect(indices.isSorted((a, b) => a.compareTo(b)), isTrue, | ||
reason: 'Expected order $expected, but indices were $indices'); | ||
} | ||
|
||
checkSignalDeclarationOrder(['a', 'l', 'w']); | ||
checkSignalDeclarationOrder(['b', 'm', 'x']); | ||
checkSignalDeclarationOrder(['c', 'o', 'y']); | ||
}); | ||
} |