/
GraphvizDump.tpl
211 lines (187 loc) · 7.62 KB
/
GraphvizDump.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package GraphvizDump
import interface GraphvizDumpTV;
import CodegenUtil.*;
template dumpBackendDAE(BackendDAE.BackendDAE backendDAE, String suffix)
::=
match backendDAE
case dae as BackendDAE.DAE(eqs=eqs, shared=BackendDAE.SHARED(info=info as BackendDAE.EXTRA_INFO(__))) then
let _ = textFile(dumpDependence(dae, suffix), '<%info.fileNamePrefix%>_<%suffix%>_dependence.dot')
let _ = textFile(dumpMatching(dae, suffix), '<%info.fileNamePrefix%>_<%suffix%>_matching.dot')
//let _ = textFile(dumpSorting(dae, suffix), '<%info.fileNamePrefix%>_<%suffix%>_sorting.dot')
//this top-level template always returns an empty result
//since generated texts are written to files directly
''
end match
end dumpBackendDAE;
template dumpDependence(BackendDAE.BackendDAE backendDAE, String suffix)
::=
match backendDAE
case dae as BackendDAE.DAE(eqs=eqs, shared=BackendDAE.SHARED(info=info as BackendDAE.EXTRA_INFO(__))) then
let systems = (eqs |> eqSystem as BackendDAE.EQSYSTEM(__) hasindex clusterID fromindex 1 =>
let varDeclaration = (BackendVariable.varList(eqSystem.orderedVars) |> var as BackendDAE.VAR(__) hasindex varID fromindex 1 =>
if isStateVar(var) then
'var<%clusterID%>_<%varID%> [label="der(<%crefStr(var.varName)%>)", shape="box"]'
else
'var<%clusterID%>_<%varID%> [label="<%crefStr(var.varName)%>", shape="box"]'
;separator="\n")
let eqDeclaration = (BackendEquation.equationList(eqSystem.orderedEqs) |> eq hasindex eqID fromindex 1 =>
'eq<%clusterID%>_<%eqID%> [label="<%BackendDump.equationString(eq)%>", shape="box"]'
;separator="\n")
<<
subgraph cluster_<%clusterID%> {
label = "system #<%clusterID%>";
color=white
<%varDeclaration%>
<%eqDeclaration%>
<%dumpDependence2(clusterID, eqSystem.m)%>
}
>>
;separator="\n\n")
<<
digraph G {
label="<%info.fileNamePrefix%> [<%suffix%> - dependence]";
rankdir=LR;
<%systems%>
}
>>
end dumpDependence;
template dumpDependence2(Integer clusterID, Option<BackendDAE.IncidenceMatrix> m)
::=
match m
case SOME(incMatrix) then
let incNodes = (arrayList(incMatrix) |> varList hasindex eqID fromindex 1 =>
let foo = (varList |> varID =>
if intGt(varID, 0) then
'var<%clusterID%>_<%varID%> -> eq<%clusterID%>_<%eqID%> [style="dashed", arrowhead="none"];'
;separator="\n")
'<%foo%>'
;separator="\n")
'<%incNodes%>'
else
'// no incidence matrix'
end dumpDependence2;
template dumpMatching(BackendDAE.BackendDAE backendDAE, String suffix)
::=
match backendDAE
case dae as BackendDAE.DAE(eqs=eqs, shared=BackendDAE.SHARED(info=info as BackendDAE.EXTRA_INFO(__))) then
let systems = (eqs |> eqSystem as BackendDAE.EQSYSTEM(__) hasindex clusterID fromindex 1 =>
let varDeclaration = (BackendVariable.varList(eqSystem.orderedVars) |> var as BackendDAE.VAR(__) hasindex varID fromindex 1 =>
if isStateVar(var) then
'var<%clusterID%>_<%varID%> [label="der(<%crefStr(var.varName)%>)", shape="box"]'
else
'var<%clusterID%>_<%varID%> [label="<%crefStr(var.varName)%>", shape="box"]'
;separator="\n")
let eqDeclaration = (BackendEquation.equationList(eqSystem.orderedEqs) |> eq hasindex eqID fromindex 1 =>
<<
eq<%clusterID%>_<%eqID%> [label="<%BackendDump.equationString(eq)%>", shape="box"]
>>
;separator="\n")
<<
subgraph cluster_<%clusterID%> {
label = "system #<%clusterID%>";
color=white
<%varDeclaration%>
<%eqDeclaration%>
<%connections(clusterID, eqSystem.matching, eqSystem.m)%>
}
>>
;separator="\n\n")
<<
digraph G {
label="<%info.fileNamePrefix%> [<%suffix%> - matching]";
rankdir=LR;
<%systems%>
}
>>
end dumpMatching;
template connections(Integer clusterID, BackendDAE.Matching matching, Option<BackendDAE.IncidenceMatrix> m)
::=
match m
case SOME(incMatrix) then
match matching
case matching as BackendDAE.MATCHING(ass2=ass2) then
let incNodes = (arrayList(incMatrix) |> varList hasindex eqID fromindex 1 =>
let foo = (varList |> varID =>
if intEq(listGet(arrayList(ass2), eqID), varID) then
'var<%clusterID%>_<%varID%> -> eq<%clusterID%>_<%eqID%> [style="bold", arrowhead="none"];'
else
if intGt(varID, 0) then
'var<%clusterID%>_<%varID%> -> eq<%clusterID%>_<%eqID%> [style="dashed", arrowhead="none"];'
;separator="\n")
'<%foo%>'
;separator="\n")
'<%incNodes%>'
else
let incNodes = (arrayList(incMatrix) |> varList hasindex eqID fromindex 1 =>
let foo = (varList |> varID =>
if intGt(varID, 0) then
'var<%clusterID%>_<%varID%> -> eq<%clusterID%>_<%eqID%> [style="dashed", arrowhead="none"];'
;separator="\n")
'<%foo%>'
;separator="\n")
<<
// no matching
<%incNodes%>
>>
else
match matching
case matching as BackendDAE.MATCHING(ass2=ass2) then
let matchedNodes = (arrayList(ass2) |> varID hasindex eqID fromindex 1 =>
if intGt(varID, 0) then
'var<%clusterID%>_<%varID%> -> eq<%clusterID%>_<%eqID%> [style="bold", arrowhead="none"];'
;separator="\n")
<<
// no incidence matrix
<%matchedNodes%>
>>
else
<<
// no incidence matrix
// no matching
>>
end connections;
template dumpSorting(BackendDAE.BackendDAE backendDAE, String suffix)
::=
match backendDAE
case dae as BackendDAE.DAE(eqs=eqs, shared=BackendDAE.SHARED(info=info as BackendDAE.EXTRA_INFO(__))) then
let systems = (eqs |> eqSystem as BackendDAE.EQSYSTEM(__) hasindex clusterID fromindex 1 =>
let varDeclaration = (BackendVariable.varList(eqSystem.orderedVars) |> var as BackendDAE.VAR(__) hasindex varID fromindex 1 =>
'var<%clusterID%>_<%varID%> [label="<%crefStr(var.varName)%>", shape="box"]'
;separator="\n")
let eqDeclaration = (BackendEquation.equationList(eqSystem.orderedEqs) |> eq hasindex eqID fromindex 1 =>
'eq<%clusterID%>_<%eqID%> [label="<%BackendDump.equationString(eq)%>", shape="box"]'
;separator="\n")
<<
subgraph cluster_<%clusterID%> {
label = "system #<%clusterID%>";
color=white
<%varDeclaration%>
<%dumpStrongComponent(clusterID, eqSystem.matching)%>
}
>>
;separator="\n\n")
<<
digraph G {
label="<%info.fileNamePrefix%> [<%suffix%> - sorting]";
rankdir=LR;
<%systems%>
}
>>
end dumpSorting;
template dumpStrongComponent(Integer clusterID, BackendDAE.Matching matching)
::=
match matching
case matching as BackendDAE.MATCHING(comps=comps) then
let cmpNodes = (comps |> comp hasindex eqID fromindex 1 =>
match comp
case c as SINGLEEQUATION(__) then
'var<%clusterID%>_<%c.var%>'
case c as EQUATIONSYSTEM(__) then
let foo = (c.vars |> v => 'var<%clusterID%>_<%v%>' ;separator=" <-> ")
'<%foo%>'
else
'asd'
;separator=" -> ")
'<%cmpNodes%>'
end dumpStrongComponent;
end GraphvizDump;