From 3d12364551e75abd10f6ec547ef23479670d2553 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 15 Jul 2024 10:58:30 -0400 Subject: [PATCH 01/18] Support zero-delay cycles --- .../federated/extensions/CExtension.java | 24 ++++++++++++++++--- .../federated/extensions/CExtensionUtils.java | 14 +++++++++++ .../federated/generator/FedASTUtils.java | 5 ++-- .../federated/generator/FederateInstance.java | 5 ++++ core/src/main/resources/lib/c/reactor-c | 2 +- 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/lflang/federated/extensions/CExtension.java b/core/src/main/java/org/lflang/federated/extensions/CExtension.java index c2def97a16..bfacf95f97 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtension.java @@ -550,15 +550,33 @@ protected String makePreamble( // that handles incoming network messages destined to the specified // port. This will only be used if there are federates. int numOfNetworkActions = federate.networkMessageActions.size(); + int numZDCNetworkActions = federate.zeroDelayCycleNetworkMessageActions.size(); code.pr( """ interval_t _lf_action_delay_table[%1$s]; lf_action_base_t* _lf_action_table[%1$s]; size_t _lf_action_table_size = %1$s; - lf_action_base_t* _lf_zero_delay_cycle_action_table[%2$s]; - size_t _lf_zero_delay_cycle_action_table_size = %2$s; """ - .formatted(numOfNetworkActions, federate.zeroDelayCycleNetworkMessageActions.size())); + .formatted(numOfNetworkActions)); + if (numZDCNetworkActions > 0) { + code.pr( + """ + lf_action_base_t* _lf_zero_delay_cycle_action_table[%1$s]; + size_t _lf_zero_delay_cycle_action_table_size = %1$s; + uint16_t _lf_zero_delay_cycle_upstream_ids[%1$s]; + bool _lf_zero_delay_cycle_upstream_disconnected[%1$s] = { false }; + """ + .formatted(numZDCNetworkActions)); + } else { + // Make sure these symbols are defined, even though only size will be used. + code.pr( + """ + lf_action_base_t** _lf_zero_delay_cycle_action_table = NULL; + size_t _lf_zero_delay_cycle_action_table_size = 0; + uint16_t* _lf_zero_delay_cycle_upstream_ids = NULL; + bool* _lf_zero_delay_cycle_upstream_disconnected[%1$s] = NULL; + """); + } int numOfNetworkReactions = federate.networkReceiverReactions.size(); code.pr( 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 9e4976c9dc..6a4f8316ee 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java @@ -64,6 +64,7 @@ public static String initializeTriggersForNetworkActions( var actionInstance = reactor.lookupActionInstance(action); var trigger = CUtil.actionRef(actionInstance, null); var delay = federate.networkMessageActionDelays.get(i); + var upstream = federate.zeroDelayCycleNetworkUpstreamFeds.get(i); code.pr( "_lf_action_delay_table[" + actionTableCount @@ -77,6 +78,19 @@ public static String initializeTriggersForNetworkActions( + trigger + "; \\"); if (federate.zeroDelayCycleNetworkMessageActions.contains(action)) { + code.pr( + "_lf_zero_delay_cycle_upstream_ids[" + + zeroDelayActionTableCount + + "] = " + + upstream.id + + "; \\"); + if (federate.isTransient) { + // Transient federates are assumed to be initially disconnected. + code.pr( + "_lf_zero_delay_cycle_upstream_disconnected[" + + zeroDelayActionTableCount + + "] = true; \\"); + } code.pr( "_lf_zero_delay_cycle_action_table[" + zeroDelayActionTableCount++ diff --git a/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java b/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java index 5315e8562a..ec171995f6 100644 --- a/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java +++ b/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java @@ -278,9 +278,10 @@ private static void addNetworkReceiverReactor( connection.dstFederate.networkMessageActions.add(networkAction); connection.dstFederate.networkMessageActionDelays.add(connection.getDefinition().getDelay()); if (connection.srcFederate.isInZeroDelayCycle() - && connection.getDefinition().getDelay() == null) + && connection.getDefinition().getDelay() == null) { connection.dstFederate.zeroDelayCycleNetworkMessageActions.add(networkAction); - + connection.dstFederate.zeroDelayCycleNetworkUpstreamFeds.add(connection.srcFederate); + } // Get the largest STAA for any reaction triggered by the destination port. TimeValue maxSTP = findMaxSTP(connection, coordination); diff --git a/core/src/main/java/org/lflang/federated/generator/FederateInstance.java b/core/src/main/java/org/lflang/federated/generator/FederateInstance.java index fa4be9f810..f065719631 100644 --- a/core/src/main/java/org/lflang/federated/generator/FederateInstance.java +++ b/core/src/main/java/org/lflang/federated/generator/FederateInstance.java @@ -190,6 +190,11 @@ public Instantiation getInstantiation() { */ public List zeroDelayCycleNetworkMessageActions = new ArrayList<>(); + /** + * List of upstream federates corresponding to actions in the zeroDelayCycleNetworkMessageActions list. + */ + public List zeroDelayCycleNetworkUpstreamFeds = new ArrayList<>(); + /** * A set of federates with which this federate has an inbound connection There will only be one * physical connection even if federate A has defined multiple physical connections to federate B. diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 71d706b884..fea2eed540 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 71d706b88409e48234f389320a1dc06ddd77f5d3 +Subproject commit fea2eed540d292b8b015b72163326d40ab4d6c82 From 0d26545793a8a30987d3b13d55b1c8507a40068f Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 15 Jul 2024 16:31:01 -0400 Subject: [PATCH 02/18] Fixed compile and Docker errors --- .../java/org/lflang/federated/extensions/CExtension.java | 2 +- .../org/lflang/federated/extensions/CExtensionUtils.java | 2 +- core/src/main/java/org/lflang/generator/c/CCompiler.java | 5 +++++ core/src/main/resources/lib/c/reactor-c | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/lflang/federated/extensions/CExtension.java b/core/src/main/java/org/lflang/federated/extensions/CExtension.java index bfacf95f97..889917c654 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtension.java @@ -574,7 +574,7 @@ protected String makePreamble( lf_action_base_t** _lf_zero_delay_cycle_action_table = NULL; size_t _lf_zero_delay_cycle_action_table_size = 0; uint16_t* _lf_zero_delay_cycle_upstream_ids = NULL; - bool* _lf_zero_delay_cycle_upstream_disconnected[%1$s] = NULL; + bool* _lf_zero_delay_cycle_upstream_disconnected = NULL; """); } 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 6a4f8316ee..b96aa06342 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java @@ -64,7 +64,6 @@ public static String initializeTriggersForNetworkActions( var actionInstance = reactor.lookupActionInstance(action); var trigger = CUtil.actionRef(actionInstance, null); var delay = federate.networkMessageActionDelays.get(i); - var upstream = federate.zeroDelayCycleNetworkUpstreamFeds.get(i); code.pr( "_lf_action_delay_table[" + actionTableCount @@ -78,6 +77,7 @@ public static String initializeTriggersForNetworkActions( + trigger + "; \\"); if (federate.zeroDelayCycleNetworkMessageActions.contains(action)) { + var upstream = federate.zeroDelayCycleNetworkUpstreamFeds.get(i); code.pr( "_lf_zero_delay_cycle_upstream_ids[" + zeroDelayActionTableCount 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 2c34d713d3..e0e5e919fb 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -40,6 +40,7 @@ import org.lflang.target.TargetConfig; import org.lflang.target.property.BuildTypeProperty; import org.lflang.target.property.CompilerProperty; +import org.lflang.target.property.DockerProperty; import org.lflang.target.property.PlatformProperty; import org.lflang.target.property.PlatformProperty.Option; import org.lflang.target.property.PlatformProperty.PlatformOptions; @@ -230,6 +231,10 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f srcGenPath = srcGenPath.replaceAll("\\\\", "\\\\\\\\"); binPath = binPath.replaceAll("\\\\", "\\\\\\\\"); } + if (targetConfig.get(DockerProperty.INSTANCE).enabled()) { + // Docker seems to require an extra level of quotes. + maybeQuote = "\\\""; + } arguments.addAll( List.of( "-DCMAKE_BUILD_TYPE=" diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index fea2eed540..ac14760bc4 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit fea2eed540d292b8b015b72163326d40ab4d6c82 +Subproject commit ac14760bc4fa3feb930073b858d46e1b6167821d From 1dd9c18fc8c0736a9a660e99dac8b5f297ab6731 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Mon, 15 Jul 2024 16:37:02 -0400 Subject: [PATCH 03/18] Format --- .../federated/extensions/CExtension.java | 4 +- .../federated/extensions/CExtensionUtils.java | 168 ++++++++---------- .../federated/generator/FederateInstance.java | 3 +- 3 files changed, 78 insertions(+), 97 deletions(-) diff --git a/core/src/main/java/org/lflang/federated/extensions/CExtension.java b/core/src/main/java/org/lflang/federated/extensions/CExtension.java index 889917c654..ac8ad51764 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtension.java @@ -557,7 +557,7 @@ protected String makePreamble( lf_action_base_t* _lf_action_table[%1$s]; size_t _lf_action_table_size = %1$s; """ - .formatted(numOfNetworkActions)); + .formatted(numOfNetworkActions)); if (numZDCNetworkActions > 0) { code.pr( """ @@ -566,7 +566,7 @@ protected String makePreamble( uint16_t _lf_zero_delay_cycle_upstream_ids[%1$s]; bool _lf_zero_delay_cycle_upstream_disconnected[%1$s] = { false }; """ - .formatted(numZDCNetworkActions)); + .formatted(numZDCNetworkActions)); } else { // Make sure these symbols are defined, even though only size will be used. code.pr( 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 b96aa06342..be59e8100e 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java @@ -36,20 +36,17 @@ public class CExtensionUtils { // Regular expression pattern for shared_ptr types. - static final Pattern sharedPointerVariable = Pattern - .compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); + static final Pattern sharedPointerVariable = + Pattern.compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); /** * Generate C code that initializes network actions. * - *

- * These network actions will be triggered by federate.c whenever a message is - * received from + *

These network actions will be triggered by federate.c whenever a message is received from * the network. * * @param federate The federate. - * @param main The main reactor that contains the federate (used to lookup - * references). + * @param main The main reactor that contains the federate (used to lookup references). */ public static String initializeTriggersForNetworkActions( FederateInstance federate, ReactorInstance main) { @@ -79,7 +76,7 @@ public static String initializeTriggersForNetworkActions( if (federate.zeroDelayCycleNetworkMessageActions.contains(action)) { var upstream = federate.zeroDelayCycleNetworkUpstreamFeds.get(i); code.pr( - "_lf_zero_delay_cycle_upstream_ids[" + "_lf_zero_delay_cycle_upstream_ids[" + zeroDelayActionTableCount + "] = " + upstream.id @@ -87,7 +84,7 @@ public static String initializeTriggersForNetworkActions( if (federate.isTransient) { // Transient federates are assumed to be initially disconnected. code.pr( - "_lf_zero_delay_cycle_upstream_disconnected[" + "_lf_zero_delay_cycle_upstream_disconnected[" + zeroDelayActionTableCount + "] = true; \\"); } @@ -106,11 +103,8 @@ public static String initializeTriggersForNetworkActions( /** * Generate C code that holds a sorted list of STP structs by time. * - *

- * For decentralized execution, on every logical timestep, a thread will iterate - * through each - * staa struct, wait for the designated offset time, and set the associated port - * status to absent + *

For decentralized execution, on every logical timestep, a thread will iterate through each + * staa struct, wait for the designated offset time, and set the associated port status to absent * if it isn't known. * * @param federate The federate. @@ -126,7 +120,8 @@ public static String stpStructs(FederateInstance federate) { // main reactor for each Action. for (int i = 0; i < federate.staaOffsets.size(); ++i) { // Find the corresponding ActionInstance. - List networkActions = federate.stpToNetworkActionMap.get(federate.staaOffsets.get(i)); + List networkActions = + federate.stpToNetworkActionMap.get(federate.staaOffsets.get(i)); code.pr("staa_lst[" + i + "] = (staa_t*) malloc(sizeof(staa_t));"); code.pr( @@ -159,8 +154,7 @@ public static String stpStructs(FederateInstance federate) { } /** - * Create a port status field variable for a network input port "input" in the - * self struct of a + * Create a port status field variable for a network input port "input" in the self struct of a * reactor. * * @param input The network input port @@ -181,23 +175,15 @@ public static String createPortStatusFieldForInput(Input input) { } /** - * Given a connection 'delay' expression, return a string that represents the - * interval_t value of + * Given a connection 'delay' expression, return a string that represents the interval_t value of * the additional delay that needs to be applied to the outgoing message. * - *

- * The returned additional delay in absence of after on network connection - * (i.e., if delay is - * passed as a null) is NEVER. This has a special meaning in C library functions - * that send network - * messages that carry timestamps (@see lf_send_tagged_message and - * lf_send_port_absent_to_federate - * in lib/core/federate.c). In this case, the sender will send its current tag - * as the timestamp of - * the outgoing message without adding a microstep delay. If the user has - * assigned an after delay - * to the network connection (that can be zero) either as a time value (e.g., - * 200 msec) or as a + *

The returned additional delay in absence of after on network connection (i.e., if delay is + * passed as a null) is NEVER. This has a special meaning in C library functions that send network + * messages that carry timestamps (@see lf_send_tagged_message and lf_send_port_absent_to_federate + * in lib/core/federate.c). In this case, the sender will send its current tag as the timestamp of + * the outgoing message without adding a microstep delay. If the user has assigned an after delay + * to the network connection (that can be zero) either as a time value (e.g., 200 msec) or as a * literal (e.g., a parameter), that delay in nsec will be returned. * * @param delay The delay associated with a connection. @@ -241,9 +227,11 @@ public static void handleCompileDefinitions( } private static void handleAdvanceMessageInterval(FederateInstance federate) { - var advanceMessageInterval = federate.targetConfig.get(CoordinationOptionsProperty.INSTANCE).advanceMessageInterval; + var advanceMessageInterval = + federate.targetConfig.get(CoordinationOptionsProperty.INSTANCE).advanceMessageInterval; if (advanceMessageInterval != null) { - federate.targetConfig + federate + .targetConfig .get(CompileDefinitionsProperty.INSTANCE) .put("ADVANCE_MESSAGE_INTERVAL", String.valueOf(advanceMessageInterval.toNanoSeconds())); } @@ -256,15 +244,12 @@ static boolean clockSyncIsOn(FederateInstance federate, RtiConfig rtiConfig) { } /** - * Initialize clock synchronization (if enabled) and its related options for a - * given federate. + * Initialize clock synchronization (if enabled) and its related options for a given federate. * - *

- * Clock synchronization can be enabled using the clock-sync target property. + *

Clock synchronization can be enabled using the clock-sync target property. * - * @see Documentation + * @see Documentation */ public static void initializeClockSynchronization( FederateInstance federate, RtiConfig rtiConfig, MessageReporter messageReporter) { @@ -291,15 +276,12 @@ public static void initializeClockSynchronization( } /** - * Initialize clock synchronization (if enabled) and its related options for a - * given federate. + * Initialize clock synchronization (if enabled) and its related options for a given federate. * - *

- * Clock synchronization can be enabled using the clock-sync target property. + *

Clock synchronization can be enabled using the clock-sync target property. * - * @see Documentation + * @see Documentation */ public static void addClockSyncCompileDefinitions(FederateInstance federate) { @@ -330,9 +312,10 @@ public static void generateCMakeInclude( FederateInstance federate, FederationFileConfig fileConfig) throws IOException { Files.createDirectories(fileConfig.getSrcPath().resolve("include")); - Path cmakeIncludePath = fileConfig - .getSrcPath() - .resolve("include" + File.separator + federate.name + "_extension.cmake"); + Path cmakeIncludePath = + fileConfig + .getSrcPath() + .resolve("include" + File.separator + federate.name + "_extension.cmake"); CodeBuilder cmakeIncludeCode = new CodeBuilder(); @@ -344,7 +327,9 @@ public static void generateCMakeInclude( cmakeIncludeCode.pr( "add_compile_definitions(LF_SOURCE_GEN_DIRECTORY=\"" + fileConfig.getSrcGenPath() + "\")"); cmakeIncludeCode.pr( - "add_compile_definitions(LF_FEDERATES_BIN_DIRECTORY=\"" + fileConfig.getFedBinPath() + "\")"); + "add_compile_definitions(LF_FEDERATES_BIN_DIRECTORY=\"" + + fileConfig.getFedBinPath() + + "\")"); try (var srcWriter = Files.newBufferedWriter(cmakeIncludePath)) { srcWriter.write(cmakeIncludeCode.getCode()); } @@ -355,8 +340,7 @@ public static void generateCMakeInclude( } /** - * Generate code that sends the neighbor structure message to the RTI. See - * {@code + * Generate code that sends the neighbor structure message to the RTI. See {@code * MSG_TYPE_NEIGHBOR_STRUCTURE} in {@code federated/net_common.h}. * * @param federate The federate that is sending its neighbor structure @@ -429,13 +413,14 @@ public static String generateFederateNeighborStructure(FederateInstance federate // Use NEVER to encode no delay at all. code.pr("candidate_tmp = NEVER;"); } else { - var delayTime = delay instanceof ParameterReference - // In that case use the default value. - ? CTypes.getInstance() - .getTargetTimeExpr( - ASTUtils.getDefaultAsTimeValue( - ((ParameterReference) delay).getParameter())) - : CTypes.getInstance().getTargetExpr(delay, InferredType.time()); + var delayTime = + delay instanceof ParameterReference + // In that case use the default value. + ? CTypes.getInstance() + .getTargetTimeExpr( + ASTUtils.getDefaultAsTimeValue( + ((ParameterReference) delay).getParameter())) + : CTypes.getInstance().getTargetExpr(delay, InferredType.time()); code.pr( String.join( @@ -492,27 +477,26 @@ public static String surroundWithIfElseFederated(String insideIf, String insideE return surroundWithIfFederated(insideIf); } else { return """ - #ifdef FEDERATED - %s - #else - %s - #endif // FEDERATED - """ + #ifdef FEDERATED + %s + #else + %s + #endif // FEDERATED + """ .formatted(insideIf, insideElse); } } /** - * Surround {@code code} with blocks to ensure that code only executes if the - * program is + * Surround {@code code} with blocks to ensure that code only executes if the program is * federated. */ public static String surroundWithIfFederated(String code) { return """ - #ifdef FEDERATED - %s - #endif // FEDERATED - """ + #ifdef FEDERATED + %s + #endif // FEDERATED + """ .formatted(code); } @@ -521,41 +505,39 @@ public static String surroundWithIfElseFederatedCentralized(String insideIf, Str return surroundWithIfFederatedCentralized(insideIf); } else { return """ - #ifdef FEDERATED_CENTRALIZED - %s - #else - %s - #endif // FEDERATED_CENTRALIZED - """ + #ifdef FEDERATED_CENTRALIZED + %s + #else + %s + #endif // FEDERATED_CENTRALIZED + """ .formatted(insideIf, insideElse); } } /** - * Surround {@code code} with blocks to ensure that code only executes if the - * program is federated + * Surround {@code code} with blocks to ensure that code only executes if the program is federated * and has a centralized coordination. */ public static String surroundWithIfFederatedCentralized(String code) { return """ - #ifdef FEDERATED_CENTRALIZED - %s - #endif // FEDERATED_CENTRALIZED - """ + #ifdef FEDERATED_CENTRALIZED + %s + #endif // FEDERATED_CENTRALIZED + """ .formatted(code); } /** - * Surround {@code code} with blocks to ensure that code only executes if the - * program is federated + * Surround {@code code} with blocks to ensure that code only executes if the program is federated * and has a decentralized coordination. */ public static String surroundWithIfFederatedDecentralized(String code) { return """ - #ifdef FEDERATED_DECENTRALIZED - %s - #endif // FEDERATED_DECENTRALIZED - """ + #ifdef FEDERATED_DECENTRALIZED + %s + #endif // FEDERATED_DECENTRALIZED + """ .formatted(code); } @@ -576,9 +558,7 @@ public static String generateSerializationIncludes(FederateInstance federate) { return code.getCode(); } - /** - * Generate cmake-include code needed for enabled serializers of the federate. - */ + /** Generate cmake-include code needed for enabled serializers of the federate. */ public static String generateSerializationCMakeExtension(FederateInstance federate) { CodeBuilder code = new CodeBuilder(); for (SupportedSerializers serializer : federate.enabledSerializers) { diff --git a/core/src/main/java/org/lflang/federated/generator/FederateInstance.java b/core/src/main/java/org/lflang/federated/generator/FederateInstance.java index f065719631..b298afadcc 100644 --- a/core/src/main/java/org/lflang/federated/generator/FederateInstance.java +++ b/core/src/main/java/org/lflang/federated/generator/FederateInstance.java @@ -191,7 +191,8 @@ public Instantiation getInstantiation() { public List zeroDelayCycleNetworkMessageActions = new ArrayList<>(); /** - * List of upstream federates corresponding to actions in the zeroDelayCycleNetworkMessageActions list. + * List of upstream federates corresponding to actions in the zeroDelayCycleNetworkMessageActions + * list. */ public List zeroDelayCycleNetworkUpstreamFeds = new ArrayList<>(); From f0b6a12d9f461bfb0621b74b1f38cdb4d358db21 Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 17 Jul 2024 07:04:24 +0100 Subject: [PATCH 04/18] Align 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 ac14760bc4..ec5b2d6e6b 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit ac14760bc4fa3feb930073b858d46e1b6167821d +Subproject commit ec5b2d6e6b9f1ffcdfee739759d017f9e19849ee From ff7953b1fd4a483b5957ad34658c46fdc879d368 Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 17 Jul 2024 12:22:23 +0100 Subject: [PATCH 05/18] Fix code printing of eroDelayCycleNetworkUpstreamFeds --- .../federated/extensions/CExtensionUtils.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 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 be59e8100e..8fc4ffa7a0 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java @@ -74,13 +74,15 @@ public static String initializeTriggersForNetworkActions( + trigger + "; \\"); if (federate.zeroDelayCycleNetworkMessageActions.contains(action)) { - var upstream = federate.zeroDelayCycleNetworkUpstreamFeds.get(i); - code.pr( - "_lf_zero_delay_cycle_upstream_ids[" - + zeroDelayActionTableCount - + "] = " - + upstream.id - + "; \\"); + for (int j = 0; j < federate.zeroDelayCycleNetworkUpstreamFeds.size(); ++j) { + var upstream = federate.zeroDelayCycleNetworkUpstreamFeds.get(j); + code.pr( + "_lf_zero_delay_cycle_upstream_ids[" + + zeroDelayActionTableCount + + "] = " + + upstream.id + + "; \\"); + } if (federate.isTransient) { // Transient federates are assumed to be initially disconnected. code.pr( From 00e3f51418aadd13dfafe4bbc71c336a007611d4 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Wed, 17 Jul 2024 09:03:43 -0400 Subject: [PATCH 06/18] Corrected upstream settings --- .../federated/extensions/CExtensionUtils.java | 26 +++++++++---------- core/src/main/resources/lib/c/reactor-c | 2 +- 2 files changed, 13 insertions(+), 15 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 8fc4ffa7a0..4074f69b78 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java @@ -53,7 +53,6 @@ public static String initializeTriggersForNetworkActions( CodeBuilder code = new CodeBuilder(); if (!federate.networkMessageActions.isEmpty()) { var actionTableCount = 0; - var zeroDelayActionTableCount = 0; for (int i = 0; i < federate.networkMessageActions.size(); ++i) { // Find the corresponding ActionInstance. Action action = federate.networkMessageActions.get(i); @@ -73,26 +72,25 @@ public static String initializeTriggersForNetworkActions( + "] = (lf_action_base_t*)&" + trigger + "; \\"); - if (federate.zeroDelayCycleNetworkMessageActions.contains(action)) { - for (int j = 0; j < federate.zeroDelayCycleNetworkUpstreamFeds.size(); ++j) { - var upstream = federate.zeroDelayCycleNetworkUpstreamFeds.get(j); - code.pr( - "_lf_zero_delay_cycle_upstream_ids[" - + zeroDelayActionTableCount - + "] = " - + upstream.id - + "; \\"); - } - if (federate.isTransient) { + int j = federate.zeroDelayCycleNetworkMessageActions.indexOf(action); + if (j >= 0) { + var upstream = federate.zeroDelayCycleNetworkUpstreamFeds.get(j); + code.pr( + "_lf_zero_delay_cycle_upstream_ids[" + + j + + "] = " + + upstream.id + + "; \\"); + if (upstream.isTransient) { // Transient federates are assumed to be initially disconnected. code.pr( "_lf_zero_delay_cycle_upstream_disconnected[" - + zeroDelayActionTableCount + + j + "] = true; \\"); } code.pr( "_lf_zero_delay_cycle_action_table[" - + zeroDelayActionTableCount++ + + j + "] = (lf_action_base_t*)&" + trigger + "; \\"); diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index ec5b2d6e6b..322dde61fd 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit ec5b2d6e6b9f1ffcdfee739759d017f9e19849ee +Subproject commit 322dde61fd016435f1872d3231dd2dcc8221a16b From 79829e3dce3400cb9472400370c47c7dd622a656 Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 24 Jul 2024 15:51:29 +0100 Subject: [PATCH 07/18] Align 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 322dde61fd..71a4cb6fba 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 322dde61fd016435f1872d3231dd2dcc8221a16b +Subproject commit 71a4cb6fba62da6de89be6fbbade9fdbf8081109 From 7402c6ecd884ae7aa4a12ed1f3af92d1e7f78a2f Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 24 Jul 2024 17:23:41 +0100 Subject: [PATCH 08/18] Fix merge of maybeQuote in CCmpiler + Align reactor-c --- .../main/java/org/lflang/generator/c/CCompiler.java | 12 ++++++------ core/src/main/resources/lib/c/reactor-c | 2 +- 2 files changed, 7 insertions(+), 7 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 4a221e4aff..db0b285ff6 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -222,7 +222,7 @@ public LFCommand compileCmakeCommand() { private static List cmakeOptions(TargetConfig targetConfig, FileConfig fileConfig) { List arguments = new ArrayList<>(); String separator = File.separator; - String quote = "\""; + String maybeQuote = ""; // Windows seems to require extra level of quoting. String srcPath = fileConfig.srcPath.toString(); String rootPath = fileConfig.srcPkgPath.toString(); String binPath = fileConfig.binPath.toString(); @@ -230,7 +230,7 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f if (separator.equals("\\")) { // Windows requires escaping the backslashes. separator = "\\\\\\\\"; - quote = "\\\""; + maybeQuote = "\\\""; srcPath = srcPath.replaceAll("\\\\", "\\\\\\\\"); rootPath = rootPath.replaceAll("\\\\", "\\\\\\\\"); srcGenPath = srcGenPath.replaceAll("\\\\", "\\\\\\\\"); @@ -249,16 +249,16 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f "-DCMAKE_INSTALL_PREFIX=" + FileUtil.toUnixString(fileConfig.getOutPath()), "-DCMAKE_INSTALL_BINDIR=" + FileUtil.toUnixString(fileConfig.getOutPath().relativize(fileConfig.binPath)), - "-DLF_FILE_SEPARATOR='" + quote + separator + quote + "'")); + "-DLF_FILE_SEPARATOR='" + maybeQuote + separator + maybeQuote + "'")); // 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). if (!fileConfig.srcPath.toString().contains("fed-gen")) { // Do not convert to Unix path - arguments.add("-DLF_SOURCE_DIRECTORY='" + quote + srcPath + quote + "'"); - arguments.add("-DLF_PACKAGE_DIRECTORY='" + quote + rootPath + quote + "'"); - arguments.add("-DLF_SOURCE_GEN_DIRECTORY='" + quote + srcGenPath + quote + "'"); + arguments.add("-DLF_SOURCE_DIRECTORY='" + maybeQuote + srcPath + maybeQuote + "'"); + arguments.add("-DLF_PACKAGE_DIRECTORY='" + maybeQuote + rootPath + maybeQuote + "'"); + arguments.add("-DLF_SOURCE_GEN_DIRECTORY='" + maybeQuote + srcGenPath + maybeQuote + "'"); } else { arguments.add("-DLF_FEDERATES_BIN_DIRECTORY=\"" + maybeQuote + binPath + maybeQuote + "\""); } diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 71a4cb6fba..5ef6b54760 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 71a4cb6fba62da6de89be6fbbade9fdbf8081109 +Subproject commit 5ef6b5476061657748355c6f4fef003a5b637a22 From 8a75fb2b3be711b64ba0c8e00bbf12c963a9f680 Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 7 Aug 2024 18:59:17 +0100 Subject: [PATCH 09/18] Revert quotes specification in cmakeOptions() --- .../org/lflang/generator/c/CCompiler.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 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 db0b285ff6..3c99b61848 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -222,23 +222,17 @@ public LFCommand compileCmakeCommand() { private static List cmakeOptions(TargetConfig targetConfig, FileConfig fileConfig) { List arguments = new ArrayList<>(); String separator = File.separator; - String maybeQuote = ""; // Windows seems to require extra level of quoting. + String quote = "\""; String srcPath = fileConfig.srcPath.toString(); String rootPath = fileConfig.srcPkgPath.toString(); - String binPath = fileConfig.binPath.toString(); String srcGenPath = fileConfig.getSrcGenPath().toString(); if (separator.equals("\\")) { // Windows requires escaping the backslashes. separator = "\\\\\\\\"; - maybeQuote = "\\\""; + quote = "\\\""; srcPath = srcPath.replaceAll("\\\\", "\\\\\\\\"); rootPath = rootPath.replaceAll("\\\\", "\\\\\\\\"); srcGenPath = srcGenPath.replaceAll("\\\\", "\\\\\\\\"); - binPath = binPath.replaceAll("\\\\", "\\\\\\\\"); - } - if (targetConfig.get(DockerProperty.INSTANCE).enabled()) { - // Docker seems to require an extra level of quotes. - maybeQuote = "\\\""; } arguments.addAll( List.of( @@ -249,18 +243,18 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f "-DCMAKE_INSTALL_PREFIX=" + FileUtil.toUnixString(fileConfig.getOutPath()), "-DCMAKE_INSTALL_BINDIR=" + FileUtil.toUnixString(fileConfig.getOutPath().relativize(fileConfig.binPath)), - "-DLF_FILE_SEPARATOR='" + maybeQuote + separator + maybeQuote + "'")); + "-DLF_FILE_SEPARATOR='" + quote + separator + quote + "'")); // 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). if (!fileConfig.srcPath.toString().contains("fed-gen")) { // Do not convert to Unix path - arguments.add("-DLF_SOURCE_DIRECTORY='" + maybeQuote + srcPath + maybeQuote + "'"); - arguments.add("-DLF_PACKAGE_DIRECTORY='" + maybeQuote + rootPath + maybeQuote + "'"); - arguments.add("-DLF_SOURCE_GEN_DIRECTORY='" + maybeQuote + srcGenPath + maybeQuote + "'"); + arguments.add("-DLF_SOURCE_DIRECTORY='" + quote + srcPath + quote + "'"); + arguments.add("-DLF_PACKAGE_DIRECTORY='" + quote + rootPath + quote + "'"); + arguments.add("-DLF_SOURCE_GEN_DIRECTORY='" + quote + srcGenPath + quote + "'"); } else { - arguments.add("-DLF_FEDERATES_BIN_DIRECTORY=\"" + maybeQuote + binPath + maybeQuote + "\""); + arguments.add("-DLF_SOURCE_GEN_DIRECTORY='" + quote + srcGenPath + quote + "'"); } arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath())); From 29a1db787c8c4fb0ead8982e27f20e14cac4a2dd Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 7 Aug 2024 19:00:35 +0100 Subject: [PATCH 10/18] Remove no more needed import --- core/src/main/java/org/lflang/generator/c/CCompiler.java | 1 - 1 file changed, 1 deletion(-) 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 3c99b61848..b385df985f 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -40,7 +40,6 @@ import org.lflang.target.TargetConfig; import org.lflang.target.property.BuildTypeProperty; import org.lflang.target.property.CompilerProperty; -import org.lflang.target.property.DockerProperty; import org.lflang.target.property.PlatformProperty; import org.lflang.target.property.PlatformProperty.Option; import org.lflang.target.property.PlatformProperty.PlatformOptions; From 20186a25054249ade64050330a5a6e31d69d2aa1 Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 7 Aug 2024 19:01:41 +0100 Subject: [PATCH 11/18] Update the preamble in transients tests --- test/C/src/federated/transient/TransientDownstreamWithTimer.lf | 1 + .../federated/transient/TransientDownstreamWithTwoUpstream.lf | 1 + test/C/src/federated/transient/TransientHotSwap.lf | 1 + test/C/src/federated/transient/TransientStatePersistence.lf | 1 + 4 files changed, 4 insertions(+) diff --git a/test/C/src/federated/transient/TransientDownstreamWithTimer.lf b/test/C/src/federated/transient/TransientDownstreamWithTimer.lf index a403057e48..8a493b432e 100644 --- a/test/C/src/federated/transient/TransientDownstreamWithTimer.lf +++ b/test/C/src/federated/transient/TransientDownstreamWithTimer.lf @@ -13,6 +13,7 @@ target C { preamble {= #include #include + #include "federate.h" =} /** Persistent federate that is responsible for lauching the transient federate */ diff --git a/test/C/src/federated/transient/TransientDownstreamWithTwoUpstream.lf b/test/C/src/federated/transient/TransientDownstreamWithTwoUpstream.lf index 49960b05b4..3fac7d04ac 100644 --- a/test/C/src/federated/transient/TransientDownstreamWithTwoUpstream.lf +++ b/test/C/src/federated/transient/TransientDownstreamWithTwoUpstream.lf @@ -19,6 +19,7 @@ import Middle from "TransientDownstreamWithTimer.lf" preamble {= #include #include + #include "federate.h" =} /** Persistent federate that is responsible for lauching the transient federate */ diff --git a/test/C/src/federated/transient/TransientHotSwap.lf b/test/C/src/federated/transient/TransientHotSwap.lf index a4c986d3d4..4f49bf74e4 100644 --- a/test/C/src/federated/transient/TransientHotSwap.lf +++ b/test/C/src/federated/transient/TransientHotSwap.lf @@ -18,6 +18,7 @@ import Down from "TransientDownstreamWithTimer.lf" preamble {= #include #include + #include "federate.h" =} /** Persistent federate that is responsible for lauching the transient federate */ diff --git a/test/C/src/federated/transient/TransientStatePersistence.lf b/test/C/src/federated/transient/TransientStatePersistence.lf index 71f3ed2b2d..29b932853b 100644 --- a/test/C/src/federated/transient/TransientStatePersistence.lf +++ b/test/C/src/federated/transient/TransientStatePersistence.lf @@ -13,6 +13,7 @@ target C { preamble {= #include #include + #include "federate.h" // The internal federate state to be persistent across executions typedef struct federate_state_t { From 475466458cd75e8a63e44d6954d9e34e44af2f14 Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 7 Aug 2024 19:21:14 +0100 Subject: [PATCH 12/18] Align 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 07f3671cfd..6c20e647c4 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 07f3671cfd8f3da30a1edd0f6ee56c615bdbf18d +Subproject commit 6c20e647c4962c1288f57d545d2ce8335a2e4058 From 3e34fa977aa2a38546b114cc850981321fbf4721 Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 7 Aug 2024 19:43:37 +0100 Subject: [PATCH 13/18] Remove compile definition of the federate bin path + Align reactor-c --- .../federated/extensions/CExtensionUtils.java | 158 ++++++++++-------- core/src/main/resources/lib/c/reactor-c | 2 +- 2 files changed, 88 insertions(+), 72 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 4074f69b78..3fbc91ed3b 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java @@ -36,17 +36,20 @@ public class CExtensionUtils { // Regular expression pattern for shared_ptr types. - static final Pattern sharedPointerVariable = - Pattern.compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); + static final Pattern sharedPointerVariable = Pattern + .compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); /** * Generate C code that initializes network actions. * - *

These network actions will be triggered by federate.c whenever a message is received from + *

+ * These network actions will be triggered by federate.c whenever a message is + * received from * the network. * * @param federate The federate. - * @param main The main reactor that contains the federate (used to lookup references). + * @param main The main reactor that contains the federate (used to lookup + * references). */ public static String initializeTriggersForNetworkActions( FederateInstance federate, ReactorInstance main) { @@ -103,8 +106,11 @@ public static String initializeTriggersForNetworkActions( /** * Generate C code that holds a sorted list of STP structs by time. * - *

For decentralized execution, on every logical timestep, a thread will iterate through each - * staa struct, wait for the designated offset time, and set the associated port status to absent + *

+ * For decentralized execution, on every logical timestep, a thread will iterate + * through each + * staa struct, wait for the designated offset time, and set the associated port + * status to absent * if it isn't known. * * @param federate The federate. @@ -120,8 +126,7 @@ public static String stpStructs(FederateInstance federate) { // main reactor for each Action. for (int i = 0; i < federate.staaOffsets.size(); ++i) { // Find the corresponding ActionInstance. - List networkActions = - federate.stpToNetworkActionMap.get(federate.staaOffsets.get(i)); + List networkActions = federate.stpToNetworkActionMap.get(federate.staaOffsets.get(i)); code.pr("staa_lst[" + i + "] = (staa_t*) malloc(sizeof(staa_t));"); code.pr( @@ -154,7 +159,8 @@ public static String stpStructs(FederateInstance federate) { } /** - * Create a port status field variable for a network input port "input" in the self struct of a + * Create a port status field variable for a network input port "input" in the + * self struct of a * reactor. * * @param input The network input port @@ -175,15 +181,23 @@ public static String createPortStatusFieldForInput(Input input) { } /** - * Given a connection 'delay' expression, return a string that represents the interval_t value of + * Given a connection 'delay' expression, return a string that represents the + * interval_t value of * the additional delay that needs to be applied to the outgoing message. * - *

The returned additional delay in absence of after on network connection (i.e., if delay is - * passed as a null) is NEVER. This has a special meaning in C library functions that send network - * messages that carry timestamps (@see lf_send_tagged_message and lf_send_port_absent_to_federate - * in lib/core/federate.c). In this case, the sender will send its current tag as the timestamp of - * the outgoing message without adding a microstep delay. If the user has assigned an after delay - * to the network connection (that can be zero) either as a time value (e.g., 200 msec) or as a + *

+ * The returned additional delay in absence of after on network connection + * (i.e., if delay is + * passed as a null) is NEVER. This has a special meaning in C library functions + * that send network + * messages that carry timestamps (@see lf_send_tagged_message and + * lf_send_port_absent_to_federate + * in lib/core/federate.c). In this case, the sender will send its current tag + * as the timestamp of + * the outgoing message without adding a microstep delay. If the user has + * assigned an after delay + * to the network connection (that can be zero) either as a time value (e.g., + * 200 msec) or as a * literal (e.g., a parameter), that delay in nsec will be returned. * * @param delay The delay associated with a connection. @@ -227,11 +241,9 @@ public static void handleCompileDefinitions( } private static void handleAdvanceMessageInterval(FederateInstance federate) { - var advanceMessageInterval = - federate.targetConfig.get(CoordinationOptionsProperty.INSTANCE).advanceMessageInterval; + var advanceMessageInterval = federate.targetConfig.get(CoordinationOptionsProperty.INSTANCE).advanceMessageInterval; if (advanceMessageInterval != null) { - federate - .targetConfig + federate.targetConfig .get(CompileDefinitionsProperty.INSTANCE) .put("ADVANCE_MESSAGE_INTERVAL", String.valueOf(advanceMessageInterval.toNanoSeconds())); } @@ -244,12 +256,14 @@ static boolean clockSyncIsOn(FederateInstance federate, RtiConfig rtiConfig) { } /** - * Initialize clock synchronization (if enabled) and its related options for a given federate. + * Initialize clock synchronization (if enabled) and its related options for a + * given federate. * - *

Clock synchronization can be enabled using the clock-sync target property. + *

+ * Clock synchronization can be enabled using the clock-sync target property. * * @see Documentation + * "https://github.com/icyphy/lingua-franca/wiki/Distributed-Execution#clock-synchronization">Documentation */ public static void initializeClockSynchronization( FederateInstance federate, RtiConfig rtiConfig, MessageReporter messageReporter) { @@ -276,12 +290,14 @@ public static void initializeClockSynchronization( } /** - * Initialize clock synchronization (if enabled) and its related options for a given federate. + * Initialize clock synchronization (if enabled) and its related options for a + * given federate. * - *

Clock synchronization can be enabled using the clock-sync target property. + *

+ * Clock synchronization can be enabled using the clock-sync target property. * * @see Documentation + * "https://github.com/icyphy/lingua-franca/wiki/Distributed-Execution#clock-synchronization">Documentation */ public static void addClockSyncCompileDefinitions(FederateInstance federate) { @@ -312,10 +328,9 @@ public static void generateCMakeInclude( FederateInstance federate, FederationFileConfig fileConfig) throws IOException { Files.createDirectories(fileConfig.getSrcPath().resolve("include")); - Path cmakeIncludePath = - fileConfig - .getSrcPath() - .resolve("include" + File.separator + federate.name + "_extension.cmake"); + Path cmakeIncludePath = fileConfig + .getSrcPath() + .resolve("include" + File.separator + federate.name + "_extension.cmake"); CodeBuilder cmakeIncludeCode = new CodeBuilder(); @@ -326,10 +341,6 @@ public static void generateCMakeInclude( "add_compile_definitions(LF_PACKAGE_DIRECTORY=\"" + fileConfig.srcPkgPath + "\")"); cmakeIncludeCode.pr( "add_compile_definitions(LF_SOURCE_GEN_DIRECTORY=\"" + fileConfig.getSrcGenPath() + "\")"); - cmakeIncludeCode.pr( - "add_compile_definitions(LF_FEDERATES_BIN_DIRECTORY=\"" - + fileConfig.getFedBinPath() - + "\")"); try (var srcWriter = Files.newBufferedWriter(cmakeIncludePath)) { srcWriter.write(cmakeIncludeCode.getCode()); } @@ -340,7 +351,8 @@ public static void generateCMakeInclude( } /** - * Generate code that sends the neighbor structure message to the RTI. See {@code + * Generate code that sends the neighbor structure message to the RTI. See + * {@code * MSG_TYPE_NEIGHBOR_STRUCTURE} in {@code federated/net_common.h}. * * @param federate The federate that is sending its neighbor structure @@ -413,14 +425,13 @@ public static String generateFederateNeighborStructure(FederateInstance federate // Use NEVER to encode no delay at all. code.pr("candidate_tmp = NEVER;"); } else { - var delayTime = - delay instanceof ParameterReference - // In that case use the default value. - ? CTypes.getInstance() - .getTargetTimeExpr( - ASTUtils.getDefaultAsTimeValue( - ((ParameterReference) delay).getParameter())) - : CTypes.getInstance().getTargetExpr(delay, InferredType.time()); + var delayTime = delay instanceof ParameterReference + // In that case use the default value. + ? CTypes.getInstance() + .getTargetTimeExpr( + ASTUtils.getDefaultAsTimeValue( + ((ParameterReference) delay).getParameter())) + : CTypes.getInstance().getTargetExpr(delay, InferredType.time()); code.pr( String.join( @@ -477,26 +488,27 @@ public static String surroundWithIfElseFederated(String insideIf, String insideE return surroundWithIfFederated(insideIf); } else { return """ - #ifdef FEDERATED - %s - #else - %s - #endif // FEDERATED - """ + #ifdef FEDERATED + %s + #else + %s + #endif // FEDERATED + """ .formatted(insideIf, insideElse); } } /** - * Surround {@code code} with blocks to ensure that code only executes if the program is + * Surround {@code code} with blocks to ensure that code only executes if the + * program is * federated. */ public static String surroundWithIfFederated(String code) { return """ - #ifdef FEDERATED - %s - #endif // FEDERATED - """ + #ifdef FEDERATED + %s + #endif // FEDERATED + """ .formatted(code); } @@ -505,39 +517,41 @@ public static String surroundWithIfElseFederatedCentralized(String insideIf, Str return surroundWithIfFederatedCentralized(insideIf); } else { return """ - #ifdef FEDERATED_CENTRALIZED - %s - #else - %s - #endif // FEDERATED_CENTRALIZED - """ + #ifdef FEDERATED_CENTRALIZED + %s + #else + %s + #endif // FEDERATED_CENTRALIZED + """ .formatted(insideIf, insideElse); } } /** - * Surround {@code code} with blocks to ensure that code only executes if the program is federated + * Surround {@code code} with blocks to ensure that code only executes if the + * program is federated * and has a centralized coordination. */ public static String surroundWithIfFederatedCentralized(String code) { return """ - #ifdef FEDERATED_CENTRALIZED - %s - #endif // FEDERATED_CENTRALIZED - """ + #ifdef FEDERATED_CENTRALIZED + %s + #endif // FEDERATED_CENTRALIZED + """ .formatted(code); } /** - * Surround {@code code} with blocks to ensure that code only executes if the program is federated + * Surround {@code code} with blocks to ensure that code only executes if the + * program is federated * and has a decentralized coordination. */ public static String surroundWithIfFederatedDecentralized(String code) { return """ - #ifdef FEDERATED_DECENTRALIZED - %s - #endif // FEDERATED_DECENTRALIZED - """ + #ifdef FEDERATED_DECENTRALIZED + %s + #endif // FEDERATED_DECENTRALIZED + """ .formatted(code); } @@ -558,7 +572,9 @@ public static String generateSerializationIncludes(FederateInstance federate) { return code.getCode(); } - /** Generate cmake-include code needed for enabled serializers of the federate. */ + /** + * Generate cmake-include code needed for enabled serializers of the federate. + */ public static String generateSerializationCMakeExtension(FederateInstance federate) { CodeBuilder code = new CodeBuilder(); for (SupportedSerializers serializer : federate.enabledSerializers) { diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 6c20e647c4..6b55db0e4f 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 6c20e647c4962c1288f57d545d2ce8335a2e4058 +Subproject commit 6b55db0e4fefc794213edcce7dec7bbcf8a82903 From 956a1b41e902ccb97c90b0b3d07712fdc1a41591 Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 7 Aug 2024 19:52:36 +0100 Subject: [PATCH 14/18] Run spotles --- .../federated/extensions/CExtensionUtils.java | 166 ++++++++---------- .../org/lflang/generator/c/CCompiler.java | 88 ++++------ 2 files changed, 105 insertions(+), 149 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 3fbc91ed3b..a894a902f8 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java @@ -36,20 +36,17 @@ public class CExtensionUtils { // Regular expression pattern for shared_ptr types. - static final Pattern sharedPointerVariable = Pattern - .compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); + static final Pattern sharedPointerVariable = + Pattern.compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); /** * Generate C code that initializes network actions. * - *

- * These network actions will be triggered by federate.c whenever a message is - * received from + *

These network actions will be triggered by federate.c whenever a message is received from * the network. * * @param federate The federate. - * @param main The main reactor that contains the federate (used to lookup - * references). + * @param main The main reactor that contains the federate (used to lookup references). */ public static String initializeTriggersForNetworkActions( FederateInstance federate, ReactorInstance main) { @@ -78,18 +75,10 @@ public static String initializeTriggersForNetworkActions( int j = federate.zeroDelayCycleNetworkMessageActions.indexOf(action); if (j >= 0) { var upstream = federate.zeroDelayCycleNetworkUpstreamFeds.get(j); - code.pr( - "_lf_zero_delay_cycle_upstream_ids[" - + j - + "] = " - + upstream.id - + "; \\"); + code.pr("_lf_zero_delay_cycle_upstream_ids[" + j + "] = " + upstream.id + "; \\"); if (upstream.isTransient) { // Transient federates are assumed to be initially disconnected. - code.pr( - "_lf_zero_delay_cycle_upstream_disconnected[" - + j - + "] = true; \\"); + code.pr("_lf_zero_delay_cycle_upstream_disconnected[" + j + "] = true; \\"); } code.pr( "_lf_zero_delay_cycle_action_table[" @@ -106,11 +95,8 @@ public static String initializeTriggersForNetworkActions( /** * Generate C code that holds a sorted list of STP structs by time. * - *

- * For decentralized execution, on every logical timestep, a thread will iterate - * through each - * staa struct, wait for the designated offset time, and set the associated port - * status to absent + *

For decentralized execution, on every logical timestep, a thread will iterate through each + * staa struct, wait for the designated offset time, and set the associated port status to absent * if it isn't known. * * @param federate The federate. @@ -126,7 +112,8 @@ public static String stpStructs(FederateInstance federate) { // main reactor for each Action. for (int i = 0; i < federate.staaOffsets.size(); ++i) { // Find the corresponding ActionInstance. - List networkActions = federate.stpToNetworkActionMap.get(federate.staaOffsets.get(i)); + List networkActions = + federate.stpToNetworkActionMap.get(federate.staaOffsets.get(i)); code.pr("staa_lst[" + i + "] = (staa_t*) malloc(sizeof(staa_t));"); code.pr( @@ -159,8 +146,7 @@ public static String stpStructs(FederateInstance federate) { } /** - * Create a port status field variable for a network input port "input" in the - * self struct of a + * Create a port status field variable for a network input port "input" in the self struct of a * reactor. * * @param input The network input port @@ -181,23 +167,15 @@ public static String createPortStatusFieldForInput(Input input) { } /** - * Given a connection 'delay' expression, return a string that represents the - * interval_t value of + * Given a connection 'delay' expression, return a string that represents the interval_t value of * the additional delay that needs to be applied to the outgoing message. * - *

- * The returned additional delay in absence of after on network connection - * (i.e., if delay is - * passed as a null) is NEVER. This has a special meaning in C library functions - * that send network - * messages that carry timestamps (@see lf_send_tagged_message and - * lf_send_port_absent_to_federate - * in lib/core/federate.c). In this case, the sender will send its current tag - * as the timestamp of - * the outgoing message without adding a microstep delay. If the user has - * assigned an after delay - * to the network connection (that can be zero) either as a time value (e.g., - * 200 msec) or as a + *

The returned additional delay in absence of after on network connection (i.e., if delay is + * passed as a null) is NEVER. This has a special meaning in C library functions that send network + * messages that carry timestamps (@see lf_send_tagged_message and lf_send_port_absent_to_federate + * in lib/core/federate.c). In this case, the sender will send its current tag as the timestamp of + * the outgoing message without adding a microstep delay. If the user has assigned an after delay + * to the network connection (that can be zero) either as a time value (e.g., 200 msec) or as a * literal (e.g., a parameter), that delay in nsec will be returned. * * @param delay The delay associated with a connection. @@ -241,9 +219,11 @@ public static void handleCompileDefinitions( } private static void handleAdvanceMessageInterval(FederateInstance federate) { - var advanceMessageInterval = federate.targetConfig.get(CoordinationOptionsProperty.INSTANCE).advanceMessageInterval; + var advanceMessageInterval = + federate.targetConfig.get(CoordinationOptionsProperty.INSTANCE).advanceMessageInterval; if (advanceMessageInterval != null) { - federate.targetConfig + federate + .targetConfig .get(CompileDefinitionsProperty.INSTANCE) .put("ADVANCE_MESSAGE_INTERVAL", String.valueOf(advanceMessageInterval.toNanoSeconds())); } @@ -256,14 +236,12 @@ static boolean clockSyncIsOn(FederateInstance federate, RtiConfig rtiConfig) { } /** - * Initialize clock synchronization (if enabled) and its related options for a - * given federate. + * Initialize clock synchronization (if enabled) and its related options for a given federate. * - *

- * Clock synchronization can be enabled using the clock-sync target property. + *

Clock synchronization can be enabled using the clock-sync target property. * * @see Documentation + * "https://github.com/icyphy/lingua-franca/wiki/Distributed-Execution#clock-synchronization">Documentation */ public static void initializeClockSynchronization( FederateInstance federate, RtiConfig rtiConfig, MessageReporter messageReporter) { @@ -290,14 +268,12 @@ public static void initializeClockSynchronization( } /** - * Initialize clock synchronization (if enabled) and its related options for a - * given federate. + * Initialize clock synchronization (if enabled) and its related options for a given federate. * - *

- * Clock synchronization can be enabled using the clock-sync target property. + *

Clock synchronization can be enabled using the clock-sync target property. * * @see Documentation + * "https://github.com/icyphy/lingua-franca/wiki/Distributed-Execution#clock-synchronization">Documentation */ public static void addClockSyncCompileDefinitions(FederateInstance federate) { @@ -328,9 +304,10 @@ public static void generateCMakeInclude( FederateInstance federate, FederationFileConfig fileConfig) throws IOException { Files.createDirectories(fileConfig.getSrcPath().resolve("include")); - Path cmakeIncludePath = fileConfig - .getSrcPath() - .resolve("include" + File.separator + federate.name + "_extension.cmake"); + Path cmakeIncludePath = + fileConfig + .getSrcPath() + .resolve("include" + File.separator + federate.name + "_extension.cmake"); CodeBuilder cmakeIncludeCode = new CodeBuilder(); @@ -351,8 +328,7 @@ public static void generateCMakeInclude( } /** - * Generate code that sends the neighbor structure message to the RTI. See - * {@code + * Generate code that sends the neighbor structure message to the RTI. See {@code * MSG_TYPE_NEIGHBOR_STRUCTURE} in {@code federated/net_common.h}. * * @param federate The federate that is sending its neighbor structure @@ -425,13 +401,14 @@ public static String generateFederateNeighborStructure(FederateInstance federate // Use NEVER to encode no delay at all. code.pr("candidate_tmp = NEVER;"); } else { - var delayTime = delay instanceof ParameterReference - // In that case use the default value. - ? CTypes.getInstance() - .getTargetTimeExpr( - ASTUtils.getDefaultAsTimeValue( - ((ParameterReference) delay).getParameter())) - : CTypes.getInstance().getTargetExpr(delay, InferredType.time()); + var delayTime = + delay instanceof ParameterReference + // In that case use the default value. + ? CTypes.getInstance() + .getTargetTimeExpr( + ASTUtils.getDefaultAsTimeValue( + ((ParameterReference) delay).getParameter())) + : CTypes.getInstance().getTargetExpr(delay, InferredType.time()); code.pr( String.join( @@ -488,27 +465,26 @@ public static String surroundWithIfElseFederated(String insideIf, String insideE return surroundWithIfFederated(insideIf); } else { return """ - #ifdef FEDERATED - %s - #else - %s - #endif // FEDERATED - """ + #ifdef FEDERATED + %s + #else + %s + #endif // FEDERATED + """ .formatted(insideIf, insideElse); } } /** - * Surround {@code code} with blocks to ensure that code only executes if the - * program is + * Surround {@code code} with blocks to ensure that code only executes if the program is * federated. */ public static String surroundWithIfFederated(String code) { return """ - #ifdef FEDERATED - %s - #endif // FEDERATED - """ + #ifdef FEDERATED + %s + #endif // FEDERATED + """ .formatted(code); } @@ -517,41 +493,39 @@ public static String surroundWithIfElseFederatedCentralized(String insideIf, Str return surroundWithIfFederatedCentralized(insideIf); } else { return """ - #ifdef FEDERATED_CENTRALIZED - %s - #else - %s - #endif // FEDERATED_CENTRALIZED - """ + #ifdef FEDERATED_CENTRALIZED + %s + #else + %s + #endif // FEDERATED_CENTRALIZED + """ .formatted(insideIf, insideElse); } } /** - * Surround {@code code} with blocks to ensure that code only executes if the - * program is federated + * Surround {@code code} with blocks to ensure that code only executes if the program is federated * and has a centralized coordination. */ public static String surroundWithIfFederatedCentralized(String code) { return """ - #ifdef FEDERATED_CENTRALIZED - %s - #endif // FEDERATED_CENTRALIZED - """ + #ifdef FEDERATED_CENTRALIZED + %s + #endif // FEDERATED_CENTRALIZED + """ .formatted(code); } /** - * Surround {@code code} with blocks to ensure that code only executes if the - * program is federated + * Surround {@code code} with blocks to ensure that code only executes if the program is federated * and has a decentralized coordination. */ public static String surroundWithIfFederatedDecentralized(String code) { return """ - #ifdef FEDERATED_DECENTRALIZED - %s - #endif // FEDERATED_DECENTRALIZED - """ + #ifdef FEDERATED_DECENTRALIZED + %s + #endif // FEDERATED_DECENTRALIZED + """ .formatted(code); } @@ -572,9 +546,7 @@ public static String generateSerializationIncludes(FederateInstance federate) { return code.getCode(); } - /** - * Generate cmake-include code needed for enabled serializers of the federate. - */ + /** Generate cmake-include code needed for enabled serializers of the federate. */ public static String generateSerializationCMakeExtension(FederateInstance federate) { CodeBuilder code = new CodeBuilder(); for (SupportedSerializers serializer : federate.enabledSerializers) { 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 b385df985f..5d30d2d176 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -49,8 +49,7 @@ import org.lflang.util.LFCommand; /** - * Responsible for creating and executing the necessary CMake command to compile - * code that is + * Responsible for creating and executing the necessary CMake command to compile code that is * generated by the CGenerator. This class uses CMake to compile. * * @author Soroush Bateni @@ -67,8 +66,7 @@ public class CCompiler { MessageReporter messageReporter; /** - * Indicate whether the compiler is in C++ mode. In C++ mode, the compiler - * produces .cpp files + * Indicate whether the compiler is in C++ mode. In C++ mode, the compiler produces .cpp files * instead of .c files and uses a C++ compiler to compiler the code. */ private final boolean cppMode; @@ -79,11 +77,10 @@ public class CCompiler { /** * Create an instance of CCompiler. * - * @param targetConfig The current target configuration. - * @param fileConfig The current file configuration. + * @param targetConfig The current target configuration. + * @param fileConfig The current file configuration. * @param messageReporter Used to report errors. - * @param cppMode Whether the generated code should be compiled as if it - * were C++. + * @param cppMode Whether the generated code should be compiled as if it were C++. */ public CCompiler( TargetConfig targetConfig, @@ -100,9 +97,8 @@ public CCompiler( /** * Run the C compiler by invoking cmake and make. * - * @param generator An instance of GeneratorBase, only used to report error line - * numbers in the - * Eclipse IDE. + * @param generator An instance of GeneratorBase, only used to report error line numbers in the + * Eclipse IDE. * @return true if compilation succeeds, false otherwise. */ public boolean runCCompiler(GeneratorBase generator, LFGeneratorContext context) @@ -197,15 +193,15 @@ public boolean runCCompiler(GeneratorBase generator, LFGeneratorContext context) } /** - * Return a command to compile the specified C file using CMake. This produces a - * C-specific + * Return a command to compile the specified C file using CMake. This produces a C-specific * compile command. */ public LFCommand compileCmakeCommand() { // Set the build directory to be "build" Path buildPath = fileConfig.getSrcGenPath().resolve("build"); - LFCommand command = commandFactory.createCommand("cmake", cmakeOptions(targetConfig, fileConfig), buildPath); + LFCommand command = + commandFactory.createCommand("cmake", cmakeOptions(targetConfig, fileConfig), buildPath); if (command == null) { messageReporter .nowhere() @@ -277,31 +273,29 @@ private String buildTypeToCmakeConfig(BuildType type) { } /** - * Return a command to build the specified C file using CMake. This produces a - * C-specific build + * Return a command to build the specified C file using CMake. This produces a C-specific build * command. * - *

- * Note: It appears that configuration and build cannot happen in one command. - * Therefore, this + *

Note: It appears that configuration and build cannot happen in one command. Therefore, this * is separated into a compile command and a build command. */ public LFCommand buildCmakeCommand() { // Set the build directory to be "build" Path buildPath = fileConfig.getSrcGenPath().resolve("build"); String cores = String.valueOf(Runtime.getRuntime().availableProcessors()); - LFCommand command = commandFactory.createCommand( - "cmake", - List.of( - "--build", - ".", - "--target", - "install", - "--parallel", - cores, - "--config", - buildTypeToCmakeConfig(targetConfig.get(BuildTypeProperty.INSTANCE))), - buildPath); + LFCommand command = + commandFactory.createCommand( + "cmake", + List.of( + "--build", + ".", + "--target", + "install", + "--parallel", + cores, + "--config", + buildTypeToCmakeConfig(targetConfig.get(BuildTypeProperty.INSTANCE))), + buildPath); if (command == null) { messageReporter .nowhere() @@ -314,10 +308,8 @@ public LFCommand buildCmakeCommand() { } /** - * Return a flash/emulate command using west. If board is null (defaults to - * qemu_cortex_m3) or - * qemu_* Return a flash command which runs the target as an emulation If - * ordinary target, return + * Return a flash/emulate command using west. If board is null (defaults to qemu_cortex_m3) or + * qemu_* Return a flash command which runs the target as an emulation If ordinary target, return * {@code west flash} */ public LFCommand buildWestFlashCommand(PlatformOptions options) { @@ -339,23 +331,18 @@ public LFCommand buildWestFlashCommand(PlatformOptions options) { } /** - * Check if the output produced by CMake has any known and common errors. If a - * known error is + * Check if the output produced by CMake has any known and common errors. If a known error is * detected, a specialized, more informative message is shown. * - *

- * Errors currently detected: + *

Errors currently detected: * *

    - *
  • C++ compiler used to compile C files: This error shows up as '#error - * "The - * CMAKE_C_COMPILER is set to a C++ compiler"' in the - * 'CMakeOutput' string. + *
  • C++ compiler used to compile C files: This error shows up as '#error "The + * CMAKE_C_COMPILER is set to a C++ compiler"' in the 'CMakeOutput' string. *
* * @param CMakeOutput The captured output from CMake. - * @return true if the provided 'CMakeOutput' contains a known error. false - * otherwise. + * @return true if the provided 'CMakeOutput' contains a known error. false otherwise. */ @SuppressWarnings("BooleanMethodIsAlwaysInverted") private boolean outputContainsKnownCMakeErrors(String CMakeOutput) { @@ -385,10 +372,8 @@ private boolean outputContainsKnownCMakeErrors(String CMakeOutput) { * Produces the filename including the target-specific extension * * @param fileName The base name of the file without any extensions - * @param cppMode Indicate whether the compiler is in C++ mode In C++ mode, the - * compiler produces - * .cpp files instead of .c files and uses a C++ compiler to - * compiler the code. + * @param cppMode Indicate whether the compiler is in C++ mode In C++ mode, the compiler produces + * .cpp files instead of .c files and uses a C++ compiler to compiler the code. */ static String getTargetFileName(String fileName, boolean cppMode, TargetConfig targetConfig) { return fileName + getFileExtension(cppMode, targetConfig); @@ -397,9 +382,8 @@ static String getTargetFileName(String fileName, boolean cppMode, TargetConfig t /** * Return the file extension of the output source files. * - * @param cppMode Whether we are building C code using a C++ compiler. - * @param targetConfig The target configuration that parameterizes the build - * process. + * @param cppMode Whether we are building C code using a C++ compiler. + * @param targetConfig The target configuration that parameterizes the build process. */ static String getFileExtension(boolean cppMode, TargetConfig targetConfig) { if (targetConfig.getOrDefault(PlatformProperty.INSTANCE).platform() == Platform.ARDUINO) { From bffdb1d3c9545e492db7cf67ba14dec5c6e66736 Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 14 Aug 2024 07:50:28 +0100 Subject: [PATCH 15/18] Apply formatter --- .../federated/extensions/CExtensionUtils.java | 154 ++++++++---------- 1 file changed, 67 insertions(+), 87 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 90822cf00d..4e58cbd373 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java @@ -36,20 +36,17 @@ public class CExtensionUtils { // Regular expression pattern for shared_ptr types. - static final Pattern sharedPointerVariable = Pattern - .compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); + static final Pattern sharedPointerVariable = + Pattern.compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); /** * Generate C code that initializes network actions. * - *

- * These network actions will be triggered by federate.c whenever a message is - * received from + *

These network actions will be triggered by federate.c whenever a message is received from * the network. * * @param federate The federate. - * @param main The main reactor that contains the federate (used to lookup - * references). + * @param main The main reactor that contains the federate (used to lookup references). */ public static String initializeTriggersForNetworkActions( FederateInstance federate, ReactorInstance main) { @@ -98,11 +95,8 @@ public static String initializeTriggersForNetworkActions( /** * Generate C code that holds a sorted list of STAA structs by time. * - *

- * For decentralized execution, on every logical timestep, a thread will iterate - * through each - * staa struct, wait for the designated offset time, and set the associated port - * status to absent + *

For decentralized execution, on every logical timestep, a thread will iterate through each + * staa struct, wait for the designated offset time, and set the associated port status to absent * if it isn't known. * * @param federate The federate. @@ -118,7 +112,8 @@ public static String stpStructs(FederateInstance federate) { // main reactor for each Action. for (int i = 0; i < federate.staaOffsets.size(); ++i) { // Find the corresponding ActionInstance. - List networkActions = federate.staToNetworkActionMap.get(federate.staaOffsets.get(i)); + List networkActions = + federate.staToNetworkActionMap.get(federate.staaOffsets.get(i)); code.pr("staa_lst[" + i + "] = (staa_t*) malloc(sizeof(staa_t));"); code.pr( @@ -151,8 +146,7 @@ public static String stpStructs(FederateInstance federate) { } /** - * Create a port status field variable for a network input port "input" in the - * self struct of a + * Create a port status field variable for a network input port "input" in the self struct of a * reactor. * * @param input The network input port @@ -173,23 +167,15 @@ public static String createPortStatusFieldForInput(Input input) { } /** - * Given a connection 'delay' expression, return a string that represents the - * interval_t value of + * Given a connection 'delay' expression, return a string that represents the interval_t value of * the additional delay that needs to be applied to the outgoing message. * - *

- * The returned additional delay in absence of after on network connection - * (i.e., if delay is - * passed as a null) is NEVER. This has a special meaning in C library functions - * that send network - * messages that carry timestamps (@see lf_send_tagged_message and - * lf_send_port_absent_to_federate - * in lib/core/federate.c). In this case, the sender will send its current tag - * as the timestamp of - * the outgoing message without adding a microstep delay. If the user has - * assigned an after delay - * to the network connection (that can be zero) either as a time value (e.g., - * 200 msec) or as a + *

The returned additional delay in absence of after on network connection (i.e., if delay is + * passed as a null) is NEVER. This has a special meaning in C library functions that send network + * messages that carry timestamps (@see lf_send_tagged_message and lf_send_port_absent_to_federate + * in lib/core/federate.c). In this case, the sender will send its current tag as the timestamp of + * the outgoing message without adding a microstep delay. If the user has assigned an after delay + * to the network connection (that can be zero) either as a time value (e.g., 200 msec) or as a * literal (e.g., a parameter), that delay in nsec will be returned. * * @param delay The delay associated with a connection. @@ -233,9 +219,11 @@ public static void handleCompileDefinitions( } private static void handleAdvanceMessageInterval(FederateInstance federate) { - var advanceMessageInterval = federate.targetConfig.get(CoordinationOptionsProperty.INSTANCE).advanceMessageInterval; + var advanceMessageInterval = + federate.targetConfig.get(CoordinationOptionsProperty.INSTANCE).advanceMessageInterval; if (advanceMessageInterval != null) { - federate.targetConfig + federate + .targetConfig .get(CompileDefinitionsProperty.INSTANCE) .put("ADVANCE_MESSAGE_INTERVAL", String.valueOf(advanceMessageInterval.toNanoSeconds())); } @@ -248,14 +236,12 @@ static boolean clockSyncIsOn(FederateInstance federate, RtiConfig rtiConfig) { } /** - * Initialize clock synchronization (if enabled) and its related options for a - * given federate. + * Initialize clock synchronization (if enabled) and its related options for a given federate. * - *

- * Clock synchronization can be enabled using the clock-sync target property. + *

Clock synchronization can be enabled using the clock-sync target property. * * @see Documentation + * "https://github.com/icyphy/lingua-franca/wiki/Distributed-Execution#clock-synchronization">Documentation */ public static void initializeClockSynchronization( FederateInstance federate, RtiConfig rtiConfig, MessageReporter messageReporter) { @@ -282,14 +268,12 @@ public static void initializeClockSynchronization( } /** - * Initialize clock synchronization (if enabled) and its related options for a - * given federate. + * Initialize clock synchronization (if enabled) and its related options for a given federate. * - *

- * Clock synchronization can be enabled using the clock-sync target property. + *

Clock synchronization can be enabled using the clock-sync target property. * * @see Documentation + * "https://github.com/icyphy/lingua-franca/wiki/Distributed-Execution#clock-synchronization">Documentation */ public static void addClockSyncCompileDefinitions(FederateInstance federate) { @@ -320,9 +304,10 @@ public static void generateCMakeInclude( FederateInstance federate, FederationFileConfig fileConfig) throws IOException { Files.createDirectories(fileConfig.getSrcPath().resolve("include")); - Path cmakeIncludePath = fileConfig - .getSrcPath() - .resolve("include" + File.separator + federate.name + "_extension.cmake"); + Path cmakeIncludePath = + fileConfig + .getSrcPath() + .resolve("include" + File.separator + federate.name + "_extension.cmake"); CodeBuilder cmakeIncludeCode = new CodeBuilder(); @@ -343,8 +328,7 @@ public static void generateCMakeInclude( } /** - * Generate code that sends the neighbor structure message to the RTI. See - * {@code + * Generate code that sends the neighbor structure message to the RTI. See {@code * MSG_TYPE_NEIGHBOR_STRUCTURE} in {@code federated/net_common.h}. * * @param federate The federate that is sending its neighbor structure @@ -417,13 +401,14 @@ public static String generateFederateNeighborStructure(FederateInstance federate // Use NEVER to encode no delay at all. code.pr("candidate_tmp = NEVER;"); } else { - var delayTime = delay instanceof ParameterReference - // In that case use the default value. - ? CTypes.getInstance() - .getTargetTimeExpr( - ASTUtils.getDefaultAsTimeValue( - ((ParameterReference) delay).getParameter())) - : CTypes.getInstance().getTargetExpr(delay, InferredType.time()); + var delayTime = + delay instanceof ParameterReference + // In that case use the default value. + ? CTypes.getInstance() + .getTargetTimeExpr( + ASTUtils.getDefaultAsTimeValue( + ((ParameterReference) delay).getParameter())) + : CTypes.getInstance().getTargetExpr(delay, InferredType.time()); code.pr( String.join( @@ -480,27 +465,26 @@ public static String surroundWithIfElseFederated(String insideIf, String insideE return surroundWithIfFederated(insideIf); } else { return """ - #ifdef FEDERATED - %s - #else - %s - #endif // FEDERATED - """ + #ifdef FEDERATED + %s + #else + %s + #endif // FEDERATED + """ .formatted(insideIf, insideElse); } } /** - * Surround {@code code} with blocks to ensure that code only executes if the - * program is + * Surround {@code code} with blocks to ensure that code only executes if the program is * federated. */ public static String surroundWithIfFederated(String code) { return """ - #ifdef FEDERATED - %s - #endif // FEDERATED - """ + #ifdef FEDERATED + %s + #endif // FEDERATED + """ .formatted(code); } @@ -509,41 +493,39 @@ public static String surroundWithIfElseFederatedCentralized(String insideIf, Str return surroundWithIfFederatedCentralized(insideIf); } else { return """ - #ifdef FEDERATED_CENTRALIZED - %s - #else - %s - #endif // FEDERATED_CENTRALIZED - """ + #ifdef FEDERATED_CENTRALIZED + %s + #else + %s + #endif // FEDERATED_CENTRALIZED + """ .formatted(insideIf, insideElse); } } /** - * Surround {@code code} with blocks to ensure that code only executes if the - * program is federated + * Surround {@code code} with blocks to ensure that code only executes if the program is federated * and has a centralized coordination. */ public static String surroundWithIfFederatedCentralized(String code) { return """ - #ifdef FEDERATED_CENTRALIZED - %s - #endif // FEDERATED_CENTRALIZED - """ + #ifdef FEDERATED_CENTRALIZED + %s + #endif // FEDERATED_CENTRALIZED + """ .formatted(code); } /** - * Surround {@code code} with blocks to ensure that code only executes if the - * program is federated + * Surround {@code code} with blocks to ensure that code only executes if the program is federated * and has a decentralized coordination. */ public static String surroundWithIfFederatedDecentralized(String code) { return """ - #ifdef FEDERATED_DECENTRALIZED - %s - #endif // FEDERATED_DECENTRALIZED - """ + #ifdef FEDERATED_DECENTRALIZED + %s + #endif // FEDERATED_DECENTRALIZED + """ .formatted(code); } @@ -564,9 +546,7 @@ public static String generateSerializationIncludes(FederateInstance federate) { return code.getCode(); } - /** - * Generate cmake-include code needed for enabled serializers of the federate. - */ + /** Generate cmake-include code needed for enabled serializers of the federate. */ public static String generateSerializationCMakeExtension(FederateInstance federate) { CodeBuilder code = new CodeBuilder(); for (SupportedSerializers serializer : federate.enabledSerializers) { From ad268e0a89a3605daf3abd958f2bf48a48da88aa Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 14 Aug 2024 12:15:32 +0100 Subject: [PATCH 16/18] Align 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 f00c5af0ae..e8c930d331 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit f00c5af0ae44d688fd1eca8f1e5aa0bce6c08053 +Subproject commit e8c930d331061fd5fcea8dd105435a511420d15a From caecfdf726b6f6fa2376fbfa0d07293034bec4e3 Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 21 Aug 2024 11:56:53 +0100 Subject: [PATCH 17/18] Align 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 e8c930d331..29815425b2 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit e8c930d331061fd5fcea8dd105435a511420d15a +Subproject commit 29815425b2835b06920293f9fe326d8a59be5501 From fd2ff504ebae3830ea3a548d002faea82e9903f4 Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Wed, 28 Aug 2024 14:27:59 +0100 Subject: [PATCH 18/18] Align 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 29815425b2..859a0780a2 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 29815425b2835b06920293f9fe326d8a59be5501 +Subproject commit 859a0780a26197a205008d5fe20600b5c7c8f086