From 6a95a82a0af58186d016e37c798a18d216617c00 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 18 Sep 2024 11:43:01 -0700 Subject: [PATCH 01/61] Remove Epoch from CI --- .github/workflows/build.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index da1990ca3f..e84f9fce42 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,10 +30,3 @@ jobs: uses: ./.github/actions/report-code-coverage with: files: core/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml,cli/base/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml,cli/lfc/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml,cli/lfd/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml,cli/lff/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml - - epoch: - uses: lf-lang/epoch/.github/workflows/build.yml@main - with: - lingua-franca-ref: ${{ github.head_ref || github.ref_name }} - lingua-franca-repo: ${{ github.event.pull_request.head.repo.full_name }} - upload-artifacts: false From f8785bd0b5895f4d8f32fdf5f942b8bc840ca503 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 18 Sep 2024 15:55:42 -0700 Subject: [PATCH 02/61] Disable FlexPRET tests --- .github/workflows/c-embedded.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/c-embedded.yml b/.github/workflows/c-embedded.yml index f36bf3c73b..df6cfa81c7 100644 --- a/.github/workflows/c-embedded.yml +++ b/.github/workflows/c-embedded.yml @@ -20,6 +20,6 @@ jobs: zephyr: uses: ./.github/workflows/c-zephyr-tests.yml - # Run the C FlexPRET integration tests. - flexpret: - uses: ./.github/workflows/c-flexpret-tests.yml +# # Run the C FlexPRET integration tests. +# flexpret: +# uses: ./.github/workflows/c-flexpret-tests.yml From e702d87ec46fda438baac43be6dbfca09866434c Mon Sep 17 00:00:00 2001 From: erlingrj Date: Mon, 16 Sep 2024 09:33:26 +0200 Subject: [PATCH 03/61] Re-enable Zephyr CI tests --- .github/workflows/c-zephyr-tests.yml | 52 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 53ce259cda..2a69452506 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -39,27 +39,27 @@ jobs: path: core/src/main/resources/lib/c/reactor-c ref: ${{ inputs.runtime-ref }} if: ${{ inputs.runtime-ref }} - # - name: Run Zephyr smoke tests - # run: | - # ./gradlew core:integrationTest \ - # --tests org.lflang.tests.runtime.CZephyrTest.buildZephyrUnthreaded* \ - # --tests org.lflang.tests.runtime.CZephyrTest.buildZephyrThreaded* core:integrationTestCodeCoverageReport - # ./.github/scripts/run-zephyr-tests.sh test/C/src-gen - # rm -rf test/C/src-gen - # - name: Run basic tests - # run: | - # ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildBasic* core:integrationTestCodeCoverageReport - # ./.github/scripts/run-zephyr-tests.sh test/C/src-gen - # rm -rf test/C/src-gen - # - name: Run concurrent tests - # run: | - # ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildConcurrent* core:integrationTestCodeCoverageReport - # ./.github/scripts/run-zephyr-tests.sh test/C/src-gen - # rm -rf test/C/src-gen - # - name: Run Zephyr board tests - # run: | - # ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildZephyrBoards* core:integrationTestCodeCoverageReport - # rm -rf test/C/src-gen + - name: Run Zephyr smoke tests + run: | + ./gradlew core:integrationTest \ + --tests org.lflang.tests.runtime.CZephyrTest.buildZephyrUnthreaded* \ + --tests org.lflang.tests.runtime.CZephyrTest.buildZephyrThreaded* core:integrationTestCodeCoverageReport + ./.github/scripts/run-zephyr-tests.sh test/C/src-gen + rm -rf test/C/src-gen + - name: Run basic tests + run: | + ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildBasic* core:integrationTestCodeCoverageReport + ./.github/scripts/run-zephyr-tests.sh test/C/src-gen + rm -rf test/C/src-gen + - name: Run concurrent tests + run: | + ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildConcurrent* core:integrationTestCodeCoverageReport + ./.github/scripts/run-zephyr-tests.sh test/C/src-gen + rm -rf test/C/src-gen + - name: Run Zephyr board tests + run: | + ./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildZephyrBoards* core:integrationTestCodeCoverageReport + rm -rf test/C/src-gen - name: Smoke test of lf-west-template run: | export LFC=$(pwd)/bin/lfc-dev @@ -68,8 +68,8 @@ jobs: west lfc apps/NrfBlinky/src/NrfBlinky.lf --lfc $LFC --build "-p always" west lfc apps/NrfBlinky/src/NrfToggleGPIO.lf --lfc $LFC --build "-p always" west build -b qemu_cortex_m3 -p always apps/HelloZephyr - # - name: Report to CodeCov - # uses: ./.github/actions/report-code-coverage - # with: - # files: core/build/reports/jacoco/integrationTestCodeCoverageReport/integrationTestCodeCoverageReport.xml - # if: ${{ github.repository == 'lf-lang/lingua-franca' }} + - name: Report to CodeCov + uses: ./.github/actions/report-code-coverage + with: + files: core/build/reports/jacoco/integrationTestCodeCoverageReport/integrationTestCodeCoverageReport.xml + if: ${{ github.repository == 'lf-lang/lingua-franca' }} From d1b1c9e1e1f9b7c57c49a2baf35f8e38699048ee Mon Sep 17 00:00:00 2001 From: erlingrj Date: Mon, 16 Sep 2024 19:39:16 +0200 Subject: [PATCH 04/61] Update to Zephyr v3.7.0 --- .github/actions/setup-zephyr/action.yml | 2 +- .../src/main/java/org/lflang/generator/c/CCmakeGenerator.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/setup-zephyr/action.yml b/.github/actions/setup-zephyr/action.yml index 06baf10907..e0c55059c4 100644 --- a/.github/actions/setup-zephyr/action.yml +++ b/.github/actions/setup-zephyr/action.yml @@ -5,7 +5,7 @@ runs: steps: - name: Setup environment variables run: | - echo "SDK_VERSION=0.16.3" >> $GITHUB_ENV + echo "SDK_VERSION=0.16.8" >> $GITHUB_ENV shell: bash - name: Dependencies run: | diff --git a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java index 2cf6f58239..e184faedd6 100644 --- a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java @@ -158,8 +158,8 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("# Selecting default board"); cMakeCode.pr("set(BOARD qemu_cortex_m3)"); } - cMakeCode.pr("# We recommend Zephyr v3.4.0 but we are compatible with older versions also"); - cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} 3.4.0)"); + cMakeCode.pr("# We recommend Zephyr v3.7.0 but we are compatible with older versions also"); + cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} 3.7.0)"); cMakeCode.newLine(); cMakeCode.pr("project(" + executableName + " LANGUAGES C)"); cMakeCode.newLine(); From 26c595d75a63fa00e9c25d0a0acf2d5001ebb637 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Mon, 16 Sep 2024 20:02:06 +0200 Subject: [PATCH 05/61] Update FlexPRET CI to reflect recent changes --- .github/actions/setup-flexpret/action.yml | 19 ++++--------------- .github/workflows/c-flexpret-tests.yml | 1 - 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/.github/actions/setup-flexpret/action.yml b/.github/actions/setup-flexpret/action.yml index 9866c15c6b..e97521d66a 100644 --- a/.github/actions/setup-flexpret/action.yml +++ b/.github/actions/setup-flexpret/action.yml @@ -9,23 +9,12 @@ runs: git clone --recurse-submodules https://github.com/pretis/flexpret # This rest is copied directly from FlexPRET's `azure-pipelines.yml` - - # Ubuntu 20.04 only has Verilator 4.028 but we neeed a more modern version - # so we do not use 'sudo apt-get install -y -qq verilator' here. - wget -q https://github.com/sifive/verilator/releases/download/4.036-0sifive2/verilator_4.036-0sifive2_amd64.deb -O verilator.deb - sudo dpkg -i verilator.deb + sudo apt install verilator # Install riscv compiler - wget https://github.com/stnolting/riscv-gcc-prebuilt/releases/download/rv32i-4.0.0/riscv32-unknown-elf.gcc-12.1.0.tar.gz - sudo mkdir /opt/riscv - sudo tar -xzf riscv32-unknown-elf.gcc-12.1.0.tar.gz -C /opt/riscv/ - rm riscv32-unknown-elf.gcc-12.1.0.tar.gz - - # Update submodules - git submodule update --init --recursive - - # Save location of RISC-V compiler to reuse later - echo "FP_RISCV_COMPILER=/opt/riscv" >> "$GITHUB_ENV" + wget -q --show-progress https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v14.2.0-2/xpack-riscv-none-elf-gcc-14.2.0-2-linux-x64.tar.gz -O gcc.tar.gz + tar xvf gcc.tar.gz --directory=/opt + echo "RISCV_TOOL_PATH_PREFIX=/opt/xpack-riscv-none-elf-gcc-14.2.0-2" >> $GITHUB_ENV shell: bash - name: Build FlexPRET and install to SDK run: | diff --git a/.github/workflows/c-flexpret-tests.yml b/.github/workflows/c-flexpret-tests.yml index 0df6abe62f..d6c4eb9ad4 100644 --- a/.github/workflows/c-flexpret-tests.yml +++ b/.github/workflows/c-flexpret-tests.yml @@ -46,7 +46,6 @@ jobs: - name: Run FlexPRET smoke tests run: | cd "$FP_DIR" && source env.bash && cd - - export RISCV_TOOL_PATH_PREFIX=$FP_RISCV_COMPILER ./gradlew core:integrationTest \ --tests org.lflang.tests.runtime.CFlexPRETTest.* \ core:integrationTestCodeCoverageReport From 5c4a7cea3484b903e88135e3a2f846c97d53b521 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Mon, 16 Sep 2024 21:12:08 +0200 Subject: [PATCH 06/61] Bump reactor-c --- core/src/main/resources/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 26cc23b5ee..42d4334be9 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 26cc23b5eeb0bd6dcb49b00824e5ae5ac28b3b44 +Subproject commit 42d4334be9c21facdb3a02339843b1767bbaf4bf From bf9e8dbdf87c760f7d7f4dc3eb311e1a6b997c82 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 17 Sep 2024 14:22:38 +0200 Subject: [PATCH 07/61] Increase timeout of Zephyr tests --- .github/scripts/run-zephyr-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/run-zephyr-tests.sh b/.github/scripts/run-zephyr-tests.sh index d1c1d1c4e9..48a956da7b 100755 --- a/.github/scripts/run-zephyr-tests.sh +++ b/.github/scripts/run-zephyr-tests.sh @@ -45,7 +45,7 @@ run_qemu_zephyr_test() { pid=$! return_val=2 wait_count=0 - timeout=60 + timeout=120 # Parse the file and match on known outputs. With timeout. while [ "$wait_count" -le "$timeout" ]; do sleep 1 From 5319a20df8e43eb78ca391568a01ef9e6720cbb4 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 19 Sep 2024 08:54:42 +0200 Subject: [PATCH 08/61] Bump reactor-c --- core/src/main/resources/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 42d4334be9..dc9e9fdcf0 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 42d4334be9c21facdb3a02339843b1767bbaf4bf +Subproject commit dc9e9fdcf070b25270ca349ca5895628d9118529 From 00819c779f83a220572acfbc3f5029aec774889c Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 19 Sep 2024 10:01:24 +0200 Subject: [PATCH 09/61] Investigate failing zephyr test --- test/C/src/zephyr/threaded/ScheduleAt.lf | 87 ++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 test/C/src/zephyr/threaded/ScheduleAt.lf diff --git a/test/C/src/zephyr/threaded/ScheduleAt.lf b/test/C/src/zephyr/threaded/ScheduleAt.lf new file mode 100644 index 0000000000..7caf03b0fe --- /dev/null +++ b/test/C/src/zephyr/threaded/ScheduleAt.lf @@ -0,0 +1,87 @@ +/** + * Test _lf_schedule_at_tag which is an internal API function not meant to be used in user code. + * + * @author Soroush Bateni + */ +target C { + timeout: 1 sec, + keepalive: true, + platform: "Zephyr" +} + +reactor Scheduler { + preamble {= + #ifdef __cplusplus + extern "C" { + #endif + #include "include/core/reactor_common.h" + #ifdef __cplusplus + } + #endif + =} + logical action act + // List of microsteps. Size = 16 + state microstep_delay_list: uint32_t[] = {0, 1, 1, 2, 2, 0, 0, 1, 1, 0, 2, 3, 3, 4, 4, 5} + + state times: int[] = { + 0, + 0, + 0, + 0, + 0, + 400 msec, + 400 msec, + 400 msec, + 400 msec, // List of the corresponding times. Size = 16 + 800 msec, + 800 msec, + 800 msec, + 800 msec, + 900 msec, + 900 msec, + 900 msec} + // Size = 9 + state action_hit_list_microstep: int[] = {1, 2, 0, 1, 0, 2, 3, 4, 5} + state action_hit_list_times: int[] = { + 0, + 0, + 400 msec, + 400 msec, + 800 msec, + 800 msec, + 800 msec, + 900 msec, + 900 msec} + // Size = 9 + state action_hit_list_index: int = 0 + + reaction(startup) -> act {= + for (int i=0; i < 16; i++) { + _lf_schedule_at_tag(self->base.environment, act->_base.trigger, + (tag_t) { .time = self->times[i] + lf_time_logical(), .microstep = self->microstep_delay_list[i]}, + NULL); + } + =} + + reaction(act) {= + microstep_t microstep = lf_tag().microstep; + instant_t elapsed_time = lf_time_logical_elapsed(); + if (elapsed_time == self->action_hit_list_times[self->action_hit_list_index] && + microstep == self->action_hit_list_microstep[self->action_hit_list_index]) { + self->action_hit_list_index++; + } + printf("Triggered at tag (" PRINTF_TIME ", %u).\n", elapsed_time, microstep); + =} + + reaction(shutdown) {= + if (self->action_hit_list_index != 9) { + fprintf(stderr, "ERROR: incorrect number of actions were correctly scheduled: %d.", self->action_hit_list_index); + exit(1); + } + printf("SUCCESS: successfully scheduled all the events.\n"); + =} +} + +main reactor ScheduleAt { + sender = new Scheduler() +} From f6f8ff34afdb162ed30e042e3c65f60f230989a5 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 20 Sep 2024 17:22:26 -0700 Subject: [PATCH 10/61] Fix memory error in ScheduleAt --- test/C/src/concurrent/ScheduleAt.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/C/src/concurrent/ScheduleAt.lf b/test/C/src/concurrent/ScheduleAt.lf index a32cb47cbe..5997dfdc37 100644 --- a/test/C/src/concurrent/ScheduleAt.lf +++ b/test/C/src/concurrent/ScheduleAt.lf @@ -65,7 +65,7 @@ reactor Scheduler { reaction(act) {= microstep_t microstep = lf_tag().microstep; instant_t elapsed_time = lf_time_logical_elapsed(); - if (elapsed_time == self->action_hit_list_times[self->action_hit_list_index] && + if (self->action_hit_list_index < 9 && elapsed_time == self->action_hit_list_times[self->action_hit_list_index] && microstep == self->action_hit_list_microstep[self->action_hit_list_index]) { self->action_hit_list_index++; } From 5f096d72e630cf10e6d697b2dce5a26d59e51c6e Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 20 Sep 2024 17:22:40 -0700 Subject: [PATCH 11/61] Enable CBPRINTF for Zephyr --- core/src/main/resources/lib/platform/zephyr/prj_lf.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/resources/lib/platform/zephyr/prj_lf.conf b/core/src/main/resources/lib/platform/zephyr/prj_lf.conf index 5b026c5035..a63d1db027 100644 --- a/core/src/main/resources/lib/platform/zephyr/prj_lf.conf +++ b/core/src/main/resources/lib/platform/zephyr/prj_lf.conf @@ -3,6 +3,7 @@ # Enable printf CONFIG_PRINTK=y +CONFIG_CBPRINTF_LIBC_SUBSTS=y # Use the newlib C library CONFIG_NEWLIB_LIBC=y CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y From e82aa389e87b1c4725ece708bed739f4781f4ec4 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 20 Sep 2024 17:22:51 -0700 Subject: [PATCH 12/61] Bump reactor-c --- core/src/main/resources/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index dc9e9fdcf0..85e56ecbcc 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit dc9e9fdcf070b25270ca349ca5895628d9118529 +Subproject commit 85e56ecbcc557b4b31d63e6896fa205d699472eb From 6bbd6af0e0af21c047ec363b8ee21d72a753604f Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 20 Sep 2024 17:23:34 -0700 Subject: [PATCH 13/61] Remove duplicate test --- test/C/src/zephyr/{threaded => threaded copy}/ScheduleAt.lf | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/C/src/zephyr/{threaded => threaded copy}/ScheduleAt.lf (100%) diff --git a/test/C/src/zephyr/threaded/ScheduleAt.lf b/test/C/src/zephyr/threaded copy/ScheduleAt.lf similarity index 100% rename from test/C/src/zephyr/threaded/ScheduleAt.lf rename to test/C/src/zephyr/threaded copy/ScheduleAt.lf From be48720773b38e76630cb6c2ad3f2dac922b4406 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 20 Sep 2024 17:34:44 -0700 Subject: [PATCH 14/61] Remove mistakenly commited test --- test/C/src/zephyr/threaded copy/ScheduleAt.lf | 87 ------------------- 1 file changed, 87 deletions(-) delete mode 100644 test/C/src/zephyr/threaded copy/ScheduleAt.lf diff --git a/test/C/src/zephyr/threaded copy/ScheduleAt.lf b/test/C/src/zephyr/threaded copy/ScheduleAt.lf deleted file mode 100644 index 7caf03b0fe..0000000000 --- a/test/C/src/zephyr/threaded copy/ScheduleAt.lf +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Test _lf_schedule_at_tag which is an internal API function not meant to be used in user code. - * - * @author Soroush Bateni - */ -target C { - timeout: 1 sec, - keepalive: true, - platform: "Zephyr" -} - -reactor Scheduler { - preamble {= - #ifdef __cplusplus - extern "C" { - #endif - #include "include/core/reactor_common.h" - #ifdef __cplusplus - } - #endif - =} - logical action act - // List of microsteps. Size = 16 - state microstep_delay_list: uint32_t[] = {0, 1, 1, 2, 2, 0, 0, 1, 1, 0, 2, 3, 3, 4, 4, 5} - - state times: int[] = { - 0, - 0, - 0, - 0, - 0, - 400 msec, - 400 msec, - 400 msec, - 400 msec, // List of the corresponding times. Size = 16 - 800 msec, - 800 msec, - 800 msec, - 800 msec, - 900 msec, - 900 msec, - 900 msec} - // Size = 9 - state action_hit_list_microstep: int[] = {1, 2, 0, 1, 0, 2, 3, 4, 5} - state action_hit_list_times: int[] = { - 0, - 0, - 400 msec, - 400 msec, - 800 msec, - 800 msec, - 800 msec, - 900 msec, - 900 msec} - // Size = 9 - state action_hit_list_index: int = 0 - - reaction(startup) -> act {= - for (int i=0; i < 16; i++) { - _lf_schedule_at_tag(self->base.environment, act->_base.trigger, - (tag_t) { .time = self->times[i] + lf_time_logical(), .microstep = self->microstep_delay_list[i]}, - NULL); - } - =} - - reaction(act) {= - microstep_t microstep = lf_tag().microstep; - instant_t elapsed_time = lf_time_logical_elapsed(); - if (elapsed_time == self->action_hit_list_times[self->action_hit_list_index] && - microstep == self->action_hit_list_microstep[self->action_hit_list_index]) { - self->action_hit_list_index++; - } - printf("Triggered at tag (" PRINTF_TIME ", %u).\n", elapsed_time, microstep); - =} - - reaction(shutdown) {= - if (self->action_hit_list_index != 9) { - fprintf(stderr, "ERROR: incorrect number of actions were correctly scheduled: %d.", self->action_hit_list_index); - exit(1); - } - printf("SUCCESS: successfully scheduled all the events.\n"); - =} -} - -main reactor ScheduleAt { - sender = new Scheduler() -} From a748f4f0598edea8cdc9456e26508055ecfd964a Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 20 Sep 2024 21:33:51 -0700 Subject: [PATCH 15/61] Bump reactor-c --- core/src/main/resources/lib/c/reactor-c | 2 +- core/src/main/resources/lib/platform/zephyr/prj_lf.conf | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 85e56ecbcc..8986632a79 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 85e56ecbcc557b4b31d63e6896fa205d699472eb +Subproject commit 8986632a796c444b3e498a7d4226f52fb2c93cb6 diff --git a/core/src/main/resources/lib/platform/zephyr/prj_lf.conf b/core/src/main/resources/lib/platform/zephyr/prj_lf.conf index a63d1db027..5b026c5035 100644 --- a/core/src/main/resources/lib/platform/zephyr/prj_lf.conf +++ b/core/src/main/resources/lib/platform/zephyr/prj_lf.conf @@ -3,7 +3,6 @@ # Enable printf CONFIG_PRINTK=y -CONFIG_CBPRINTF_LIBC_SUBSTS=y # Use the newlib C library CONFIG_NEWLIB_LIBC=y CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y From e3f5a6b9572d9ef8fd717dba761a6b89f548352c Mon Sep 17 00:00:00 2001 From: erlingrj Date: Sat, 21 Sep 2024 06:40:52 -0700 Subject: [PATCH 16/61] Dont run zephyr tests that spawn several user threads for scheduling actios --- .github/scripts/run-zephyr-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/run-zephyr-tests.sh b/.github/scripts/run-zephyr-tests.sh index 48a956da7b..2f1982d80f 100755 --- a/.github/scripts/run-zephyr-tests.sh +++ b/.github/scripts/run-zephyr-tests.sh @@ -1,7 +1,7 @@ #!/bin/bash # Skip -skip=("FileReader" "FilePkgReader") +skip=("FileReader" "FilePkgReader" "AsyncCallback" "AsyncCallbackDrop" "AsyncCallbackReplace") find_kconfig_folders() { if [ -f "$folder/CMakeLists.txt" ]; then From 5b3d9ae46fe7a46bfdf686828c8b0d9b4d17ea59 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Sat, 21 Sep 2024 06:41:10 -0700 Subject: [PATCH 17/61] Increase Zephyr main stack size to avoid stack overflow in a test --- core/src/main/resources/lib/platform/zephyr/prj_lf.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/resources/lib/platform/zephyr/prj_lf.conf b/core/src/main/resources/lib/platform/zephyr/prj_lf.conf index 5b026c5035..20ed364571 100644 --- a/core/src/main/resources/lib/platform/zephyr/prj_lf.conf +++ b/core/src/main/resources/lib/platform/zephyr/prj_lf.conf @@ -7,3 +7,4 @@ CONFIG_PRINTK=y CONFIG_NEWLIB_LIBC=y CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y CONFIG_THREAD_CUSTOM_DATA=y +CONFIG_MAIN_STACK_SIZE=2048 From f1616d800253bcb2e0211d8ec5abe555de1cb1f6 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sat, 21 Sep 2024 22:00:27 -0700 Subject: [PATCH 18/61] Update reactor-c submodule --- core/src/main/resources/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 8986632a79..e0eae5fe52 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 8986632a796c444b3e498a7d4226f52fb2c93cb6 +Subproject commit e0eae5fe520a94c2cf198c4a904d7f60d7e34a1e From 86e5bb7cceb1724cb92e03fe913a15b555a397ad Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 24 Sep 2024 13:52:57 -0700 Subject: [PATCH 19/61] For actions, add the status field to the is_present_fields array --- .../org/lflang/generator/c/CGenerator.java | 6 ++-- core/src/main/resources/lib/c/reactor-c | 2 +- test/C/src/ActionIsPresentReset.lf | 30 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 test/C/src/ActionIsPresentReset.lf diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 789b6dbef5..f607dd4449 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1468,11 +1468,11 @@ private void generateStartTimeStep(ReactorInstance instance) { "\n", "// Add action " + action.getFullName() + " to array of is_present fields.", enclaveStruct + ".is_present_fields[" + enclaveInfo.numIsPresentFields + "] ", - " = &" + " = (bool *) &" + containerSelfStructName - + "->_lf_" + + "->_lf__" + action.getName() - + ".is_present;")); + + ".status;")); // Intended_tag is only applicable to actions in federated execution with decentralized // coordination. diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index e0eae5fe52..dc0376d97c 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit e0eae5fe520a94c2cf198c4a904d7f60d7e34a1e +Subproject commit dc0376d97c9ac4f46becf04b2d096e6b57099158 diff --git a/test/C/src/ActionIsPresentReset.lf b/test/C/src/ActionIsPresentReset.lf new file mode 100644 index 0000000000..596dedec26 --- /dev/null +++ b/test/C/src/ActionIsPresentReset.lf @@ -0,0 +1,30 @@ +target C { + timeout: 7 msecs, + fast: true +} + +main reactor { + logical action a; + logical action b; + + reaction(startup) -> a {= + lf_schedule(a, MSEC(1)); + =} + + reaction(a, b) -> a, b {= + if (a->is_present) { + printf("A"); + lf_schedule(b, MSEC(2)); + } + if (b->is_present) { + printf("B"); + lf_schedule(a, MSEC(1)); + } + + lf_print(" at %d msecs with triggers (%d,%d)", lf_time_logical_elapsed() / MSEC(1), a->is_present, b->is_present); + + if (a->is_present && b->is_present) { + lf_print_error_and_exit("Both triggers should not be present"); + } + =} +} \ No newline at end of file From cf1ecac689f4498f6578086338a7a29c04460e68 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 24 Sep 2024 16:13:13 -0700 Subject: [PATCH 20/61] Fix code-generator issues with is_present_fields and multiport and banks --- .../org/lflang/generator/c/CGenerator.java | 21 +++++++++++++++---- core/src/main/resources/lib/c/reactor-c | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index f607dd4449..6ae3e9590b 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1426,6 +1426,8 @@ private void generateStartTimeStep(ReactorInstance instance) { temp.pr( enclaveStruct + ".is_present_fields[" + + CUtil.bankIndex(instance) + + " + " + enclaveInfo.numIsPresentFields + " + count] = &" + portRef @@ -1436,6 +1438,8 @@ private void generateStartTimeStep(ReactorInstance instance) { CExtensionUtils.surroundWithIfFederatedDecentralized( enclaveStruct + "._lf_intended_tag_fields[" + + CUtil.bankIndex(instance) + + " + " + enclaveInfo.numIsPresentFields + " + count] = &" + portRef @@ -1461,13 +1465,14 @@ private void generateStartTimeStep(ReactorInstance instance) { for (ActionInstance action : instance.actions) { foundOne = true; + temp.startScopedBlock(); + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); temp.startScopedBlock(instance); - temp.pr( String.join( "\n", "// Add action " + action.getFullName() + " to array of is_present fields.", - enclaveStruct + ".is_present_fields[" + enclaveInfo.numIsPresentFields + "] ", + enclaveStruct + ".is_present_fields[" + CUtil.bankIndex(instance) + " + " + enclaveInfo.numIsPresentFields + " + count] ", " = (bool *) &" + containerSelfStructName + "->_lf__" @@ -1483,16 +1488,20 @@ private void generateStartTimeStep(ReactorInstance instance) { "// Add action " + action.getFullName() + " to array of intended_tag fields.", enclaveStruct + "._lf_intended_tag_fields[" + + CUtil.bankIndex(instance) + + " + " + enclaveInfo.numIsPresentFields - + "] ", + + "+ count] ", " = &" + containerSelfStructName + "->_lf_" + action.getName() + ".intended_tag;"))); - enclaveInfo.numIsPresentFields += action.getParent().getTotalWidth(); + temp.pr("count++;"); temp.endScopedBlock(); + temp.endScopedBlock(); + enclaveInfo.numIsPresentFields += action.getParent().getTotalWidth(); } if (foundOne) startTimeStep.pr(temp.toString()); temp = new CodeBuilder(); @@ -1515,6 +1524,8 @@ private void generateStartTimeStep(ReactorInstance instance) { temp.pr( enclaveStruct + ".is_present_fields[" + + CUtil.bankIndex(instance) + + " + " + enclaveInfo.numIsPresentFields + " + count] = &" + CUtil.portRef(output) @@ -1529,6 +1540,8 @@ private void generateStartTimeStep(ReactorInstance instance) { "// Add port " + output.getFullName() + " to array of intended_tag fields.", enclaveStruct + "._lf_intended_tag_fields[" + + CUtil.bankIndex(instance) + + " + rt" + enclaveInfo.numIsPresentFields + " + count] = &" + CUtil.portRef(output) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index dc0376d97c..1d79e1162f 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit dc0376d97c9ac4f46becf04b2d096e6b57099158 +Subproject commit 1d79e1162f8f07b4f396b3b325a02567ed87cbef From 4e47ce96c6758f0d8886057e632409ac2044f87a Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 24 Sep 2024 16:25:29 -0700 Subject: [PATCH 21/61] Fix minor typos --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 2 +- core/src/main/resources/lib/c/reactor-c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 6ae3e9590b..0a07e545c3 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1541,7 +1541,7 @@ private void generateStartTimeStep(ReactorInstance instance) { enclaveStruct + "._lf_intended_tag_fields[" + CUtil.bankIndex(instance) - + " + rt" + + " + " + enclaveInfo.numIsPresentFields + " + count] = &" + CUtil.portRef(output) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 1d79e1162f..b17ed4fdf3 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 1d79e1162f8f07b4f396b3b325a02567ed87cbef +Subproject commit b17ed4fdf3fbf44391fd5ffb0b528cf420634ee1 From e01c51df3bc3e1483635ccf6008e2fdf251c1d1c Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 24 Sep 2024 18:25:22 -0700 Subject: [PATCH 22/61] Try getting the action is_present field setup correct --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 0a07e545c3..ff07f0ba55 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1465,14 +1465,11 @@ private void generateStartTimeStep(ReactorInstance instance) { for (ActionInstance action : instance.actions) { foundOne = true; - temp.startScopedBlock(); - temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - temp.startScopedBlock(instance); temp.pr( String.join( "\n", "// Add action " + action.getFullName() + " to array of is_present fields.", - enclaveStruct + ".is_present_fields[" + CUtil.bankIndex(instance) + " + " + enclaveInfo.numIsPresentFields + " + count] ", + enclaveStruct + ".is_present_fields[" + CUtil.bankIndex(instance) + " + " + enclaveInfo.numIsPresentFields + "] ", " = (bool *) &" + containerSelfStructName + "->_lf__" @@ -1498,9 +1495,6 @@ private void generateStartTimeStep(ReactorInstance instance) { + action.getName() + ".intended_tag;"))); - temp.pr("count++;"); - temp.endScopedBlock(); - temp.endScopedBlock(); enclaveInfo.numIsPresentFields += action.getParent().getTotalWidth(); } if (foundOne) startTimeStep.pr(temp.toString()); From 9104111dfd1fcb0624a3c3aabce42f6a1d11d73c Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 24 Sep 2024 18:26:11 -0700 Subject: [PATCH 23/61] Bump reactor-c --- core/src/main/resources/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index b17ed4fdf3..6650f3616d 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit b17ed4fdf3fbf44391fd5ffb0b528cf420634ee1 +Subproject commit 6650f3616dde885393d97f5732645e4a60da8596 From 5a2f8cde1dadd9c15a8e96be37972a9b5dafe254 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 24 Sep 2024 21:56:12 -0700 Subject: [PATCH 24/61] Typo --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index ff07f0ba55..ac3dd54c42 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1488,7 +1488,7 @@ private void generateStartTimeStep(ReactorInstance instance) { + CUtil.bankIndex(instance) + " + " + enclaveInfo.numIsPresentFields - + "+ count] ", + + "]", " = &" + containerSelfStructName + "->_lf_" From 08762b6631ed812ebbaac5c62cd077c070f3978b Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 25 Sep 2024 07:56:01 -0700 Subject: [PATCH 25/61] Trial and error... --- .../org/lflang/generator/c/CGenerator.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index ac3dd54c42..30ffe08bec 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1375,10 +1375,6 @@ private void recordBuiltinTriggers(ReactorInstance instance) { } } - /** - * Generate code to set up the tables used in _lf_start_time_step to decrement reference counts - * and mark outputs absent between time steps. This function puts the code into startTimeStep. - */ /** * Generate code to set up the tables used in _lf_start_time_step to decrement reference counts * and mark outputs absent between time steps. This function puts the code into startTimeStep. @@ -1465,11 +1461,17 @@ private void generateStartTimeStep(ReactorInstance instance) { for (ActionInstance action : instance.actions) { foundOne = true; + temp.startScopedBlock(); + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); + temp.startScopedBlock(instance); temp.pr( String.join( "\n", "// Add action " + action.getFullName() + " to array of is_present fields.", - enclaveStruct + ".is_present_fields[" + CUtil.bankIndex(instance) + " + " + enclaveInfo.numIsPresentFields + "] ", + enclaveStruct + + ".is_present_fields[" + + enclaveInfo.numIsPresentFields + + " + count] ", " = (bool *) &" + containerSelfStructName + "->_lf__" @@ -1485,17 +1487,18 @@ private void generateStartTimeStep(ReactorInstance instance) { "// Add action " + action.getFullName() + " to array of intended_tag fields.", enclaveStruct + "._lf_intended_tag_fields[" - + CUtil.bankIndex(instance) - + " + " + enclaveInfo.numIsPresentFields - + "]", + + " + count]", " = &" + containerSelfStructName + "->_lf_" + action.getName() + ".intended_tag;"))); - enclaveInfo.numIsPresentFields += action.getParent().getTotalWidth(); + temp.pr("count++;"); + temp.endScopedBlock(); + temp.endScopedBlock(); + enclaveInfo.numIsPresentFields += action.getParent().getTotalWidth(); } if (foundOne) startTimeStep.pr(temp.toString()); temp = new CodeBuilder(); @@ -1518,8 +1521,6 @@ private void generateStartTimeStep(ReactorInstance instance) { temp.pr( enclaveStruct + ".is_present_fields[" - + CUtil.bankIndex(instance) - + " + " + enclaveInfo.numIsPresentFields + " + count] = &" + CUtil.portRef(output) @@ -1534,8 +1535,6 @@ private void generateStartTimeStep(ReactorInstance instance) { "// Add port " + output.getFullName() + " to array of intended_tag fields.", enclaveStruct + "._lf_intended_tag_fields[" - + CUtil.bankIndex(instance) - + " + " + enclaveInfo.numIsPresentFields + " + count] = &" + CUtil.portRef(output) From 8d29e6b4de9ffe1dadd4cd916b75f9a34906567b Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 25 Sep 2024 08:02:38 -0700 Subject: [PATCH 26/61] Spotless --- .../java/org/lflang/generator/c/CGenerator.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 30ffe08bec..1e8406fa04 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1468,10 +1468,7 @@ private void generateStartTimeStep(ReactorInstance instance) { String.join( "\n", "// Add action " + action.getFullName() + " to array of is_present fields.", - enclaveStruct - + ".is_present_fields[" - + enclaveInfo.numIsPresentFields - + " + count] ", + enclaveStruct + ".is_present_fields[" + enclaveInfo.numIsPresentFields + " + count] ", " = (bool *) &" + containerSelfStructName + "->_lf__" @@ -1495,10 +1492,10 @@ private void generateStartTimeStep(ReactorInstance instance) { + action.getName() + ".intended_tag;"))); - temp.pr("count++;"); - temp.endScopedBlock(); - temp.endScopedBlock(); - enclaveInfo.numIsPresentFields += action.getParent().getTotalWidth(); + temp.pr("count++;"); + temp.endScopedBlock(); + temp.endScopedBlock(); + enclaveInfo.numIsPresentFields += action.getParent().getTotalWidth(); } if (foundOne) startTimeStep.pr(temp.toString()); temp = new CodeBuilder(); From be745a4f3d6ad1c7dc7e27f996a0cef0626640e7 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 25 Sep 2024 08:34:59 -0700 Subject: [PATCH 27/61] More trials --- .../main/java/org/lflang/generator/c/CGenerator.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 1e8406fa04..b097b883bd 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1513,11 +1513,14 @@ private void generateStartTimeStep(ReactorInstance instance) { for (PortInstance output : child.outputs) { if (!output.getDependsOnReactions().isEmpty()) { foundOne = true; - temp.pr("// Add port " + output.getFullName() + " to array of is_present fields."); + temp.pr( + "// Add output port " + output.getFullName() + " to array of is_present fields."); temp.startChannelIteration(output); temp.pr( enclaveStruct + ".is_present_fields[" + + CUtil.bankIndex(instance) + + " + " + enclaveInfo.numIsPresentFields + " + count] = &" + CUtil.portRef(output) @@ -1529,9 +1532,13 @@ private void generateStartTimeStep(ReactorInstance instance) { CExtensionUtils.surroundWithIfFederatedDecentralized( String.join( "\n", - "// Add port " + output.getFullName() + " to array of intended_tag fields.", + "// Add output port " + + output.getFullName() + + " to array of intended_tag fields.", enclaveStruct + "._lf_intended_tag_fields[" + + CUtil.bankIndex(instance) + + " + " + enclaveInfo.numIsPresentFields + " + count] = &" + CUtil.portRef(output) From 6a9be53a57e7ad01b5cf9823efccf7555153966a Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 25 Sep 2024 15:49:47 -0700 Subject: [PATCH 28/61] Rework the assignment add some smoke tests --- .../org/lflang/generator/c/CGenerator.java | 86 ++++++++++++++----- .../multiport/BankMultiportIsPresentSetup.lf | 29 +++++++ .../multiport/BankOfActionsIsPresentSetup.lf | 26 ++++++ 3 files changed, 118 insertions(+), 23 deletions(-) create mode 100644 test/C/src/multiport/BankMultiportIsPresentSetup.lf create mode 100644 test/C/src/multiport/BankOfActionsIsPresentSetup.lf diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index b097b883bd..f220da6904 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1395,6 +1395,17 @@ private void generateStartTimeStep(ReactorInstance instance) { // port so we have to avoid listing the port more than once. var portsSeen = new LinkedHashSet(); for (ReactionInstance reaction : instance.reactions) { + + // Need to find the total number of channels over all output ports of the child before + // generating the + // iteration. + var totalChannelCount = 0; + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { + totalChannelCount += port.getWidth(); + } + } + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { portsSeen.add(port); @@ -1419,13 +1430,19 @@ private void generateStartTimeStep(ReactorInstance instance) { var portRef = CUtil.portRefNested(port); var con = (port.isMultiport()) ? "->" : "."; + var indexString = + String.valueOf(enclaveInfo.numIsPresentFields) + + " + (" + + CUtil.runtimeIndex(instance) + + ") * " + + totalChannelCount * port.getParent().getWidth() + + " + count"; + temp.pr( enclaveStruct + ".is_present_fields[" - + CUtil.bankIndex(instance) - + " + " - + enclaveInfo.numIsPresentFields - + " + count] = &" + + indexString + + "] = &" + portRef + con + "is_present;"); @@ -1434,10 +1451,8 @@ private void generateStartTimeStep(ReactorInstance instance) { CExtensionUtils.surroundWithIfFederatedDecentralized( enclaveStruct + "._lf_intended_tag_fields[" - + CUtil.bankIndex(instance) - + " + " - + enclaveInfo.numIsPresentFields - + " + count] = &" + + indexString + + "] = &" + portRef + con + "intended_tag;")); @@ -1462,13 +1477,26 @@ private void generateStartTimeStep(ReactorInstance instance) { for (ActionInstance action : instance.actions) { foundOne = true; temp.startScopedBlock(); + + // Build the index into `is_present_fields` for this action. + var indexString = + String.valueOf(enclaveInfo.numIsPresentFields) + + " + (" + + CUtil.runtimeIndex(instance.getParent()) + + ") * " + + action.getParent().getWidth(); + + if (instance.isBank()) { + indexString += " + " + CUtil.bankIndexName(instance); + } + temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); - temp.startScopedBlock(instance); + temp.pr("// Add action " + action.getFullName() + " to array of is_present fields."); temp.pr( String.join( "\n", "// Add action " + action.getFullName() + " to array of is_present fields.", - enclaveStruct + ".is_present_fields[" + enclaveInfo.numIsPresentFields + " + count] ", + enclaveStruct + ".is_present_fields[" + indexString + "]", " = (bool *) &" + containerSelfStructName + "->_lf__" @@ -1482,10 +1510,7 @@ private void generateStartTimeStep(ReactorInstance instance) { String.join( "\n", "// Add action " + action.getFullName() + " to array of intended_tag fields.", - enclaveStruct - + "._lf_intended_tag_fields[" - + enclaveInfo.numIsPresentFields - + " + count]", + enclaveStruct + "._lf_intended_tag_fields[" + indexString, " = &" + containerSelfStructName + "->_lf_" @@ -1494,7 +1519,6 @@ private void generateStartTimeStep(ReactorInstance instance) { temp.pr("count++;"); temp.endScopedBlock(); - temp.endScopedBlock(); enclaveInfo.numIsPresentFields += action.getParent().getTotalWidth(); } if (foundOne) startTimeStep.pr(temp.toString()); @@ -1509,20 +1533,35 @@ private void generateStartTimeStep(ReactorInstance instance) { temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); temp.startScopedBlock(child); - var channelCount = 0; + // Need to find the total number of channels over all output ports of the child before + // generating the + // iteration. + var totalChannelCount = 0; + for (PortInstance output : child.outputs) { + if (!output.getDependsOnReactions().isEmpty()) { + totalChannelCount += output.getWidth(); + } + } for (PortInstance output : child.outputs) { if (!output.getDependsOnReactions().isEmpty()) { foundOne = true; temp.pr( "// Add output port " + output.getFullName() + " to array of is_present fields."); temp.startChannelIteration(output); + var indexString = + "(" + + CUtil.runtimeIndex(instance) + + ") * " + + totalChannelCount * child.getWidth() + + " + " + + enclaveInfo.numIsPresentFields + + " + count"; + temp.pr( enclaveStruct + ".is_present_fields[" - + CUtil.bankIndex(instance) - + " + " - + enclaveInfo.numIsPresentFields - + " + count] = &" + + indexString + + "] = &" + CUtil.portRef(output) + ".is_present;"); @@ -1538,6 +1577,8 @@ private void generateStartTimeStep(ReactorInstance instance) { enclaveStruct + "._lf_intended_tag_fields[" + CUtil.bankIndex(instance) + + " * " + + totalChannelCount * child.getTotalWidth() + " + " + enclaveInfo.numIsPresentFields + " + count] = &" @@ -1545,13 +1586,12 @@ private void generateStartTimeStep(ReactorInstance instance) { + ".intended_tag;"))); temp.pr("count++;"); - channelCount += output.getWidth(); temp.endChannelIteration(output); } } - enclaveInfo.numIsPresentFields += channelCount * child.getTotalWidth(); temp.endScopedBlock(); temp.endScopedBlock(); + enclaveInfo.numIsPresentFields += totalChannelCount * child.getTotalWidth(); } } if (foundOne) startTimeStep.pr(temp.toString()); @@ -2037,7 +2077,7 @@ protected boolean targetLanguageIsCpp() { * if there is none), and the message (or an empty string if there is none). */ @Override - public GeneratorBase.ErrorFileAndLine parseCommandOutput(String line) { + public ErrorFileAndLine parseCommandOutput(String line) { var matcher = compileErrorPattern.matcher(line); if (matcher.find()) { var result = new ErrorFileAndLine(); diff --git a/test/C/src/multiport/BankMultiportIsPresentSetup.lf b/test/C/src/multiport/BankMultiportIsPresentSetup.lf new file mode 100644 index 0000000000..2560e4dd56 --- /dev/null +++ b/test/C/src/multiport/BankMultiportIsPresentSetup.lf @@ -0,0 +1,29 @@ +// Smoke test for checking that the `is_present_fields` is setup correctly +// for a complicated hierarchy of banks with multiports and actions. +target C; + +reactor R1 { + output [2] out: int +} + +reactor R4 { + input [6] in: int +} + +reactor R2 { + r1 = new [3] R1() + r4 = new R4() + r1.out -> r4.in +} + +reactor R3 { + r2 = new [4] R2() + logical action a1 + logical action a2 +} + +main reactor { + r = new [2] R3() + logical action a1 + logical action a2 +} \ No newline at end of file diff --git a/test/C/src/multiport/BankOfActionsIsPresentSetup.lf b/test/C/src/multiport/BankOfActionsIsPresentSetup.lf new file mode 100644 index 0000000000..4e5837fedf --- /dev/null +++ b/test/C/src/multiport/BankOfActionsIsPresentSetup.lf @@ -0,0 +1,26 @@ +// Smoke test for checking that the `is_present_fields` is setup correctly +// for a complicated hierarchy of nested banks with actions. +target C; + +reactor R1 { + logical action a1 + logical action a2 +} + +reactor R2 { + r1 = new [3] R1() + logical action a1 + logical action a2 +} + +reactor R3 { + r2 = new [4] R2() + logical action a1 + logical action a2 +} + +main reactor { + r = new [2] R3() + logical action a1 + logical action a2 +} \ No newline at end of file From 70e2de7fa402428ffa394bb7cfaa302eabddcaf4 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 25 Sep 2024 16:19:27 -0700 Subject: [PATCH 29/61] Typo --- .../main/java/org/lflang/generator/c/CGenerator.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index f220da6904..8eff2b5087 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1510,7 +1510,7 @@ private void generateStartTimeStep(ReactorInstance instance) { String.join( "\n", "// Add action " + action.getFullName() + " to array of intended_tag fields.", - enclaveStruct + "._lf_intended_tag_fields[" + indexString, + enclaveStruct + "._lf_intended_tag_fields[" + indexString + "]", " = &" + containerSelfStructName + "->_lf_" @@ -1575,13 +1575,7 @@ private void generateStartTimeStep(ReactorInstance instance) { + output.getFullName() + " to array of intended_tag fields.", enclaveStruct - + "._lf_intended_tag_fields[" - + CUtil.bankIndex(instance) - + " * " - + totalChannelCount * child.getTotalWidth() - + " + " - + enclaveInfo.numIsPresentFields - + " + count] = &" + + "._lf_intended_tag_fields[" + indexString + "] = &" + CUtil.portRef(output) + ".intended_tag;"))); From 464e680048508301228d6d070118962587717087 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 25 Sep 2024 17:43:41 -0700 Subject: [PATCH 30/61] Spotless --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 8eff2b5087..12fce0d171 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1575,7 +1575,9 @@ private void generateStartTimeStep(ReactorInstance instance) { + output.getFullName() + " to array of intended_tag fields.", enclaveStruct - + "._lf_intended_tag_fields[" + indexString + "] = &" + + "._lf_intended_tag_fields[" + + indexString + + "] = &" + CUtil.portRef(output) + ".intended_tag;"))); From 5017c83ab4cc616d9bc990cb3ab749c1580f0cbe Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 25 Sep 2024 22:12:49 -0700 Subject: [PATCH 31/61] Use runtime index of parent --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 12fce0d171..ed5fa0c215 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1433,7 +1433,7 @@ private void generateStartTimeStep(ReactorInstance instance) { var indexString = String.valueOf(enclaveInfo.numIsPresentFields) + " + (" - + CUtil.runtimeIndex(instance) + + CUtil.runtimeIndex(instance.getParent()) + ") * " + totalChannelCount * port.getParent().getWidth() + " + count"; From 594cb132451d6ccebbc8792e79bd616209733f66 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 26 Sep 2024 09:21:28 -0700 Subject: [PATCH 32/61] REmove unused count variable --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index ed5fa0c215..1aa5dc482c 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1490,7 +1490,6 @@ private void generateStartTimeStep(ReactorInstance instance) { indexString += " + " + CUtil.bankIndexName(instance); } - temp.pr("int count = 0; SUPPRESS_UNUSED_WARNING(count);"); temp.pr("// Add action " + action.getFullName() + " to array of is_present fields."); temp.pr( String.join( From a676df5ca0927cefbd21a659bfce202e2df85965 Mon Sep 17 00:00:00 2001 From: depetrol Date: Thu, 26 Sep 2024 14:09:45 -0700 Subject: [PATCH 33/61] fix: bank_index parameter override --- .../python/PythonReactorGenerator.java | 22 +++++++++++-------- test/Python/src/federated/BankIndex.lf | 11 ++++++++++ .../Python/src/federated/BankIndexOverride.lf | 12 ++++++++++ 3 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 test/Python/src/federated/BankIndex.lf create mode 100644 test/Python/src/federated/BankIndexOverride.lf diff --git a/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java index 99dbae7349..373170c2fe 100644 --- a/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java +++ b/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java @@ -167,17 +167,21 @@ private static String generatePythonClassInstantiation( CodeBuilder code = new CodeBuilder(); code.pr(PyUtil.reactorRef(instance) + " = _" + className + "("); code.indent(); - // Always add the bank_index - code.pr("_bank_index = " + PyUtil.bankIndex(instance) + ","); + boolean hasBankIndexParameter = false; for (ParameterInstance param : instance.parameters) { - if (!param.getName().equals("bank_index")) { - code.pr( - "_" - + param.getName() - + "=" - + PythonParameterGenerator.generatePythonInitializer(param) - + ","); + if (param.getName().equals("bank_index")) { + hasBankIndexParameter = true; } + code.pr( + "_" + + param.getName() + + "=" + + PythonParameterGenerator.generatePythonInitializer(param) + + ","); + } + if (!hasBankIndexParameter) { + // Only add bank_index if not explicitly set + code.pr("_bank_index = " + PyUtil.bankIndex(instance) + ","); } code.unindent(); code.pr(")"); diff --git a/test/Python/src/federated/BankIndex.lf b/test/Python/src/federated/BankIndex.lf new file mode 100644 index 0000000000..76c9ac00e2 --- /dev/null +++ b/test/Python/src/federated/BankIndex.lf @@ -0,0 +1,11 @@ +target Python + +reactor A(bank_index=0) { + reaction(startup) {= + print("bank_index: {:d}".format(self.bank_index)) + =} +} + +federated reactor { + a = new[4] A() +} diff --git a/test/Python/src/federated/BankIndexOverride.lf b/test/Python/src/federated/BankIndexOverride.lf new file mode 100644 index 0000000000..2c79f91790 --- /dev/null +++ b/test/Python/src/federated/BankIndexOverride.lf @@ -0,0 +1,12 @@ +target Python + +reactor A(bank_index=0, aaaaaaa=0) { + reaction(startup) {= + print("bank_index: {:d}".format(self.bank_index)) + assert(self.bank_index == 2) + =} +} + +main reactor { + a = new A(bank_index=2) +} From 361f921695ce34504bb710fe10be7790c57bec46 Mon Sep 17 00:00:00 2001 From: depetrol Date: Thu, 26 Sep 2024 14:54:40 -0700 Subject: [PATCH 34/61] test: update bankindex test --- test/Python/src/federated/BankIndex.lf | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/Python/src/federated/BankIndex.lf b/test/Python/src/federated/BankIndex.lf index 76c9ac00e2..3023c428fe 100644 --- a/test/Python/src/federated/BankIndex.lf +++ b/test/Python/src/federated/BankIndex.lf @@ -1,11 +1,28 @@ target Python reactor A(bank_index=0) { - reaction(startup) {= + output out + + reaction(startup) -> out {= print("bank_index: {:d}".format(self.bank_index)) + out.set(self.bank_index) + =} +} + +reactor B { + input[4] inp + + reaction(inp) {= + for i, port in enumerate(inp): + assert port.is_present + print("in[{:d}]: {:d}".format(i, port.value)) + assert port.value == i + request_stop() =} } federated reactor { a = new[4] A() + b = new B() + a.out -> b.inp } From acc7501d0a2d9cea0a1000758d2110458884e4cc Mon Sep 17 00:00:00 2001 From: depetrol Date: Thu, 26 Sep 2024 15:06:46 -0700 Subject: [PATCH 35/61] test: update test --- test/Cpp/src/ActionWithNoReaction.lf | 2 +- test/Python/src/federated/BankIndex.lf | 8 ++++---- test/Python/src/federated/BankIndexOverride.lf | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/Cpp/src/ActionWithNoReaction.lf b/test/Cpp/src/ActionWithNoReaction.lf index 3dd6e3f236..dafd81dcd9 100644 --- a/test/Cpp/src/ActionWithNoReaction.lf +++ b/test/Cpp/src/ActionWithNoReaction.lf @@ -11,7 +11,7 @@ reactor foo { logical action a reaction(x) -> y, a {= - y.set(2*(*x.get())); + y.set(2*(*x.undefined_name15291838())); a.schedule(500ms); =} } diff --git a/test/Python/src/federated/BankIndex.lf b/test/Python/src/federated/BankIndex.lf index 3023c428fe..fe914ac116 100644 --- a/test/Python/src/federated/BankIndex.lf +++ b/test/Python/src/federated/BankIndex.lf @@ -1,6 +1,6 @@ target Python -reactor A(bank_index=0) { +reactor FirstReactor(bank_index=0) { output out reaction(startup) -> out {= @@ -9,7 +9,7 @@ reactor A(bank_index=0) { =} } -reactor B { +reactor SecondReactor { input[4] inp reaction(inp) {= @@ -22,7 +22,7 @@ reactor B { } federated reactor { - a = new[4] A() - b = new B() + a = new[4] FirstReactor() + b = new SecondReactor() a.out -> b.inp } diff --git a/test/Python/src/federated/BankIndexOverride.lf b/test/Python/src/federated/BankIndexOverride.lf index 2c79f91790..70aa800519 100644 --- a/test/Python/src/federated/BankIndexOverride.lf +++ b/test/Python/src/federated/BankIndexOverride.lf @@ -1,6 +1,6 @@ target Python -reactor A(bank_index=0, aaaaaaa=0) { +reactor SingleReactor(bank_index=0) { reaction(startup) {= print("bank_index: {:d}".format(self.bank_index)) assert(self.bank_index == 2) @@ -8,5 +8,5 @@ reactor A(bank_index=0, aaaaaaa=0) { } main reactor { - a = new A(bank_index=2) + a = new SingleReactor(bank_index=2) } From c16702b068cec8ed2570baa2c8b87367b82e6a36 Mon Sep 17 00:00:00 2001 From: depetrol Date: Thu, 26 Sep 2024 15:24:28 -0700 Subject: [PATCH 36/61] fix: resolve test name conflict --- test/Python/src/federated/{BankIndex.lf => BankIndexFed.lf} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/Python/src/federated/{BankIndex.lf => BankIndexFed.lf} (100%) diff --git a/test/Python/src/federated/BankIndex.lf b/test/Python/src/federated/BankIndexFed.lf similarity index 100% rename from test/Python/src/federated/BankIndex.lf rename to test/Python/src/federated/BankIndexFed.lf From 9e804d2960986b65374b257ea899b3a1744b86b3 Mon Sep 17 00:00:00 2001 From: Shulu Li <65802727+Depetrol@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:35:06 -0700 Subject: [PATCH 37/61] fix: unintended change --- test/Cpp/src/ActionWithNoReaction.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Cpp/src/ActionWithNoReaction.lf b/test/Cpp/src/ActionWithNoReaction.lf index dafd81dcd9..3dd6e3f236 100644 --- a/test/Cpp/src/ActionWithNoReaction.lf +++ b/test/Cpp/src/ActionWithNoReaction.lf @@ -11,7 +11,7 @@ reactor foo { logical action a reaction(x) -> y, a {= - y.set(2*(*x.undefined_name15291838())); + y.set(2*(*x.get())); a.schedule(500ms); =} } From 4cfd1ceb7358b6313cbd1bf7a628b2ec3ad6d36d Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 26 Sep 2024 16:39:33 -0700 Subject: [PATCH 38/61] Remove count incremet --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 1aa5dc482c..fbe5cdecce 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1516,7 +1516,6 @@ private void generateStartTimeStep(ReactorInstance instance) { + action.getName() + ".intended_tag;"))); - temp.pr("count++;"); temp.endScopedBlock(); enclaveInfo.numIsPresentFields += action.getParent().getTotalWidth(); } From 0911b10c2e39b1bd03d09b5d5e8981aea7b4490e Mon Sep 17 00:00:00 2001 From: depetrol Date: Thu, 26 Sep 2024 17:02:47 -0700 Subject: [PATCH 39/61] fix --- .../org/lflang/generator/python/PythonReactorGenerator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java index 373170c2fe..73b4651b18 100644 --- a/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java +++ b/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java @@ -170,7 +170,8 @@ private static String generatePythonClassInstantiation( boolean hasBankIndexParameter = false; for (ParameterInstance param : instance.parameters) { if (param.getName().equals("bank_index")) { - hasBankIndexParameter = true; + if (param.getOverride() != null) hasBankIndexParameter = true; + else continue; // Skip bank_index if it is not explicitly set } code.pr( "_" From 384a68a7844e618bbc7d60c7c7ed2e0befe50eab Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 26 Sep 2024 18:49:13 -0700 Subject: [PATCH 40/61] Spotless --- test/C/src/ActionIsPresentReset.lf | 46 +++++++++---------- .../multiport/BankMultiportIsPresentSetup.lf | 14 +++--- .../multiport/BankOfActionsIsPresentSetup.lf | 10 ++-- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/test/C/src/ActionIsPresentReset.lf b/test/C/src/ActionIsPresentReset.lf index 596dedec26..84388f3d0b 100644 --- a/test/C/src/ActionIsPresentReset.lf +++ b/test/C/src/ActionIsPresentReset.lf @@ -1,30 +1,30 @@ target C { - timeout: 7 msecs, - fast: true + timeout: 7 msecs, + fast: true } main reactor { - logical action a; - logical action b; - - reaction(startup) -> a {= - lf_schedule(a, MSEC(1)); - =} + logical action a + logical action b + + reaction(startup) -> a {= + lf_schedule(a, MSEC(1)); + =} - reaction(a, b) -> a, b {= - if (a->is_present) { - printf("A"); - lf_schedule(b, MSEC(2)); - } - if (b->is_present) { - printf("B"); - lf_schedule(a, MSEC(1)); - } + reaction(a, b) -> a, b {= + if (a->is_present) { + printf("A"); + lf_schedule(b, MSEC(2)); + } + if (b->is_present) { + printf("B"); + lf_schedule(a, MSEC(1)); + } - lf_print(" at %d msecs with triggers (%d,%d)", lf_time_logical_elapsed() / MSEC(1), a->is_present, b->is_present); + lf_print(" at %d msecs with triggers (%d,%d)", lf_time_logical_elapsed() / MSEC(1), a->is_present, b->is_present); - if (a->is_present && b->is_present) { - lf_print_error_and_exit("Both triggers should not be present"); - } - =} -} \ No newline at end of file + if (a->is_present && b->is_present) { + lf_print_error_and_exit("Both triggers should not be present"); + } + =} +} diff --git a/test/C/src/multiport/BankMultiportIsPresentSetup.lf b/test/C/src/multiport/BankMultiportIsPresentSetup.lf index 2560e4dd56..232d0ed16c 100644 --- a/test/C/src/multiport/BankMultiportIsPresentSetup.lf +++ b/test/C/src/multiport/BankMultiportIsPresentSetup.lf @@ -1,29 +1,29 @@ // Smoke test for checking that the `is_present_fields` is setup correctly // for a complicated hierarchy of banks with multiports and actions. -target C; +target C reactor R1 { - output [2] out: int + output[2] out: int } reactor R4 { - input [6] in: int + input[6] in: int } reactor R2 { - r1 = new [3] R1() + r1 = new[3] R1() r4 = new R4() r1.out -> r4.in } reactor R3 { - r2 = new [4] R2() + r2 = new[4] R2() logical action a1 logical action a2 } main reactor { - r = new [2] R3() + r = new[2] R3() logical action a1 logical action a2 -} \ No newline at end of file +} diff --git a/test/C/src/multiport/BankOfActionsIsPresentSetup.lf b/test/C/src/multiport/BankOfActionsIsPresentSetup.lf index 4e5837fedf..5348ebaded 100644 --- a/test/C/src/multiport/BankOfActionsIsPresentSetup.lf +++ b/test/C/src/multiport/BankOfActionsIsPresentSetup.lf @@ -1,6 +1,6 @@ // Smoke test for checking that the `is_present_fields` is setup correctly // for a complicated hierarchy of nested banks with actions. -target C; +target C reactor R1 { logical action a1 @@ -8,19 +8,19 @@ reactor R1 { } reactor R2 { - r1 = new [3] R1() + r1 = new[3] R1() logical action a1 logical action a2 } reactor R3 { - r2 = new [4] R2() + r2 = new[4] R2() logical action a1 logical action a2 } main reactor { - r = new [2] R3() + r = new[2] R3() logical action a1 logical action a2 -} \ No newline at end of file +} From 3b14a061deb0525a50c5dee427792d8b4f3c3419 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 06:21:30 -0700 Subject: [PATCH 41/61] Typo --- core/src/main/java/org/lflang/generator/c/CUtil.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CUtil.java b/core/src/main/java/org/lflang/generator/c/CUtil.java index 4dc2ff9c91..6c0c14eec8 100644 --- a/core/src/main/java/org/lflang/generator/c/CUtil.java +++ b/core/src/main/java/org/lflang/generator/c/CUtil.java @@ -93,8 +93,8 @@ public static String actionRef(ActionInstance instance, String runtimeIndex) { } /** - * Return a default name of a variable to refer to the bank index of a reactor in a bank. This is - * has the form uniqueID_i where uniqueID is an identifier for the instance that is guaranteed to + * Return a default name of a variable to refer to the bank index of a reactor in a bank. This + * has the form uniqueID_i, where uniqueID is an identifier for the instance that is guaranteed to * be different from the ID of any other instance in the program. If the instance is not a bank, * return "0". * @@ -106,8 +106,8 @@ public static String bankIndex(ReactorInstance instance) { } /** - * Return a default name of a variable to refer to the bank index of a reactor in a bank. This is - * has the form uniqueID_i where uniqueID is an identifier for the instance that is guaranteed to + * Return a default name of a variable to refer to the bank index of a reactor in a bank. This + * has the form uniqueID_i, where uniqueID is an identifier for the instance that is guaranteed to * be different from the ID of any other instance in the program. * * @param instance A reactor instance. From 439aedaa8c40e4126b0ab94d68147fedacf9b390 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 07:33:48 -0700 Subject: [PATCH 42/61] Simplified one iteration, elaborated test, and aligned reactor-c --- .../org/lflang/generator/c/CGenerator.java | 14 +------ core/src/main/resources/lib/c/reactor-c | 2 +- .../multiport/BankMultiportIsPresentSetup.lf | 40 ++++++++++++++++++- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index fbe5cdecce..603651c6b8 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1396,16 +1396,6 @@ private void generateStartTimeStep(ReactorInstance instance) { var portsSeen = new LinkedHashSet(); for (ReactionInstance reaction : instance.reactions) { - // Need to find the total number of channels over all output ports of the child before - // generating the - // iteration. - var totalChannelCount = 0; - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { - totalChannelCount += port.getWidth(); - } - } - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { portsSeen.add(port); @@ -1435,7 +1425,7 @@ private void generateStartTimeStep(ReactorInstance instance) { + " + (" + CUtil.runtimeIndex(instance.getParent()) + ") * " - + totalChannelCount * port.getParent().getWidth() + + instance.getWidth() * port.getWidth() + " + count"; temp.pr( @@ -1457,7 +1447,7 @@ private void generateStartTimeStep(ReactorInstance instance) { + con + "intended_tag;")); - enclaveInfo.numIsPresentFields += port.getWidth() * port.getParent().getTotalWidth(); + enclaveInfo.numIsPresentFields += instance.getWidth() * port.getWidth(); if (!Objects.equal(port.getParent(), instance)) { temp.pr("count++;"); diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 6650f3616d..12ba4ee56a 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 6650f3616dde885393d97f5732645e4a60da8596 +Subproject commit 12ba4ee56a70fc87b7e7b0a53dd5f9a425a9dc00 diff --git a/test/C/src/multiport/BankMultiportIsPresentSetup.lf b/test/C/src/multiport/BankMultiportIsPresentSetup.lf index 232d0ed16c..be8782acb8 100644 --- a/test/C/src/multiport/BankMultiportIsPresentSetup.lf +++ b/test/C/src/multiport/BankMultiportIsPresentSetup.lf @@ -3,17 +3,53 @@ target C reactor R1 { + logical action a1 + logical action a2 output[2] out: int + reaction(startup) -> out {= + lf_set(out[0], 42); + =} + reaction(startup) -> out {= + lf_set(out[1], 43); + =} } reactor R4 { - input[6] in: int + logical action a1 + logical action a2 + input[3] in: int + input[3] in2: int + input[2] in3: int + reaction(in) {= + lf_print("in = [%d, %d, %d]", in[0]->value, in[1]->value, in[2]->value); + =} + reaction(in2) {= + lf_print("in2 = [%d, %d, %d]", in2[0]->value, in2[1]->value, in2[2]->value); + =} + reaction(in3) {= + lf_print("in3 = [%d, %d]", in3[0]->value, in3[1]->value); + =} } reactor R2 { + logical action a1 + logical action a2 r1 = new[3] R1() - r4 = new R4() + r4 = new[2] R4() r1.out -> r4.in + reaction(startup) -> r4.in2, r4.in3 {= + lf_set(r4[0].in2[0], 44); + lf_set(r4[1].in2[0], 45); + lf_set(r4[0].in2[1], 46); + lf_set(r4[1].in2[1], 47); + lf_set(r4[0].in2[2], 48); + lf_set(r4[1].in2[2], 49); + + lf_set(r4[0].in3[0], 50); + lf_set(r4[1].in3[0], 51); + lf_set(r4[0].in3[1], 52); + lf_set(r4[1].in3[1], 53); + =} } reactor R3 { From c626bb143870e5883433d47b41f36466c4e64017 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 07:44:36 -0700 Subject: [PATCH 43/61] Extra cautious with branch that should not occur --- .../src/main/java/org/lflang/generator/c/CGenerator.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 603651c6b8..e60f8f511c 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1395,7 +1395,6 @@ private void generateStartTimeStep(ReactorInstance instance) { // port so we have to avoid listing the port more than once. var portsSeen = new LinkedHashSet(); for (ReactionInstance reaction : instance.reactions) { - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { portsSeen.add(port); @@ -1407,6 +1406,8 @@ private void generateStartTimeStep(ReactorInstance instance) { temp.pr("// Add port " + port.getFullName() + " to array of is_present fields."); + var width = instance.getWidth(); + if (!Objects.equal(port.getParent(), instance)) { // The port belongs to contained reactor, so we also have // iterate over the instance bank members. @@ -1415,7 +1416,11 @@ private void generateStartTimeStep(ReactorInstance instance) { temp.startScopedBlock(instance); temp.startScopedBankChannelIteration(port, null); } else { + // This branch should not occur because if the port's parent is instance and the port + // is an effect of a reaction of instance, then the port must be an output, not an input. + // Nevertheless, leave this here in case we missed something. temp.startScopedBankChannelIteration(port, "count"); + width = port.getParent().getWidth(); } var portRef = CUtil.portRefNested(port); var con = (port.isMultiport()) ? "->" : "."; @@ -1425,7 +1430,7 @@ private void generateStartTimeStep(ReactorInstance instance) { + " + (" + CUtil.runtimeIndex(instance.getParent()) + ") * " - + instance.getWidth() * port.getWidth() + + width * port.getWidth() + " + count"; temp.pr( From 8331d1caff97bb58259438b10fcc47a1be6599a6 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 07:46:22 -0700 Subject: [PATCH 44/61] Small fix for branch that should not occur --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index e60f8f511c..648c38ea29 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1452,7 +1452,7 @@ private void generateStartTimeStep(ReactorInstance instance) { + con + "intended_tag;")); - enclaveInfo.numIsPresentFields += instance.getWidth() * port.getWidth(); + enclaveInfo.numIsPresentFields += width * port.getWidth(); if (!Objects.equal(port.getParent(), instance)) { temp.pr("count++;"); From 7f246be91eda7ca52b4236531e6a11d149dcf692 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 07:51:34 -0700 Subject: [PATCH 45/61] Corrected order of endScopedBlock calls --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 648c38ea29..3134b68100 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1456,9 +1456,9 @@ private void generateStartTimeStep(ReactorInstance instance) { if (!Objects.equal(port.getParent(), instance)) { temp.pr("count++;"); + temp.endScopedBankChannelIteration(port, null); temp.endScopedBlock(); temp.endScopedBlock(); - temp.endScopedBankChannelIteration(port, null); } else { temp.endScopedBankChannelIteration(port, "count"); } From cdcfb33ae4614db326e2e97ffaffb32285f5973a Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 08:06:30 -0700 Subject: [PATCH 46/61] Removed unnecessary scoped block --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 3134b68100..1840483ad7 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1471,7 +1471,6 @@ private void generateStartTimeStep(ReactorInstance instance) { for (ActionInstance action : instance.actions) { foundOne = true; - temp.startScopedBlock(); // Build the index into `is_present_fields` for this action. var indexString = @@ -1485,7 +1484,6 @@ private void generateStartTimeStep(ReactorInstance instance) { indexString += " + " + CUtil.bankIndexName(instance); } - temp.pr("// Add action " + action.getFullName() + " to array of is_present fields."); temp.pr( String.join( "\n", @@ -1511,7 +1509,6 @@ private void generateStartTimeStep(ReactorInstance instance) { + action.getName() + ".intended_tag;"))); - temp.endScopedBlock(); enclaveInfo.numIsPresentFields += action.getParent().getTotalWidth(); } if (foundOne) startTimeStep.pr(temp.toString()); From d8a3f274f0c1600c1141276f39cd104f898b864e Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 08:20:42 -0700 Subject: [PATCH 47/61] Corrected stride on action and run spotless --- .../main/java/org/lflang/generator/c/CGenerator.java | 9 ++++----- core/src/main/java/org/lflang/generator/c/CUtil.java | 12 ++++++------ test/C/src/multiport/BankMultiportIsPresentSetup.lf | 6 ++++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 1840483ad7..852fb960ec 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1417,7 +1417,8 @@ private void generateStartTimeStep(ReactorInstance instance) { temp.startScopedBankChannelIteration(port, null); } else { // This branch should not occur because if the port's parent is instance and the port - // is an effect of a reaction of instance, then the port must be an output, not an input. + // is an effect of a reaction of instance, then the port must be an output, not an + // input. // Nevertheless, leave this here in case we missed something. temp.startScopedBankChannelIteration(port, "count"); width = port.getParent().getWidth(); @@ -1475,10 +1476,8 @@ private void generateStartTimeStep(ReactorInstance instance) { // Build the index into `is_present_fields` for this action. var indexString = String.valueOf(enclaveInfo.numIsPresentFields) - + " + (" - + CUtil.runtimeIndex(instance.getParent()) - + ") * " - + action.getParent().getWidth(); + + " + " + + CUtil.runtimeIndex(instance.getParent()); if (instance.isBank()) { indexString += " + " + CUtil.bankIndexName(instance); diff --git a/core/src/main/java/org/lflang/generator/c/CUtil.java b/core/src/main/java/org/lflang/generator/c/CUtil.java index 6c0c14eec8..64e63bfe95 100644 --- a/core/src/main/java/org/lflang/generator/c/CUtil.java +++ b/core/src/main/java/org/lflang/generator/c/CUtil.java @@ -93,9 +93,9 @@ public static String actionRef(ActionInstance instance, String runtimeIndex) { } /** - * Return a default name of a variable to refer to the bank index of a reactor in a bank. This - * has the form uniqueID_i, where uniqueID is an identifier for the instance that is guaranteed to - * be different from the ID of any other instance in the program. If the instance is not a bank, + * Return a default name of a variable to refer to the bank index of a reactor in a bank. This has + * the form uniqueID_i, where uniqueID is an identifier for the instance that is guaranteed to be + * different from the ID of any other instance in the program. If the instance is not a bank, * return "0". * * @param instance A reactor instance. @@ -106,9 +106,9 @@ public static String bankIndex(ReactorInstance instance) { } /** - * Return a default name of a variable to refer to the bank index of a reactor in a bank. This - * has the form uniqueID_i, where uniqueID is an identifier for the instance that is guaranteed to - * be different from the ID of any other instance in the program. + * Return a default name of a variable to refer to the bank index of a reactor in a bank. This has + * the form uniqueID_i, where uniqueID is an identifier for the instance that is guaranteed to be + * different from the ID of any other instance in the program. * * @param instance A reactor instance. */ diff --git a/test/C/src/multiport/BankMultiportIsPresentSetup.lf b/test/C/src/multiport/BankMultiportIsPresentSetup.lf index be8782acb8..66adf0f3c3 100644 --- a/test/C/src/multiport/BankMultiportIsPresentSetup.lf +++ b/test/C/src/multiport/BankMultiportIsPresentSetup.lf @@ -6,9 +6,11 @@ reactor R1 { logical action a1 logical action a2 output[2] out: int + reaction(startup) -> out {= lf_set(out[0], 42); =} + reaction(startup) -> out {= lf_set(out[1], 43); =} @@ -20,12 +22,15 @@ reactor R4 { input[3] in: int input[3] in2: int input[2] in3: int + reaction(in) {= lf_print("in = [%d, %d, %d]", in[0]->value, in[1]->value, in[2]->value); =} + reaction(in2) {= lf_print("in2 = [%d, %d, %d]", in2[0]->value, in2[1]->value, in2[2]->value); =} + reaction(in3) {= lf_print("in3 = [%d, %d]", in3[0]->value, in3[1]->value); =} @@ -37,6 +42,7 @@ reactor R2 { r1 = new[3] R1() r4 = new[2] R4() r1.out -> r4.in + reaction(startup) -> r4.in2, r4.in3 {= lf_set(r4[0].in2[0], 44); lf_set(r4[1].in2[0], 45); From db3ef25e3e23060ff4dd8adca5f9feb235288fb3 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 08:24:29 -0700 Subject: [PATCH 48/61] Restored stride as needed --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 852fb960ec..715923955f 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1476,8 +1476,10 @@ private void generateStartTimeStep(ReactorInstance instance) { // Build the index into `is_present_fields` for this action. var indexString = String.valueOf(enclaveInfo.numIsPresentFields) - + " + " - + CUtil.runtimeIndex(instance.getParent()); + + " + (" + + CUtil.runtimeIndex(instance.getParent()) + + ") * " + + action.getParent().getWidth(); if (instance.isBank()) { indexString += " + " + CUtil.bankIndexName(instance); From 232534f49864ab8fb5857f088a24349ab9f31135 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 09:07:59 -0700 Subject: [PATCH 49/61] Reversed simplification which didn't work --- .../java/org/lflang/generator/c/CGenerator.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 715923955f..61215d385b 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1395,6 +1395,15 @@ private void generateStartTimeStep(ReactorInstance instance) { // port so we have to avoid listing the port more than once. var portsSeen = new LinkedHashSet(); for (ReactionInstance reaction : instance.reactions) { + + // Need to find the total number of channels over all output ports of the child before + // generating the iteration. + var totalChannelCount = 0; + for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { + totalChannelCount += port.getWidth(); + } + } for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { portsSeen.add(port); @@ -1406,8 +1415,6 @@ private void generateStartTimeStep(ReactorInstance instance) { temp.pr("// Add port " + port.getFullName() + " to array of is_present fields."); - var width = instance.getWidth(); - if (!Objects.equal(port.getParent(), instance)) { // The port belongs to contained reactor, so we also have // iterate over the instance bank members. @@ -1421,7 +1428,6 @@ private void generateStartTimeStep(ReactorInstance instance) { // input. // Nevertheless, leave this here in case we missed something. temp.startScopedBankChannelIteration(port, "count"); - width = port.getParent().getWidth(); } var portRef = CUtil.portRefNested(port); var con = (port.isMultiport()) ? "->" : "."; @@ -1431,7 +1437,7 @@ private void generateStartTimeStep(ReactorInstance instance) { + " + (" + CUtil.runtimeIndex(instance.getParent()) + ") * " - + width * port.getWidth() + + totalChannelCount * port.getParent().getWidth() + " + count"; temp.pr( @@ -1453,7 +1459,7 @@ private void generateStartTimeStep(ReactorInstance instance) { + con + "intended_tag;")); - enclaveInfo.numIsPresentFields += width * port.getWidth(); + enclaveInfo.numIsPresentFields += port.getWidth() * port.getParent().getTotalWidth(); if (!Objects.equal(port.getParent(), instance)) { temp.pr("count++;"); From fada31861f7dcf96b2cd29f71499596a76f92dd2 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 09:37:30 -0700 Subject: [PATCH 50/61] Corrected simplication --- .../java/org/lflang/generator/c/CGenerator.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 61215d385b..9d4353b248 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1395,15 +1395,6 @@ private void generateStartTimeStep(ReactorInstance instance) { // port so we have to avoid listing the port more than once. var portsSeen = new LinkedHashSet(); for (ReactionInstance reaction : instance.reactions) { - - // Need to find the total number of channels over all output ports of the child before - // generating the iteration. - var totalChannelCount = 0; - for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { - if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { - totalChannelCount += port.getWidth(); - } - } for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { if (port.getDefinition() instanceof Input && !portsSeen.contains(port)) { portsSeen.add(port); @@ -1415,6 +1406,8 @@ private void generateStartTimeStep(ReactorInstance instance) { temp.pr("// Add port " + port.getFullName() + " to array of is_present fields."); + var width = instance.getWidth(); + if (!Objects.equal(port.getParent(), instance)) { // The port belongs to contained reactor, so we also have // iterate over the instance bank members. @@ -1428,6 +1421,7 @@ private void generateStartTimeStep(ReactorInstance instance) { // input. // Nevertheless, leave this here in case we missed something. temp.startScopedBankChannelIteration(port, "count"); + width = port.getParent().getWidth(); } var portRef = CUtil.portRefNested(port); var con = (port.isMultiport()) ? "->" : "."; @@ -1437,7 +1431,7 @@ private void generateStartTimeStep(ReactorInstance instance) { + " + (" + CUtil.runtimeIndex(instance.getParent()) + ") * " - + totalChannelCount * port.getParent().getWidth() + + width * port.getWidth() + " + count"; temp.pr( @@ -1459,7 +1453,7 @@ private void generateStartTimeStep(ReactorInstance instance) { + con + "intended_tag;")); - enclaveInfo.numIsPresentFields += port.getWidth() * port.getParent().getTotalWidth(); + enclaveInfo.numIsPresentFields += instance.getTotalWidth() * port.getWidth(); if (!Objects.equal(port.getParent(), instance)) { temp.pr("count++;"); From 359aae05bb80418b0f3ab3a1cd806d3ed1e17ef6 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 11:20:48 -0700 Subject: [PATCH 51/61] Another refinement --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 9d4353b248..e78a2490e1 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1406,7 +1406,8 @@ private void generateStartTimeStep(ReactorInstance instance) { temp.pr("// Add port " + port.getFullName() + " to array of is_present fields."); - var width = instance.getWidth(); + // We will be iterating over instance (if a bank) and the parent of the port (if a bank). + var width = instance.getWidth() * port.getParent().getWidth(); if (!Objects.equal(port.getParent(), instance)) { // The port belongs to contained reactor, so we also have @@ -1453,7 +1454,7 @@ private void generateStartTimeStep(ReactorInstance instance) { + con + "intended_tag;")); - enclaveInfo.numIsPresentFields += instance.getTotalWidth() * port.getWidth(); + enclaveInfo.numIsPresentFields += port.getParent().getTotalWidth() * port.getWidth(); if (!Objects.equal(port.getParent(), instance)) { temp.pr("count++;"); From 1cf93032264a5887d1a19c65d82102472cee86db Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 11:30:53 -0700 Subject: [PATCH 52/61] Sigh. Spotless --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index e78a2490e1..f6ee943085 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -1477,10 +1477,10 @@ private void generateStartTimeStep(ReactorInstance instance) { // Build the index into `is_present_fields` for this action. var indexString = String.valueOf(enclaveInfo.numIsPresentFields) - + " + (" - + CUtil.runtimeIndex(instance.getParent()) - + ") * " - + action.getParent().getWidth(); + + " + (" + + CUtil.runtimeIndex(instance.getParent()) + + ") * " + + action.getParent().getWidth(); if (instance.isBank()) { indexString += " + " + CUtil.bankIndexName(instance); From a38dfce0e154ccf7190fc423dfbb9ad45fea7b0b Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 29 Sep 2024 07:29:11 -0700 Subject: [PATCH 53/61] Added reactions to test --- core/src/main/resources/lib/c/reactor-c | 2 +- test/C/src/multiport/BankOfActionsIsPresentSetup.lf | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 12ba4ee56a..165f3fe107 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 12ba4ee56a70fc87b7e7b0a53dd5f9a425a9dc00 +Subproject commit 165f3fe1077eb98f3a888a70d61a710bfac59778 diff --git a/test/C/src/multiport/BankOfActionsIsPresentSetup.lf b/test/C/src/multiport/BankOfActionsIsPresentSetup.lf index 5348ebaded..41e0c555e9 100644 --- a/test/C/src/multiport/BankOfActionsIsPresentSetup.lf +++ b/test/C/src/multiport/BankOfActionsIsPresentSetup.lf @@ -5,6 +5,16 @@ target C reactor R1 { logical action a1 logical action a2 + reaction(startup) -> a1, a2 {= + lf_schedule(a1, MSEC(10)); + lf_schedule(a2, MSEC(10)); + =} + reaction(a1) {= + lf_print("a1"); + =} + reaction(a2) {= + lf_print("a2"); + =} } reactor R2 { From da8d98a903a0cb366afda0c163f4688bc17ff89d Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 29 Sep 2024 10:31:53 -0700 Subject: [PATCH 54/61] Spotless --- test/C/src/multiport/BankOfActionsIsPresentSetup.lf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/C/src/multiport/BankOfActionsIsPresentSetup.lf b/test/C/src/multiport/BankOfActionsIsPresentSetup.lf index 41e0c555e9..fe2ce8e4bc 100644 --- a/test/C/src/multiport/BankOfActionsIsPresentSetup.lf +++ b/test/C/src/multiport/BankOfActionsIsPresentSetup.lf @@ -5,13 +5,16 @@ target C reactor R1 { logical action a1 logical action a2 + reaction(startup) -> a1, a2 {= lf_schedule(a1, MSEC(10)); lf_schedule(a2, MSEC(10)); =} + reaction(a1) {= lf_print("a1"); =} + reaction(a2) {= lf_print("a2"); =} From e15a0c03f7e8a48dbf6fc337eaec92db455ea436 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 29 Sep 2024 10:14:17 -0700 Subject: [PATCH 55/61] Default Docker image for Python changed to Alpine --- .../generator/docker/PythonDockerGenerator.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/docker/PythonDockerGenerator.java b/core/src/main/java/org/lflang/generator/docker/PythonDockerGenerator.java index 6a55669752..de287b346e 100644 --- a/core/src/main/java/org/lflang/generator/docker/PythonDockerGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/PythonDockerGenerator.java @@ -9,7 +9,7 @@ * @author Hou Seng Wong */ public class PythonDockerGenerator extends CDockerGenerator { - public static final String DEFAULT_BASE_IMAGE = "python:3.10-slim"; + public static final String DEFAULT_BASE_IMAGE = "python:3.10-alpine"; public PythonDockerGenerator(LFGeneratorContext context) { super(context); @@ -20,15 +20,6 @@ public String defaultImage() { return DEFAULT_BASE_IMAGE; } - @Override - protected String generateRunForInstallingDeps() { - if (builderBase().equals(defaultImage())) { - return "RUN set -ex && apt-get update && apt-get install -y python3-pip && pip install cmake"; - } else { - return "# (Skipping installation of build dependencies; custom base image.)"; - } - } - @Override protected String generateCopyOfExecutable() { var lfModuleName = context.getFileConfig().name; From dd3aaef5c1a8b43a10257d3f5b67d9f303991623 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 29 Sep 2024 13:45:42 -0700 Subject: [PATCH 56/61] Prevent NPE and provide informative message about federated support --- .../lflang/federated/generator/FedGenerator.java | 13 +++++++++++-- .../lflang/target/property/PlatformProperty.java | 9 ++++++++- .../lflang/target/property/type/PlatformType.java | 8 ++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/lflang/federated/generator/FedGenerator.java b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java index e1f36a9ad1..0d1d29a3cc 100644 --- a/core/src/main/java/org/lflang/federated/generator/FedGenerator.java +++ b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java @@ -1,6 +1,7 @@ package org.lflang.federated.generator; import static org.lflang.generator.docker.DockerGenerator.dockerGeneratorFactory; +import static org.lflang.target.property.type.PlatformType.Platform.supportsFederated; import com.google.inject.Injector; import java.io.IOException; @@ -63,6 +64,7 @@ import org.lflang.target.property.DockerProperty.DockerOptions; import org.lflang.target.property.KeepaliveProperty; import org.lflang.target.property.NoCompileProperty; +import org.lflang.target.property.PlatformProperty; import org.lflang.target.property.type.CoordinationModeType.CoordinationMode; import org.lflang.util.Averager; import org.lflang.util.FileUtil; @@ -121,7 +123,7 @@ public FedGenerator(LFGeneratorContext context) { * @return False if no errors have occurred, true otherwise. */ public boolean doGenerate(Resource resource, LFGeneratorContext context) throws IOException { - if (!federatedExecutionIsSupported(resource)) return true; + if (!federatedExecutionIsSupported(resource, context)) return true; cleanIfNeeded(context); // In a federated execution, we need keepalive to be true, @@ -300,7 +302,7 @@ private void cleanIfNeeded(LFGeneratorContext context) { } /** Return whether federated execution is supported for {@code resource}. */ - private boolean federatedExecutionIsSupported(Resource resource) { + private boolean federatedExecutionIsSupported(Resource resource, LFGeneratorContext context) { TargetDecl targetDecl = GeneratorUtils.findTargetDecl(resource); var target = Target.fromDecl(targetDecl); var targetOK = @@ -316,6 +318,13 @@ private boolean federatedExecutionIsSupported(Resource resource) { .error("Federated LF programs with a C target are currently not supported on Windows."); targetOK = false; } + var platform = context.getTargetConfig().get(PlatformProperty.INSTANCE).platform(); + if (!supportsFederated(platform)) { + messageReporter + .at(targetDecl) + .error("Federations are not supported by the " + platform.getcMakeName() + " platform."); + targetOK = false; + } return targetOK; } diff --git a/core/src/main/java/org/lflang/target/property/PlatformProperty.java b/core/src/main/java/org/lflang/target/property/PlatformProperty.java index 12399319f7..9051a7c74a 100644 --- a/core/src/main/java/org/lflang/target/property/PlatformProperty.java +++ b/core/src/main/java/org/lflang/target/property/PlatformProperty.java @@ -2,6 +2,7 @@ import org.lflang.MessageReporter; import org.lflang.ast.ASTUtils; +import org.lflang.federated.generator.FederateTargetConfig; import org.lflang.lf.Element; import org.lflang.lf.KeyValuePair; import org.lflang.lf.KeyValuePairs; @@ -163,10 +164,16 @@ private void validateFlexPRET(TargetConfig config, MessageReporter reporter) { } } + private void federatedNotSupported(TargetConfig config, MessageReporter reporter) { + if (config instanceof FederateTargetConfig) { + reporter.nowhere().error("This platform does not support federations."); + } + } + private void validateZephyr(TargetConfig config, MessageReporter reporter) { var platform = config.get(PlatformProperty.INSTANCE); var singleThreaded = config.get(SingleThreadedProperty.INSTANCE); - + federatedNotSupported(config, reporter); if (singleThreaded) { if (platform.userThreads().value() > 0) { reporter diff --git a/core/src/main/java/org/lflang/target/property/type/PlatformType.java b/core/src/main/java/org/lflang/target/property/type/PlatformType.java index f861753bf8..4eb1103f30 100644 --- a/core/src/main/java/org/lflang/target/property/type/PlatformType.java +++ b/core/src/main/java/org/lflang/target/property/type/PlatformType.java @@ -53,5 +53,13 @@ public boolean isMultiThreaded() { public Platform getDefault() { return Platform.AUTO; } + + /** Return {@code true} if the given platform supports federated. */ + public static boolean supportsFederated(Platform platform) { + return switch (platform) { + case AUTO, LINUX, MAC -> true; + default -> false; + }; + } } } From 1406621978dcbb94fae3d0f696c66805340e9304 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 29 Sep 2024 13:50:13 -0700 Subject: [PATCH 57/61] Dead code removal --- .../target/property/PlatformProperty.java | 8 ------ .../target/property/type/PlatformType.java | 26 +++++++------------ 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/org/lflang/target/property/PlatformProperty.java b/core/src/main/java/org/lflang/target/property/PlatformProperty.java index 9051a7c74a..ecd6574b8b 100644 --- a/core/src/main/java/org/lflang/target/property/PlatformProperty.java +++ b/core/src/main/java/org/lflang/target/property/PlatformProperty.java @@ -2,7 +2,6 @@ import org.lflang.MessageReporter; import org.lflang.ast.ASTUtils; -import org.lflang.federated.generator.FederateTargetConfig; import org.lflang.lf.Element; import org.lflang.lf.KeyValuePair; import org.lflang.lf.KeyValuePairs; @@ -164,16 +163,9 @@ private void validateFlexPRET(TargetConfig config, MessageReporter reporter) { } } - private void federatedNotSupported(TargetConfig config, MessageReporter reporter) { - if (config instanceof FederateTargetConfig) { - reporter.nowhere().error("This platform does not support federations."); - } - } - private void validateZephyr(TargetConfig config, MessageReporter reporter) { var platform = config.get(PlatformProperty.INSTANCE); var singleThreaded = config.get(SingleThreadedProperty.INSTANCE); - federatedNotSupported(config, reporter); if (singleThreaded) { if (platform.userThreads().value() > 0) { reporter diff --git a/core/src/main/java/org/lflang/target/property/type/PlatformType.java b/core/src/main/java/org/lflang/target/property/type/PlatformType.java index 4eb1103f30..4bfc726f9f 100644 --- a/core/src/main/java/org/lflang/target/property/type/PlatformType.java +++ b/core/src/main/java/org/lflang/target/property/type/PlatformType.java @@ -12,27 +12,23 @@ protected Class enumClass() { public enum Platform { AUTO, - ARDUINO, // FIXME: not multithreaded - NRF52("nRF52", false), - RP2040("Rp2040", true), - LINUX("Linux", true), - MAC("Darwin", true), - ZEPHYR("Zephyr", true), - FLEXPRET("FlexPRET", true), - WINDOWS("Windows", true); + ARDUINO, + NRF52("nRF52"), + RP2040("Rp2040"), + LINUX("Linux"), + MAC("Darwin"), + ZEPHYR("Zephyr"), + FLEXPRET("FlexPRET"), + WINDOWS("Windows"); final String cMakeName; - private final boolean multiThreaded; - Platform() { this.cMakeName = this.toString(); - this.multiThreaded = true; } - Platform(String cMakeName, boolean isMultiThreaded) { + Platform(String cMakeName) { this.cMakeName = cMakeName; - this.multiThreaded = isMultiThreaded; } /** Return the name in lower case. */ @@ -46,10 +42,6 @@ public String getcMakeName() { return this.cMakeName; } - public boolean isMultiThreaded() { - return this.multiThreaded; - } - public Platform getDefault() { return Platform.AUTO; } From 0c30bcf8f8dfc4ce0f1ff180b8f4a3bb6a1c84ca Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 29 Sep 2024 14:30:08 -0700 Subject: [PATCH 58/61] Produce target code but do no run target compiler for each federate when `--no-compile` is used --- .../java/org/lflang/federated/generator/FedGenerator.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/core/src/main/java/org/lflang/federated/generator/FedGenerator.java b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java index e1f36a9ad1..93f67bc927 100644 --- a/core/src/main/java/org/lflang/federated/generator/FedGenerator.java +++ b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java @@ -174,12 +174,6 @@ public boolean doGenerate(Resource resource, LFGeneratorContext context) throws federates.stream().map(fed -> fed.name).collect(Collectors.toList()))); } - // Do not invoke target code generators if --no-compile flag is used. - if (context.getTargetConfig().get(NoCompileProperty.INSTANCE)) { - context.finish(Status.GENERATED, lf2lfCodeMapMap); - return false; - } - // If the RTI is to be built locally, set up a build environment for it. prepareRtiBuildEnvironment(context); From 4fc3f5f21024ed044e7b403a0bb84ddf99b66446 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 29 Sep 2024 14:37:08 -0700 Subject: [PATCH 59/61] Reduce scope of check --- .../lflang/federated/generator/FedGenerator.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/lflang/federated/generator/FedGenerator.java b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java index 0d1d29a3cc..dd94a4354d 100644 --- a/core/src/main/java/org/lflang/federated/generator/FedGenerator.java +++ b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java @@ -318,12 +318,15 @@ private boolean federatedExecutionIsSupported(Resource resource, LFGeneratorCont .error("Federated LF programs with a C target are currently not supported on Windows."); targetOK = false; } - var platform = context.getTargetConfig().get(PlatformProperty.INSTANCE).platform(); - if (!supportsFederated(platform)) { - messageReporter - .at(targetDecl) - .error("Federations are not supported by the " + platform.getcMakeName() + " platform."); - targetOK = false; + if (target.equals(Target.C) || target.equals(Target.CCPP)) { + // Currently, only the C runtime has a platform abstraction. + var platform = context.getTargetConfig().get(PlatformProperty.INSTANCE).platform(); + if (!supportsFederated(platform)) { + messageReporter + .at(targetDecl) + .error("Federations are not supported by the " + platform.getcMakeName() + " platform."); + targetOK = false; + } } return targetOK; From 777e2316276b3007f78d42d2261173ef0b6f7ddf Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 29 Sep 2024 15:03:39 -0700 Subject: [PATCH 60/61] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 261636f015..5af0226c8d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,10 @@ [Contributing](CONTRIBUTING.md) | [Changelog](CHANGELOG.md) -[![Build Status](https://github.com/lf-lang/lingua-franca/workflows/CI/badge.svg)](https://github.com/lf-lang/lingua-franca/actions/) +[![CI (targets)](https://github.com/lf-lang/lingua-franca/actions/workflows/all-targets.yml/badge.svg)](https://github.com/lf-lang/lingua-franca/actions/workflows/all-targets.yml?query=branch%3Amaster) +[![CI (misc)](https://github.com/lf-lang/lingua-franca/actions/workflows/all-misc.yml/badge.svg)](https://github.com/lf-lang/lingua-franca/actions/workflows/all-misc.yml?query=branch%3Amaster) +[![CI (misc)](https://github.com/lf-lang/lingua-franca/actions/workflows/all-embedded.yml/badge.svg)]([https://github.com/lf-lang/lingua-franca/actions/](https://github.com/lf-lang/lingua-franca/actions/workflows/all-embedded.yml?query=branch%3Amaster)) + [![Nightly Build](https://github.com/lf-lang/lingua-franca/actions/workflows/nightly-build.yml/badge.svg)](https://github.com/lf-lang/lingua-franca/actions/workflows/nightly-build.yml) [![CodeCov](https://codecov.io/gh/lf-lang/lingua-franca/branch/master/graph/badge.svg?token=b7LrpihI5a)](https://codecov.io/gh/lf-lang/lingua-franca) [![GitHub Contributors](https://img.shields.io/github/contributors/lf-lang/lingua-franca)](https://github.com/lf-lang/lingua-franca/graphs/contributors) From 805f95bf4b6a2d69bba8a9c32e928d29b84a2772 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 29 Sep 2024 15:05:07 -0700 Subject: [PATCH 61/61] Formatting --- .../main/java/org/lflang/federated/generator/FedGenerator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/lflang/federated/generator/FedGenerator.java b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java index dd94a4354d..94df476594 100644 --- a/core/src/main/java/org/lflang/federated/generator/FedGenerator.java +++ b/core/src/main/java/org/lflang/federated/generator/FedGenerator.java @@ -324,7 +324,8 @@ private boolean federatedExecutionIsSupported(Resource resource, LFGeneratorCont if (!supportsFederated(platform)) { messageReporter .at(targetDecl) - .error("Federations are not supported by the " + platform.getcMakeName() + " platform."); + .error( + "Federations are not supported by the " + platform.getcMakeName() + " platform."); targetOK = false; } }