/
SimCodeMain.mo
1534 lines (1384 loc) · 68.9 KB
/
SimCodeMain.mo
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
encapsulated package SimCodeMain
" file: SimCodeMain.mo
package: SimCodeMain
description: Code generation using Susan templates
The entry points to this module are the translateModel function and the
translateFunctions function."
// public imports
public
import Absyn;
import BackendDAE;
import BackendDAEUtil;
import Ceval;
import DAE;
import FCore;
import HashTableExpToIndex;
import Tpl;
import Values;
import SimCode;
// protected imports
protected
import Autoconf;
import AvlSetString;
import BackendDAECreate;
import BackendDump;
import BackendVariable;
import Builtin;
import ClockIndexes;
import CevalScriptBackend;
import CodegenC;
import CodegenEmbeddedC;
import CodegenFMU;
import CodegenFMUCppOld;
import CodegenOMSICpp;
import CodegenFMUCppHpcomOld;
import CodegenSparseFMI;
import CodegenCppOld;
import CodegenCppHpcomOld;
import CodegenOMSIC;
import CodegenOMSI_common;
import CodegenXML;
import CodegenJava;
import CodegenJS;
import Config;
import DAEMode;
import DAEUtil;
import Debug;
import DoubleEnded;
import Error;
import ErrorExt;
import ExecStat;
import Flags;
import FMI;
import GC;
import HashTable;
import HashTableCrefSimVar;
import HashTableCrIListArray;
import HashTableCrILst;
import HpcOmSimCodeMain;
import HpcOmTaskGraph;
import RuntimeSources;
import SerializeModelInfo;
import SerializeInitXML;
import SimCodeUtil;
import StackOverflow;
import StringUtil;
import SymbolicJacobian;
import SymbolTable;
import System;
import Testsuite;
import Util;
import SerializeTaskSystemInfo;
public
constant Boolean debug=true;
uniontype TranslateModelKind
record NORMAL
end NORMAL;
record XML
end XML;
record FMU
String kind;
String targetName;
end FMU;
end TranslateModelKind;
public function createSimulationSettings
input Real startTime;
input Real stopTime;
input Integer inumberOfIntervals;
input Real tolerance;
input String method;
input String options;
input String outputFormat;
input String variableFilter;
input String cflags;
output SimCode.SimulationSettings simSettings;
protected
Real stepSize;
Integer numberOfIntervals;
algorithm
numberOfIntervals := if inumberOfIntervals <= 0 then 1 else inumberOfIntervals;
stepSize := (stopTime - startTime) / intReal(numberOfIntervals);
simSettings := SimCode.SIMULATION_SETTINGS(
startTime, stopTime, numberOfIntervals, stepSize, tolerance,
method, options, outputFormat, variableFilter, cflags);
end createSimulationSettings;
protected function generateModelCodeFMU "
Generates code for a model by creating a SimCode structure and calling the
template-based code generator on it."
input BackendDAE.BackendDAE inBackendDAE;
input BackendDAE.BackendDAE inInitDAE;
input Option<BackendDAE.BackendDAE> inInitDAE_lambda0;
input BackendDAE.SymbolicJacobians inFMIDer;
input list<BackendDAE.Equation> inRemovedInitialEquationLst;
input Absyn.Program p;
input Absyn.Path className;
input String FMUVersion;
input String FMUType;
input String filenamePrefix;
input String fmuTargetName;
input Option<SimCode.SimulationSettings> simSettings;
output list<String> libs;
output String fileDir;
output Real timeSimCode;
output Real timeTemplates;
protected
list<String> includes,includeDirs;
list<SimCodeFunction.Function> functions;
String filename, funcfilename;
SimCode.SimCode simCode;
list<SimCodeFunction.RecordDeclaration> recordDecls;
BackendDAE.BackendDAE indexed_dlow,indexed_dlow_1;
Absyn.ComponentRef a_cref;
list<String> libPaths;
tuple<Integer,HashTableExpToIndex.HashTable,list<DAE.Exp>> literals;
algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE);
a_cref := AbsynUtil.pathToCref(className);
/*Temporary disabled omsicpp*/
if ((Config.simCodeTarget() == "omsic") /*or (Config.simCodeTarget() == "omsicpp")*/) then
fileDir := listHead(AbsynUtil.pathToStringList(className))+".tmp";
else
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
end if;
(libs,libPaths,includes, includeDirs, recordDecls, functions, literals) :=
SimCodeUtil.createFunctions(p, inBackendDAE.shared.functionTree);
simCode := createSimCode(inBackendDAE, inInitDAE, inInitDAE_lambda0, NONE(),
inRemovedInitialEquationLst, className, filenamePrefix, fileDir, functions,
includes, includeDirs, libs, libPaths, p, simSettings, recordDecls,
literals, Absyn.FUNCTIONARGS({},{}), isFMU=true, FMUVersion=FMUVersion,
fmuTargetName=fmuTargetName, inFMIDer=inFMIDer);
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
ExecStat.execStat("SimCode");
System.realtimeTick(ClockIndexes.RT_CLOCK_TEMPLATES);
/*Temporary disabled omsi fmu and generate C-fmu for omsicpp simcodetarget*/
if Config.simCodeTarget() == "omsicpp" then
callTargetTemplatesFMU(simCode, "C", FMUVersion, FMUType);
else
callTargetTemplatesFMU(simCode, Config.simCodeTarget(), FMUVersion, FMUType);
end if;
timeTemplates := System.realtimeTock(ClockIndexes.RT_CLOCK_TEMPLATES);
end generateModelCodeFMU;
protected function generateModelCodeXML "
Generates code for a model by creating a SimCode structure and calling the
template-based code generator on it."
input BackendDAE.BackendDAE inBackendDAE;
input BackendDAE.BackendDAE inInitDAE;
input Option<BackendDAE.BackendDAE> inInitDAE_lambda0;
input list<BackendDAE.Equation> inRemovedInitialEquationLst;
input Absyn.Program p;
input Absyn.Path className;
input String filenamePrefix;
input Option<SimCode.SimulationSettings> simSettingsOpt;
output list<String> libs;
output String fileDir;
output Real timeSimCode;
output Real timeTemplates;
protected
list<String> includes,includeDirs;
list<SimCodeFunction.Function> functions;
String filename, funcfilename;
SimCode.SimCode simCode;
list<SimCodeFunction.RecordDeclaration> recordDecls;
BackendDAE.BackendDAE indexed_dlow,indexed_dlow_1;
list<String> libPaths;
Absyn.ComponentRef a_cref;
tuple<Integer,HashTableExpToIndex.HashTable,list<DAE.Exp>> literals;
list<tuple<String, String>> program;
algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE);
a_cref := AbsynUtil.pathToCref(className);
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
(libs, libPaths, includes, includeDirs, recordDecls, functions, literals) :=
SimCodeUtil.createFunctions(p, inBackendDAE.shared.functionTree);
(simCode,_) := SimCodeUtil.createSimCode(inBackendDAE, inInitDAE, inInitDAE_lambda0, NONE(), inRemovedInitialEquationLst,
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, p, simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{}));
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
ExecStat.execStat("SimCode");
System.realtimeTick(ClockIndexes.RT_CLOCK_TEMPLATES);
callTargetTemplatesXML(simCode, Config.simCodeTarget());
timeTemplates := System.realtimeTock(ClockIndexes.RT_CLOCK_TEMPLATES);
end generateModelCodeXML;
public function generateModelCode "
Generates code for a model by creating a SimCode structure and calling the
template-based code generator on it."
input BackendDAE.BackendDAE inBackendDAE;
input BackendDAE.BackendDAE inInitDAE;
input Option<BackendDAE.BackendDAE> inInitDAE_lambda0;
input Option<BackendDAE.InlineData> inInlineData;
input list<BackendDAE.Equation> inRemovedInitialEquationLst;
input Absyn.Program p;
input Absyn.Path className;
input String filenamePrefix;
input Option<SimCode.SimulationSettings> simSettingsOpt;
input Absyn.FunctionArgs args;
input BackendDAE.SymbolicJacobians inFMIDer = {};
output list<String> libs;
output String fileDir;
output Real timeSimCode;
output Real timeTemplates;
protected
list<String> includes, includeDirs,libPaths;
list<SimCodeFunction.Function> functions;
SimCode.SimCode simCode;
list<SimCodeFunction.RecordDeclaration> recordDecls;
Absyn.ComponentRef a_cref;
tuple<Integer, HashTableExpToIndex.HashTable, list<DAE.Exp>> literals;
list<tuple<String, String>> program;
Integer numCheckpoints;
String fmuVersion;
algorithm
numCheckpoints:=ErrorExt.getNumCheckpoints();
try
StackOverflow.clearStacktraceMessages();
if Flags.isSet(Flags.GRAPHML) then
HpcOmTaskGraph.dumpTaskGraph(inBackendDAE, filenamePrefix);
BackendDump.dumpBackendDAEBipartiteGraph(inBackendDAE, "BipartiteGraph_CompleteDAE_"+filenamePrefix);
end if;
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE);
a_cref := AbsynUtil.pathToCref(className);
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
(libs, libPaths, includes, includeDirs, recordDecls, functions, literals) := SimCodeUtil.createFunctions(p, inBackendDAE.shared.functionTree);
/*Temporary disabled omsicpp
if Config.simCodeTarget() == "omsicpp" then
fmuVersion:="2.0";
simCode := createSimCode(inBackendDAE, inInitDAE, inInitDAE_lambda0, inInlineData, inRemovedInitialEquationLst, className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, p, simSettingsOpt, recordDecls, literals, args,isFMU=true, FMUVersion=fmuVersion,
fmuTargetName=listHead(AbsynUtil.pathToStringList(className)), inFMIDer=inFMIDer);
else*/
simCode := createSimCode(inBackendDAE, inInitDAE, inInitDAE_lambda0, inInlineData, inRemovedInitialEquationLst, className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, p, simSettingsOpt, recordDecls, literals, args,inFMIDer=inFMIDer);
/*end if;*/
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
ExecStat.execStat("SimCode");
if Flags.isSet(Flags.SERIALIZED_SIZE) then
serializeNotify(simCode, "SimCode");
ExecStat.execStat("Serialize simCode");
end if;
System.realtimeTick(ClockIndexes.RT_CLOCK_TEMPLATES);
callTargetTemplates(simCode, Config.simCodeTarget());
timeTemplates := System.realtimeTock(ClockIndexes.RT_CLOCK_TEMPLATES);
ExecStat.execStat("Templates");
return;
else
setGlobalRoot(Global.stackoverFlowIndex, NONE());
ErrorExt.rollbackNumCheckpoints(ErrorExt.getNumCheckpoints()-numCheckpoints);
Error.addInternalError("Stack overflow in "+getInstanceName()+"...\n"+stringDelimitList(StackOverflow.readableStacktraceMessages(), "\n"), sourceInfo());
/* Do not fail or we can loop too much */
StackOverflow.clearStacktraceMessages();
end try annotation(__OpenModelica_stackOverflowCheckpoint=true);
fail();
end generateModelCode;
protected function createSimCode "
SimCode generator switch - if the NUMPROC-Flag is set, the simcode will be extended with parallel informations."
input BackendDAE.BackendDAE inBackendDAE;
input BackendDAE.BackendDAE inInitDAE;
input Option<BackendDAE.BackendDAE> inInitDAE_lambda0;
input Option<BackendDAE.InlineData> inInlineData;
input list<BackendDAE.Equation> inRemovedInitialEquationLst;
input Absyn.Path inClassName;
input String filenamePrefix;
input String inString11;
input list<SimCodeFunction.Function> functions;
input list<String> externalFunctionIncludes;
input list<String> includeDirs;
input list<String> libs;
input list<String> libPaths;
input Absyn.Program program;
input Option<SimCode.SimulationSettings> simSettingsOpt;
input list<SimCodeFunction.RecordDeclaration> recordDecls;
input tuple<Integer, HashTableExpToIndex.HashTable, list<DAE.Exp>> literals;
input Absyn.FunctionArgs args;
input Boolean isFMU=false;
input String FMUVersion="";
input String fmuTargetName="";
input BackendDAE.SymbolicJacobians inFMIDer = {};
output SimCode.SimCode simCode;
algorithm
simCode := matchcontinue(inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths, program,simSettingsOpt, recordDecls, literals, args)
local
Integer numProc;
SimCode.SimCode tmpSimCode;
case(_, _, _, _, _, _, _, _, _, _,_, _, _, _) equation
// MULTI_RATE PARTITIONINIG
true = Flags.isSet(Flags.MULTIRATE_PARTITION);
then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inInitDAE_lambda0, inRemovedInitialEquationLst, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths, program, simSettingsOpt, recordDecls, literals, args);
case(_, _, _, _, _, _, _, _, _, _,_, _, _, _) equation
true = Flags.isSet(Flags.HPCOM);
// either generate code for profiling or for parallel simulation
//bcall(not stringEq("none",Flags.getConfigString(Flags.PROFILING_LEVEL)),print,"Deactivate profiling if you want to simulate in parallel.\n");
//_ = bcallret2((not stringEq("none",Flags.getConfigString(Flags.PROFILING_LEVEL))) and (not stringEq("all_perf",Flags.getConfigString(Flags.PROFILING_LEVEL))),FlagsUtil.set,Flags.HPCOM,false,true);
//true = stringEq("none",Flags.getConfigString(Flags.PROFILING_LEVEL)) or stringEq("all_perf",Flags.getConfigString(Flags.PROFILING_LEVEL));
numProc = Flags.getConfigInt(Flags.NUM_PROC);
true = numProc == 0;
print("hpcom computes the ideal number of processors. If you want to set the number manually, use the flag +n=_ \n");
then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inInitDAE_lambda0, inRemovedInitialEquationLst, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,program, simSettingsOpt, recordDecls, literals, args);
case(_, _, _, _, _, _, _, _, _,_, _, _, _, _) equation
true = Flags.isSet(Flags.HPCOM);
// either generate code for profiling or for parallel simulation
//bcall((not stringEq("none",Flags.getConfigString(Flags.PROFILING_LEVEL))) and (not stringEq("all_perf",Flags.getConfigString(Flags.PROFILING_LEVEL))),print,"Deactivate profiling if you want to simulate in parallel.\n");
//_ = bcallret2(not stringEq("none",Flags.getConfigString(Flags.PROFILING_LEVEL)),FlagsUtil.set,Flags.HPCOM,false,true);
//true = stringEq("none",Flags.getConfigString(Flags.PROFILING_LEVEL)) or stringEq("all_perf",Flags.getConfigString(Flags.PROFILING_LEVEL));
numProc = Flags.getConfigInt(Flags.NUM_PROC);
true = (numProc > 0);
then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inInitDAE_lambda0, inRemovedInitialEquationLst, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,program,simSettingsOpt, recordDecls, literals, args);
else equation
(tmpSimCode, _) = SimCodeUtil.createSimCode(inBackendDAE, inInitDAE, inInitDAE_lambda0, inInlineData, inRemovedInitialEquationLst, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,program, simSettingsOpt, recordDecls, literals, args, isFMU=isFMU, FMUVersion=FMUVersion, fmuTargetName=fmuTargetName, inFMIDer=inFMIDer);
then tmpSimCode;
end matchcontinue;
end createSimCode;
protected
partial function PartialRunTpl
output tuple<Boolean,list<String>> res;
end PartialRunTpl;
partial function FuncText
input Tpl.Text txt;
output Tpl.Text out_txt;
end FuncText;
function runTplWriteFile
extends PartialRunTpl;
input FuncText func;
input String file;
protected
Integer nErr;
algorithm
res := (false,{});
try
SimCodeUtil.resetFunctionIndex();
SimCodeFunctionUtil.codegenResetTryThrowIndex();
if Config.acceptMetaModelicaGrammar() or Flags.isSet(Flags.GEN_DEBUG_SYMBOLS) then
Tpl.textFileConvertLines(Tpl.tplCallWithFailErrorNoArg(func), file);
else
nErr := Error.getNumErrorMessages();
Tpl.closeFile(Tpl.tplCallWithFailErrorNoArg(func,Tpl.redirectToFile(Tpl.emptyTxt, file)));
Tpl.failIfTrue(Error.getNumErrorMessages() > nErr);
end if;
res := (true,SimCodeUtil.getFunctionIndex());
else
end try;
end runTplWriteFile;
function runTpl
extends PartialRunTpl;
input FuncText func;
algorithm
res := (false,{});
try
SimCodeUtil.resetFunctionIndex();
SimCodeFunctionUtil.codegenResetTryThrowIndex();
Tpl.tplCallWithFailErrorNoArg(func);
res := (true,SimCodeUtil.getFunctionIndex());
else
end try;
end runTpl;
// TODO: use another switch ... later make it first class option like -target or so
protected function callTargetTemplates "
Generate target code by passing the SimCode data structure to templates."
input SimCode.SimCode simCode;
input String target;
protected
partial function Func
input Tpl.Text txt;
input SimCode.SimCode a_simCode;
output Tpl.Text out_txt;
end Func;
partial function FuncText
input Tpl.Text txt;
output Tpl.Text out_txt;
end FuncText;
partial function BoolFunc
input Tpl.Text txt;
input SimCode.SimCode a_simCode;
output Tpl.Text out_txt;
end BoolFunc;
Func func;
Tpl.Text txt;
function runToStr
extends PartialRunTpl;
input Func func;
partial function Func
output String str;
end Func;
algorithm
res := (false,{});
try
SimCodeUtil.resetFunctionIndex();
SimCodeFunctionUtil.codegenResetTryThrowIndex();
func();
res := (true,SimCodeUtil.getFunctionIndex());
else
end try;
end runToStr;
function runCodegenFunc
input PartialRunTpl func;
output tuple<Boolean,list<String>> res;
protected
Boolean b;
algorithm
(res as (b,_)) := func();
if not b then
Error.addInternalError(System.dladdr(func) + " failed\n", sourceInfo());
end if;
if ErrorExt.getNumMessages() > 0 then
ErrorExt.moveMessagesToParentThread();
end if;
end runCodegenFunc;
function runToBoolean
input Func func;
output tuple<Boolean,list<String>> res;
protected
partial function Func
output Boolean b;
end Func;
algorithm
res := (func(),{});
end runToBoolean;
AvlSetString.Tree generatedObjects=AvlSetString.EMPTY();
algorithm
setGlobalRoot(Global.optionSimCode, SOME(simCode));
_ := match target
local
String str, guid;
list<PartialRunTpl> codegenFuncs;
Integer numThreads, n;
list<tuple<Boolean,list<String>>> res;
list<String> strs, tmp, matches;
case "Cpp"
algorithm
callTargetTemplatesCPP(simCode);
for str in {"CalcHelperMain.o\n",".so\n"} loop
generatedObjects := AvlSetString.add(generatedObjects, "OMCpp" + simCode.fileNamePrefix + str);
end for;
then ();
case "sfmi" equation
Tpl.tplNoret(function CodegenSparseFMI.translateModel(in_a_FMUVersion="2.0", in_a_FMUType="me", in_a_sourceFiles={}), simCode);
then ();
case "C"
algorithm
guid := System.getUUIDStr();
System.realtimeTick(ClockIndexes.RT_PROFILER0);
codegenFuncs := {};
codegenFuncs := (function runToBoolean(func=function SerializeInitXML.simulationInitFileReturnBool(simCode=simCode, guid=guid))) :: codegenFuncs;
codegenFuncs := (function runTpl(func=function CodegenC.translateModel(in_a_simCode=simCode))) :: codegenFuncs;
for f in {
// external objects
(CodegenC.simulationFile_exo, "_01exo.c"),
// non-linear systems
(CodegenC.simulationFile_nls, "_02nls.c"),
(CodegenC.simulationFile_lsy, "_03lsy.c"),
(CodegenC.simulationFile_set, "_04set.c"),
(CodegenC.simulationFile_evt, "_05evt.c"),
(CodegenC.simulationFile_inz, "_06inz.c"),
(CodegenC.simulationFile_dly, "_07dly.c"),
(CodegenC.simulationFile_bnd, "_08bnd.c"),
(CodegenC.simulationFile_alg, "_09alg.c"),
(CodegenC.simulationFile_asr, "_10asr.c"),
(CodegenC.simulationFile_jac, "_12jac.c"),
(CodegenC.simulationFile_jac_header, "_12jac.h"),
(CodegenC.simulationFile_opt, "_13opt.c"),
(CodegenC.simulationFile_opt_header, "_13opt.h"),
(CodegenC.simulationFile_lnz, "_14lnz.c"),
(CodegenC.simulationFile_syn, "_15syn.c"),
(CodegenC.simulationFile_dae, "_16dae.c"),
(CodegenC.simulationFile_dae_header, "_16dae.h"),
(CodegenC.simulationFile_inl, "_17inl.c"),
(CodegenC.simulationHeaderFile, "_model.h")
} loop
(func,str) := f;
codegenFuncs := (function runTplWriteFile(func=function func(a_simCode=simCode), file=simCode.fileNamePrefix + str)) :: codegenFuncs;
(n,matches) := System.regex(str, "\\(.*\\)[.]c$", 2, false, false);
if n==2 then
_::str::_ := matches;
generatedObjects := AvlSetString.add(generatedObjects, simCode.fileNamePrefix + str + ".o\n");
end if;
end for;
for str in {"_11mix.o\n","_functions.o\n","_info.json\n","_init.xml\n"} loop
generatedObjects := AvlSetString.add(generatedObjects, simCode.fileNamePrefix + str);
end for;
codegenFuncs := (function runTpl(func=function CodegenC.simulationFile_mixAndHeader(a_simCode=simCode, a_modelNamePrefix=simCode.fileNamePrefix))) :: codegenFuncs;
codegenFuncs := (function runTplWriteFile(func=function CodegenC.simulationFile(in_a_simCode=simCode, in_a_guid=guid, in_a_isModelExchangeFMU=""), file=simCode.fileNamePrefix + ".c")) :: codegenFuncs;
codegenFuncs := (function runTplWriteFile(func=function CodegenC.simulationFunctionsFile(a_filePrefix=simCode.fileNamePrefix, a_functions=simCode.modelInfo.functions), file=simCode.fileNamePrefix + "_functions.c")) :: codegenFuncs;
codegenFuncs := (function runToStr(func=function SerializeModelInfo.serialize(code=simCode, withOperations=Flags.isSet(Flags.INFO_XML_OPERATIONS)))) :: codegenFuncs;
if Flags.getConfigBool(Flags.PARMODAUTO) then
codegenFuncs := (function runToStr(func=function SerializeTaskSystemInfo.serializeParMod(code=simCode, withOperations=Flags.isSet(Flags.INFO_XML_OPERATIONS)))) :: codegenFuncs;
end if;
// Test the parallel code generator in the test suite. Should give decent results given that the task is disk-intensive.
numThreads := max(1, if Testsuite.isRunning() then min(2, System.numProcessors()) else Config.noProc());
if (not Flags.isSet(Flags.PARALLEL_CODEGEN)) or numThreads==1 then
res := list(func() for func in codegenFuncs);
else
res := System.launchParallelTasks(numThreads, codegenFuncs, runCodegenFunc);
end if;
strs := {};
for tpl in res loop
(true,tmp) := tpl;
strs := List.append_reverse(tmp, strs);
end for;
strs := listReverse(strs);
// Some files are only sometimes generated, like initialization when it has >2000 equations
for str in strs loop
(n,matches) := System.regex(str, "\\(.*\\)[.]c$", 2, false, false);
if n==2 then
_::str::_ := matches;
generatedObjects := AvlSetString.add(generatedObjects, simCode.fileNamePrefix + str + ".o\n");
end if;
end for;
// write the makefile last!
Tpl.closeFile(Tpl.tplCallWithFailError3(CodegenC.simulationMakefile,Config.simulationCodeTarget(),simCode,strs,txt=Tpl.redirectToFile(Tpl.emptyTxt, simCode.fileNamePrefix+".makefile")));
then ();
case "ExperimentalEmbeddedC"
algorithm
_ := System.getUUIDStr();
System.realtimeTick(ClockIndexes.RT_PROFILER0);
codegenFuncs := {};
for f in {
(CodegenEmbeddedC.mainFile, "_main.c")
} loop
(func,str) := f;
codegenFuncs := (function runTplWriteFile(func=function func(a_simCode=simCode), file=simCode.fileNamePrefix + str)) :: codegenFuncs;
end for;
// Test the parallel code generator in the test suite. Should give decent results given that the task is disk-intensive.
numThreads := max(1, if Testsuite.isRunning() then min(2, System.numProcessors()) else Config.noProc());
if (not Flags.isSet(Flags.PARALLEL_CODEGEN)) or numThreads==1 then
res := list(func() for func in codegenFuncs);
else
res := System.launchParallelTasks(numThreads, codegenFuncs, runCodegenFunc);
end if;
strs := {};
for tpl in res loop
(true,tmp) := tpl;
strs := List.append_reverse(tmp, strs);
end for;
strs := listReverse(strs);
// write the makefile last!
then ();
case "JavaScript" equation
guid = System.getUUIDStr();
Tpl.tplNoret(CodegenC.translateModel, simCode);
SerializeInitXML.simulationInitFile(simCode, guid);
System.covertTextFileToCLiteral(simCode.fileNamePrefix+"_init.xml",simCode.fileNamePrefix+"_init.c", Config.simulationCodeTarget());
SerializeModelInfo.serialize(simCode, Flags.isSet(Flags.INFO_XML_OPERATIONS));
Tpl.tplNoret(CodegenJS.markdownFile, simCode);
then ();
case "XML" equation
Tpl.tplNoret(CodegenXML.translateModel, simCode);
then ();
case "Java" equation
Tpl.tplNoret(CodegenJava.translateModel, simCode);
then ();
case "None"
then ();
else equation
str = "Unknown template target: " + target;
Error.addMessage(Error.INTERNAL_ERROR, {str});
then fail();
end match;
if Testsuite.isRunning() then
System.appendFile(Testsuite.getTempFilesFile(), stringAppendList(AvlSetString.listKeys(generatedObjects)));
end if;
setGlobalRoot(Global.optionSimCode, NONE());
end callTargetTemplates;
protected function callTargetTemplatesCPP
input SimCode.SimCode iSimCode;
algorithm
if(Flags.isSet(Flags.HPCOM)) then
Tpl.tplNoret(CodegenCppHpcomOld.translateModel, iSimCode);
else
Tpl.tplNoret(CodegenCppOld.translateModel, iSimCode);
end if;
end callTargetTemplatesCPP;
protected function callTargetTemplatesOMSICpp
input SimCode.SimCode iSimCode;
protected
String fmuVersion;
String fmuType;
algorithm
fmuVersion:="2.0";
fmuType:="me";
Tpl.tplNoret3(CodegenOMSICpp.translateModel, iSimCode, fmuVersion, fmuType);
callTargetTemplatesFMU(iSimCode,"C",fmuVersion,fmuType);
end callTargetTemplatesOMSICpp;
protected function callTargetTemplatesFMU
"Generate target code by passing the SimCode data structure to templates."
input SimCode.SimCode simCode;
input String target;
input String FMUVersion;
input String FMUType;
algorithm
setGlobalRoot(Global.optionSimCode, SOME(simCode));
_ := match (simCode,target)
local
String str, newdir, newpath, resourcesDir, dirname;
String fmutmp;
String guid;
Boolean b;
Boolean needSundials = false;
String fileprefix;
list<String> allFiles, sourceFiles, defaultFiles, extraFiles, runtimeFiles, dgesvFiles, sundialsFiles;
SimCode.VarInfo varInfo;
case (SimCode.SIMCODE(),"C")
algorithm
fmutmp := simCode.fileNamePrefix + ".fmutmp";
if System.directoryExists(fmutmp) then
if not System.removeDirectory(fmutmp) then
Error.addInternalError("Failed to remove directory: " + fmutmp, sourceInfo());
fail();
end if;
end if;
Util.createDirectoryTree(fmutmp + "/sources/include/");
Util.createDirectoryTree(fmutmp + "/resources/");
resourcesDir := fmutmp + "/resources/";
for path in simCode.modelInfo.resourcePaths loop
dirname := System.dirname(path);
// on windows, remove ":" from the path!
if Autoconf.os == "Windows_NT" then
dirname := System.stringReplace(dirname, ":", "");
end if;
newdir := resourcesDir + dirname;
newpath := resourcesDir + path;
if System.regularFileExists(newpath) or System.directoryExists(newpath) then
/* Already copied. Maybe one resource loaded a library and this one only a file in the directory */
continue;
end if;
Util.createDirectoryTree(newdir);
// copy the file or directory
if 0 <> System.systemCall("cp -rf \"" + path + "\" \"" + newdir + "/\"") then
Error.addInternalError("Failed to copy path " + path + " to " + fmutmp + "/resources/" + dirname, sourceInfo());
end if;
end for;
// Add optional _flags.json to resources
_ := match simCode.fmiSimulationFlags
local
SimCode.FmiSimulationFlags fmiSimFlags;
String pathToFlagsJson;
case SOME(fmiSimFlags as SimCode.FMI_SIMULATION_FLAGS_FILE(path=pathToFlagsJson))
algorithm
needSundials := true;
if 0 <> System.systemCall("cp -rf \"" + pathToFlagsJson + "\" \"" + fmutmp + "/resources/" + simCode.fileNamePrefix+"_flags.json\"") then
Error.addInternalError("Failed to copy " + pathToFlagsJson + " to " + fmutmp + "/resources/" + simCode.fileNamePrefix + "_flags.json", sourceInfo());
end if;
then();
else
then();
end match;
SerializeModelInfo.serialize(simCode, Flags.isSet(Flags.INFO_XML_OPERATIONS));
str := fmutmp + "/sources/" + simCode.fileNamePrefix;
if FMUVersion == "1.0" then
b := System.covertTextFileToCLiteral(simCode.fileNamePrefix+"_info.json", str+"_info.c", Flags.getConfigString(Flags.TARGET));
if not b then
Error.addMessage(Error.INTERNAL_ERROR, {"System.covertTextFileToCLiteral failed. Could not write "+str+"_info.c\n"});
fail();
end if;
else
// check for _info.json file in resource directory when --fmiFilter=blackBox is not set
if Flags.getConfigEnum(Flags.FMI_FILTER) <> Flags.FMI_BLACKBOX then
if 0 <> System.systemCall("mv '" + simCode.fileNamePrefix + "_info.json"+"' '" + fmutmp+"/resources/" + "'") then
Error.addInternalError("Failed to move " + simCode.fileNamePrefix + "_info.json file", sourceInfo());
end if;
end if;
end if;
SimCodeUtil.resetFunctionIndex();
varInfo := simCode.modelInfo.varInfo;
allFiles := {};
allFiles := listAppend(RuntimeSources.commonHeaders, listAppend(RuntimeSources.commonFiles, allFiles));
allFiles := listAppend(if FMUVersion=="1.0" then RuntimeSources.fmi1Files else RuntimeSources.fmi2Files, allFiles);
if isSome(simCode.fmiSimulationFlags) then
allFiles := listAppend(RuntimeSources.external3rdPartyFiles, allFiles);
sundialsFiles := RuntimeSources.cvodeRuntimeFiles;
allFiles := listAppend(sundialsFiles, allFiles);
else
sundialsFiles := {""};
end if;
if varInfo.numLinearSystems > 0 then
allFiles := listAppend(RuntimeSources.lsFiles, allFiles);
end if;
if varInfo.numNonLinearSystems > 0 then
allFiles := listAppend(RuntimeSources.nlsFiles, allFiles);
end if;
if varInfo.numMixedSystems > 0 then
allFiles := listAppend(RuntimeSources.mixedFiles, allFiles);
end if;
System.writeFile(fmutmp+"/sources/isfmi" + (if FMUVersion=="1.0" then "1" else "2"), "");
dgesvFiles := if varInfo.numLinearSystems > 0 or varInfo.numNonLinearSystems > 0 then RuntimeSources.dgesvFiles else {};
defaultFiles := list(simCode.fileNamePrefix + f for f in RuntimeSources.defaultFileSuffixes);
runtimeFiles := list(f for f guard Util.endsWith(f, ".c") in allFiles);
// check for fmiSource=false or --fmiFilter=blackBox
if not Flags.getConfigBool(Flags.FMI_SOURCES) or Flags.getConfigEnum(Flags.FMI_FILTER) == Flags.FMI_BLACKBOX then
sourceFiles := {}; // set the sourceFiles to empty, to remove the sources in modeldescription.xml
else
sourceFiles := listAppend(defaultFiles, runtimeFiles);
end if;
Tpl.tplNoret(function CodegenFMU.translateModel(in_a_FMUVersion=FMUVersion, in_a_FMUType=FMUType, in_a_sourceFiles=sourceFiles), simCode);
extraFiles := SimCodeUtil.getFunctionIndex();
copyFiles(listAppend(dgesvFiles, allFiles), source=Settings.getInstallationDirectoryPath() + "/include/omc/c/", destination=fmutmp+"/sources/");
Tpl.closeFile(Tpl.tplCallWithFailErrorNoArg(function CodegenFMU.fmuMakefile(a_target=Config.simulationCodeTarget(), a_simCode=simCode, a_FMUVersion=FMUVersion, a_sourceFiles=listAppend(extraFiles, defaultFiles), a_runtimeObjectFiles=list(System.stringReplace(f,".c",".o") for f in runtimeFiles), a_dgesvObjectFiles=list(System.stringReplace(f,".c",".o") for f guard Util.endsWith(f, ".c") in dgesvFiles), a_sundialsObjectFiles=list(System.stringReplace(f,".c",".o") for f guard Util.endsWith(f, ".c") in sundialsFiles)),
txt=Tpl.redirectToFile(Tpl.emptyTxt, simCode.fileNamePrefix+".fmutmp/sources/Makefile.in")));
Tpl.closeFile(Tpl.tplCallWithFailError(CodegenFMU.settingsfile, simCode,
txt=Tpl.redirectToFile(Tpl.emptyTxt, simCode.fileNamePrefix+".fmutmp/sources/omc_simulation_settings.h")));
/*Temporary generate extra files for omsicpp simcodetarget, additionaly to C-fmu code*/
if Config.simCodeTarget() == "omsicpp" then
runTpl(func = function CodegenOMSICpp.translateModel(a_simCode=simCode, a_FMUVersion=FMUVersion, a_FMUType=FMUType));
end if;
then ();
case (_,"omsic")
algorithm
guid := System.getUUIDStr();
fileprefix := simCode.fileNamePrefix;
// create tmp directory for generated files, but first remove the old one!
if System.directoryExists(simCode.fullPathPrefix) then
if not System.removeDirectory(simCode.fullPathPrefix) then
Error.addInternalError("Failed to remove directory: " + simCode.fullPathPrefix, sourceInfo());
fail();
end if;
end if;
if not System.createDirectory(simCode.fullPathPrefix) then
Error.addInternalError("Failed to create tmp folder "+simCode.fullPathPrefix, sourceInfo());
System.fflush();
fail();
end if;
SerializeInitXML.simulationInitFileReturnBool(simCode=simCode, guid=guid);
SerializeModelInfo.serialize(simCode, Flags.isSet(Flags.INFO_XML_OPERATIONS));
//runTplWriteFile(func = function CodegenFMU.fmuModelDescriptionFile(in_a_simCode=simCode, in_a_guid=guid, in_a_FMUVersion=FMUVersion, in_a_FMUType=FMUType, in_a_sourceFiles={}), file=simCode.fullPathPrefix+"/"+"modelDescription.xml");
runTpl(func = function CodegenOMSI_common.generateFMUModelDescriptionFile(a_simCode=simCode, a_guid=guid, a_FMUVersion=FMUVersion, a_FMUType=FMUType, a_sourceFiles={}, a_fileName=simCode.fullPathPrefix+"/"+"modelDescription.xml"));
runTplWriteFile(func = function CodegenOMSIC.createMakefile(a_simCode=simCode, a_target=Config.simulationCodeTarget(), a_makeflieName=fileprefix+"_FMU.makefile"), file=simCode.fullPathPrefix+"/"+fileprefix+"_FMU.makefile");
runTplWriteFile(func = function CodegenOMSIC.generateOMSIC(a_simCode=simCode), file=simCode.fullPathPrefix+"/"+fileprefix+"_omsic.c");
runTpl(func = function CodegenOMSI_common.generateEquationsCode(a_simCode=simCode, a_FileNamePrefix=fileprefix));
then ();
/*Temporarily disabled
case (_,"omsicpp")
algorithm
guid := System.getUUIDStr();
fileprefix := simCode.fileNamePrefix;
// create tmp directory for generated files, but first remove the old one!
if System.directoryExists(simCode.fullPathPrefix) then
if not System.removeDirectory(simCode.fullPathPrefix) then
Error.addInternalError("Failed to remove directory: " + simCode.fullPathPrefix, sourceInfo());
fail();
end if;
end if;
if not System.createDirectory(simCode.fullPathPrefix) then
Error.addInternalError("Failed to create tmp folder "+simCode.fullPathPrefix, sourceInfo());
System.fflush();
fail();
end if;
SerializeInitXML.simulationInitFileReturnBool(simCode=simCode, guid=guid);
SerializeModelInfo.serialize(simCode, Flags.isSet(Flags.INFO_XML_OPERATIONS));
//runTplWriteFile(func = function CodegenFMU.fmuModelDescriptionFile(in_a_simCode=simCode, in_a_guid=guid, in_a_FMUVersion=FMUVersion, in_a_FMUType=FMUType, in_a_sourceFiles={}), file=simCode.fullPathPrefix+"/"+"modelDescription.xml");
runTpl(func = function CodegenOMSI_common.generateFMUModelDescriptionFile(a_simCode=simCode, a_guid=guid, a_FMUVersion=FMUVersion, a_FMUType=FMUType, a_sourceFiles={}, a_fileName=simCode.fullPathPrefix+"/"+"modelDescription.xml"));
runTplWriteFile(func = function CodegenOMSIC.createMakefile(a_simCode=simCode, a_target=Config.simulationCodeTarget(), a_makeflieName=fileprefix+"_FMU.makefile"), file=simCode.fullPathPrefix+"/"+fileprefix+"_FMU.makefile");
runTplWriteFile(func = function CodegenOMSIC.generateOMSIC(a_simCode=simCode), file=simCode.fullPathPrefix+"/"+fileprefix+"_omsic.c");
runTpl(func = function CodegenOMSI_common.generateEquationsCode(a_simCode=simCode, a_FileNamePrefix=fileprefix));
runTpl(func = function CodegenOMSICpp.translateModel(a_simCode=simCode, a_FMUVersion=FMUVersion, a_FMUType=FMUType));
then ();
*/
case (_,"Cpp")
equation
if(Flags.isSet(Flags.HPCOM)) then
Tpl.tplNoret3(CodegenFMUCppHpcomOld.translateModel, simCode, FMUVersion, FMUType);
else
Tpl.tplNoret(function CodegenFMUCppOld.translateModel(in_a_FMUVersion=FMUVersion, in_a_FMUType=FMUType, in_a_sourceFiles={}), simCode);
end if;
then ();
else
equation
str = "Unknown FMU template target: " + target;
Error.addMessage(Error.INTERNAL_ERROR, {str});
then fail();
end match;
setGlobalRoot(Global.optionSimCode, NONE());
end callTargetTemplatesFMU;
protected function callTargetTemplatesXML
"Generate target code by passing the SimCode data structure to templates."
input SimCode.SimCode simCode;
input String target;
algorithm
Tpl.tplNoret(CodegenXML.translateModel, simCode);
end callTargetTemplatesXML;
public function translateModel "
Entry point to translate a Modelica model for simulation / FMU / XML.
Called from other places in the compiler."
output Boolean success;
input TranslateModelKind kind;
input output FCore.Cache cache;
input FCore.Graph inEnv;
input Absyn.Path className "path for the model";
input String inFileNamePrefix;
input Boolean addDummy "if true, add a dummy state";
input Option<SimCode.SimulationSettings> inSimSettingsOpt;
input Absyn.FunctionArgs args=Absyn.emptyFunctionArgs "labels for remove terms";
output list<String> outStringLst;
output String outFileDir;
output list<tuple<String, Values.Value>> resultValues;
protected
FCore.Cache inCache = cache;
Boolean generateFunctions = false;
Real timeSimCode=0.0, timeTemplates=0.0, timeBackend=0.0, timeFrontend=0.0;
type State = enumeration(frontend, backend, templates, simcode);
State state = State.frontend;
algorithm
FlagsUtil.setConfigBool(Flags.BUILDING_MODEL, true);
(success, outStringLst, outFileDir) :=
matchcontinue (inEnv, className, inFileNamePrefix, addDummy, inSimSettingsOpt, args)
local
String filenameprefix, file_dir, resstr, description;
DAE.DAElist dae, dae1;
FCore.Graph graph;
BackendDAE.BackendDAE dlow, dlow_1;
BackendDAE.Shared shared;
list<String> libs;
BackendDAE.BackendDAE initDAE;
Option<BackendDAE.BackendDAE> initDAE_lambda0;
Option<BackendDAE.InlineData> inlineData;
list<BackendDAE.Equation> removedInitialEquationLst;
Real fsize;
Option<DAE.DAElist> odae;
Option<list<String>> strPreOptModules;
Boolean isFMI2;
BackendDAE.SymbolicJacobians fmiDer;
DAE.FunctionTree funcs;
list<Option<Integer>> allRoots;
case (graph, _, filenameprefix, _, _, _) algorithm
// calculate stuff that we need to create SimCode data structure
System.realtimeTick(ClockIndexes.RT_CLOCK_FRONTEND);
ExecStat.execStatReset();
(cache, graph, odae) := CevalScriptBackend.runFrontEnd(cache, graph, className, false);
ExecStat.execStat("FrontEnd");
SOME(dae1) := odae;
if Flags.isSet(Flags.SERIALIZED_SIZE) then
allRoots := {};
for i in 1:300 loop
try
allRoots := getGlobalRoot(i)::allRoots;
else
end try;
end for;
serializeNotify(allRoots, "All local+global roots (1:300)");
serializeNotify(dae1, "FrontEnd DAE");
serializeNotify((graph,inEnv,cache,inCache), "FCore.Graph + Cache + Old graph + Old cache");
serializeNotify((SymbolTable.get(),dae1,graph,inEnv,cache,inCache), "Symbol Table, DAE, Graph, OldGraph, Cache, OldCache");
ExecStat.execStat("Serialize FrontEnd");
end if;
timeFrontend := System.realtimeTock(ClockIndexes.RT_CLOCK_FRONTEND);
System.realtimeTick(ClockIndexes.RT_CLOCK_BACKEND);
state := State.backend;
dae := DAEUtil.transformationsBeforeBackend(cache, graph, dae1);
ExecStat.execStat("Transformations before backend");
if Flags.isSet(Flags.SERIALIZED_SIZE) then
serializeNotify(dae, "FrontEnd DAE after transformations");
serializeNotify((dae,dae1), "FrontEnd DAE before+after transformations");
ExecStat.execStat("Serialize DAE (2)");
end if;
GC.free(dae1);
GC.free(odae);
odae := NONE();
dae1 := DAE.emptyDae;
generateFunctions := FlagsUtil.set(Flags.GEN, false);
// We should not need to lookup constants and classes in the backend,
// so let's free up the old graph and just make it the initial environment.
if not Flags.isSet(Flags.BACKEND_KEEP_ENV_GRAPH) then
(cache,graph) := Builtin.initialGraph(cache);
end if;
description := DAEUtil.daeDescription(dae);
dlow := BackendDAECreate.lower(dae, cache, graph, BackendDAE.EXTRA_INFO(description,filenameprefix));
GC.free(dae);
dae := DAE.emptyDae;
if Flags.isSet(Flags.SERIALIZED_SIZE) then
serializeNotify(dlow, "BackendDAECreate.lower");
ExecStat.execStat("Serialize dlow");
end if;