Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 0 / 37
Functions: -% 0 / 1 / 1
Branches: 0.0% 0 / 0 / 2

OMCompiler/Compiler/FFrontEnd/FInst.mo
Line Branch Exec Source
1 /*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36 encapsulated package FInst
37 " file: FInst.mo
38 package: FInst
39 description: Graph based instantiation
40
41
42 "
43
44 // public imports
45 public
46 import Absyn;
47 import AbsynUtil;
48 import SCode;
49 import DAE;
50 import FCore;
51
52 protected
53 import ClockIndexes;
54 import FBuiltin;
55 import FGraph;
56 import FExpand;
57 import FGraphBuild;
58 import FGraphDump;
59 import System;
60 import InstUtil;
61 import Flags;
62 import List;
63 import FNode;
64
65 public
66 type Name = FCore.Name;
67 type Id = FCore.Id;
68 type Seq = FCore.Seq;
69 type Next = FCore.Next;
70 type Node = FCore.Node;
71 type Data = FCore.Data;
72 type Kind = FCore.Kind;
73 type Ref = FCore.Ref;
74 type Refs = FCore.Refs;
75 type Children = FCore.Children;
76 type Parents = FCore.Parents;
77 type ImportTable = FCore.ImportTable;
78 type Graph = FCore.Graph;
79 type Extra = FCore.Extra;
80 type Visited = FCore.Visited;
81 type Import = FCore.Import;
82
83 type Msg = Option<SourceInfo>;
84
85
86 public function inst
87 "@author: adrpo
88 instantiate an entire program"
89 input Absyn.Path inPath;
90 input SCode.Program inProgram;
91 output DAE.DAElist dae;
92 algorithm
93 dae := matchcontinue inProgram
94 local
95 Graph g;
96 SCode.Program p;
97 list<Real> lst;
98
99 case _
100 algorithm
101 ✗ p := doSCodeDep(inProgram, inPath);
102
103 lst := {};
104
105 ✗ System.realtimeTick(ClockIndexes.RT_CLOCK_FINST);
106 ✗ (_, g) := FBuiltin.initialGraph(FCore.emptyCache());
107 ✗ g := FGraphBuild.mkProgramGraph(
108 p,
109 FCore.USERDEFINED(),
110 g);
111 ✗ lst := List.consr(lst, System.realtimeTock(ClockIndexes.RT_CLOCK_FINST));
112 ✗ print("SCode->FGraph: " + realString(listHead(lst)) + "\n");
113 //print("FGraph nodes: " + intString(listLength(FNode.dfs(FGraph.top(g)))) + "\n");
114 //print("FGraph refs: " + intString(listLength(FNode.dfs_filter(FGraph.top(g), FNode.isRefReference))) + "\n");
115
116 ✗ System.realtimeTick(ClockIndexes.RT_CLOCK_FINST);
117 // resolve all
118 ✗ g := FExpand.all(g);
119 ✗ lst := List.consr(lst, System.realtimeTock(ClockIndexes.RT_CLOCK_FINST));
120
121 //print("FGraph nodes: " + intString(listLength(FNode.dfs(FGraph.top(g)))) + "\n");
122 //print("FGraph refs: " + intString(listLength(FNode.dfs_filter(FGraph.top(g), FNode.isRefReference))) + "\n");
123 ✗ print("Total time: " + realString(List.fold(lst, realAdd, 0.0)) + "\n");
124
125 ✗ FGraphDump.dumpGraph(g, "F:\\dev\\" + AbsynUtil.pathString(inPath) + ".graph.graphml");
126
127 ✗ System.realtimeTick(ClockIndexes.RT_CLOCK_FINST);
128 ✗ FGraph.clone(g);
129 ✗ lst := List.consr(lst, System.realtimeTock(ClockIndexes.RT_CLOCK_FINST));
130 ✗ print("FGraph->clone: " + realString(listHead(lst)) + "\n");
131
132 // FGraphDump.dumpGraph(gclone, "F:\\dev\\" + AbsynUtil.pathString(inPath) + ".graph.clone.graphml");
133 then
134 DAE.emptyDae;
135
136 case _
137 algorithm
138 ✗ print("FInst.inst failed!\n");
139 then
140 DAE.emptyDae;
141
142 end matchcontinue;
143 end inst;
144
145 public function instPath
146 "@author: adrpo
147 instantiate path in program"
148 input Absyn.Path inPath;
149 input SCode.Program inProgram;
150 output DAE.DAElist dae;
151 algorithm
152 dae := matchcontinue inProgram
153 local
154 Graph g;
155 SCode.Program p;
156 list<Real> lst;
157
158 case _ then inst(inPath, inProgram);
159
160 case _
161 algorithm
162 lst := {};
163
164 ✗ System.realtimeTick(ClockIndexes.RT_CLOCK_FINST);
165 ✗ p := doSCodeDep(inProgram, inPath);
166 ✗ lst := List.consr(lst, System.realtimeTock(ClockIndexes.RT_CLOCK_FINST));
167 ✗ print("SCode depend: " + realString(listHead(lst)) + "\n");
168
169 ✗ System.realtimeTick(ClockIndexes.RT_CLOCK_FINST);
170 ✗ (_, g) := FBuiltin.initialGraph(FCore.emptyCache());
171 ✗ lst := List.consr(lst, System.realtimeTock(ClockIndexes.RT_CLOCK_FINST));
172 ✗ print("Initial graph: " + realString(listHead(lst)) + "\n");
173
174 ✗ System.realtimeTick(ClockIndexes.RT_CLOCK_FINST);
175 ✗ g := FGraphBuild.mkProgramGraph(
176 p,
177 FCore.USERDEFINED(),
178 g);
179 ✗ lst := List.consr(lst, System.realtimeTock(ClockIndexes.RT_CLOCK_FINST));
180 ✗ print("SCode->FGraph: " + realString(listHead(lst)) + "\n");
181
182 ✗ System.realtimeTick(ClockIndexes.RT_CLOCK_FINST);
183 // resolve all references on path
184 ✗ (g,_) := FExpand.path(g, inPath);
185 ✗ lst := List.consr(lst, System.realtimeTock(ClockIndexes.RT_CLOCK_FINST));
186 ✗ print("FExpand.path: " + realString(listHead(lst)) + "\n");
187
188 // print("FGraph nodes: " + intString(FGraph.lastId(g)) + "\n");
189 ✗ print("Total time: " + realString(List.fold(lst, realAdd, 0.0)) + "\n");
190
191 ✗ FGraphDump.dumpGraph(g, "F:\\dev\\" + AbsynUtil.pathString(inPath) + ".graph.graphml");
192 then
193 DAE.emptyDae;
194
195 case _
196 algorithm
197 ✗ print("FInst.inst failed!\n");
198 then
199 DAE.emptyDae;
200
201 end matchcontinue;
202 end instPath;
203
204 protected function doSCodeDep
205 "do or not do scode dependency based on a flag"
206 input SCode.Program inProgram;
207 input Absyn.Path inPath;
208 output SCode.Program outProgram;
209 algorithm
210 outProgram := matchcontinue inPath
211
212 case _
213 algorithm
214 ✗ true := Flags.isSet(Flags.GRAPH_INST_RUN_DEP);
215 ✗ outProgram := InstUtil.scodeFlatten(inProgram, inPath);
216 then
217 outProgram;
218
219 else inProgram;
220
221 end matchcontinue;
222 end doSCodeDep;
223
224 annotation(__OpenModelica_Interface="frontend");
225 end FInst;
226