|
| 1 | +/* |
| 2 | + * generated by Xtext 2.19.0 |
| 3 | + */ |
| 4 | +package info.computationalmodeling.lang.generator |
| 5 | + |
| 6 | +import org.eclipse.emf.ecore.resource.Resource |
| 7 | +import org.eclipse.xtext.generator.AbstractGenerator |
| 8 | +import org.eclipse.xtext.generator.IFileSystemAccess2 |
| 9 | +import org.eclipse.xtext.generator.IGeneratorContext |
| 10 | +import com.google.inject.Inject |
| 11 | +import org.eclipse.xtext.naming.IQualifiedNameProvider |
| 12 | +import info.computationalmodeling.lang.dataflow.DataflowModel |
| 13 | +import info.computationalmodeling.lang.dataflow.Edge |
| 14 | +import info.computationalmodeling.lang.DataflowSupport |
| 15 | + |
| 16 | +/** |
| 17 | + * Generates code from your model files on save. |
| 18 | + * |
| 19 | + * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation |
| 20 | + */ |
| 21 | +class DataflowGeneratorGraphviz extends AbstractGenerator { |
| 22 | + |
| 23 | + |
| 24 | + @Inject extension IQualifiedNameProvider |
| 25 | + |
| 26 | + override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { |
| 27 | + |
| 28 | + |
| 29 | + for (m : resource.allContents.toIterable.filter(DataflowModel)) { |
| 30 | + var ds = new DataflowSupport() |
| 31 | + ds.getChannelNames(m) |
| 32 | + ds.extractActorProperties(m) |
| 33 | + ds.extractInputOutputNames(m) |
| 34 | + ds.extractChannelProperties(m) |
| 35 | + ds.determinePortNames(m) |
| 36 | + fsa.generateFile( |
| 37 | + m.fullyQualifiedName.toString("/") + ".dot", |
| 38 | + m.compile(ds) |
| 39 | + ) |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + def compile(DataflowModel m, DataflowSupport ds) ''' |
| 44 | + digraph «m.name» { |
| 45 | + rankdir="LR"; |
| 46 | + graph [bgcolor=transparent,overlap=false] |
| 47 | + node [fontsize=20 fontname="Calibri" fillcolor="#FDF498" width=0.6 penwidth=2 style=filled shape=circle] |
| 48 | + edge [fontsize=16 fontname="Calibri"] |
| 49 | + «this.compileActors(m, ds)» |
| 50 | + «this.compileInputs(m, ds)» |
| 51 | + «this.compileOutputs(m, ds)» |
| 52 | + «this.compileGraph(m, ds)» |
| 53 | + } |
| 54 | + ''' |
| 55 | +
|
| 56 | + def compileActors(DataflowModel m, DataflowSupport ds) ''' |
| 57 | + «FOR a: ds.setOfActors(m)» |
| 58 | + «a» [label="«a»\n«ds.getExecutionTime(a)»"] |
| 59 | + «ENDFOR» |
| 60 | + |
| 61 | + ''' |
| 62 | +
|
| 63 | + def compileInputs(DataflowModel m, DataflowSupport ds) ''' |
| 64 | + «FOR i:m.inputs» |
| 65 | + «i.name» [shape=point, label="«i.name»", fillcolor="#000000" width=0.05 style=filled] |
| 66 | + «ENDFOR» |
| 67 | + |
| 68 | + ''' |
| 69 | +
|
| 70 | + def compileOutputs(DataflowModel m, DataflowSupport ds) ''' |
| 71 | + «FOR o:m.outputs» |
| 72 | + «o.name» [shape=point, label="«o.name»", fillcolor="#000000" width=0.05 style=filled] |
| 73 | + «ENDFOR» |
| 74 | + |
| 75 | + ''' |
| 76 | +
|
| 77 | + def compileGraph(DataflowModel m, DataflowSupport ds) ''' |
| 78 | + «FOR e:m.edges» |
| 79 | + «this.compileEdge(m, e, ds)» |
| 80 | + «ENDFOR» |
| 81 | + |
| 82 | + ''' |
| 83 | +
|
| 84 | + def String prodLabel(Edge e) { |
| 85 | + } |
| 86 | +
|
| 87 | + def compileInputEdge(Edge e, DataflowSupport ds) ''' |
| 88 | + «e.srcact.name» -> «e.dstact.name» [minlen=1 len=1 xlabel="" headlabel="" taillabel="«e.srcact.name»"] |
| 89 | + ''' |
| 90 | +
|
| 91 | + def compileOutputEdge(Edge e, DataflowSupport ds) ''' |
| 92 | + «e.srcact.name» -> «e.dstact.name» [minlen=1 len=1 xlabel="" headlabel="«e.dstact.name»" taillabel=""] |
| 93 | + ''' |
| 94 | +
|
| 95 | + def compileRegularEdge(Edge e, DataflowSupport ds) ''' |
| 96 | + «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»"] |
| 97 | + ''' |
| 98 | +
|
| 99 | +
|
| 100 | + def compileEdge(DataflowModel m, Edge e, DataflowSupport ds) ''' |
| 101 | + «IF ds.inputNames.contains(e.srcact.name)» |
| 102 | + «compileInputEdge(e, ds)» |
| 103 | + «ELSE» |
| 104 | + «IF ds.outputNames.contains(e.dstact.name)» |
| 105 | + «compileOutputEdge(e, ds)» |
| 106 | + «ELSE» |
| 107 | + «compileRegularEdge(e, ds)» |
| 108 | + «ENDIF» |
| 109 | + «ENDIF» |
| 110 | + ''' |
| 111 | +} |
0 commit comments