Skip to content

Commit

Permalink
Support for Patmos platform
Browse files Browse the repository at this point in the history
  • Loading branch information
lhstrh authored and EhsanKhodadad committed Aug 1, 2024
2 parents a088c1a + 55a1680 commit 1144a7b
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 4 deletions.
43 changes: 42 additions & 1 deletion core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -616,4 +630,31 @@ private static String setUpMainTargetFlexPRET(

return code.toString();
}

private static String setUpMainTargetPatmos(
boolean hasMain, String executableName, Stream<String> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/cpp/reactor-cpp
3 changes: 3 additions & 0 deletions test/C/src/PreambleInherited.lf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ reactor A {
}

reactor B extends A {
reaction(startup) {=
printf("FOO 2: %d\n", FOO);
=}
}

main reactor {
Expand Down
12 changes: 12 additions & 0 deletions test/C/src/patmos/HelloPatmos.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
target C {
platform: "Patmos",
single-threaded: true,
build-type: Debug,
}

main reactor {
reaction(startup) {=
printf("Hello World!\n");
=}
}

18 changes: 18 additions & 0 deletions test/Python/src/PreambleInherited.lf
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 1144a7b

Please sign in to comment.