diff --git a/org.lflang/src/org/lflang/generator/PortInstance.java b/org.lflang/src/org/lflang/generator/PortInstance.java index 2841d3c854..303a9777b0 100644 --- a/org.lflang/src/org/lflang/generator/PortInstance.java +++ b/org.lflang/src/org/lflang/generator/PortInstance.java @@ -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. * diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index d55bfb514d..a8f5af627d 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -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(); } diff --git a/test/C/src/multiport/DualBanks.lf b/test/C/src/multiport/DualBanks.lf new file mode 100644 index 0000000000..8d5ec2727c --- /dev/null +++ b/test/C/src/multiport/DualBanks.lf @@ -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); + } + =} +} diff --git a/test/C/src/multiport/DualBanksMultiport.lf b/test/C/src/multiport/DualBanksMultiport.lf new file mode 100644 index 0000000000..b3300108f5 --- /dev/null +++ b/test/C/src/multiport/DualBanksMultiport.lf @@ -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); + } + =} +}