-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1101 from lf-lang/bank-index-in-initializers
Allow bank_index in initializers.
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 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
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,43 @@ | ||
// Test bank of reactors to multiport input with id parameter in the bank. | ||
target C; | ||
|
||
preamble {= | ||
int table[] = {4, 3, 2, 1}; | ||
=} | ||
|
||
reactor Source( | ||
bank_index:int(0), | ||
value:int(0) | ||
) { | ||
output out:int; | ||
reaction (startup) -> out {= | ||
SET(out, self->value); | ||
=} | ||
} | ||
|
||
reactor Sink(width:int(4)) { | ||
input[width] in:int; | ||
state received:bool(false); | ||
|
||
reaction (in) {= | ||
for (int idx = 0; idx < in_width; idx++) { | ||
if (in[idx]->is_present) { | ||
printf("Received on channel %d: %d\n", idx, in[idx]->value); | ||
self->received = true; | ||
if (in[idx]->value != 4 - idx) { | ||
error_print_and_exit("Expected %d.", 4 - idx); | ||
} | ||
} | ||
} | ||
=} | ||
reaction(shutdown) {= | ||
if (!self->received) { | ||
error_print_and_exit("Sink received no data."); | ||
} | ||
=} | ||
} | ||
main reactor(width:int(4)) { | ||
source = new[width] Source(value = {= table[bank_index] =}); | ||
sink = new Sink(width = width); | ||
source.out -> sink.in; | ||
} |
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,41 @@ | ||
// Test bank of reactors to multiport input with id parameter in the bank. | ||
target Python; | ||
|
||
preamble {= | ||
table = [4, 3, 2, 1] | ||
=} | ||
|
||
reactor Source( | ||
bank_index(0), | ||
value(0) | ||
) { | ||
output out; | ||
reaction (startup) -> out {= | ||
out.set(self.value) | ||
=} | ||
} | ||
|
||
reactor Sink(width(4)) { | ||
input[width] _in; | ||
state received(false); | ||
|
||
reaction (_in) {= | ||
for (idx, port) in enumerate(_in): | ||
if port.is_present is True: | ||
print("Received on channel {:d}: {:d}".format(idx, port.value)) | ||
self.received = True | ||
if port.value != 4 - idx: | ||
sys.stderr.write("ERROR: expected {:d}\n".format(4 - idx)) | ||
exit(1) | ||
=} | ||
reaction(shutdown) {= | ||
if self.received is False: | ||
sys.stderr.write("ERROR: Sink received no data\n") | ||
exit(1) | ||
=} | ||
} | ||
main reactor(width(4)) { | ||
source = new[width] Source(value = {= table[bank_index] =}); | ||
sink = new Sink(width = width); | ||
source.out -> sink._in; | ||
} |