-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various fixes to get all standalone tests to pass again
- Loading branch information
Showing
6 changed files
with
94 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
lfc/core/src/main/kotlin/org/lflang/generator/uc/UcFederatedMainGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.lflang.generator.uc | ||
|
||
import org.lflang.target.TargetConfig | ||
import org.lflang.generator.PrependOperator | ||
import org.lflang.generator.uc.UcInstanceGenerator.Companion.codeTypeFederate | ||
import org.lflang.generator.uc.UcReactorGenerator.Companion.codeType | ||
import org.lflang.inferredType | ||
import org.lflang.lf.Instantiation | ||
import org.lflang.lf.Parameter | ||
import org.lflang.lf.Reactor | ||
import org.lflang.reactor | ||
import org.lflang.target.property.FastProperty | ||
import org.lflang.target.property.KeepaliveProperty | ||
import org.lflang.target.property.PlatformProperty | ||
import org.lflang.target.property.TimeOutProperty | ||
import org.lflang.target.property.type.PlatformType | ||
import org.lflang.toUnixString | ||
|
||
class UcFederatedMainGenerator( | ||
private val main: Instantiation, | ||
private val targetConfig: TargetConfig, | ||
private val fileConfig: UcFileConfig, | ||
) { | ||
|
||
private val top = main.eContainer() as Reactor | ||
private val ucParameterGenerator = UcParameterGenerator(main.reactor) | ||
private val ucConnectionGenerator = UcConnectionGenerator(top, main) | ||
|
||
fun getDuration() = if (targetConfig.isSet(TimeOutProperty.INSTANCE)) targetConfig.get(TimeOutProperty.INSTANCE).toCCode() else "FOREVER" | ||
|
||
fun keepAlive() = if(targetConfig.isSet(KeepaliveProperty.INSTANCE)) "true" else "false" | ||
|
||
fun fast() = if(targetConfig.isSet(FastProperty.INSTANCE)) "true" else "false" | ||
|
||
fun generateStartSource() = with(PrependOperator) { | ||
""" | ||
|#include "reactor-uc/reactor-uc.h" | ||
|#include "Federate.h" | ||
|static ${main.codeTypeFederate} main_reactor; | ||
|static Environment lf_environment; | ||
|void lf_exit(void) { | ||
| Environment_free(&lf_environment); | ||
|} | ||
|void lf_start(void) { | ||
| Environment_ctor(&lf_environment, (Reactor *)&main_reactor); | ||
| lf_environment.scheduler->duration = ${getDuration()}; | ||
| lf_environment.scheduler->keep_alive = ${keepAlive()}; | ||
| lf_environment.scheduler->leader = ${top.instantiations.first() == main}; | ||
| lf_environment.fast_mode = ${fast()}; | ||
| lf_environment.has_async_events = ${main.reactor.inputs.isNotEmpty()}; | ||
| ${main.codeTypeFederate}_ctor(&main_reactor, NULL, &lf_environment); | ||
| lf_environment.net_bundles_size = ${ucConnectionGenerator.getNumFederatedConnectionBundles()}; | ||
| lf_environment.net_bundles = (FederatedConnectionBundle **) &main_reactor._bundles; | ||
| lf_environment.assemble(&lf_environment); | ||
| lf_environment.start(&lf_environment); | ||
| lf_exit(); | ||
|} | ||
""".trimMargin() | ||
} | ||
|
||
fun generateStartHeader() = with(PrependOperator) { | ||
""" | ||
|#ifndef REACTOR_UC_LF_MAIN_H | ||
|#define REACTOR_UC_LF_MAIN_H | ||
| | ||
|void lf_start(void); | ||
| | ||
|#endif | ||
| | ||
""".trimMargin() | ||
} | ||
|
||
fun generateMainSource() = with(PrependOperator) { | ||
""" | ||
|#include "lf_start.h" | ||
|int main(void) { | ||
| lf_start(); | ||
|} | ||
""".trimMargin() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters