Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable support for tracing in the Python target #568

Merged
merged 1 commit into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}