From cc3c3451a0ab6d4d423111d539e9c9d1cbe01761 Mon Sep 17 00:00:00 2001 From: Shaokai Lin Date: Fri, 16 Sep 2022 15:58:32 -0700 Subject: [PATCH 1/4] Fix the code generator and add a test for #1368. --- .../generator/c/CTriggerObjectsGenerator.java | 3 +++ test/C/src/MultipleOutputs.lf | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/C/src/MultipleOutputs.lf diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index c525ae6a07..4debd09931 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -731,6 +731,9 @@ private static String deferredFillTriggerTable( } var cumulativePortWidth = 0; for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + // If this port does not have any destinations, do not generate code for it. + if (port.eventualDestinations().isEmpty()) continue; + code.pr("for (int i = 0; i < "+reaction.getParent().getTotalWidth()+"; i++) triggers_index[i] = "+cumulativePortWidth+";"); for (SendRange srcRange : port.eventualDestinations()) { if (currentFederate.contains(port.getParent())) { diff --git a/test/C/src/MultipleOutputs.lf b/test/C/src/MultipleOutputs.lf new file mode 100644 index 0000000000..7db09945c9 --- /dev/null +++ b/test/C/src/MultipleOutputs.lf @@ -0,0 +1,22 @@ +// This test checks for one of the issues arised in the solution of EECS149 Lab Chapter 7. +// In this case, a reactor has two output ports, the first one of which is dangling. +// The generated code should not have any segmentation faults. +target C { + timeout: 1 sec, + fast: true +}; +reactor C { + output x:int; + output z:int; + timer t(0, 100 msec); + reaction(t) -> x, z {= + lf_set(x, 42); + lf_set(z, 44); + =} +} +main reactor { + c = new C(); + reaction(c.z) {= + lf_print("c.z = %d", c.z->value); + =} +} \ No newline at end of file From 86284560e38de11dd35ac9c116d4c263e13f0cc8 Mon Sep 17 00:00:00 2001 From: "Shaokai (Jerry) Lin" Date: Fri, 16 Sep 2022 16:18:25 -0700 Subject: [PATCH 2/4] Update test/C/src/MultipleOutputs.lf Co-authored-by: Marten Lohstroh --- test/C/src/MultipleOutputs.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/C/src/MultipleOutputs.lf b/test/C/src/MultipleOutputs.lf index 7db09945c9..8c1559bd71 100644 --- a/test/C/src/MultipleOutputs.lf +++ b/test/C/src/MultipleOutputs.lf @@ -19,4 +19,4 @@ main reactor { reaction(c.z) {= lf_print("c.z = %d", c.z->value); =} -} \ No newline at end of file +} From 0517021c6f6a4d4ccd7105ba74ce054dc87148b4 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 16 Sep 2022 16:45:59 -0700 Subject: [PATCH 3/4] Applied formatter --- test/C/src/MultipleOutputs.lf | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/C/src/MultipleOutputs.lf b/test/C/src/MultipleOutputs.lf index 8c1559bd71..d601a0600d 100644 --- a/test/C/src/MultipleOutputs.lf +++ b/test/C/src/MultipleOutputs.lf @@ -1,22 +1,25 @@ -// This test checks for one of the issues arised in the solution of EECS149 Lab Chapter 7. -// In this case, a reactor has two output ports, the first one of which is dangling. -// The generated code should not have any segmentation faults. +// This test checks for one of the issues arised in the solution of EECS149 Lab +// Chapter 7. In this case, a reactor has two output ports, the first one of +// which is dangling. The generated code should not have any segmentation +// faults. target C { timeout: 1 sec, fast: true -}; +} + reactor C { - output x:int; - output z:int; - timer t(0, 100 msec); + output x: int + output z: int + timer t(0, 100 msec) + reaction(t) -> x, z {= lf_set(x, 42); lf_set(z, 44); =} } + main reactor { - c = new C(); - reaction(c.z) {= - lf_print("c.z = %d", c.z->value); - =} + c = new C() + + reaction(c.z) {= lf_print("c.z = %d", c.z->value); =} } From 15e1df3afe9824e91ff961596125251a68efa2c9 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Fri, 16 Sep 2022 19:02:58 -0700 Subject: [PATCH 4/4] Added check to test as suggested by @edwardalee --- test/C/src/MultipleOutputs.lf | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/C/src/MultipleOutputs.lf b/test/C/src/MultipleOutputs.lf index d601a0600d..8db9e5e6f9 100644 --- a/test/C/src/MultipleOutputs.lf +++ b/test/C/src/MultipleOutputs.lf @@ -20,6 +20,16 @@ reactor C { main reactor { c = new C() + state triggered: bool(true) - reaction(c.z) {= lf_print("c.z = %d", c.z->value); =} + reaction(c.z) {= + lf_print("c.z = %d", c.z->value); + self->triggered = true; + =} + + reaction(shutdown) {= + if (!self->triggered) { + lf_print_error_and_exit("Reaction never triggered.\n"); + } + =} }