Skip to content

Commit

Permalink
Enabled support for tracing in the Python target
Browse files Browse the repository at this point in the history
  • Loading branch information
Soroosh129 committed Oct 4, 2021
1 parent ec1f83c commit 5899b68
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion org.lflang/src/org/lflang/TargetProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public enum TargetProperty {
* true or false, or a dictionary of options.
*/
TRACING("tracing", UnionType.TRACING_UNION,
Arrays.asList(Target.C, Target.CCPP, Target.CPP), (config, value) -> {
Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Python), (config, value) -> {
if (value.getLiteral() != null) {
if (ASTUtils.toBoolean(value)) {
config.tracing = new TracingOptions();
Expand Down
13 changes: 12 additions & 1 deletion org.lflang/src/org/lflang/generator/PythonGenerator.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -1000,8 +1000,19 @@ class PythonGenerator extends CGenerator {
*/
override includeTargetLanguageHeaders() {
pr('''#define MODULE_NAME LinguaFranca«topLevelName»''')
pr('''#define __GARBAGE_COLLECTED''')
pr('''#define __GARBAGE_COLLECTED''')
if (targetConfig.tracing !== null) {
var filename = "";
if (targetConfig.tracing.traceFileName !== null) {
filename = targetConfig.tracing.traceFileName;
}
pr('#define LINGUA_FRANCA_TRACE ' + filename)
}

pr('#include "pythontarget.c"')
if (targetConfig.tracing !== null) {
pr('#include "core/trace.c"')
}
}

/** Generate C code from the Lingua Franca model contained by the
Expand Down
6 changes: 4 additions & 2 deletions test/Python/src/HelloWorld.lf
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
target Python;
target Python {
tracing: true
};
reactor HelloWorld2 {
reaction(startup) {=
print("Hello World.")
=}
}
main reactor HelloWorld {
a = new HelloWorld2();
}
}

0 comments on commit 5899b68

Please sign in to comment.