Skip to content

Commit

Permalink
[Issue-225] Add Else.s() constructor to for single then execution (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
quekyj authored Jan 4, 2023
1 parent ea3ceba commit 11b411d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/src/modules/conditional.dart
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,12 @@ class Else extends Iff {
/// If none of the proceding [Iff] or [ElseIf] are executed, then
/// [then] will be executed.
Else(List<Conditional> then) : super(Const(1), then);

/// If none of the proceding [Iff] or [ElseIf] are executed, then
/// [then] will be executed.
///
/// Use this constructor when you only have a single [then] condition.
Else.s(Conditional then) : this([then]);
}

/// Represents a chain of blocks of code to be conditionally executed, like
Expand Down
32 changes: 32 additions & 0 deletions test/conditionals_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,23 @@ class SingleIfOrElseModule extends Module {
}
}

class SingleElseModule extends Module {
SingleElseModule(Logic a, Logic b) : super(name: 'combmodule') {
a = addInput('a', a);
b = addInput('b', b);

final q = addOutput('q');
final x = addOutput('x');

Combinational([
IfBlock([
Iff.s(a, q < 1),
Else.s(x < 1),
])
]);
}
}

class SignalRedrivenSequentialModule extends Module {
SignalRedrivenSequentialModule(Logic a, Logic b, Logic d)
: super(name: 'ffmodule') {
Expand Down Expand Up @@ -465,6 +482,21 @@ void main() {
expect(simResult, equals(true));
});

test(
'should return true on simcompare when '
'execute Else.s() for single else conditional', () async {
final mod = SingleElseModule(Logic(), Logic());
await mod.build();
final vectors = [
Vector({'a': 1}, {'q': 1}),
Vector({'a': 0}, {'x': 1}),
];
await SimCompare.checkFunctionalVector(mod, vectors);
final simResult = SimCompare.iverilogVector(
mod.generateSynth(), mod.runtimeType.toString(), vectors);
expect(simResult, equals(true));
});

test(
'should return SignalRedrivenException when there are multiple drivers '
'for a flop.', () async {
Expand Down

0 comments on commit 11b411d

Please sign in to comment.