diff --git a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java index 2cf6f58239..c421c3e603 100644 --- a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java @@ -225,7 +225,14 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("set(FP_FLASH_DEVICE " + selectedFlashDevice.value() + ")"); cMakeCode.newLine(); } // No FP_FLASH_DEVICE will automatically become /dev/ttyUSB0 - + break; + case PATMOS: + cMakeCode.newLine(); + cMakeCode.pr("# Include toolchain file and set project"); + cMakeCode.pr("find_program(CLANG_EXECUTABLE NAMES patmos-clang clang DOC \"Path to the clang front-end.\")"); + cMakeCode.pr("set(CMAKE_C_COMPILER ${CLANG_EXECUTABLE})"); + cMakeCode.pr("project(" + executableName + " LANGUAGES C)"); + cMakeCode.newLine(); break; default: cMakeCode.pr("project(" + executableName + " LANGUAGES C)"); @@ -328,6 +335,13 @@ CodeBuilder generateCMakeCode( executableName, Stream.concat(additionalSources.stream(), sources.stream()))); break; + case PATMOS: + cMakeCode.pr( + setUpMainTargetPatmos( + hasMain, + executableName, + Stream.concat(additionalSources.stream(), sources.stream()))); + break; default: cMakeCode.pr( setUpMainTarget.getCmakeCode( @@ -616,4 +630,31 @@ private static String setUpMainTargetFlexPRET( return code.toString(); } + + private static String setUpMainTargetPatmos( + boolean hasMain, String executableName, Stream cSources) { + var code = new CodeBuilder(); + code.pr("add_subdirectory(core)"); + code.newLine(); + + code.pr("set(LF_MAIN_TARGET " + executableName + ")"); + code.newLine(); + + if (hasMain) { + code.pr("# Declare a new executable target and list all its sources"); + code.pr("add_executable("); + } else { + code.pr("# Declare a new library target and list all its sources"); + code.pr("add_library("); + } + code.indent(); + code.pr("${LF_MAIN_TARGET}"); + + cSources.forEach(code::pr); + code.unindent(); + code.pr(")"); + code.newLine(); + + return code.toString(); + } } diff --git a/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java index 10c7e400df..99dbae7349 100644 --- a/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java +++ b/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java @@ -46,7 +46,8 @@ public static String generatePythonClass( pythonClasses.pr(generatePythonClassHeader(className)); // Generate preamble code pythonClasses.indent(); - pythonClasses.pr(PythonPreambleGenerator.generatePythonPreambles(reactor.getPreambles())); + pythonClasses.pr( + PythonPreambleGenerator.generatePythonPreambles(ASTUtils.allPreambles(reactor))); // Handle runtime initializations pythonClasses.pr(generatePythonConstructor(decl, types)); pythonClasses.pr(PythonParameterGenerator.generatePythonGetters(decl)); diff --git a/core/src/main/java/org/lflang/target/property/type/PlatformType.java b/core/src/main/java/org/lflang/target/property/type/PlatformType.java index f861753bf8..29f4fc9937 100644 --- a/core/src/main/java/org/lflang/target/property/type/PlatformType.java +++ b/core/src/main/java/org/lflang/target/property/type/PlatformType.java @@ -19,6 +19,7 @@ public enum Platform { MAC("Darwin", true), ZEPHYR("Zephyr", true), FLEXPRET("FlexPRET", true), + PATMOS("Patmos", false), WINDOWS("Windows", true); final String cMakeName; diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 76ec485017..3d15df1f4a 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 76ec485017ae682a7f00aa9bc5609410c638c703 +Subproject commit 3d15df1f4a08c0ccb9ce62038873ee324d6a1c29 diff --git a/core/src/main/resources/lib/cpp/reactor-cpp b/core/src/main/resources/lib/cpp/reactor-cpp index dfdac2c19e..65dff1fd22 160000 --- a/core/src/main/resources/lib/cpp/reactor-cpp +++ b/core/src/main/resources/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit dfdac2c19e8d111cf4741c8bf8f304678a59d025 +Subproject commit 65dff1fd22d80305473acaf34a7e5209521b5ec0 diff --git a/test/C/src/PreambleInherited.lf b/test/C/src/PreambleInherited.lf index 771185bdbc..2a2240a606 100644 --- a/test/C/src/PreambleInherited.lf +++ b/test/C/src/PreambleInherited.lf @@ -12,6 +12,9 @@ reactor A { } reactor B extends A { + reaction(startup) {= + printf("FOO 2: %d\n", FOO); + =} } main reactor { diff --git a/test/C/src/patmos/HelloPatmos.lf b/test/C/src/patmos/HelloPatmos.lf new file mode 100644 index 0000000000..8f289c980a --- /dev/null +++ b/test/C/src/patmos/HelloPatmos.lf @@ -0,0 +1,12 @@ +target C { + platform: "Patmos", + single-threaded: true, + build-type: Debug, + } + + main reactor { + reaction(startup) {= + printf("Hello World!\n"); + =} + } + \ No newline at end of file diff --git a/test/Python/src/PreambleInherited.lf b/test/Python/src/PreambleInherited.lf new file mode 100644 index 0000000000..3c27e03b52 --- /dev/null +++ b/test/Python/src/PreambleInherited.lf @@ -0,0 +1,18 @@ +target Python + +reactor Base { + preamble {= + def initiation(self): + print("Hello World\n") + =} +} + +reactor Extended extends Base { + reaction(startup) {= + self.initiation() + =} +} + +main reactor { + e = new Extended() +}