Skip to content

Commit

Permalink
WIP. Might abandon this effort altogether in favor of an LFGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
lhstrh authored and petervdonovan committed Jun 13, 2022
1 parent 90d719e commit f8e9096
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 6 additions & 2 deletions org.lflang/src/org/lflang/federated/FedFileConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ public FedFileConfig(FileConfig fileConfig) throws IOException {
}

/**
* FIXME
* @return
* Return the path to the root of a LF project generated on the basis of a
* federated LF program currently under compilation.
*/
public Path getFedGenPath() {
return srcPkgPath.resolve("fed-gen").resolve(this.name);
}

/**
* Return the path for storing generated LF sources that jointly constitute a
* federation.
*/
Path getFedSrcPath() {
return getFedGenPath().resolve("src");
}
Expand Down
15 changes: 14 additions & 1 deletion org.lflang/src/org/lflang/federated/FedGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.lflang.ErrorReporter;
import org.lflang.generator.LFGeneratorContext;
import org.lflang.lf.Instantiation;
import org.lflang.lf.LfFactory;
import org.lflang.lf.Reactor;

public class FedGenerator {
Expand All @@ -23,6 +24,13 @@ public FedGenerator(FedFileConfig fileConfig, ErrorReporter errorReporter) {
}
public boolean doGenerate(Resource resource, LFGeneratorContext context) throws IOException {
Reactor fedReactor = FedASTUtils.findFederatedReactor(resource);

// Create proxies for all instances.
for (Instantiation fedInstantiation : fedReactor.getInstantiations()) {
// this.proxies.add ...
}

// Generate code for each federate
for (Instantiation fedInstantiation : fedReactor.getInstantiations()) {
generateFederate(fedInstantiation);
}
Expand All @@ -43,8 +51,13 @@ private void generateFederate(Instantiation fed) throws IOException {

// FIXME: Do magic...

// Create import statements for definition of class that fed is an instance of.

// Go through all instances and

try (var srcWriter = Files.newBufferedWriter(lfFilePath)) {
srcWriter.write(NodeModelUtils.getNode(fed.eContainer()).getText());
srcWriter.write(NodeModelUtils.getNode(LfFactory.eINSTANCE.createReactor()).getText());
//srcWriter.write(NodeModelUtils.getNode(fed.eContainer()).getText());
}

}
Expand Down

0 comments on commit f8e9096

Please sign in to comment.