-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,164 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
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
111 changes: 111 additions & 0 deletions
111
...g/src/main/java/info/computationalmodeling/lang/generator/DataflowGeneratorGraphviz.xtend
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,111 @@ | ||
/* | ||
* generated by Xtext 2.19.0 | ||
*/ | ||
package info.computationalmodeling.lang.generator | ||
|
||
import org.eclipse.emf.ecore.resource.Resource | ||
import org.eclipse.xtext.generator.AbstractGenerator | ||
import org.eclipse.xtext.generator.IFileSystemAccess2 | ||
import org.eclipse.xtext.generator.IGeneratorContext | ||
import com.google.inject.Inject | ||
import org.eclipse.xtext.naming.IQualifiedNameProvider | ||
import info.computationalmodeling.lang.dataflow.DataflowModel | ||
import info.computationalmodeling.lang.dataflow.Edge | ||
import info.computationalmodeling.lang.DataflowSupport | ||
|
||
/** | ||
* Generates code from your model files on save. | ||
* | ||
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation | ||
*/ | ||
class DataflowGeneratorGraphviz extends AbstractGenerator { | ||
|
||
|
||
@Inject extension IQualifiedNameProvider | ||
|
||
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { | ||
|
||
|
||
for (m : resource.allContents.toIterable.filter(DataflowModel)) { | ||
var ds = new DataflowSupport() | ||
ds.getChannelNames(m) | ||
ds.extractActorProperties(m) | ||
ds.extractInputOutputNames(m) | ||
ds.extractChannelProperties(m) | ||
ds.determinePortNames(m) | ||
fsa.generateFile( | ||
m.fullyQualifiedName.toString("/") + ".dot", | ||
m.compile(ds) | ||
) | ||
} | ||
} | ||
|
||
def compile(DataflowModel m, DataflowSupport ds) ''' | ||
digraph «m.name» { | ||
rankdir="LR"; | ||
graph [bgcolor=transparent,overlap=false] | ||
node [fontsize=20 fontname="Calibri" fillcolor="#FDF498" width=0.6 penwidth=2 style=filled shape=circle] | ||
edge [fontsize=16 fontname="Calibri"] | ||
«this.compileActors(m, ds)» | ||
«this.compileInputs(m, ds)» | ||
«this.compileOutputs(m, ds)» | ||
«this.compileGraph(m, ds)» | ||
} | ||
''' | ||
def compileActors(DataflowModel m, DataflowSupport ds) ''' | ||
«FOR a: ds.setOfActors(m)» | ||
«a» [label="«a»\n«ds.getExecutionTime(a)»"] | ||
«ENDFOR» | ||
|
||
''' | ||
def compileInputs(DataflowModel m, DataflowSupport ds) ''' | ||
«FOR i:m.inputs» | ||
«i.name» [shape=point, label="«i.name»", fillcolor="#000000" width=0.05 style=filled] | ||
«ENDFOR» | ||
|
||
''' | ||
def compileOutputs(DataflowModel m, DataflowSupport ds) ''' | ||
«FOR o:m.outputs» | ||
«o.name» [shape=point, label="«o.name»", fillcolor="#000000" width=0.05 style=filled] | ||
«ENDFOR» | ||
|
||
''' | ||
def compileGraph(DataflowModel m, DataflowSupport ds) ''' | ||
«FOR e:m.edges» | ||
«this.compileEdge(m, e, ds)» | ||
«ENDFOR» | ||
|
||
''' | ||
def String prodLabel(Edge e) { | ||
} | ||
def compileInputEdge(Edge e, DataflowSupport ds) ''' | ||
«e.srcact.name» -> «e.dstact.name» [minlen=1 len=1 xlabel="" headlabel="" taillabel="«e.srcact.name»"] | ||
''' | ||
def compileOutputEdge(Edge e, DataflowSupport ds) ''' | ||
«e.srcact.name» -> «e.dstact.name» [minlen=1 len=1 xlabel="" headlabel="«e.dstact.name»" taillabel=""] | ||
''' | ||
def compileRegularEdge(Edge e, DataflowSupport ds) ''' | ||
«e.srcact.name» -> «e.dstact.name» [minlen=3 len=3 xlabel="«ds.getInitialTokens(e).toString»" headlabel="«ds.getConsRate(e).toString»" taillabel="«ds.getProdRate(e).toString»"] | ||
''' | ||
def compileEdge(DataflowModel m, Edge e, DataflowSupport ds) ''' | ||
«IF ds.inputNames.contains(e.srcact.name)» | ||
«compileInputEdge(e, ds)» | ||
«ELSE» | ||
«IF ds.outputNames.contains(e.dstact.name)» | ||
«compileOutputEdge(e, ds)» | ||
«ELSE» | ||
«compileRegularEdge(e, ds)» | ||
«ENDIF» | ||
«ENDIF» | ||
''' | ||
} |
103 changes: 103 additions & 0 deletions
103
....lang/src/main/java/info/computationalmodeling/lang/generator/DataflowGeneratorSDF3.xtend
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,103 @@ | ||
/* | ||
* generated by Xtext 2.19.0 | ||
*/ | ||
package info.computationalmodeling.lang.generator | ||
|
||
import org.eclipse.emf.ecore.resource.Resource | ||
import org.eclipse.xtext.generator.AbstractGenerator | ||
import org.eclipse.xtext.generator.IFileSystemAccess2 | ||
import org.eclipse.xtext.generator.IGeneratorContext | ||
import com.google.inject.Inject | ||
import org.eclipse.xtext.naming.IQualifiedNameProvider | ||
import info.computationalmodeling.lang.dataflow.DataflowModel | ||
import info.computationalmodeling.lang.DataflowSupport | ||
import java.util.Map | ||
|
||
/** | ||
* Generates code from your model files on save. | ||
* | ||
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation | ||
*/ | ||
class DataflowGeneratorSDF3 extends AbstractGenerator { | ||
|
||
|
||
@Inject extension IQualifiedNameProvider | ||
|
||
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { | ||
|
||
|
||
for (m : resource.allContents.toIterable.filter(DataflowModel)) { | ||
var ds = new DataflowSupport() | ||
ds.getChannelNames(m) | ||
ds.extractActorProperties(m) | ||
ds.extractChannelProperties(m) | ||
ds.determinePortNames(m) | ||
fsa.generateFile( | ||
m.fullyQualifiedName.toString("/") + ".sdfx", | ||
m.compile(ds)) | ||
} | ||
} | ||
|
||
|
||
|
||
// Below the code generation methods | ||
|
||
def compile(DataflowModel m, DataflowSupport ds) ''' | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<sdf3 xsi:noNamespaceSchemaLocation="http://www.es.ele.tue.nl/sdf3/xsd/sdf3-sdf.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" type="sdf"> | ||
<applicationGraph name="«m.name»"> | ||
<sdf name="«m.name»" type="«m.name»"> | ||
«this.compileActorlist(m, ds)» | ||
«this.compileChannellist(m, ds)» | ||
</sdf> | ||
<sdfProperties> | ||
«this.compileActorProperties(m, ds)» | ||
«this.compileChannelProperties(m, ds)» | ||
</sdfProperties> | ||
</applicationGraph> | ||
</sdf3> | ||
''' | ||
|
||
|
||
def compileActorlist(DataflowModel m, DataflowSupport ds) ''' | ||
«FOR a: ds.setOfActors(m)» | ||
<actor name="«a»" type="«a»"> | ||
«this.compilePortsOfActor(a, ds)» | ||
</actor> | ||
«ENDFOR» | ||
''' | ||
|
||
def compilePortsOfActor(String a, DataflowSupport ds) ''' | ||
«FOR p: ds.getPortsOfActor(a).entrySet» | ||
«this.compilePort(p)» | ||
«ENDFOR» | ||
''' | ||
|
||
def compilePort(Map.Entry<String,Pair<Integer,String>> p) ''' | ||
<port type="«p.getValue().getValue()»" name="«p.getKey()»" rate="«p.getValue().getKey()»"/> | ||
''' | ||
|
||
def compileChannellist(DataflowModel m, DataflowSupport ds) ''' | ||
«FOR e: m.edges» | ||
<channel name="«ds.channelNames.get(e)»" dstPort="«ds.getDstPortName(e)»" dstActor="«e.dstact.name»" srcPort="«ds.getSrcPortName(e)»" srcActor="«e.srcact.name»" initialTokens="«ds.channelProperties.get(ds.channelNames.get(e)).get("initialtokens")»"/> | ||
«ENDFOR» | ||
''' | ||
|
||
def compileActorProperties(DataflowModel m, DataflowSupport ds)''' | ||
«FOR a: ds.setOfActors(m)» | ||
<actorProperties actor="«a»"> | ||
<processor type="p1" default="true"> | ||
<executionTime time="«ds.getExecutionTime(a).toString()»"/> | ||
</processor> | ||
</actorProperties> | ||
«ENDFOR» | ||
''' | ||
|
||
def compileChannelProperties(DataflowModel m, DataflowSupport ds)''' | ||
«FOR e: m.edges» | ||
<channelProperties channel="«ds.channelNames.get(e)»"/> | ||
«ENDFOR» | ||
''' | ||
|
||
|
||
} |
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
Oops, something went wrong.