Skip to content

Commit

Permalink
Merge pull request #1289 from lf-lang/dual-bank-bugfix
Browse files Browse the repository at this point in the history
Dual bank bugfix
  • Loading branch information
edwardalee authored Jul 12, 2022
2 parents f232b9d + 30a0cdf commit 2f62939
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
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 @@ -780,7 +780,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);
}
=}
}

0 comments on commit 2f62939

Please sign in to comment.