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

Environments in the C target #1772

Merged
merged 153 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from 144 commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
45e757f
Point to reactor-c enclaves branch
edwardalee May 17, 2023
08bc2a3
Add code-generator support for initial environment porting
erlingrj May 18, 2023
3b5e0a7
Add env pointer to code generated functions
erlingrj May 18, 2023
467e553
Code-generate more of the enclaves stuff
erlingrj May 19, 2023
d77916d
Revert some premature enclave changes. Also, add example enclaves pro…
erlingrj May 20, 2023
b12a79d
Align to reactor-c enclaves branch
edwardalee May 22, 2023
981ae96
Merge in master
edwardalee May 22, 2023
0322afb
Merge with mater
erlingrj May 22, 2023
c83430d
More work towards introducing an environment struct for all C programs
erlingrj May 23, 2023
045aa95
Merge with upstream watchdog work
erlingrj May 23, 2023
703ff11
Remove startup,shutdown and reset trigger table generation
erlingrj May 23, 2023
db75f89
Create EnclaveInfo which holds, among other things, the number of isP…
erlingrj May 23, 2023
fdbd1e9
Use EnclaveInfo to generate environment functions
erlingrj May 23, 2023
cc9438b
Update Startup, Shutdown and Reset reactions to use the EnclaveInfo
erlingrj May 23, 2023
14c8872
Fix getEnclaves function
erlingrj May 23, 2023
9f2c7dd
Merge commit '1fef9e6d1' into enclaves
petervdonovan May 23, 2023
04b5396
Merge commit '206ea18a2' into enclaves
petervdonovan May 23, 2023
6727953
Apply formatter.
petervdonovan May 23, 2023
84e8f8e
Merge branch 'master' into enclaves
petervdonovan May 23, 2023
6786aaa
Fix mistake from merge.
petervdonovan May 23, 2023
4343136
Fix typo in some names
erlingrj May 23, 2023
5b8e479
Mark NonCommunicating test as @enclave
erlingrj May 23, 2023
a4eb451
Merge branch 'enclaves' of github.com:lf-lang/lingua-franca into encl…
erlingrj May 23, 2023
13b870b
Typos
erlingrj May 23, 2023
cd1c747
Bump reactor-c
erlingrj May 23, 2023
33c029b
Run formatter
erlingrj May 23, 2023
18d4985
Start towards supporting federated execution as well
erlingrj May 23, 2023
e993911
Code-generate correct terminate_execution function
erlingrj May 24, 2023
7d3e1fa
Bump reactor-C
erlingrj May 24, 2023
ad84238
Code-generate the correct call to create the p2p federated thread cre…
erlingrj May 24, 2023
499c02e
Code generate correct call to wait_until_port_status_known
erlingrj May 24, 2023
0d67cc0
typo
erlingrj May 24, 2023
82eaed1
update
erlingrj May 24, 2023
5cfff86
bump reactor-c
erlingrj May 24, 2023
c3659c0
Minor fixes
erlingrj May 24, 2023
d6b0130
Update SheduleAt test to use new API
erlingrj May 24, 2023
f565791
Code-generate environment pointer for watchdogs
erlingrj May 24, 2023
d9aed97
Move DelayedCommunication test into failing
erlingrj May 24, 2023
8c71565
Add timeouts to enclave tests
erlingrj May 24, 2023
a0d2318
Move all enclaved tests to failing
erlingrj May 24, 2023
dd4580e
Initial support for modal reactors
erlingrj May 25, 2023
b02202a
no_inlining tests are moved to failure since the self pointer forward…
erlingrj May 25, 2023
d331ece
Only do CI on ubuntu. Will adrress Windows failures later
erlingrj May 26, 2023
10b807e
Count the numModalReactors inside EnclaveInfo
erlingrj May 26, 2023
236c2b0
Handle auto reset of modal state. All modal tests pass locally
erlingrj May 27, 2023
ab46a69
Use updated version of send_timed_message in federated test
erlingrj May 27, 2023
ba4b8ac
Have top-level enclave use the global _lf_number_of_workers. Other en…
erlingrj May 27, 2023
9bca6ab
Bump reactor-c
erlingrj May 27, 2023
93a84ed
Fix modal shutdown code-generation
erlingrj May 27, 2023
d0a914f
Move environment include behind CPP ifdef
erlingrj May 27, 2023
fbc4171
also update testing gradle config
cmnrd May 30, 2023
27db4a1
hotfix: fallback to insecure protocol for fetching from kieler repo
cmnrd May 30, 2023
84bfe36
Bump reactor-c
erlingrj May 30, 2023
72ca9bf
Remove duplicate environment include
erlingrj May 30, 2023
f6fd57e
Move clock initialization into runtime
erlingrj May 31, 2023
4af3a35
Bump reactor-c
erlingrj May 31, 2023
4259aa2
Bump reactor-c
erlingrj May 31, 2023
8bd165e
Merge remote-tracking branch 'origin/master' into enclaves
erlingrj May 31, 2023
332ea01
Surpress som unused warnings
erlingrj May 31, 2023
c6c8c39
Minor typos
erlingrj May 31, 2023
df1afb4
High-level architecure of the EnclaveReactorTransformation
erlingrj May 31, 2023
9e0109a
Fix ScheduleAt.lf
erlingrj Jun 1, 2023
3a8a202
Bump reactor-c
erlingrj Jun 1, 2023
a4b30b7
FIx init of source_reactor pointer of ports
erlingrj Jun 1, 2023
aea09c8
Try out qemu_cortex_m3 for zephyr tests
erlingrj Jun 1, 2023
ada3748
Set source_reactor pointer, also of dangling pointer.
erlingrj Jun 1, 2023
3dc707e
Due to alot of problems with qemu emulations. Try using just native e…
erlingrj Jun 1, 2023
8cb9a05
Debug output seems to not be a problem for zephyr native execution
erlingrj Jun 1, 2023
6630c34
Bump reactor-C
erlingrj Jun 1, 2023
66f8f83
Move to native execution of Zephyr CI tests, then we dont need the ru…
erlingrj Jun 1, 2023
10169b6
Merge remote-tracking branch 'origin/master' into enclaves
erlingrj Jun 2, 2023
da050b4
Bump reactor-c
erlingrj Jun 2, 2023
c890283
Disable logging again for Zephyr
erlingrj Jun 2, 2023
d016668
Merge branch 'enclaves' of github.com:lf-lang/lingua-franca into encl…
erlingrj Jun 2, 2023
7bb36ca
Merge remote-tracking branch 'origin/master' into enclaves-merge
erlingrj Jun 5, 2023
dee847d
Add the EnclaveReactorTransformation
erlingrj Jun 5, 2023
f0a743b
Finish merge
erlingrj Jun 5, 2023
056d26b
Run Spotless
erlingrj Jun 5, 2023
faeda3a
Split Zephyr tests into threaded and unthreaded.
erlingrj Jun 5, 2023
59e98f4
Merge branch 'enclaves' of github.com:lf-lang/lingua-franca into encl…
erlingrj Jun 5, 2023
cbab4a3
Run spotless
erlingrj Jun 5, 2023
31bea4e
Go back to qemu-based Zephyr testing
erlingrj Jun 5, 2023
9e01f1f
Bump reactor-C
erlingrj Jun 5, 2023
f795afb
Lint
erlingrj Jun 5, 2023
f690c27
Dont do ZEPHYR_THREADED except for in the Zephyr tests
erlingrj Jun 5, 2023
0c49c12
Typo
erlingrj Jun 5, 2023
e9f856a
Mova some failing federated tests temporarily to failing
erlingrj Jun 5, 2023
3827c5c
Add enclave AST transformation
erlingrj Jun 6, 2023
f6045b1
Add AST transformation
erlingrj Jun 6, 2023
d912c7f
Move enclaves tests out of failing
erlingrj Jun 6, 2023
22edd1d
Merge remote-tracking branch 'origin/master' into enclaves
erlingrj Jun 6, 2023
9108b74
Rename run back to build in Zephyr
erlingrj Jun 6, 2023
9d80a45
Fix merge
erlingrj Jun 6, 2023
2dc0fd2
Spotless
erlingrj Jun 6, 2023
4f7e89b
Add back missing tests
erlingrj Jun 6, 2023
0217c65
Spotless
erlingrj Jun 6, 2023
6afd8e2
Remove the use of a variable named template for the CCpp target
erlingrj Jun 6, 2023
179dec6
Add extern C for CCpp
erlingrj Jun 6, 2023
3d3f8f9
Fix ConnectionReactor for CCpp
erlingrj Jun 6, 2023
29b63a1
Spotless
erlingrj Jun 6, 2023
1648110
Remove debug logging from test
erlingrj Jun 6, 2023
60680bc
Code aut-formatted with Spotless
erlingrj Jun 6, 2023
6a9c3cc
Update gitignore
erlingrj Jun 6, 2023
9adfe98
Update Zephyr tests
erlingrj Jun 6, 2023
9c233fd
CI
erlingrj Jun 6, 2023
0d0c3db
Remove assertion on deadline avoidance, because CI suck at real-time
erlingrj Jun 6, 2023
a1157f2
Merge branch 'master' into enclaves
erlingrj Jun 6, 2023
20b06a1
Move _lf_initialize_timers to reactor-c
erlingrj Jun 7, 2023
0938349
Bump reactor-c
erlingrj Jun 7, 2023
43e7a1c
Move _lf_trigger_Startup_reactions to reactor-c
erlingrj Jun 7, 2023
38c5326
Merge branch 'enclaves' of github.com:lf-lang/lingua-franca into encl…
erlingrj Jun 7, 2023
94458a0
Move code-generated mode functions back to reactor-c
erlingrj Jun 7, 2023
b94c641
Apply suggestions from code review
erlingrj Jun 7, 2023
697d069
Apply suggestions from code review
erlingrj Jun 7, 2023
57854e1
Remove initialization of action parent
erlingrj Jun 7, 2023
7562292
Docs
erlingrj Jun 7, 2023
d52e328
Code auto-formatted with Spotless
erlingrj Jun 7, 2023
990c3a6
Docs
erlingrj Jun 7, 2023
9f8b495
Docs++
erlingrj Jun 7, 2023
2d888be
Code auto-formatted with Spotless
erlingrj Jun 7, 2023
70e0fc5
Remove some stale functions
erlingrj Jun 7, 2023
db799f2
Bump reactor-c
erlingrj Jun 7, 2023
861557c
Bump reactor-c
erlingrj Jun 7, 2023
bcfb3f2
Bump reactor-C
erlingrj Jun 7, 2023
5ccf29a
Bump reactor-c
erlingrj Jun 7, 2023
6adfa69
Make no_inlining compatible with environments
erlingrj Jun 8, 2023
0a01d40
Merge branch 'enclaves' of github.com:lf-lang/lingua-franca into encl…
erlingrj Jun 8, 2023
927b40c
Remove the enclaved stuff from this PR and only focus on the environment
erlingrj Jun 8, 2023
688c9d8
Update tracing API
erlingrj Jun 8, 2023
ebc7cdc
Merge branch 'master' into enclaves
erlingrj Jun 8, 2023
e558cca
Move back federated test from failiing
erlingrj Jun 8, 2023
a1e003c
Handle tracing per environment
erlingrj Jun 8, 2023
abd3682
Code auto-formatted with Spotless
erlingrj Jun 8, 2023
b3e0542
Bump reactor-C
erlingrj Jun 8, 2023
146d9b6
Update tracing test to use new Tracing API
erlingrj Jun 8, 2023
5308899
Bump reactor-c
erlingrj Jun 8, 2023
89d74dd
Another update on trace API
erlingrj Jun 9, 2023
f24d464
Bump reactor-c
erlingrj Jun 9, 2023
9f0f093
Bump reactor-C
erlingrj Jun 9, 2023
d709f96
Merge remote-tracking branch 'origin/master' into enclaves
erlingrj Jun 9, 2023
c506493
Merge branch 'master' into enclaves
erlingrj Jun 9, 2023
15222f1
Rename lf test because of naming conflict with windows
erlingrj Jun 9, 2023
9b8f8e0
Bump reactor-c
erlingrj Jun 9, 2023
349062d
Merge branches 'enclaves' and 'enclaves' of github.com:lf-lang/lingua…
erlingrj Jun 9, 2023
e852271
Merge branch 'master' into enclaves
erlingrj Jun 10, 2023
ea14a38
Merge branch 'master' into enclaves
erlingrj Jun 10, 2023
5c48e93
Merge branch 'master' into enclaves
erlingrj Jun 13, 2023
580edd4
Address Peter's comments
erlingrj Jun 14, 2023
16b4570
Code auto-formatted with Spotless
erlingrj Jun 14, 2023
2e3abe9
Merge branch 'master' into enclaves
erlingrj Jun 14, 2023
c974994
Merge branch 'master' into enclaves
erlingrj Jun 15, 2023
9c59626
Merge branch 'master' into enclaves
erlingrj Jun 16, 2023
9acca40
Merge branch 'master' into enclaves
erlingrj Jun 16, 2023
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
15 changes: 13 additions & 2 deletions .github/workflows/c-zephyr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,21 @@ jobs:
path: core/src/main/resources/lib/c/reactor-c
ref: ${{ inputs.runtime-ref }}
if: ${{ inputs.runtime-ref }}
- name: Perform Zephyr tests for C target with default scheduler
- name: Run Zephyr smoke tests
run: |
./gradlew targetTest -Ptarget=CZephyr
./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildZephyr*
erlingrj marked this conversation as resolved.
Show resolved Hide resolved
util/RunZephyrTests.sh test/C/src-gen
rm -r test/C/src-gen
- name: Run basic tests
run: |
./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildBasic*
util/RunZephyrTests.sh test/C/src-gen
rm -r test/C/src-gen
- name: Run concurrent tests
run: |
./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildConcurrent*
util/RunZephyrTests.sh test/C/src-gen
rm -r test/C/src-gen
- name: Collect code coverage
run: ./gradlew jacocoTestReport
- name: Report to CodeCov
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,8 @@ gradle-app.setting

