-
Notifications
You must be signed in to change notification settings - Fork 297
/
Config.mo
652 lines (560 loc) · 19.6 KB
/
Config.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
/*
* 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 Config
" file: Config.mo
package: Config
description: Functions for configurating the compiler.
This module contains functions which are mostly just wrappers for the Flags
module, which makes it easier to manipulate the configuration of the compiler."
public import Flags;
protected
import Error;
import FlagsUtil;
import System;
public
type LanguageStandard = enumeration('1.x', '2.x', '3.0', '3.1', '3.2', '3.3', '3.4', '3.5', latest, experimental)
"Defines the various modelica language versions that OMC can use.";
public function typeinfo "+t"
output Boolean outBoolean;
algorithm
outBoolean := Flags.getConfigBool(Flags.TYPE_INFO);
end typeinfo;
public function splitArrays
output Boolean outBoolean;
algorithm
outBoolean := not Flags.getConfigBool(Flags.KEEP_ARRAYS);
end splitArrays;
public function modelicaOutput
output Boolean outBoolean;
algorithm
outBoolean := Flags.getConfigBool(Flags.MODELICA_OUTPUT);
end modelicaOutput;
public function noProc
output Integer outInteger;
algorithm
outInteger := noProcWork(Flags.getConfigInt(Flags.NUM_PROC));
end noProc;
protected function noProcWork
input Integer inProc;
output Integer outInteger;
algorithm
outInteger := match inProc
case 0 then System.numProcessors();
else inProc;
end match;
end noProcWork;
public function simulationCg
output Boolean outBoolean;
algorithm
outBoolean := Flags.getConfigBool(Flags.SIMULATION_CG);
end simulationCg;
public function simulation
output Boolean outBoolean;
algorithm
outBoolean := Flags.getConfigBool(Flags.SIMULATION);
end simulation;
public function simulationCodeTarget
"@author: adrpo
returns: 'gcc' or 'msvc'
usage: omc [+target=gcc|msvc], default to 'gcc'."
output String outCodeTarget;
algorithm
outCodeTarget := Flags.getConfigString(Flags.TARGET);
end simulationCodeTarget;
public function classToInstantiate
output String modelName;
algorithm
modelName := Flags.getConfigString(Flags.INST_CLASS);
end classToInstantiate;
public function silent
output Boolean outBoolean;
algorithm
outBoolean := Flags.getConfigBool(Flags.SILENT);
end silent;
public function versionRequest
output Boolean outBoolean;
algorithm
outBoolean := Flags.getConfigBool(Flags.SHOW_VERSION);
end versionRequest;
public function helpRequest
output Boolean outBoolean;
algorithm
outBoolean := not stringEq(Flags.getConfigString(Flags.HELP), "");
end helpRequest;
public function acceptedGrammar
"returns: the flag number representing the accepted grammer. Instead of using
booleans. This way more extensions can be added easily.
usage: omc [-g=Modelica|MetaModelica|ParModelica|Optimica], default to 'Modelica'."
output Integer outGrammer;
algorithm
outGrammer := Flags.getConfigEnum(Flags.GRAMMAR);
end acceptedGrammar;
public function acceptMetaModelicaGrammar
"returns: true if MetaModelica grammar is accepted or false otherwise
usage: omc [-g=Modelica|MetaModelica|ParModelica|Optimica], default to 'Modelica'."
output Boolean outBoolean;
algorithm
outBoolean := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.METAMODELICA);
end acceptMetaModelicaGrammar;
public function acceptParModelicaGrammar
"returns: true if ParModelica grammar is accepted or false otherwise
usage: omc [-g=Modelica|MetaModelica|ParModelica|Optimica], default to 'Modelica'."
output Boolean outBoolean;
algorithm
outBoolean := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PARMODELICA);
end acceptParModelicaGrammar;
public function acceptOptimicaGrammar
"returns: true if Optimica grammar is accepted or false otherwise
usage: omc [-g=Modelica|MetaModelica|ParModelica|Optimica], default to 'Modelica'."
output Boolean outBoolean;
algorithm
outBoolean := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.OPTIMICA);
end acceptOptimicaGrammar;
public function acceptPDEModelicaGrammar
"returns: true if Optimica grammar is accepted or false otherwise
usage: omc [-g=Modelica|MetaModelica|ParModelica|Optimica], default to 'Modelica'."
output Boolean outBoolean;
algorithm
outBoolean := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA);
end acceptPDEModelicaGrammar;
public function getAnnotationVersion
"returns what flag was given at start
omc [+annotationVersion=3.x]
or via the API
setAnnotationVersion(\"3.x\");
for annotations: 1.x or 2.x or 3.x"
output String annotationVersion;
algorithm
annotationVersion := Flags.getConfigString(Flags.ANNOTATION_VERSION);
end getAnnotationVersion;
public function setAnnotationVersion
"setAnnotationVersion(\"3.x\");
for annotations: 1.x or 2.x or 3.x"
input String annotationVersion;
algorithm
FlagsUtil.setConfigString(Flags.ANNOTATION_VERSION, annotationVersion);
end setAnnotationVersion;
public function getNoSimplify
"returns what flag was given at start
omc [+noSimplify]
or via the API
setNoSimplify(true|false);"
output Boolean noSimplify;
algorithm
noSimplify := Flags.getConfigBool(Flags.NO_SIMPLIFY);
end getNoSimplify;
public function setNoSimplify
input Boolean noSimplify;
algorithm
FlagsUtil.setConfigBool(Flags.NO_SIMPLIFY, noSimplify);
end setNoSimplify;
public function vectorizationLimit
"Returns the vectorization limit that is used to determine how large an array
can be before it no longer is expanded by Static.crefVectorize."
output Integer limit;
algorithm
limit := Flags.getConfigInt(Flags.VECTORIZATION_LIMIT);
end vectorizationLimit;
public function setVectorizationLimit
"Sets the vectorization limit, see vectorizationLimit above."
input Integer limit;
algorithm
FlagsUtil.setConfigInt(Flags.VECTORIZATION_LIMIT, limit);
end setVectorizationLimit;
public function getDefaultOpenCLDevice
"Returns the id for the default OpenCL device to be used."
output Integer defdevid;
algorithm
defdevid := Flags.getConfigInt(Flags.DEFAULT_OPENCL_DEVICE);
end getDefaultOpenCLDevice;
public function setDefaultOpenCLDevice
"Sets the default OpenCL device to be used."
input Integer defdevid;
algorithm
FlagsUtil.setConfigInt(Flags.DEFAULT_OPENCL_DEVICE, defdevid);
end setDefaultOpenCLDevice;
public function showAnnotations
output Boolean show;
algorithm
show := Flags.getConfigBool(Flags.SHOW_ANNOTATIONS);
end showAnnotations;
public function setShowAnnotations
input Boolean show;
algorithm
FlagsUtil.setConfigBool(Flags.SHOW_ANNOTATIONS, show);
end setShowAnnotations;
public function showStructuralAnnotations
output Boolean show;
algorithm
show := Flags.getConfigBool(Flags.SHOW_STRUCTURAL_ANNOTATIONS);
end showStructuralAnnotations;
public function showStartOrigin
output Boolean show;
algorithm
show := Flags.isSet(Flags.SHOW_START_ORIGIN);
end showStartOrigin;
public function getEvaluateParametersInAnnotations
"@author: adrpo
flag to tell us if we should evaluate parameters in annotations"
output Boolean shouldEvaluate;
algorithm
shouldEvaluate := Flags.getConfigBool(Flags.EVAL_PARAMS_IN_ANNOTATIONS);
end getEvaluateParametersInAnnotations;
public function setEvaluateParametersInAnnotations
"@author: adrpo
flag to tell us if we should evaluate parameters in annotations"
input Boolean shouldEvaluate;
algorithm
FlagsUtil.setConfigBool(Flags.EVAL_PARAMS_IN_ANNOTATIONS, shouldEvaluate);
end setEvaluateParametersInAnnotations;
public function getGraphicsExpMode
"flag to tell us if we should ignore some errors (when evaluating icons)"
output Boolean graphicsExpMode;
algorithm
graphicsExpMode := Flags.getConfigBool(Flags.GRAPHICS_EXP_MODE);
end getGraphicsExpMode;
public function setGraphicsExpMode
"flag to tell us if we should ignore some errors (when evaluating icons)"
input Boolean graphicsExpMode;
algorithm
FlagsUtil.setConfigBool(Flags.GRAPHICS_EXP_MODE, graphicsExpMode);
end setGraphicsExpMode;
public function orderConnections
output Boolean show;
algorithm
show := Flags.getConfigBool(Flags.ORDER_CONNECTIONS);
end orderConnections;
public function setOrderConnections
input Boolean show;
algorithm
FlagsUtil.setConfigBool(Flags.ORDER_CONNECTIONS, show);
end setOrderConnections;
public function getPreOptModules
output list<String> outStringLst;
algorithm
outStringLst := Flags.getConfigStringList(Flags.PRE_OPT_MODULES);
end getPreOptModules;
public function getPostOptModules
output list<String> outStringLst;
algorithm
outStringLst := Flags.getConfigStringList(Flags.POST_OPT_MODULES);
end getPostOptModules;
public function getPostOptModulesDAE
output list<String> outStringLst;
algorithm
outStringLst := Flags.getConfigStringList(Flags.POST_OPT_MODULES_DAE);
end getPostOptModulesDAE;
public function getInitOptModules
output list<String> outStringLst;
algorithm
outStringLst := Flags.getConfigStringList(Flags.INIT_OPT_MODULES);
end getInitOptModules;
public function setPreOptModules
input list<String> inStringLst;
algorithm
FlagsUtil.setConfigStringList(Flags.PRE_OPT_MODULES, inStringLst);
end setPreOptModules;
public function setPostOptModules
input list<String> inStringLst;
algorithm
FlagsUtil.setConfigStringList(Flags.POST_OPT_MODULES, inStringLst);
end setPostOptModules;
public function getIndexReductionMethod
output String outString;
algorithm
outString := Flags.getConfigString(Flags.INDEX_REDUCTION_METHOD);
end getIndexReductionMethod;
public function setIndexReductionMethod
input String inString;
algorithm
FlagsUtil.setConfigString(Flags.INDEX_REDUCTION_METHOD, inString);
end setIndexReductionMethod;
public function getCheapMatchingAlgorithm
output Integer outInteger;
algorithm
outInteger := Flags.getConfigInt(Flags.CHEAPMATCHING_ALGORITHM);
end getCheapMatchingAlgorithm;
public function setCheapMatchingAlgorithm
input Integer inInteger;
algorithm
FlagsUtil.setConfigInt(Flags.CHEAPMATCHING_ALGORITHM, inInteger);
end setCheapMatchingAlgorithm;
public function getMatchingAlgorithm
output String outString;
algorithm
outString := Flags.getConfigString(Flags.MATCHING_ALGORITHM);
end getMatchingAlgorithm;
public function setMatchingAlgorithm
input String inString;
algorithm
FlagsUtil.setConfigString(Flags.MATCHING_ALGORITHM, inString);
end setMatchingAlgorithm;
public function getTearingMethod
output String outString;
algorithm
outString := Flags.getConfigString(Flags.TEARING_METHOD);
end getTearingMethod;
public function setTearingMethod
input String inString;
algorithm
FlagsUtil.setConfigString(Flags.TEARING_METHOD, inString);
end setTearingMethod;
public function getTearingHeuristic
output String outString;
algorithm
outString := Flags.getConfigString(Flags.TEARING_HEURISTIC);
end getTearingHeuristic;
public function setTearingHeuristic
input String inString;
algorithm
FlagsUtil.setConfigString(Flags.TEARING_HEURISTIC, inString);
end setTearingHeuristic;
public function simCodeTarget "Default is set by +simCodeTarget=C"
output String target;
algorithm
target := Flags.getConfigString(Flags.SIMCODE_TARGET);
end simCodeTarget;
public function setsimCodeTarget
input String inString;
algorithm
FlagsUtil.setConfigString(Flags.SIMCODE_TARGET, inString);
end setsimCodeTarget;
public function getLanguageStandard
output LanguageStandard outStandard;
algorithm
outStandard := intLanguageStandard(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD));
end getLanguageStandard;
public function setLanguageStandard
input LanguageStandard inStandard;
algorithm
FlagsUtil.setConfigEnum(Flags.LANGUAGE_STANDARD, languageStandardInt(inStandard));
end setLanguageStandard;
public function languageStandardAtLeast
input LanguageStandard inStandard;
output Boolean outRes;
protected
LanguageStandard std;
algorithm
std := getLanguageStandard();
outRes := intGe(languageStandardInt(std), languageStandardInt(inStandard));
end languageStandardAtLeast;
public function languageStandardAtMost
input LanguageStandard inStandard;
output Boolean outRes;
protected
LanguageStandard std;
algorithm
std := getLanguageStandard();
outRes := intLe(languageStandardInt(std), languageStandardInt(inStandard));
end languageStandardAtMost;
protected function languageStandardInt
input LanguageStandard inStandard;
output Integer outValue;
protected
constant Integer lookup[LanguageStandard] = array(10, 20, 30, 31, 32, 33, 34, 1000, 1035, 9999);
algorithm
outValue := lookup[inStandard];
end languageStandardInt;
protected function intLanguageStandard
input Integer inValue;
output LanguageStandard outStandard;
algorithm
outStandard := match(inValue)
case 10 then LanguageStandard.'1.x';
case 20 then LanguageStandard.'2.x';
case 30 then LanguageStandard.'3.0';
case 31 then LanguageStandard.'3.1';
case 32 then LanguageStandard.'3.2';
case 33 then LanguageStandard.'3.3';
case 34 then LanguageStandard.'3.4';
case 35 then LanguageStandard.'3.5';
case 1000 then LanguageStandard.latest;
case 9999 then LanguageStandard.experimental;
end match;
end intLanguageStandard;
public function languageStandardString
input LanguageStandard inStandard;
output String outString;
protected
constant String lookup[LanguageStandard] = array("1.x","2.x","3.0","3.1","3.2","3.3","3.4","3.5","3.5","experimental" /*Change this to latest version if you add more versions!*/);
algorithm
outString := lookup[inStandard];
end languageStandardString;
public function setLanguageStandardFromMSL
input String inLibraryName;
input Boolean force = false "Set the standard even if it was already set";
protected
LanguageStandard current_std;
algorithm
current_std := getLanguageStandard();
if not force and current_std <> LanguageStandard.latest then
// If we selected an MSL version manually, we respect that choice.
return;
end if;
_ := matchcontinue(inLibraryName)
local
String version;
LanguageStandard new_std;
case _
algorithm
"Modelica" :: version :: _ := System.strtok(inLibraryName, " ");
new_std := versionStringToStd(version);
if new_std <> current_std then
setLanguageStandard(new_std);
if hasLanguageStandardChanged(current_std) then
Error.addMessage(Error.CHANGED_STD_VERSION,
{languageStandardString(new_std), version});
end if;
end if;
then ();
else ();
end matchcontinue;
end setLanguageStandardFromMSL;
protected function hasLanguageStandardChanged
input LanguageStandard inOldStandard;
output Boolean outHasChanged;
algorithm
// If the old standard wasn't set by the user, then we consider it to have
// changed only if the new standard is 3.0 or less. This is to avoid
// printing a notice if the user loads e.g. MSL 3.1.
outHasChanged := languageStandardAtMost(LanguageStandard.'3.0');
end hasLanguageStandardChanged;
public function versionStringToStd
input String inVersion;
output LanguageStandard outStandard;
protected
list<String> version;
algorithm
version := System.strtok(inVersion, ".");
outStandard := versionStringToStd2(version);
end versionStringToStd;
protected function versionStringToStd2
input list<String> inVersion;
output LanguageStandard outStandard;
algorithm
outStandard := match(inVersion)
case "1" :: _ then LanguageStandard.'1.x';
case "2" :: _ then LanguageStandard.'2.x';
case "3" :: "0" :: _ then LanguageStandard.'3.0';
case "3" :: "1" :: _ then LanguageStandard.'3.1';
case "3" :: _ then LanguageStandard.'3.2';
case "4" :: "0" :: _ then LanguageStandard.'3.4';
case _ then LanguageStandard.latest;
end match;
end versionStringToStd2;
public function showErrorMessages
output Boolean outShowErrorMessages;
algorithm
outShowErrorMessages := Flags.getConfigBool(Flags.SHOW_ERROR_MESSAGES);
end showErrorMessages;
public function scalarizeMinMax
output Boolean outScalarizeMinMax;
algorithm
outScalarizeMinMax := Flags.getConfigBool(Flags.SCALARIZE_MINMAX);
end scalarizeMinMax;
public function scalarizeBindings
output Boolean outScalarizeBindings;
algorithm
outScalarizeBindings := Flags.getConfigBool(Flags.SCALARIZE_BINDINGS);
end scalarizeBindings;
public function intEnumConversion
output Boolean outIntEnumConversion;
algorithm
outIntEnumConversion := Flags.getConfigBool(Flags.INT_ENUM_CONVERSION);
end intEnumConversion;
public function profileSome
output Boolean outBoolean;
algorithm
outBoolean := 0==System.strncmp(Flags.getConfigString(Flags.PROFILING_LEVEL), "blocks", 6);
end profileSome;
public function profileAll
output Boolean outBoolean;
algorithm
outBoolean := stringEq(Flags.getConfigString(Flags.PROFILING_LEVEL), "all");
end profileAll;
public function profileHtml
output Boolean outBoolean;
algorithm
outBoolean := stringEq(Flags.getConfigString(Flags.PROFILING_LEVEL), "blocks+html");
end profileHtml;
public function profileFunctions
output Boolean outBoolean;
algorithm
outBoolean := not stringEq(Flags.getConfigString(Flags.PROFILING_LEVEL), "none");
end profileFunctions;
public function dynamicTearing
output String outString;
algorithm
outString := Flags.getConfigString(Flags.DYNAMIC_TEARING);
end dynamicTearing;
public function ignoreCommandLineOptionsAnnotation
output Boolean outBoolean;
algorithm
outBoolean := Flags.getConfigBool(Flags.IGNORE_COMMAND_LINE_OPTIONS_ANNOTATION);
end ignoreCommandLineOptionsAnnotation;
public function globalHomotopy
output Boolean outBoolean;
algorithm
outBoolean := match(Flags.getConfigString(Flags.HOMOTOPY_APPROACH))
case("equidistantLocal") then false;
case("adaptiveLocal") then false;
case("equidistantGlobal") then true;
case("adaptiveGlobal") then true;
end match;
end globalHomotopy;
public function adaptiveHomotopy
output Boolean outBoolean;
algorithm
outBoolean := match(Flags.getConfigString(Flags.HOMOTOPY_APPROACH))
case("equidistantLocal") then false;
case("adaptiveLocal") then true;
case("equidistantGlobal") then false;
case("adaptiveGlobal") then true;
end match;
end adaptiveHomotopy;
public function synchronousFeaturesAllowed
"@autor: adrpo
checks returns true if language standard is above or equal to Modelica 3.3"
output Boolean outRes = getLanguageStandard() >= LanguageStandard.'3.3';
end synchronousFeaturesAllowed;
public function flatModelica
output Boolean value;
algorithm
value := Flags.getConfigBool(Flags.BASE_MODELICA);
// Ignore the flag unless the new frontend is enabled, otherwise it won't work.
if value and not Flags.isSet(Flags.SCODE_INST) then
Error.addMessage(Error.INVALID_FLAG_CONDITION,
{"-f", "flat modelica requires flag -d=newInst to be set"});
value := false;
end if;
end flatModelica;
annotation(__OpenModelica_Interface="util");
end Config;