From d8fbe136691511779f53ef472d7d979b61bf7b7f Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 2 Feb 2024 15:35:23 -0800 Subject: [PATCH 01/20] Make changes needed to pluginfy tracing. --- .../org/lflang/federated/extensions/CExtensionUtils.java | 1 + core/src/main/java/org/lflang/generator/CodeBuilder.java | 9 +++++++-- .../src/main/java/org/lflang/generator/c/CGenerator.java | 4 +--- .../java/org/lflang/generator/c/CTracingGenerator.java | 9 ++------- core/src/main/java/org/lflang/util/FileUtil.java | 5 ++++- core/src/main/resources/lib/c/reactor-c | 2 +- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java index fb74f98c1a..5737efe116 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java @@ -201,6 +201,7 @@ public static void handleCompileDefinitions( } definitions.put("NUMBER_OF_FEDERATES", String.valueOf(numOfFederates)); definitions.put("EXECUTABLE_PREAMBLE", ""); + definitions.put("FEDERATE_ID", String.valueOf(federate.id)); CompileDefinitionsProperty.INSTANCE.update(federate.targetConfig, definitions); diff --git a/core/src/main/java/org/lflang/generator/CodeBuilder.java b/core/src/main/java/org/lflang/generator/CodeBuilder.java index 9fe82e46fd..af82d70512 100644 --- a/core/src/main/java/org/lflang/generator/CodeBuilder.java +++ b/core/src/main/java/org/lflang/generator/CodeBuilder.java @@ -126,7 +126,8 @@ public void prSourceLineNumber(EObject eObject, boolean suppress) { } } // Extract the filename from eResource, an astonishingly difficult thing to do. - String filePath = CommonPlugin.resolve(eObject.eResource().getURI()).path(); + String filePath = + CommonPlugin.resolve(eObject.eResource().getURI()).path().replace("\\", "\\\\"); pr("#line " + (node.getStartLine() + offset) + " \"" + filePath + "\""); } } @@ -558,7 +559,11 @@ public CodeMap writeToFile(String path) throws IOException { for (var line : (Iterable) () -> s.lines().iterator()) { lineNumber++; if (line.contains(END_SOURCE_LINE_NUMBER_TAG) && !path.endsWith(".ino")) { - out.append("#line ").append(lineNumber).append(" \"").append(path).append("\""); + out.append("#line ") + .append(lineNumber) + .append(" \"") + .append(path.replace("\\", "\\\\")) + .append("\""); } else { out.append(line); } 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 603af72443..52ce40fb26 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -921,6 +921,7 @@ protected void copyTargetFiles() throws IOException { FileUtil.copyDirectoryContents(coreLib, dest, true); } else { FileUtil.copyFromClassPath("/lib/c/reactor-c/core", dest, true, false); + FileUtil.copyFromClassPath("/lib/c/reactor-c/plugin-defaults", dest, true, false); FileUtil.copyFromClassPath("/lib/c/reactor-c/lib", dest, true, false); } } @@ -1377,13 +1378,10 @@ private void recordBuiltinTriggers(ReactorInstance instance) { if (targetConfig.get(TracingProperty.INSTANCE).isEnabled()) { var description = CUtil.getShortenedName(reactor); var reactorRef = CUtil.reactorRef(reactor); - var envTraceRef = CUtil.getEnvironmentStruct(reactor) + ".trace"; temp.pr( String.join( "\n", "_lf_register_trace_event(" - + envTraceRef - + "," + reactorRef + ", &(" + reactorRef diff --git a/core/src/main/java/org/lflang/generator/c/CTracingGenerator.java b/core/src/main/java/org/lflang/generator/c/CTracingGenerator.java index b013913756..8439d562b0 100644 --- a/core/src/main/java/org/lflang/generator/c/CTracingGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CTracingGenerator.java @@ -30,12 +30,10 @@ public static String generateTraceTableEntries(ReactorInstance instance) { List code = new ArrayList<>(); var description = CUtil.getShortenedName(instance); var selfStruct = CUtil.reactorRef(instance); - var envTraceRef = CUtil.getEnvironmentStruct(instance) + ".trace"; - code.add(registerTraceEvent(envTraceRef, selfStruct, "NULL", "trace_reactor", description)); + code.add(registerTraceEvent(selfStruct, "NULL", "trace_reactor", description)); for (ActionInstance action : instance.actions) { code.add( registerTraceEvent( - envTraceRef, selfStruct, getTrigger(selfStruct, action.getName()), "trace_trigger", @@ -44,7 +42,6 @@ public static String generateTraceTableEntries(ReactorInstance instance) { for (TimerInstance timer : instance.timers) { code.add( registerTraceEvent( - envTraceRef, selfStruct, getTrigger(selfStruct, timer.getName()), "trace_trigger", @@ -54,10 +51,8 @@ public static String generateTraceTableEntries(ReactorInstance instance) { } private static String registerTraceEvent( - String envTrace, String obj, String trigger, String type, String description) { + String obj, String trigger, String type, String description) { return "_lf_register_trace_event(" - + envTrace - + ", " + obj + ", " + trigger diff --git a/core/src/main/java/org/lflang/util/FileUtil.java b/core/src/main/java/org/lflang/util/FileUtil.java index ade0def1c2..cbbf75fdd9 100644 --- a/core/src/main/java/org/lflang/util/FileUtil.java +++ b/core/src/main/java/org/lflang/util/FileUtil.java @@ -663,6 +663,7 @@ public static void arduinoDeleteHelper(Path srcGenPath, boolean threadingOn) thr deleteDirectory(srcGenPath.resolve("include/core/threaded")); deleteDirectory(srcGenPath.resolve("src/core/platform/arduino_mbed")); } + deleteDirectory(srcGenPath.resolve("src").resolve("plugin-defaults").resolve("trace")); // Delete all the federated headers deleteDirectory(srcGenPath.resolve("include/core/federated")); // arduino-cli needs all headers to be under a "include" directory. @@ -748,7 +749,9 @@ public static void relativeIncludeHelper( if (path.getFileName().toString().contains("CMakeLists.txt")) continue; if (fileStringToFilePath.put(fileName, path) != null) { throw new IOException( - "Directory has different files with the same name. Cannot Relativize."); + String.format( + "Directory has different files with the same name (%s). Cannot relativize.", + fileName)); } } Pattern regexExpression = Pattern.compile("#include\s+[\"]([^\"]+)*[\"]"); diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 3cb75cf710..c9005b234c 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 3cb75cf7104bb4ef88629271c19f1b3b3556823a +Subproject commit c9005b234c4f7c47462fb0f1d1e635cc049a6969 From ee17fbb85be0f9c9a47c4e71dafd6521f7b69c11 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 2 Feb 2024 21:29:34 -0800 Subject: [PATCH 02/20] Update Zephyr config file --- 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 88613edc08..6b171daff2 100644 --- a/core/src/main/resources/lib/platform/zephyr/prj_lf.conf +++ b/core/src/main/resources/lib/platform/zephyr/prj_lf.conf @@ -12,3 +12,4 @@ CONFIG_NEWLIB_LIBC=y CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y # Enable the counter API used for hi-res clock CONFIG_COUNTER=y +CONFIG_THREAD_CUSTOM_DATA=y From bf01947ecb0973a6a6b99066a42d5dbf5d251c69 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 13 Feb 2024 13:35:11 -0800 Subject: [PATCH 03/20] Update 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 c9005b234c..93a6423838 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit c9005b234c4f7c47462fb0f1d1e635cc049a6969 +Subproject commit 93a6423838665b12fcdac086d3441857f3d35563 From 31d30088539666237649a41a33a74ae19e71dde6 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 13 Feb 2024 21:37:03 -0800 Subject: [PATCH 04/20] Update 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 93a6423838..d54db27952 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 93a6423838665b12fcdac086d3441857f3d35563 +Subproject commit d54db27952b2fc0cc91c3f99341eed9759b929e6 From c2aed67f921ac4894723393560a275dec8b19ae6 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 13 Feb 2024 21:43:16 -0800 Subject: [PATCH 05/20] Update 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 d54db27952..e13b59d711 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit d54db27952b2fc0cc91c3f99341eed9759b929e6 +Subproject commit e13b59d7112e90e64f5c286f8bcd991471c47b9f From accac0adf7a7a1e22395b5e91a73811d973bb2f2 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 18 Feb 2024 00:38:54 -0800 Subject: [PATCH 06/20] Fix automatic release tag --- .github/workflows/custom-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/custom-build.yml b/.github/workflows/custom-build.yml index fbbd9c1967..9f63be882f 100644 --- a/.github/workflows/custom-build.yml +++ b/.github/workflows/custom-build.yml @@ -35,7 +35,7 @@ jobs: uses: marvinpinto/action-automatic-releases@latest with: repo_token: "${{ secrets.NIGHTLY_BUILD }}" - automatic_release_tag: '${{ github.ref_name }}-${{ github.env.timestamp }}' + automatic_release_tag: '${{ github.ref_name }}' prerelease: true draft: true title: "Custom Lingua Franca build for ${{ github.ref_name }} branch" From 82d518fef2d3c227d661a4d66a2deb195a206f64 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 22 Feb 2024 18:41:26 -0800 Subject: [PATCH 07/20] Get src/Minimal.lf to compile. --- core/src/main/java/org/lflang/generator/c/CGenerator.java | 8 ++++---- .../java/org/lflang/generator/c/CPreambleGenerator.java | 2 +- core/src/main/resources/lib/c/reactor-c | 2 +- 3 files changed, 6 insertions(+), 6 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 9c10e7920d..104ca989c2 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -927,9 +927,9 @@ protected void copyTargetFiles() throws IOException { Path coreLib = Paths.get(context.getArgs().externalRuntimeUri()); FileUtil.copyDirectoryContents(coreLib, dest, true); } else { - FileUtil.copyFromClassPath("/lib/c/reactor-c/core", dest, true, false); - FileUtil.copyFromClassPath("/lib/c/reactor-c/plugin-defaults", dest, true, false); - FileUtil.copyFromClassPath("/lib/c/reactor-c/lib", dest, true, false); + for (var directory : List.of("core", "lib", "logging", "platform", "low_level_platform", "trace", "version", "tag")) { + FileUtil.copyFromClassPath("/lib/c/reactor-c/" + directory, dest, true, false); + } } } @@ -978,7 +978,7 @@ protected void generateReactorClassHeaders( } header.pr("#include \"include/core/reactor.h\""); src.pr("#include \"include/api/schedule.h\""); - src.pr("#include \"include/core/platform.h\""); + src.pr("#include \"low_level_platform/api/low_level_platform.h\""); generateIncludes(tpr); if (cppMode) { src.pr("}"); diff --git a/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java b/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java index 3f8118a2d2..1fe0371ca0 100644 --- a/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java @@ -41,7 +41,7 @@ public static String generateIncludeStatements(TargetConfig targetConfig, boolea code.pr("extern \"C\" {"); } code.pr("#include "); - code.pr("#include \"include/core/platform.h\""); + code.pr("#include \"low_level_platform/api/low_level_platform.h\""); CCoreFilesUtils.getCTargetHeader() .forEach(it -> code.pr("#include " + StringUtil.addDoubleQuotes(it))); code.pr("#include \"include/core/reactor.h\""); diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 72b2ecc4cc..2c9f219c75 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 72b2ecc4cc15eada00d0933c6976db467e9ff3f6 +Subproject commit 2c9f219c75d8c39093cbd18fd0e1e4b151cac676 From 8ca794d4a988b5f90da5013c1db177caa3bc855b Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 22 Feb 2024 19:04:12 -0800 Subject: [PATCH 08/20] Get HelloWorld (with tracing) to compile. --- .../main/java/org/lflang/generator/c/CPreambleGenerator.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/CPreambleGenerator.java b/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java index 1fe0371ca0..f91278b455 100644 --- a/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java @@ -51,7 +51,7 @@ public static String generateIncludeStatements(TargetConfig targetConfig, boolea } if (targetConfig.get(TracingProperty.INSTANCE).isEnabled()) { - code.pr("#include \"include/core/trace.h\""); + code.pr("#include \"trace/api/trace.h\""); } code.pr("#include \"include/core/mixed_radix.h\""); code.pr("#include \"include/core/port.h\""); diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 2c9f219c75..74caa43811 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 2c9f219c75d8c39093cbd18fd0e1e4b151cac676 +Subproject commit 74caa43811fdeff20c72ca0b1284acc3a292da82 From 3b32699d5aee608de87cb2589187be2853106469 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 22 Feb 2024 22:16:33 -0800 Subject: [PATCH 09/20] Get Blink.lf (for Arduino) to compile --- .../org/lflang/generator/c/CGenerator.java | 24 +++++++++++++++++-- .../generator/c/CPreambleGenerator.java | 8 +++++-- .../main/java/org/lflang/util/FileUtil.java | 2 +- core/src/main/resources/lib/c/reactor-c | 2 +- 4 files changed, 30 insertions(+), 6 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 104ca989c2..5153961091 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -100,6 +100,7 @@ import org.lflang.target.property.ProtobufsProperty; import org.lflang.target.property.SchedulerProperty; import org.lflang.target.property.SingleThreadedProperty; +import org.lflang.target.property.TargetProperty; import org.lflang.target.property.TracingProperty; import org.lflang.target.property.WorkersProperty; import org.lflang.target.property.type.PlatformType.Platform; @@ -893,12 +894,14 @@ private void pickCompilePlatform() { /** Copy target-specific header file to the src-gen directory. */ protected void copyTargetFiles() throws IOException { Path dest = fileConfig.getSrcGenPath(); + var arduino = false; if (targetConfig.isSet(PlatformProperty.INSTANCE)) { var platform = targetConfig.get(PlatformProperty.INSTANCE).platform(); switch (platform) { case ARDUINO -> { // For Arduino, alter the destination directory. dest = dest.resolve("src"); + arduino = true; } case ZEPHYR -> { // For the Zephyr target, copy default config and board files. @@ -927,9 +930,22 @@ protected void copyTargetFiles() throws IOException { Path coreLib = Paths.get(context.getArgs().externalRuntimeUri()); FileUtil.copyDirectoryContents(coreLib, dest, true); } else { - for (var directory : List.of("core", "lib", "logging", "platform", "low_level_platform", "trace", "version", "tag")) { + for (var directory : List.of("core", "lib")) { FileUtil.copyFromClassPath("/lib/c/reactor-c/" + directory, dest, true, false); } + for (var directory : List.of("logging", "platform", "low_level_platform", "trace", "version", "tag")) { + var entry = "/lib/c/reactor-c/" + directory; + if (arduino) { + if (FileConfig.class.getResource(entry + "/api") != null) { + FileUtil.copyFromClassPath(entry + "/api", fileConfig.getSrcGenPath().resolve("include").resolve(directory), true, false); + } + if (FileConfig.class.getResource(entry + "/impl") != null) { + FileUtil.copyFromClassPath(entry + "/impl", dest.resolve(directory), true, false); + } + } else { + FileUtil.copyFromClassPath(entry, dest, true, false); + } + } } } @@ -978,7 +994,11 @@ protected void generateReactorClassHeaders( } header.pr("#include \"include/core/reactor.h\""); src.pr("#include \"include/api/schedule.h\""); - src.pr("#include \"low_level_platform/api/low_level_platform.h\""); + if (CPreambleGenerator.arduinoBased(targetConfig)) { + src.pr("#include \"include/low_level_platform/api/low_level_platform.h\""); + } else { + src.pr("#include \"low_level_platform/api/low_level_platform.h\""); + } generateIncludes(tpr); if (cppMode) { src.pr("}"); diff --git a/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java b/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java index f91278b455..53b35002f4 100644 --- a/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java @@ -30,7 +30,7 @@ */ public class CPreambleGenerator { - private static boolean arduinoBased(TargetConfig targetConfig) { + public static boolean arduinoBased(TargetConfig targetConfig) { return targetConfig.isSet(PlatformProperty.INSTANCE) && targetConfig.get(PlatformProperty.INSTANCE).platform() == Platform.ARDUINO; } @@ -41,7 +41,11 @@ public static String generateIncludeStatements(TargetConfig targetConfig, boolea code.pr("extern \"C\" {"); } code.pr("#include "); - code.pr("#include \"low_level_platform/api/low_level_platform.h\""); + if (arduinoBased(targetConfig)) { + code.pr("#include \"include/low_level_platform/api/low_level_platform.h\""); + } else { + code.pr("#include \"low_level_platform/api/low_level_platform.h\""); + } CCoreFilesUtils.getCTargetHeader() .forEach(it -> code.pr("#include " + StringUtil.addDoubleQuotes(it))); code.pr("#include \"include/core/reactor.h\""); diff --git a/core/src/main/java/org/lflang/util/FileUtil.java b/core/src/main/java/org/lflang/util/FileUtil.java index cbbf75fdd9..67b62d9a59 100644 --- a/core/src/main/java/org/lflang/util/FileUtil.java +++ b/core/src/main/java/org/lflang/util/FileUtil.java @@ -663,7 +663,7 @@ public static void arduinoDeleteHelper(Path srcGenPath, boolean threadingOn) thr deleteDirectory(srcGenPath.resolve("include/core/threaded")); deleteDirectory(srcGenPath.resolve("src/core/platform/arduino_mbed")); } - deleteDirectory(srcGenPath.resolve("src").resolve("plugin-defaults").resolve("trace")); + deleteDirectory(srcGenPath.resolve("src").resolve("trace")); // Delete all the federated headers deleteDirectory(srcGenPath.resolve("include/core/federated")); // arduino-cli needs all headers to be under a "include" directory. diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 74caa43811..182d02ea22 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 74caa43811fdeff20c72ca0b1284acc3a292da82 +Subproject commit 182d02ea22bcd4925e8254071ba4aaa4de35210b From f331b1ba13e3518a661f3e69ba0d0b6bf7958416 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 24 Feb 2024 11:18:45 -0800 Subject: [PATCH 10/20] Update 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 70e59e400b..f5c780e6d7 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 70e59e400bdc1ba07dcd60d7a71df31b15bbae47 +Subproject commit f5c780e6d70e84800a32bf08b6cbeb194b1e6043 From 85044e14e74c549b578abdaa9c254b89f68e1e56 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 24 Feb 2024 11:22:39 -0800 Subject: [PATCH 11/20] Format --- .../main/java/org/lflang/generator/c/CGenerator.java | 10 +++++++--- 1 file changed, 7 insertions(+), 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 1ffe953b77..9414010641 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -100,7 +100,6 @@ import org.lflang.target.property.ProtobufsProperty; import org.lflang.target.property.SchedulerProperty; import org.lflang.target.property.SingleThreadedProperty; -import org.lflang.target.property.TargetProperty; import org.lflang.target.property.TracingProperty; import org.lflang.target.property.WorkersProperty; import org.lflang.target.property.type.PlatformType.Platform; @@ -933,11 +932,16 @@ protected void copyTargetFiles() throws IOException { for (var directory : List.of("core", "lib")) { FileUtil.copyFromClassPath("/lib/c/reactor-c/" + directory, dest, true, false); } - for (var directory : List.of("logging", "platform", "low_level_platform", "trace", "version", "tag")) { + for (var directory : + List.of("logging", "platform", "low_level_platform", "trace", "version", "tag")) { var entry = "/lib/c/reactor-c/" + directory; if (arduino) { if (FileConfig.class.getResource(entry + "/api") != null) { - FileUtil.copyFromClassPath(entry + "/api", fileConfig.getSrcGenPath().resolve("include").resolve(directory), true, false); + FileUtil.copyFromClassPath( + entry + "/api", + fileConfig.getSrcGenPath().resolve("include").resolve(directory), + true, + false); } if (FileConfig.class.getResource(entry + "/impl") != null) { FileUtil.copyFromClassPath(entry + "/impl", dest.resolve(directory), true, false); From 42b187151f3831f43f6335e87ff035514b8c9831 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 24 Feb 2024 13:45:03 -0800 Subject: [PATCH 12/20] Update 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 f5c780e6d7..61200e9df7 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit f5c780e6d70e84800a32bf08b6cbeb194b1e6043 +Subproject commit 61200e9df7c25fa8622091f3a5416c7b372c3d5b From 71cb6e644b237a223963282b85d24a86d0239564 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 26 Feb 2024 00:24:57 -0800 Subject: [PATCH 13/20] Add trace-plugin target property. --- .../org/lflang/generator/c/CCompiler.java | 6 +++ .../main/java/org/lflang/target/Target.java | 2 + .../target/property/TracePluginProperty.java | 54 +++++++++++++++++++ core/src/main/resources/lib/c/reactor-c | 2 +- 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/org/lflang/target/property/TracePluginProperty.java diff --git a/core/src/main/java/org/lflang/generator/c/CCompiler.java b/core/src/main/java/org/lflang/generator/c/CCompiler.java index 98ca19aacf..374d31f608 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -42,6 +42,8 @@ import org.lflang.target.property.CompilerProperty; import org.lflang.target.property.PlatformProperty; import org.lflang.target.property.PlatformProperty.PlatformOptions; +import org.lflang.target.property.TargetProperty; +import org.lflang.target.property.TracePluginProperty; import org.lflang.target.property.type.BuildTypeType.BuildType; import org.lflang.target.property.type.PlatformType.Platform; import org.lflang.util.FileUtil; @@ -237,6 +239,10 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f "-DCMAKE_INSTALL_BINDIR=" + FileUtil.toUnixString(fileConfig.getOutPath().relativize(fileConfig.binPath)), "-DLF_FILE_SEPARATOR=\"" + maybeQuote + separator + maybeQuote + "\"")); + var tracePlugin = targetConfig.getOrDefault(TracePluginProperty.INSTANCE); + if (tracePlugin != null) { + arguments.add("-DLF_TRACE_PLUGIN=" + targetConfig.getOrDefault(TracePluginProperty.INSTANCE).getImplementationArchiveFile()); + } // Add #define for source file directory. // Do not do this for federated programs because for those, the definition is put // into the cmake file (and fileConfig.srcPath is the wrong directory anyway). diff --git a/core/src/main/java/org/lflang/target/Target.java b/core/src/main/java/org/lflang/target/Target.java index a01b863303..573b121566 100644 --- a/core/src/main/java/org/lflang/target/Target.java +++ b/core/src/main/java/org/lflang/target/Target.java @@ -57,6 +57,7 @@ import org.lflang.target.property.SchedulerProperty; import org.lflang.target.property.SingleFileProjectProperty; import org.lflang.target.property.SingleThreadedProperty; +import org.lflang.target.property.TracePluginProperty; import org.lflang.target.property.TracingProperty; import org.lflang.target.property.VerifyProperty; import org.lflang.target.property.WorkersProperty; @@ -605,6 +606,7 @@ public void initialize(TargetConfig config) { SchedulerProperty.INSTANCE, SingleThreadedProperty.INSTANCE, TracingProperty.INSTANCE, + TracePluginProperty.INSTANCE, VerifyProperty.INSTANCE, WorkersProperty.INSTANCE); case CPP -> config.register( diff --git a/core/src/main/java/org/lflang/target/property/TracePluginProperty.java b/core/src/main/java/org/lflang/target/property/TracePluginProperty.java new file mode 100644 index 0000000000..51c26de7dc --- /dev/null +++ b/core/src/main/java/org/lflang/target/property/TracePluginProperty.java @@ -0,0 +1,54 @@ +package org.lflang.target.property; + +import org.lflang.MessageReporter; +import org.lflang.lf.Element; +import org.lflang.target.property.TracePluginProperty.TracePluginOptions; +import org.lflang.target.property.type.PrimitiveType; + +/** + * Property that provides an alternative tracing implementation. + */ +public class TracePluginProperty extends TargetProperty { + + /** Singleton target property instance. */ + public static final TracePluginProperty INSTANCE = new TracePluginProperty(); + + private TracePluginProperty() { + super(PrimitiveType.STRING); + } + + @Override + public TracePluginOptions initialValue() { + return null; + } + + @Override + protected TracePluginOptions fromAst(Element node, MessageReporter reporter) { + throw new IllegalArgumentException("There is no representation of this property in the LF target property syntax"); + } + + @Override + protected TracePluginOptions fromString(String s, MessageReporter reporter) { + return new TracePluginOptions(s); + } + + @Override + public String name() { + return "trace-plugin"; + } + + @Override + public Element toAstElement(TracePluginOptions value) { + throw new IllegalArgumentException("There is no representation of this property in the LF target property syntax"); + } + + public static class TracePluginOptions { + private final String implementationArchiveFile; + public TracePluginOptions(String implementationArchiveFile) { + this.implementationArchiveFile = implementationArchiveFile; + } + public String getImplementationArchiveFile() { + return implementationArchiveFile; + } + } +} diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 61200e9df7..ed9202c1c8 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 61200e9df7c25fa8622091f3a5416c7b372c3d5b +Subproject commit ed9202c1c8920012588a529776394584d8b6f10e From e39f5186fbb22a57544b51ea00278f334e599189 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 26 Feb 2024 00:32:37 -0800 Subject: [PATCH 14/20] Update 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 ed9202c1c8..f0c1454303 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit ed9202c1c8920012588a529776394584d8b6f10e +Subproject commit f0c1454303ccb05d9938b4b179e2a0d70f380859 From 0b22ffd75183634236e7a1165f3cb0ecd21633b9 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 26 Feb 2024 00:39:39 -0800 Subject: [PATCH 15/20] Format --- .../org/lflang/generator/c/CCompiler.java | 7 +- .../target/property/TracePluginProperty.java | 84 ++++++++++--------- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CCompiler.java b/core/src/main/java/org/lflang/generator/c/CCompiler.java index 374d31f608..c0401b5684 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -42,7 +42,6 @@ import org.lflang.target.property.CompilerProperty; import org.lflang.target.property.PlatformProperty; import org.lflang.target.property.PlatformProperty.PlatformOptions; -import org.lflang.target.property.TargetProperty; import org.lflang.target.property.TracePluginProperty; import org.lflang.target.property.type.BuildTypeType.BuildType; import org.lflang.target.property.type.PlatformType.Platform; @@ -241,7 +240,11 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f "-DLF_FILE_SEPARATOR=\"" + maybeQuote + separator + maybeQuote + "\"")); var tracePlugin = targetConfig.getOrDefault(TracePluginProperty.INSTANCE); if (tracePlugin != null) { - arguments.add("-DLF_TRACE_PLUGIN=" + targetConfig.getOrDefault(TracePluginProperty.INSTANCE).getImplementationArchiveFile()); + arguments.add( + "-DLF_TRACE_PLUGIN=" + + targetConfig + .getOrDefault(TracePluginProperty.INSTANCE) + .getImplementationArchiveFile()); } // Add #define for source file directory. // Do not do this for federated programs because for those, the definition is put diff --git a/core/src/main/java/org/lflang/target/property/TracePluginProperty.java b/core/src/main/java/org/lflang/target/property/TracePluginProperty.java index 51c26de7dc..92c6b0c853 100644 --- a/core/src/main/java/org/lflang/target/property/TracePluginProperty.java +++ b/core/src/main/java/org/lflang/target/property/TracePluginProperty.java @@ -5,50 +5,52 @@ import org.lflang.target.property.TracePluginProperty.TracePluginOptions; import org.lflang.target.property.type.PrimitiveType; -/** - * Property that provides an alternative tracing implementation. - */ +/** Property that provides an alternative tracing implementation. */ public class TracePluginProperty extends TargetProperty { - /** Singleton target property instance. */ - public static final TracePluginProperty INSTANCE = new TracePluginProperty(); - - private TracePluginProperty() { - super(PrimitiveType.STRING); - } - - @Override - public TracePluginOptions initialValue() { - return null; - } - - @Override - protected TracePluginOptions fromAst(Element node, MessageReporter reporter) { - throw new IllegalArgumentException("There is no representation of this property in the LF target property syntax"); - } - - @Override - protected TracePluginOptions fromString(String s, MessageReporter reporter) { - return new TracePluginOptions(s); - } - - @Override - public String name() { - return "trace-plugin"; - } - - @Override - public Element toAstElement(TracePluginOptions value) { - throw new IllegalArgumentException("There is no representation of this property in the LF target property syntax"); + /** Singleton target property instance. */ + public static final TracePluginProperty INSTANCE = new TracePluginProperty(); + + private TracePluginProperty() { + super(PrimitiveType.STRING); + } + + @Override + public TracePluginOptions initialValue() { + return null; + } + + @Override + protected TracePluginOptions fromAst(Element node, MessageReporter reporter) { + throw new IllegalArgumentException( + "There is no representation of this property in the LF target property syntax"); + } + + @Override + protected TracePluginOptions fromString(String s, MessageReporter reporter) { + return new TracePluginOptions(s); + } + + @Override + public String name() { + return "trace-plugin"; + } + + @Override + public Element toAstElement(TracePluginOptions value) { + throw new IllegalArgumentException( + "There is no representation of this property in the LF target property syntax"); + } + + public static class TracePluginOptions { + private final String implementationArchiveFile; + + public TracePluginOptions(String implementationArchiveFile) { + this.implementationArchiveFile = implementationArchiveFile; } - public static class TracePluginOptions { - private final String implementationArchiveFile; - public TracePluginOptions(String implementationArchiveFile) { - this.implementationArchiveFile = implementationArchiveFile; - } - public String getImplementationArchiveFile() { - return implementationArchiveFile; - } + public String getImplementationArchiveFile() { + return implementationArchiveFile; } + } } From e436544314e08d9c648e97dc27dcb13ec464a151 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 26 Feb 2024 01:00:03 -0800 Subject: [PATCH 16/20] Address validation test failure --- .../tests/compiler/LinguaFrancaValidationTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java index 41e68fa038..d27993df24 100644 --- a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -53,6 +53,7 @@ import org.lflang.target.property.CargoDependenciesProperty; import org.lflang.target.property.PlatformProperty; import org.lflang.target.property.TargetProperty; +import org.lflang.target.property.TracePluginProperty; import org.lflang.target.property.type.ArrayType; import org.lflang.target.property.type.DictionaryType; import org.lflang.target.property.type.DictionaryType.DictionaryElement; @@ -78,6 +79,14 @@ @InjectWith(LFInjectorProvider.class) public class LinguaFrancaValidationTest { + /** + * This is a list of tests that have no representation in LF syntax, possibly because we are + * moving away from keeping these in LF files and instead are moving toward keeping them in + * configuration files. + */ + private static final List> propertiesWithoutLfSyntaxRepresentation = + List.of(TracePluginProperty.INSTANCE); + @Inject ParseHelper parser; @Inject ValidationTestHelper validator; @@ -1565,6 +1574,10 @@ public Collection checkTargetProperties() throws Exception { for (TargetProperty property : TargetConfig.getMockInstance(Target.C).getRegisteredProperties()) { + if (propertiesWithoutLfSyntaxRepresentation.stream() + .anyMatch(it -> it.getClass().isInstance(property))) { + continue; + } if (property instanceof CargoDependenciesProperty) { // we test that separately as it has better error messages continue; From 53c0f56c373aac9c0a6871be4b431ee61ef93f89 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 26 Feb 2024 15:12:31 -0800 Subject: [PATCH 17/20] Address comment from code review --- .../java/org/lflang/target/TargetConfig.java | 4 +++ .../target/property/TracePluginProperty.java | 8 +++--- .../compiler/LinguaFrancaValidationTest.java | 26 +++++++++---------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/lflang/target/TargetConfig.java b/core/src/main/java/org/lflang/target/TargetConfig.java index 96ce5efc9e..f3dc1695f6 100644 --- a/core/src/main/java/org/lflang/target/TargetConfig.java +++ b/core/src/main/java/org/lflang/target/TargetConfig.java @@ -63,6 +63,10 @@ */ public class TargetConfig { + /** Error message to use when a target property does not exist in LF syntax. */ + public static final String NOT_IN_LF_SYNTAX_MESSAGE = + "There is no representation of this property in the LF target property syntax"; + /** The target of this configuration (e.g., C, TypeScript, Python). */ public final Target target; diff --git a/core/src/main/java/org/lflang/target/property/TracePluginProperty.java b/core/src/main/java/org/lflang/target/property/TracePluginProperty.java index 92c6b0c853..2d150b9fab 100644 --- a/core/src/main/java/org/lflang/target/property/TracePluginProperty.java +++ b/core/src/main/java/org/lflang/target/property/TracePluginProperty.java @@ -2,6 +2,7 @@ import org.lflang.MessageReporter; import org.lflang.lf.Element; +import org.lflang.target.TargetConfig; import org.lflang.target.property.TracePluginProperty.TracePluginOptions; import org.lflang.target.property.type.PrimitiveType; @@ -22,8 +23,8 @@ public TracePluginOptions initialValue() { @Override protected TracePluginOptions fromAst(Element node, MessageReporter reporter) { - throw new IllegalArgumentException( - "There is no representation of this property in the LF target property syntax"); + reporter.at(node).error(TargetConfig.NOT_IN_LF_SYNTAX_MESSAGE); + return null; } @Override @@ -38,8 +39,7 @@ public String name() { @Override public Element toAstElement(TracePluginOptions value) { - throw new IllegalArgumentException( - "There is no representation of this property in the LF target property syntax"); + throw new UnsupportedOperationException(TargetConfig.NOT_IN_LF_SYNTAX_MESSAGE); } public static class TracePluginOptions { diff --git a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java index d27993df24..577c02eb23 100644 --- a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -34,6 +34,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.eclipse.xtext.diagnostics.Severity; import org.eclipse.xtext.testing.InjectWith; import org.eclipse.xtext.testing.extensions.InjectionExtension; import org.eclipse.xtext.testing.util.ParseHelper; @@ -53,7 +54,6 @@ import org.lflang.target.property.CargoDependenciesProperty; import org.lflang.target.property.PlatformProperty; import org.lflang.target.property.TargetProperty; -import org.lflang.target.property.TracePluginProperty; import org.lflang.target.property.type.ArrayType; import org.lflang.target.property.type.DictionaryType; import org.lflang.target.property.type.DictionaryType.DictionaryElement; @@ -79,14 +79,6 @@ @InjectWith(LFInjectorProvider.class) public class LinguaFrancaValidationTest { - /** - * This is a list of tests that have no representation in LF syntax, possibly because we are - * moving away from keeping these in LF files and instead are moving toward keeping them in - * configuration files. - */ - private static final List> propertiesWithoutLfSyntaxRepresentation = - List.of(TracePluginProperty.INSTANCE); - @Inject ParseHelper parser; @Inject ValidationTestHelper validator; @@ -1574,10 +1566,6 @@ public Collection checkTargetProperties() throws Exception { for (TargetProperty property : TargetConfig.getMockInstance(Target.C).getRegisteredProperties()) { - if (propertiesWithoutLfSyntaxRepresentation.stream() - .anyMatch(it -> it.getClass().isInstance(property))) { - continue; - } if (property instanceof CargoDependenciesProperty) { // we test that separately as it has better error messages continue; @@ -1593,7 +1581,17 @@ public Collection checkTargetProperties() throws Exception { Model model = createModel(Target.C, property, it); System.out.println(property.name()); System.out.println(it.toString()); - validator.assertNoErrors(model); + var issues = validator.validate(model); + if (!issues.stream() + .allMatch( + issue -> + issue.getSeverity() != Severity.ERROR + || issue + .getMessage() + .equals(TargetConfig.NOT_IN_LF_SYNTAX_MESSAGE))) { + throw new RuntimeException( + "there were unexpected errors in the generated model"); + } // Also make sure warnings are produced when files are not present. if (type == PrimitiveType.FILE) { validator.assertWarning( From a030a1571cb4f93dda9f6712fc214d8bc23dc0ce Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 26 Feb 2024 15:12:48 -0800 Subject: [PATCH 18/20] Update 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 f0c1454303..ed1d76bb51 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit f0c1454303ccb05d9938b4b179e2a0d70f380859 +Subproject commit ed1d76bb51e5782a674fc0773fbf2799cbd457e7 From af432640090114fb27e6daa0d17605de86d9b3ad Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 26 Feb 2024 15:16:47 -0800 Subject: [PATCH 19/20] Update Javadoc --- .../main/java/org/lflang/target/property/TargetProperty.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/lflang/target/property/TargetProperty.java b/core/src/main/java/org/lflang/target/property/TargetProperty.java index d2d630d6b3..e1e1c444df 100644 --- a/core/src/main/java/org/lflang/target/property/TargetProperty.java +++ b/core/src/main/java/org/lflang/target/property/TargetProperty.java @@ -126,7 +126,9 @@ public void update(TargetConfig config, T value) { } /** - * Update the given configuration based on the given corresponding AST node. + * Update the given configuration based on the given corresponding AST node. If the given + * configuration does not belong in the AST, then report an error using the error message given by + * {@code TargetConfig.NOT_IN_LF_SYNTAX_MESSAGE}. * * @param config The configuration to update. * @param pair The pair that holds the value to perform the update with. From 2a52b5c750b445f723a1547e2c5ce0fb5c2ca852 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 26 Feb 2024 21:50:34 -0800 Subject: [PATCH 20/20] 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 ed1d76bb51..4c4d4a1f75 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit ed1d76bb51e5782a674fc0773fbf2799cbd457e7 +Subproject commit 4c4d4a1f7559d7d40b6c91b5212382b9a2a7337f