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

Cpp: Add functionality for dumping the reactor structure to a yaml file #788

Merged
merged 5 commits into from
Dec 21, 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
14 changes: 12 additions & 2 deletions org.lflang/src/org/lflang/TargetConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,22 @@ public class TargetConfig {
/**
* If true, the resulting binary will output a graph visualizing all reaction dependencies.
*
* This option is currently only used for C++. This export function is a valuable tool for debugging
* LF programs and helps to understand the dependencies inferred by the C++ runtime.
* This option is currently only used for C++ and Rust. This export function is a valuable tool
* for debugging LF programs and helps to understand the dependencies inferred by the runtime.
*/
public boolean exportDependencyGraph = false;


/**
* If true, the resulting binary will output a yaml file describing the whole reactor structure
* of the program.
*
* This option is currently only used for C++. This export function is a valuable tool for debugging
* LF programs and performing external analysis.
*/
public boolean exportToYaml = false;


/** Rust-specific configuration. */
public final RustTargetConfig rust = new RustTargetConfig();

Expand Down
12 changes: 11 additions & 1 deletion org.lflang/src/org/lflang/TargetProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,19 @@ public enum TargetProperty {
List.of(Target.CPP, Target.Rust),
(config, value, err) -> {
config.exportDependencyGraph = ASTUtils.toBoolean(value);

}),

/**
* Directive to let the runtime export the program structure to a yaml file.
*
* This is a debugging feature and currently only used for C++ programs.
*/
EXPORT_TO_YAML("export-to-yaml", PrimitiveType.BOOLEAN,
List.of(Target.CPP),
(config, value, err) -> {
config.exportToYaml = ASTUtils.toBoolean(value);
}),

/**
* List of module files to link into the crate as top-level.
* For instance, a {@code target Rust { rust-modules: [ "foo.rs" ] }}
Expand Down
2 changes: 1 addition & 1 deletion org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CppGenerator(
const val libDir = "/lib/cpp"

/** Default version of the reactor-cpp runtime to be used during compilation */
const val defaultRuntimeVersion = "1d5ef9d9dc25bcf30bc4eb94b2316b32f456aaa2"
const val defaultRuntimeVersion = "f5e6ebf02a9ec68d64ea5e7e7519fcb475afcd58"
}

override fun doGenerate(resource: Resource, fsa: IFileSystemAccess2, context: IGeneratorContext) {
Expand Down
7 changes: 5 additions & 2 deletions org.lflang/src/org/lflang/generator/cpp/CppMainGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ class CppMainGenerator(
| t = std::make_unique<Timeout>("Timeout", & e, timeout);
| }
|
| // execute the reactor program
| // assemble reactor program
| e.assemble();
${" |".. if (targetConfig.exportDependencyGraph) "e.export_dependency_graph(\"${main.name}.dot\");" else ""}
${" |".. if (targetConfig.exportToYaml) "e.dump_to_yaml(\"${main.name}.yaml\");" else ""}
|
| // start execution
| auto thread = e.startup();
| thread.join();
${" |".. if (targetConfig.exportDependencyGraph) "e.export_dependency_graph(\"${main.name}.dot\");" else ""}
| return 0;
|}
""".trimMargin()
Expand Down