Skip to content

Commit

Permalink
More output in State Persistence test + Apply Spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
ChadliaJerad committed Dec 4, 2024
1 parent b937cee commit a5437f2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,13 @@ public static void generateCMakeInclude(
"add_compile_definitions(LF_PACKAGE_DIRECTORY=\"" + fileConfig.srcPkgPath + "\")");
// After federates have been divided, their root package directory is different.
cmakeIncludeCode.pr(
"add_compile_definitions(LF_FED_PACKAGE_DIRECTORY=\"" + fileConfig.srcPkgPath + File.separator
+ "fed-gen" + File.separator + fileConfig.name + "\")");
"add_compile_definitions(LF_FED_PACKAGE_DIRECTORY=\""
+ fileConfig.srcPkgPath
+ File.separator
+ "fed-gen"
+ File.separator
+ fileConfig.name
+ "\")");
cmakeIncludeCode.pr("add_compile_definitions(LF_FILE_SEPARATOR=\"" + File.separator + "\")");
try (var srcWriter = Files.newBufferedWriter(cmakeIncludePath)) {
srcWriter.write(cmakeIncludeCode.getCode());
Expand Down
88 changes: 36 additions & 52 deletions core/src/main/java/org/lflang/generator/c/CCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -275,31 +271,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.
*
* <p>
* Note: It appears that configuration and build cannot happen in one command.
* Therefore, this
* <p>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()
Expand All @@ -312,10 +306,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) {
Expand All @@ -337,23 +329,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.
*
* <p>
* Errors currently detected:
* <p>Errors currently detected:
*
* <ul>
* <li>C++ compiler used to compile C files: This error shows up as &#39;#error
* &quot;The
* CMAKE_C_COMPILER is set to a C++ compiler&quot;&#39; in the
* &#39;CMakeOutput&#39; string.
* <li>C++ compiler used to compile C files: This error shows up as &#39;#error &quot;The
* CMAKE_C_COMPILER is set to a C++ compiler&quot;&#39; in the &#39;CMakeOutput&#39; string.
* </ul>
*
* @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) {
Expand Down Expand Up @@ -383,10 +370,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);
Expand All @@ -395,9 +380,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) {
Expand Down
20 changes: 14 additions & 6 deletions test/C/src/federated/transient/TransientStatePersistence.lf
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ reactor Persistence {
reaction(in_middle_join) -> out_to_middle {=
if (!self->middle_first_join) {
lf_set(out_to_middle, self->middle_state);
lf_print("Notifying Mid of the latest state: {%c,%d}", self->middle_state.state_char,
self->middle_state.state_count);
}
self->middle_first_join = false;
=}

reaction(in_from_middle) {=
self->middle_state.state_char = in_from_middle->value.state_char;
self->middle_state.state_count = in_from_middle->value.state_count;
lf_print("Latest recieved state: {%c,%d}", self->middle_state.state_char,
self->middle_state.state_count);
=}
}

Expand Down Expand Up @@ -111,6 +115,10 @@ reactor Middle {

reaction(in_from_persistence) {=
self->middle_state = in_from_persistence->value;
lf_print("Recieved the latest state of: {%c,%d} at " PRINTF_TIME ".",
self->middle_state.state_char,
self->middle_state.state_count,
lf_time_logical_elapsed());
=}

// When an input is received, the internal state is updated, and then sent to
Expand Down Expand Up @@ -149,17 +157,17 @@ reactor Down {
lf_print("Down timer count %d", self->count_timer);
=}

reaction(in) {=
self->count_in_mid_reactions++;
lf_print("Down in %d", self->count_in_mid_reactions);
=}

reaction(join) {=
self->count_join++;
lf_print("Down count join %d", self->count_join);
=}

reaction(shutdown) in {=
reaction(in) {=
self->count_in_mid_reactions++;
lf_print("Down in %d", self->count_in_mid_reactions);
=}

reaction(shutdown) {=
if(self->count_join == 2 && in->value < 4) {
lf_print_error_and_exit("Mid Joined twice, but the state did not persist \
across executions! state_count is %d, while is should be > then %d.",
Expand Down

0 comments on commit a5437f2

Please sign in to comment.