### xtext artifaccts
*.jar
core/model/
core/model/
org.lflang/model/generated
lhstrh marked this conversation as resolved.
Show resolved Hide resolved

#### Zephyr/west
.west/
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ private static boolean isExcludedFromCCpp(TestCategory category) {
excluded |= isWindows() && (category == TestCategory.DOCKER_FEDERATED);
excluded |=
isMac() && (category == TestCategory.DOCKER_FEDERATED || category == TestCategory.DOCKER);
excluded |= category == TestCategory.ZEPHYR;
excluded |= category == TestCategory.ZEPHYR_UNTHREADED;
excluded |= category == TestCategory.ZEPHYR_THREADED;
excluded |= category == TestCategory.ARDUINO;
excluded |= category == TestCategory.NO_INLINING;
return !excluded;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,24 @@ public CZephyrTest() {
}

@Test
public void buildZephyrTests() {
public void buildZephyrUnthreadedTests() {
Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux");
super.runTestsFor(
List.of(Target.C),
Message.DESC_ZEPHYR,
TestCategory.ZEPHYR::equals,
TestCategory.ZEPHYR_UNTHREADED::equals,
Configurators::makeZephyrCompatibleUnthreaded,
TestLevel.BUILD,
false);
}

@Test
public void buildZephyrThreadedTests() {
Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux");
super.runTestsFor(
List.of(Target.C),
Message.DESC_ZEPHYR,
TestCategory.ZEPHYR_THREADED::equals,
Configurators::makeZephyrCompatible,
TestLevel.BUILD,
false);
Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/org/lflang/AttributeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package org.lflang;

import static org.lflang.ast.ASTUtils.factory;

import java.util.List;
import java.util.Objects;
import org.eclipse.emf.ecore.EObject;
Expand Down Expand Up @@ -244,4 +246,17 @@ public static Attribute getEnclaveAttribute(Instantiation node) {
public static boolean isEnclave(Instantiation node) {
return getEnclaveAttribute(node) != null;
}

/**
* Annotate @{code node} with enclave @attribute
*
* @param node
*/
public static void setEnclaveAttribute(Instantiation node) {
if (!isEnclave(node)) {
Attribute enclaveAttr = factory.createAttribute();
enclaveAttr.setAttrName("enclave");
node.getAttributes().add(enclaveAttr);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ public String generateNetworkSenderBody(
String commonArgs =
String.join(
", ",
"self->base.environment",
additionalDelayString,
messageType,
receivingPortID + "",
Expand Down Expand Up @@ -446,7 +447,8 @@ public String generateNetworkInputControlReactionBody(
result.pr("max_STP = " + CTypes.getInstance().getTargetTimeExpr(maxSTP) + ";");
}
result.pr("// Wait until the port status is known");
result.pr("wait_until_port_status_known(" + receivingPortID + ", max_STP);");
result.pr(
"wait_until_port_status_known(self->base.environment, " + receivingPortID + ", max_STP);");
return result.toString();
}

Expand Down Expand Up @@ -484,6 +486,7 @@ public String generateNetworkOutputControlReactionBody(
"if (" + sendRef + " == NULL || !" + sendRef + "->is_present) {",
" // The output port is NULL or it is not present.",
" send_port_absent_to_federate("
+ "self->base.environment, "
+ additionalDelayString
+ ", "
+ receivingPortID
Expand Down Expand Up @@ -620,7 +623,7 @@ private String generateExecutablePreamble(
code.pr(CExtensionUtils.allocateTriggersForFederate(federate));

return """
void _lf_executable_preamble() {
void _lf_executable_preamble(environment_t* env) {
%s
}
"""
Expand All @@ -641,7 +644,7 @@ private String generateCodeToInitializeFederate(FederateInstance federate, RtiCo
"\n",
"// Initialize the socket mutex",
"lf_mutex_init(&outbound_socket_mutex);",
"lf_cond_init(&port_status_changed, &mutex);"));
"lf_cond_init(&port_status_changed, &env->mutex);"));

// Find the STA (A.K.A. the global STP offset) for this federate.
if (federate.targetConfig.coordination == CoordinationType.DECENTRALIZED) {
Expand Down Expand Up @@ -746,7 +749,7 @@ private String generateCodeToInitializeFederate(FederateInstance federate, RtiCo
"// physical connections. The thread will live until all connections",
"// have been established.",
"lf_thread_create(&_fed.inbound_p2p_handling_thread_id,"
+ " handle_p2p_connections_from_federates, NULL);"));
+ " handle_p2p_connections_from_federates, env);"));
}

for (FederateInstance remoteFederate : federate.outboundP2PConnections) {
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/org/lflang/generator/EnclaveInfo.java
erlingrj marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.lflang.generator;

public class EnclaveInfo {
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
public int numIsPresentFields = 0;
public int numStartupReactions = 0;
public int numShutdownReactions = 0;
public int numTimerTriggers = 0;
public int numResetReactions = 0;
public int numWorkers = 1;
public int numModalReactors = 0;
public int numModalResetStates = 0;

public String traceFileName = null;
private ReactorInstance instance;

public EnclaveInfo(ReactorInstance inst) {
instance = inst;
}
}
10 changes: 10 additions & 0 deletions core/src/main/java/org/lflang/generator/ReactorInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package org.lflang.generator;

import static org.lflang.AttributeUtils.isEnclave;
import static org.lflang.ast.ASTUtils.getLiteralTimeValue;

import java.util.ArrayList;
Expand Down Expand Up @@ -171,6 +172,8 @@ public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter re
/** Indicator that this reactor has itself as a parent, an error condition. */
public final boolean recursive;

// An enclave object if this ReactorInstance is an enclave. null if not
public EnclaveInfo enclaveInfo = null;
public TypeParameterizedReactor tpr;

//////////////////////////////////////////////////////
Expand Down Expand Up @@ -813,6 +816,13 @@ public ReactorInstance(
? new TypeParameterizedReactor(definition, reactors)
: new TypeParameterizedReactor(definition, parent.tpr);

// If this instance is an enclave (or the main reactor). Create an
// enclaveInfo object to track information about the enclave needed for
// later code-generation
if (isEnclave(definition) || this.isMainOrFederated()) {
enclaveInfo = new EnclaveInfo(this);
}

// check for recursive instantiation
var currentParent = parent;
var foundSelfAsParent = false;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/lflang/generator/c/CCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public LFCommand buildWestFlashCommand() {
Path buildPath = fileConfig.getSrcGenPath().resolve("build");
String board = targetConfig.platformOptions.board;
LFCommand cmd;
if (board == null || board.startsWith("qemu")) {
if (board == null || board.startsWith("qemu") || board.equals("native_posix")) {
cmd = commandFactory.createCommand("west", List.of("build", "-t", "run"), buildPath);
} else {
cmd = commandFactory.createCommand("west", List.of("flash"), buildPath);
Expand Down
erlingrj marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package org.lflang.generator.c;

import java.util.ArrayList;
import java.util.List;
import org.lflang.TargetConfig;
import org.lflang.generator.CodeBuilder;
import org.lflang.generator.ReactorInstance;

/**
* This class is in charge of code generating functions and global variables related to the
* environments
*/
public class CEnvironmentFunctionGenerator {

/**
* @param main The top-level reactor instance of the program
* @param targetConfig The target config of the program
* @param lfModuleName The lfModuleName of the program
*/
public CEnvironmentFunctionGenerator(
ReactorInstance main, TargetConfig targetConfig, String lfModuleName) {
this.enclaves = CUtil.getEnclaves(main);
this.targetConfig = targetConfig;
this.lfModuleName = lfModuleName;
}

public String generateDeclarations() {
CodeBuilder code = new CodeBuilder();
code.pr(generateEnvironmentEnum());
code.pr(generateEnvironmentArray());
return code.toString();
}

public String generateDefinitions() {
CodeBuilder code = new CodeBuilder();
code.pr(generateCreateEnvironments());
code.pr(generateGetEnvironments());
return code.toString();
}

private List<ReactorInstance> enclaves = new ArrayList<>();
private TargetConfig targetConfig;
private String lfModuleName;

private String generateEnvironmentArray() {
return String.join(
"\n",
"// The global array of environments associated with each enclave",
"environment_t envs[_num_enclaves];");
}

private String generateGetEnvironments() {
return String.join(
"\n",
"// Update the pointer argument to point to the beginning of the environment array",
"// and return the size of that array",
erlingrj marked this conversation as resolved.
Show resolved Hide resolved
"int _lf_get_environments(environment_t ** return_envs) {",
" (*return_envs) = (environment_t *) envs;",
" return _num_enclaves;",
"}");
}

private String generateEnvironmentEnum() {
CodeBuilder code = new CodeBuilder();
code.pr("typedef enum {");
code.indent();
for (ReactorInstance enclave : enclaves) {
code.pr(CUtil.getEnvironmentId(enclave) + ",");
}
code.pr("_num_enclaves");
code.unindent();
code.pr("} _enclave_id;");

return code.toString();
}

private String generateCreateEnvironments() {
CodeBuilder code = new CodeBuilder();
code.pr("// 'Create' and initialize the environments in the program");
code.pr("void _lf_create_environments() {");
code.indent();
for (ReactorInstance enclave : enclaves) {
// Decide the number of workers to use. If this is the top-level
// use the global variable _lf_number_of_workers which accounts for federation etc.
String numWorkers = String.valueOf(enclave.enclaveInfo.numWorkers);
if (enclave.isMainOrFederated()) {
numWorkers = "_lf_number_of_workers";
}

// Figure out the name of the trace file
String traceFileName = "NULL";
if (targetConfig.tracing != null) {
if (targetConfig.tracing.traceFileName != null) {
if (enclave.isMainOrFederated()) {
traceFileName = "\"" + targetConfig.tracing.traceFileName + ".lft\"";
} else {
traceFileName =
"\"" + targetConfig.tracing.traceFileName + enclave.getName() + ".lft\"";
}
} else {
if (enclave.isMainOrFederated()) {
traceFileName = "\"" + lfModuleName + ".lft\"";
} else {
traceFileName = "\"" + lfModuleName + enclave.getName() + ".lft\"";
}
}
}

code.pr(
"environment_init(&"
+ CUtil.getEnvironmentStruct(enclave)
+ ","
+ CUtil.getEnvironmentId(enclave)
+ ","
+ numWorkers
+ ","
+ enclave.enclaveInfo.numTimerTriggers
+ ","
+ enclave.enclaveInfo.numStartupReactions
+ ","
+ enclave.enclaveInfo.numShutdownReactions
+ ","
+ enclave.enclaveInfo.numResetReactions
+ ","
+ enclave.enclaveInfo.numIsPresentFields
+ ","
+ enclave.enclaveInfo.numModalReactors
+ ","
+ enclave.enclaveInfo.numModalResetStates
+ ","
+ traceFileName
+ ");");
}
code.unindent();
code.pr("}");
return code.toString();
}
}
Loading