From 3b05b243a64b8a9edf94d0a966ae33df17a8535e Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 11 Jul 2022 11:20:24 -0400 Subject: [PATCH 1/5] Typo --- org.lflang/src/org/lflang/generator/PortInstance.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. * From 2887a94eb9f908481f8b8c734e8e93fa24987bbd Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 11 Jul 2022 11:21:20 -0400 Subject: [PATCH 2/5] Fixes Reactions do not consistently trigger banks #1278 --- .../src/org/lflang/generator/c/CTriggerObjectsGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index d55bfb514d..7b58d97f3b 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -781,7 +781,7 @@ private static String deferredFillTriggerTable( } } } - cumulativePortWidth += port.getWidth(); + cumulativePortWidth += port.getWidth() * port.getParent().getTotalWidth(); } if (foundPort) code.endScopedBlock(); } From 3972a67e6edaccf5146feaa2947eb6a20ca02c19 Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 11 Jul 2022 14:13:16 -0400 Subject: [PATCH 3/5] Added test --- test/C/src/multiport/DualBanks.lf | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/C/src/multiport/DualBanks.lf 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); + } + =} +} From 55a52fa673a488efe6ba9283680bd6e5b1c6d62e Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 11 Jul 2022 17:48:17 -0400 Subject: [PATCH 4/5] Second attempt at getting the index increment right --- .../src/org/lflang/generator/c/CTriggerObjectsGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index 7b58d97f3b..fd4b42074b 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -779,9 +779,9 @@ private static String deferredFillTriggerTable( code.endScopedRangeBlock(srcRange, dstRange, isFederated); multicastCount++; } + cumulativePortWidth += srcRange.width; } } - cumulativePortWidth += port.getWidth() * port.getParent().getTotalWidth(); } if (foundPort) code.endScopedBlock(); } From 30a0cdfdbcebcbd4dd95b95f6384b7b81e22e5e4 Mon Sep 17 00:00:00 2001 From: eal Date: Tue, 12 Jul 2022 05:47:24 -0400 Subject: [PATCH 5/5] Third attempt to get indexing right. Added multiport-bank test. --- .../generator/c/CTriggerObjectsGenerator.java | 8 +++- test/C/src/multiport/DualBanksMultiport.lf | 47 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 test/C/src/multiport/DualBanksMultiport.lf diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index fd4b42074b..a8f5af627d 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -779,9 +779,15 @@ private static String deferredFillTriggerTable( code.endScopedRangeBlock(srcRange, dstRange, isFederated); multicastCount++; } - cumulativePortWidth += srcRange.width; } } + // 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/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); + } + =} +}