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

Ensure that reactions consistently trigger banks #1289

Merged
merged 5 commits into from
Jul 12, 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
2 changes: 1 addition & 1 deletion org.lflang/src/org/lflang/generator/PortInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY

/**
* Representation of a compile-time instance of a port.
* Like {@link ReactorInstance}, one or more parents of this port
* Like {@link ReactorInstance}, if one or more parents of this port
* is a bank of reactors, then there will be more than one runtime instance
* corresponding to this compile-time instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,13 @@ private static String deferredFillTriggerTable(
}
}
}
cumulativePortWidth += port.getWidth();
// If the port is an input of a contained reactor, then we have to take
// into account the bank width of the contained reactor.
if (port.getParent() != reaction.getParent()) {
cumulativePortWidth += port.getWidth() * port.getParent().getWidth();
} else {
cumulativePortWidth += port.getWidth();
}
}
if (foundPort) code.endScopedBlock();
}
Expand Down
41 changes: 41 additions & 0 deletions test/C/src/multiport/DualBanks.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
target C;

reactor Base(bank_index:int(0)) {
input I:int;
state received:bool(false);

reaction(shutdown) {=
if(!self->received) {
lf_print_error_and_exit("Bank member %d received no input.",
self->bank_index
);
}
=}
}

reactor Hello extends Base {
reaction(I) {=
printf("Hello %d\n", self->bank_index);
self->received = true;
=}
}
reactor World extends Base {
reaction(I) {=
printf("World %d\n", self->bank_index);
self->received = true;
=}
}

main reactor {
hellos = new[3] Hello()
worlds = new[3] World()

reaction(startup) -> hellos.I, worlds.I {=
for(int i = 0; i < hellos_width; i++) {
lf_set(hellos[i].I, true);
}
for(int i = 0; i < worlds_width; i++) {
lf_set(worlds[i].I, true);
}
=}
}
47 changes: 47 additions & 0 deletions test/C/src/multiport/DualBanksMultiport.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
target C;

reactor Base(bank_index:int(0)) {
input[2] I:int;
state received:bool(false);

reaction(shutdown) {=
if(!self->received) {
lf_print_error_and_exit("Bank member %d did not receive all inputs.",
self->bank_index
);
}
=}
}

reactor Hello extends Base {
reaction(I) {=
if (I[0]->is_present && I[1]->is_present) {
printf("Hello %d\n", self->bank_index);
self->received = true;
}
=}
}
reactor World extends Base {
reaction(I) {=
if (I[0]->is_present && I[1]->is_present) {
printf("World %d\n", self->bank_index);
self->received = true;
}
=}
}

main reactor {
hellos = new[3] Hello()
worlds = new[3] World()

reaction(startup) -> hellos.I, worlds.I {=
for(int i = 0; i < hellos_width; i++) {
lf_set(hellos[i].I[0], true);
lf_set(hellos[i].I[1], true);
}
for(int i = 0; i < worlds_width; i++) {
lf_set(worlds[i].I[0], true);
lf_set(worlds[i].I[1], true);
}
=}
}