Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 31.6% 136 / 0 / 431
Functions: -% 0 / 1 / 1
Branches: 36.0% 93 / 0 / 258

OMCompiler/Compiler/Util/FlagsUtil.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 FlagsUtil
37 " file: FlagsUtil.mo
38 package: FlagsUtil
39 description: Tools for using compiler flags.
40
41 This package contains function for using the compiler flags in Flags.mo."
42
43 import Flags;
44
45 protected
46
47 import Error;
48 import ErrorExt;
49 import Global;
50 import IOStream;
51 import List;
52 import Print;
53 import Settings;
54 import StringUtil;
55 import System;
56 import Util;
57
58 // This is a list of all debug flags, to keep track of which flags are used. A
59 // flag can not be used unless it's in this list, and the list is checked at
60 // initialization so that all flags are sorted by index (and thus have unique
61 // indices).
62 protected
63 constant list<Flags.DebugFlag> allDebugFlags = {
64 Flags.FAILTRACE,
65 Flags.CEVAL,
66 Flags.CHECK_BACKEND_DAE,
67 Flags.PTHREADS,
68 Flags.EVENTS,
69 Flags.DUMP_INLINE_SOLVER,
70 Flags.EVAL_FUNC,
71 Flags.GEN,
72 Flags.DYN_LOAD,
73 Flags.GENERATE_CODE_CHEAT,
74 Flags.CGRAPH_GRAPHVIZ_FILE,
75 Flags.CGRAPH_GRAPHVIZ_SHOW,
76 Flags.GC_PROF,
77 Flags.CHECK_DAE_CREF_TYPE,
78 Flags.CHECK_ASUB,
79 Flags.INSTANCE,
80 Flags.CACHE,
81 Flags.RML,
82 Flags.TAIL,
83 Flags.LOOKUP,
84 Flags.PATTERNM_SKIP_FILTER_UNUSED_AS_BINDINGS,
85 Flags.PATTERNM_ALL_INFO,
86 Flags.PATTERNM_DCE,
87 Flags.PATTERNM_MOVE_LAST_EXP,
88 Flags.EXPERIMENTAL_REDUCTIONS,
89 Flags.EVAL_PARAM,
90 Flags.TYPES,
91 Flags.SHOW_STATEMENT,
92 Flags.DUMP,
93 Flags.DUMP_GRAPHVIZ,
94 Flags.EXEC_STAT,
95 Flags.TRANSFORMS_BEFORE_DUMP,
96 Flags.DAE_DUMP_GRAPHV,
97 Flags.INTERACTIVE_TCP,
98 Flags.INTERACTIVE_DUMP,
99 Flags.RELIDX,
100 Flags.DUMP_REPL,
101 Flags.DUMP_FP_REPL,
102 Flags.DUMP_PARAM_REPL,
103 Flags.DUMP_PP_REPL,
104 Flags.DUMP_EA_REPL,
105 Flags.DEBUG_ALIAS,
106 Flags.TEARING_DUMP,
107 Flags.JAC_DUMP,
108 Flags.JAC_DUMP2,
109 Flags.DUMP_BINDINGS,
110 Flags.DUMP_SORTING,
111 Flags.DUMP_SPARSE,
112 Flags.DUMP_SPARSE_VERBOSE,
113 Flags.BLT_DUMP,
114 Flags.DUMMY_SELECT,
115 Flags.DUMP_DAE_LOW,
116 Flags.DUMP_INDX_DAE,
117 Flags.OPT_DAE_DUMP,
118 Flags.EXEC_HASH,
119 Flags.PARAM_DLOW_DUMP,
120 Flags.DUMP_ENCAPSULATECONDITIONS,
121 Flags.SHORT_OUTPUT,
122 Flags.COUNT_OPERATIONS,
123 Flags.CGRAPH,
124 Flags.UPDMOD,
125 Flags.STATIC,
126 Flags.TPL_PERF_TIMES,
127 Flags.CHECK_SIMPLIFY,
128 Flags.SCODE_INST,
129 Flags.WRITE_TO_BUFFER,
130 Flags.DUMP_BACKENDDAE_INFO,
131 Flags.GEN_DEBUG_SYMBOLS,
132 Flags.DUMP_STATESELECTION_INFO,
133 Flags.DUMP_EQNINORDER,
134 Flags.SEMILINEAR,
135 Flags.UNCERTAINTIES,
136 Flags.SHOW_START_ORIGIN,
137 Flags.DUMP_SIMCODE,
138 Flags.DUMP_INITIAL_SYSTEM,
139 Flags.GRAPH_INST,
140 Flags.GRAPH_INST_RUN_DEP,
141 Flags.GRAPH_INST_GEN_GRAPH,
142 Flags.DUMP_CONST_REPL,
143 Flags.SHOW_EQUATION_SOURCE,
144 Flags.LS_ANALYTIC_JACOBIAN,
145 Flags.NLS_ANALYTIC_JACOBIAN,
146 Flags.INLINE_SOLVER,
147 Flags.HPCOM,
148 Flags.INITIALIZATION,
149 Flags.INLINE_FUNCTIONS,
150 Flags.DUMP_SCC_GRAPHML,
151 Flags.TEARING_DUMPVERBOSE,
152 Flags.DISABLE_SINGLE_FLOW_EQ,
153 Flags.DUMP_DISCRETEVARS_INFO,
154 Flags.ADDITIONAL_GRAPHVIZ_DUMP,
155 Flags.INFO_XML_OPERATIONS,
156 Flags.HPCOM_DUMP,
157 Flags.RESOLVE_LOOPS_DUMP,
158 Flags.DISABLE_WINDOWS_PATH_CHECK_WARNING,
159 Flags.DISABLE_RECORD_CONSTRUCTOR_OUTPUT,
160 Flags.IMPL_ODE,
161 Flags.EVAL_FUNC_DUMP,
162 Flags.PRINT_STRUCTURAL,
163 Flags.ITERATION_VARS,
164 Flags.ALLOW_RECORD_TOO_MANY_FIELDS,
165 Flags.HPCOM_MEMORY_OPT,
166 Flags.DUMP_SYNCHRONOUS,
167 Flags.STRIP_PREFIX,
168 Flags.DO_SCODE_DEP,
169 Flags.SHOW_INST_CACHE_INFO,
170 Flags.DUMP_UNIT,
171 Flags.DUMP_EQ_UNIT,
172 Flags.DUMP_EQ_UNIT_STRUCT,
173 Flags.SHOW_DAE_GENERATION,
174 Flags.RESHUFFLE_POST,
175 Flags.SHOW_EXPANDABLE_INFO,
176 Flags.DUMP_HOMOTOPY,
177 Flags.OMC_RELOCATABLE_FUNCTIONS,
178 Flags.GRAPHML,
179 Flags.USEMPI,
180 Flags.DUMP_CSE,
181 Flags.DUMP_CSE_VERBOSE,
182 Flags.NO_START_CALC,
183 Flags.CONSTJAC,
184 Flags.VISUAL_XML,
185 Flags.VECTORIZE,
186 Flags.CHECK_EXT_LIBS,
187 Flags.RUNTIME_STATIC_LINKING,
188 Flags.SORT_EQNS_AND_VARS,
189 Flags.DUMP_SIMPLIFY_LOOPS,
190 Flags.DUMP_RTEARING,
191 Flags.DIS_SYMJAC_FMI20,
192 Flags.EVAL_OUTPUT_ONLY,
193 Flags.HARDCODED_START_VALUES,
194 Flags.DUMP_FUNCTIONS,
195 Flags.DEBUG_DIFFERENTIATION,
196 Flags.DEBUG_DIFFERENTIATION_VERBOSE,
197 Flags.FMU_EXPERIMENTAL,
198 Flags.DUMP_DGESV,
199 Flags.MULTIRATE_PARTITION,
200 Flags.DUMP_EXCLUDED_EXP,
201 Flags.DEBUG_ALGLOOP_JACOBIAN,
202 Flags.DISABLE_JACSCC,
203 Flags.FORCE_NLS_ANALYTIC_JACOBIAN,
204 Flags.DUMP_LOOPS,
205 Flags.DUMP_LOOPS_VERBOSE,
206 Flags.SKIP_INPUT_OUTPUT_SYNTACTIC_SUGAR,
207 Flags.OMC_RECORD_ALLOC_WORDS,
208 Flags.TOTAL_TEARING_DUMP,
209 Flags.TOTAL_TEARING_DUMPVERBOSE,
210 Flags.PARALLEL_CODEGEN,
211 Flags.SERIALIZED_SIZE,
212 Flags.BACKEND_KEEP_ENV_GRAPH,
213 Flags.DUMPBACKENDINLINE,
214 Flags.DUMPBACKENDINLINE_VERBOSE,
215 Flags.BLT_MATRIX_DUMP,
216 Flags.LIST_REVERSE_WRONG_ORDER,
217 Flags.PARTITION_INITIALIZATION,
218 Flags.EVAL_PARAM_DUMP,
219 Flags.NF_UNITCHECK,
220 Flags.DISABLE_COLORING,
221 Flags.MERGE_ALGORITHM_SECTIONS,
222 Flags.WARN_NO_NOMINAL,
223 Flags.REDUCE_DAE,
224 Flags.IGNORE_CYCLES,
225 Flags.ALIAS_CONFLICTS,
226 Flags.SUSAN_MATCHCONTINUE_DEBUG,
227 Flags.OLD_FE_UNITCHECK,
228 Flags.EXEC_STAT_EXTRA_GC,
229 Flags.DEBUG_DAEMODE,
230 Flags.NF_SCALARIZE,
231 Flags.NF_EVAL_CONST_ARG_FUNCS,
232 Flags.NF_EXPAND_OPERATIONS,
233 Flags.NF_API,
234 Flags.NF_API_DYNAMIC_SELECT,
235 Flags.NF_API_NOISE,
236 Flags.FMI20_DEPENDENCIES,
237 Flags.WARNING_MINMAX_ATTRIBUTES,
238 Flags.NF_EXPAND_FUNC_ARGS,
239 Flags.DUMP_JL,
240 Flags.DUMP_ASSC,
241 Flags.SPLIT_CONSTANT_PARTS_SYMJAC,
242 Flags.DUMP_FORCE_FMI_ATTRIBUTES,
243 Flags.DUMP_DATARECONCILIATION,
244 Flags.ARRAY_CONNECT,
245 Flags.COMBINE_SUBSCRIPTS,
246 Flags.ZMQ_LISTEN_TO_ALL,
247 Flags.DUMP_CONVERSION_RULES,
248 Flags.PRINT_RECORD_TYPES,
249 Flags.DUMP_SIMPLIFY,
250 Flags.DUMP_BACKEND_CLOCKS,
251 Flags.DUMP_SET_BASED_GRAPHS,
252 Flags.MERGE_COMPONENTS,
253 Flags.DUMP_SLICE,
254 Flags.VECTORIZE_BINDINGS,
255 Flags.DUMP_EVENTS,
256 Flags.DUMP_RESIZABLE,
257 Flags.DUMP_SOLVE,
258 Flags.FORCE_SCALARIZE,
259 Flags.DEBUG_ADJOINT,
260 Flags.FLOW_ALIAS_ELIMINATION,
261 Flags.DUMP_CHECK_MODEL,
262 Flags.CHECK_DEF_USE,
263 Flags.TEARING_COST,
264 Flags.OMEDIT
265 };
266
267 protected
268 // This is a list of all configuration flags. A flag can not be used unless it's
269 // in this list, and the list is checked at initialization so that all flags are
270 // sorted by index (and thus have unique indices).
271 constant list<Flags.ConfigFlag> allConfigFlags = {
272 Flags.DEBUG,
273 Flags.HELP,
274 Flags.RUNNING_TESTSUITE,
275 Flags.SHOW_VERSION,
276 Flags.TARGET,
277 Flags.GRAMMAR,
278 Flags.ANNOTATION_VERSION,
279 Flags.LANGUAGE_STANDARD,
280 Flags.SHOW_ERROR_MESSAGES,
281 Flags.SHOW_ANNOTATIONS,
282 Flags.NO_SIMPLIFY,
283 Flags.PRE_OPT_MODULES,
284 Flags.CHEAPMATCHING_ALGORITHM,
285 Flags.MATCHING_ALGORITHM,
286 Flags.INDEX_REDUCTION_METHOD,
287 Flags.POST_OPT_MODULES,
288 Flags.SIMCODE_TARGET,
289 Flags.ORDER_CONNECTIONS,
290 Flags.TYPE_INFO,
291 Flags.KEEP_ARRAYS,
292 Flags.MODELICA_OUTPUT,
293 Flags.SILENT,
294 Flags.NUM_PROC,
295 Flags.INST_CLASS,
296 Flags.VECTORIZATION_LIMIT,
297 Flags.SIMULATION_CG,
298 Flags.EVAL_PARAMS_IN_ANNOTATIONS,
299 Flags.CHECK_MODEL,
300 Flags.CEVAL_EQUATION,
301 Flags.UNIT_CHECKING,
302 Flags.GENERATE_LABELED_SIMCODE,
303 Flags.REDUCE_TERMS,
304 Flags.REDUCTION_METHOD,
305 Flags.DEMO_MODE,
306 Flags.LOCALE_FLAG,
307 Flags.DEFAULT_OPENCL_DEVICE,
308 Flags.MAXTRAVERSALS,
309 Flags.DUMP_TARGET,
310 Flags.DELAY_BREAK_LOOP,
311 Flags.TEARING_METHOD,
312 Flags.TEARING_HEURISTIC,
313 Flags.SCALARIZE_MINMAX,
314 Flags.STRICT,
315 Flags.SCALARIZE_BINDINGS,
316 Flags.HPCOM_SCHEDULER,
317 Flags.HPCOM_CODE,
318 Flags.REWRITE_RULES_FILE,
319 Flags.REPLACE_HOMOTOPY,
320 Flags.GENERATE_DYNAMIC_JACOBIAN,
321 Flags.GENERATE_SYMBOLIC_LINEARIZATION,
322 Flags.INT_ENUM_CONVERSION,
323 Flags.PROFILING_LEVEL,
324 Flags.RESHUFFLE,
325 Flags.GENERATE_DYN_OPTIMIZATION_PROBLEM,
326 Flags.MAX_SIZE_FOR_SOLVE_LINIEAR_SYSTEM,
327 Flags.CPP_FLAGS,
328 Flags.REMOVE_SIMPLE_EQUATIONS,
329 Flags.DYNAMIC_TEARING,
330 Flags.SYM_SOLVER,
331 Flags.LOOP2CON,
332 Flags.FORCE_TEARING,
333 Flags.SIMPLIFY_LOOPS,
334 Flags.RTEARING,
335 Flags.FLOW_THRESHOLD,
336 Flags.MATRIX_FORMAT,
337 Flags.PARTLINTORN,
338 Flags.INIT_OPT_MODULES,
339 Flags.MAX_MIXED_DETERMINED_INDEX,
340 Flags.USE_LOCAL_DIRECTION,
341 Flags.DEFAULT_OPT_MODULES_ORDERING,
342 Flags.PRE_OPT_MODULES_ADD,
343 Flags.PRE_OPT_MODULES_SUB,
344 Flags.POST_OPT_MODULES_ADD,
345 Flags.POST_OPT_MODULES_SUB,
346 Flags.INIT_OPT_MODULES_ADD,
347 Flags.INIT_OPT_MODULES_SUB,
348 Flags.PERMISSIVE,
349 Flags.HETS,
350 Flags.DEFAULT_CLOCK_PERIOD,
351 Flags.INST_CACHE_SIZE,
352 Flags.MAX_SIZE_LINEAR_TEARING,
353 Flags.MAX_SIZE_NONLINEAR_TEARING,
354 Flags.NO_TEARING_FOR_COMPONENT,
355 Flags.CT_STATE_MACHINES,
356 Flags.DAE_MODE,
357 Flags.INLINE_METHOD,
358 Flags.SET_TEARING_VARS,
359 Flags.SET_RESIDUAL_EQNS,
360 Flags.IGNORE_COMMAND_LINE_OPTIONS_ANNOTATION,
361 Flags.CALCULATE_SENSITIVITIES,
362 Flags.ALARM,
363 Flags.TOTAL_TEARING,
364 Flags.IGNORE_SIMULATION_FLAGS_ANNOTATION,
365 Flags.DYNAMIC_TEARING_FOR_INITIALIZATION,
366 Flags.PREFER_TVARS_WITH_START_VALUE,
367 Flags.EQUATIONS_PER_FILE,
368 Flags.EVALUATE_FINAL_PARAMS,
369 Flags.EVALUATE_PROTECTED_PARAMS,
370 Flags.REPLACE_EVALUATED_PARAMS,
371 Flags.CONDENSE_ARRAYS,
372 Flags.WFC_ADVANCED,
373 Flags.GRAPHICS_EXP_MODE,
374 Flags.TEARING_STRICTNESS,
375 Flags.INTERACTIVE,
376 Flags.ZEROMQ_FILE_SUFFIX,
377 Flags.HOMOTOPY_APPROACH,
378 Flags.IGNORE_REPLACEABLE,
379 Flags.LABELED_REDUCTION,
380 Flags.DISABLE_EXTRA_LABELING,
381 Flags.LOAD_MSL_MODEL,
382 Flags.LOAD_PACKAGE_FILE,
383 Flags.BUILDING_FMU,
384 Flags.BUILDING_MODEL,
385 Flags.POST_OPT_MODULES_DAE,
386 Flags.EVAL_LOOP_LIMIT,
387 Flags.EVAL_RECURSION_LIMIT,
388 Flags.SINGLE_INSTANCE_AGLSOLVER,
389 Flags.SHOW_STRUCTURAL_ANNOTATIONS,
390 Flags.INITIAL_STATE_SELECTION,
391 Flags.LINEARIZATION_DUMP_LANGUAGE,
392 Flags.NO_ASSC,
393 Flags.FULL_ASSC,
394 Flags.REAL_ASSC,
395 Flags.INIT_ASSC,
396 Flags.MAX_SIZE_ASSC,
397 Flags.USE_ZEROMQ_IN_SIM,
398 Flags.ZEROMQ_PUB_PORT,
399 Flags.ZEROMQ_SUB_PORT,
400 Flags.ZEROMQ_JOB_ID,
401 Flags.ZEROMQ_SERVER_ID,
402 Flags.ZEROMQ_CLIENT_ID,
403 Flags.FMI_VERSION,
404 Flags.BASE_MODELICA,
405 Flags.FMI_FILTER,
406 Flags.FMI_SOURCES,
407 Flags.FMI_FLAGS,
408 Flags.FMU_CMAKE_BUILD,
409 Flags.NEW_BACKEND,
410 Flags.PARMODAUTO,
411 Flags.INTERACTIVE_PORT,
412 Flags.ALLOW_NON_STANDARD_MODELICA,
413 Flags.EXPORT_CLOCKS_IN_MODELDESCRIPTION,
414 Flags.LINK_TYPE,
415 Flags.TEARING_ALWAYS_DERIVATIVES,
416 Flags.DUMP_FLAT_MODEL,
417 Flags.SIMULATION,
418 Flags.OBFUSCATE,
419 Flags.FMU_RUNTIME_DEPENDS,
420 Flags.FRONTEND_INLINE,
421 Flags.EXPOSE_LOCAL_IOS,
422 Flags.BASE_MODELICA_FORMAT,
423 Flags.BASE_MODELICA_OPTIONS,
424 Flags.DEBUG_FOLLOW_EQUATIONS,
425 Flags.MAX_SIZE_LINEARIZATION,
426 Flags.RESIZABLE_ARRAYS,
427 Flags.EVALUATE_STRUCTURAL_PARAMETERS,
428 Flags.LOAD_MISSING_LIBRARIES,
429 Flags.CAUSALIZE_DAE_MODE,
430 Flags.SIM_CODE_SCALARIZE,
431 Flags.EXECUTE_COMMAND,
432 Flags.MOO_DYNAMIC_OPTIMIZATION,
433 Flags.FMI_EXTRA_ANNOTATIONS,
434 Flags.INTERACTIVE_DUMP_FORMAT,
435 Flags.EXPORT_FMU,
436 Flags.FMU_TYPE,
437 Flags.FMU_PLATFORMS,
438 Flags.FMU_VERSION,
439 Flags.TEARING_COST_MARGIN,
440 Flags.FMU_NATIVE_PLATFORMS,
441 Flags.TPL_OUTPUT_DIR,
442 Flags.FMU_DIRECTORY,
443 Flags.TPL_INTERFACE_DIR
444 };
445
446 public function new
447 "Create a new flags structure and read the given arguments."
448 input list<String> inArgs;
449 output list<String> outArgs;
450 algorithm
451 2995 loadFlags();
452 2995 outArgs := readArgs(inArgs);
453 end new;
454
455 public function saveFlags
456 "Saves the flags with setGlobalRoot."
457 input Flags.Flag inFlags;
458 algorithm
459 122295 setGlobalRoot(Global.flagsIndex, inFlags);
460 end saveFlags;
461
462 public function createConfigFlags
463 output array<Flags.FlagData> configFlags;
464 algorithm
465
4/4
✓ Branch 0 taken 460444 times.
✓ Branch 1 taken 2677 times.
✓ Branch 2 taken 460444 times.
✓ Branch 3 taken 2677 times.
463121 configFlags := listArray(list(flag.defaultValue for flag in allConfigFlags));
466 end createConfigFlags;
467
468 public function createDebugFlags
469 output array<Boolean> debugFlags;
470 algorithm
471
4/4
✓ Branch 0 taken 538077 times.
✓ Branch 1 taken 2677 times.
✓ Branch 2 taken 538077 times.
✓ Branch 3 taken 2677 times.
540754 debugFlags := listArray(list(flag.default for flag in allDebugFlags));
472 end createDebugFlags;
473
474 public function loadFlags
475 "Loads the flags with getGlobalRoot. Creates a new flags structure if it
476 hasn't been created yet."
477 input Boolean initialize = true;
478 output Flags.Flag flags;
479 algorithm
480 try
481 122615 flags := Flags.getFlags();
482 else
483
1/2
✓ Branch 0 taken 2677 times.
✗ Branch 1 not taken.
2677 if initialize then
484 2677 checkDebugFlags();
485 2677 checkConfigFlags();
486 2677 flags := Flags.FLAGS(createDebugFlags(), createConfigFlags());
487 2677 saveFlags(flags);
488 // Not in Flags.TARGET itself: a constant's initialiser cannot reach
489 // another package. new() calls readArgs() after this, so --target wins.
490
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 2677 times.
2677 if StringUtil.startsWith(System.openModelicaPlatform(), "msvc") then
491 ✗ setConfigString(Flags.TARGET, "msvc");
492 end if;
493 else
494 ✗ print("Flag loading failed!\n");
495 flags := Flags.NO_FLAGS();
496 end if;
497 end try;
498 end loadFlags;
499
500 public function backupFlags
501 "Creates a copy of the existing flags."
502 output Flags.Flag outFlags;
503 protected
504 array<Boolean> debug_flags;
505 array<Flags.FlagData> config_flags;
506 algorithm
507
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 616 times.
616 Flags.FLAGS(debug_flags, config_flags) := loadFlags();
508 616 outFlags := Flags.FLAGS(arrayCopy(debug_flags), arrayCopy(config_flags));
509 end backupFlags;
510
511 public function resetDebugFlags
512 "Resets all debug flags to their default values."
513 protected
514 array<Boolean> debug_flags;
515 array<Flags.FlagData> config_flags;
516 algorithm
517 ✗ Flags.FLAGS(_, config_flags) := loadFlags();
518 ✗ debug_flags := createDebugFlags();
519 ✗ saveFlags(Flags.FLAGS(debug_flags, config_flags));
520 end resetDebugFlags;
521
522 public function resetConfigFlags
523 "Resets all configuration flags to their default values."
524 protected
525 array<Boolean> debug_flags;
526 array<Flags.FlagData> config_flags;
527 algorithm
528 ✗ Flags.FLAGS(debug_flags, _) := loadFlags();
529 ✗ config_flags := createConfigFlags();
530 ✗ saveFlags(Flags.FLAGS(debug_flags, config_flags));
531 end resetConfigFlags;
532
533 protected function checkDebugFlags
534 "Checks that the flags listed in allDebugFlags have sequential and unique indices."
535 protected
536 Integer index = 0;
537 String err_str;
538 algorithm
539
2/2
✓ Branch 0 taken 538077 times.
✓ Branch 1 taken 2677 times.
540754 for flag in allDebugFlags loop
540 538077 index := index + 1;
541
542 // If the flag indices are borked, print an error and terminate the compiler.
543 // Only failing here could cause an infinite loop of trying to load the flags.
544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 538077 times.
538077 if flag.index <> index then
545 ✗ err_str := "Invalid flag '" + flag.name + "' with index " + String(flag.index) + " (expected " + String(index) +
546 ") in Flags.allDebugFlags. Make sure that all flags are present and ordered correctly!";
547 ✗ Error.terminateError(err_str, sourceInfo());
548 end if;
549 end for;
550 end checkDebugFlags;
551
552 protected function checkConfigFlags
553 "Checks that the flags listed in allConfigFlags have sequential and unique indices."
554 protected
555 Integer index = 0;
556 String err_str;
557 algorithm
558
2/2
✓ Branch 0 taken 460444 times.
✓ Branch 1 taken 2677 times.
463121 for flag in allConfigFlags loop
559 460444 index := index + 1;
560
561 // If the flag indices are borked, print an error and terminate the compiler.
562 // Only failing here could cause an infinite loop of trying to load the flags.
563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460444 times.
460444 if flag.index <> index then
564 ✗ err_str := "Invalid flag '" + flag.name + "' with index " + String(flag.index) + " (expected " + String(index) +
565 ") in Flags.allConfigFlags. Make sure that all flags are present and ordered correctly!";
566 ✗ Error.terminateError(err_str, sourceInfo());
567 end if;
568 end for;
569 end checkConfigFlags;
570
571 public function set
572 "Sets the value of a debug flag, and returns the old value."
573 input Flags.DebugFlag inFlag;
574 input Boolean inValue;
575 output Boolean outOldValue;
576 protected
577 array<Boolean> debug_flags;
578 array<Flags.FlagData> config_flags;
579 algorithm
580
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20823 times.
20823 Flags.FLAGS(debug_flags, config_flags) := loadFlags();
581 20823 (debug_flags, outOldValue) := updateDebugFlagArray(debug_flags, inValue, inFlag);
582 20823 saveFlags(Flags.FLAGS(debug_flags, config_flags));
583 end set;
584
585 public function enableDebug
586 "Enables a debug flag."
587 input Flags.DebugFlag inFlag;
588 output Boolean outOldValue;
589 algorithm
590 ✗ outOldValue := set(inFlag, true);
591 end enableDebug;
592
593 public function disableDebug
594 "Disables a debug flag."
595 input Flags.DebugFlag inFlag;
596 output Boolean outOldValue;
597 algorithm
598 1754 outOldValue := set(inFlag, false);
599 end disableDebug;
600
601
602 function getConfigOptionsStringList
603 "Returns the valid options of a single-string configuration flag."
604 input Flags.ConfigFlag inFlag;
605 output list<String> outOptions;
606 output list<String> outComments;
607 algorithm
608 (outOptions,outComments) := match inFlag
609 local
610 list<tuple<String, String>> options;
611 list<String> flags;
612 case Flags.CONFIG_FLAG(validOptions=SOME(Flags.STRING_DESC_OPTION(options)))
613 ✗ then (List.map(options,Util.tuple21),List.map(options, Util.tuple22));
614 case Flags.CONFIG_FLAG(validOptions=SOME(Flags.STRING_OPTION(flags)))
615 ✗ then (flags,List.fill("",listLength(flags)));
616 end match;
617 end getConfigOptionsStringList;
618
619 protected function updateDebugFlagArray
620 "Updates the value of a debug flag in the debug flag array."
621 input array<Boolean> inFlags;
622 input Boolean inValue;
623 input Flags.DebugFlag inFlag;
624 output array<Boolean> outFlags;
625 output Boolean outOldValue;
626 protected
627 Integer index;
628 algorithm
629 22727 Flags.DEBUG_FLAG(index = index) := inFlag;
630 22727 outOldValue := arrayGet(inFlags, index);
631
2/2
✓ Branch 0 taken 9937 times.
✓ Branch 1 taken 12790 times.
32664 outFlags := arrayUpdate(inFlags, index, inValue);
632 end updateDebugFlagArray;
633
634 protected function updateConfigFlagArray
635 "Updates the value of a configuration flag in the configuration flag array."
636 input array<Flags.FlagData> inFlags;
637 input Flags.FlagData inValue;
638 input Flags.ConfigFlag inFlag;
639 output array<Flags.FlagData> outFlags;
640 protected
641 Integer index;
642 algorithm
643 101339 Flags.CONFIG_FLAG(index = index) := inFlag;
644 101339 outFlags := arrayUpdate(inFlags, index, inValue);
645 101339 applySideEffects(inFlag, inValue);
646 end updateConfigFlagArray;
647
648 public function readArgs
649 "Reads the command line arguments to the compiler and sets the flags
650 accordingly. Returns a list of arguments that were not consumed, such as the
651 model filename."
652 input list<String> inArgs;
653 output list<String> outArgs = {};
654 protected
655 Flags.Flag flags;
656 Integer numError;
657 String arg;
658 list<String> rest_args = inArgs;
659 algorithm
660 4515 numError := Error.getNumErrorMessages();
661 4515 flags := loadFlags();
662
663
2/2
✓ Branch 0 taken 14667 times.
✓ Branch 1 taken 4513 times.
19180 while not listEmpty(rest_args) loop
664 14667 arg :: rest_args := rest_args;
665
666
3/4
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 14633 times.
✓ Branch 3 taken 34 times.
✗ Branch 4 not taken.
14667 if arg == "--" then
667 // Stop parsing arguments if -- is encountered.
668 break;
669 else
670 14667 (rest_args, outArgs) := readArg(arg, flags, rest_args, outArgs);
671 end if;
672 end while;
673
674 4513 outArgs := List.append_reverse(outArgs, rest_args);
675 4513 List.map2(outArgs, System.iconv, "UTF-8", "UTF-8");
676 4513 Error.assertionOrAddSourceMessage(numError == Error.getNumErrorMessages(), Error.UTF8_COMMAND_LINE_ARGS, {}, Util.dummyInfo);
677 4513 saveFlags(flags);
678
679 // after reading all flags, handle the deprecated ones
680 4513 handleDeprecatedFlags();
681 end readArgs;
682
683 protected function readArg
684 "Reads a single command line argument. Returns true if the argument was
685 consumed, otherwise false."
686 input String inArg;
687 input Flags.Flag inFlags;
688 input output list<String> restArgs;
689 input output list<String> nonFlags;
690 protected
691 String flagtype;
692 Integer len;
693 algorithm
694 14667 flagtype := stringGetStringChar(inArg, 1);
695 14667 len := stringLength(inArg);
696
697 // Flags beginning with + can be both short and long, i.e. +h or +help.
698
3/4
✓ Branch 0 taken 14667 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 3293 times.
✓ Branch 4 taken 11374 times.
14667 if flagtype == "+" then
699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3293 times.
3293 if len == 1 then
700 // + alone is not a valid flag.
701 ✗ parseFlag(inArg, Flags.NO_FLAGS(), restArgs);
702 else
703 3293 restArgs := parseFlag(substring(inArg, 2, len), inFlags, restArgs, flagtype);
704 end if;
705 // Flags beginning with - must have another - for long flags, i.e. -h or --help.
706 elseif flagtype == "-" then
707
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8379 times.
8379 if len == 1 then
708 // - alone is not a valid flag.
709 ✗ parseFlag(inArg, Flags.NO_FLAGS(), restArgs);
710 elseif len == 2 then
711 // Short flag without argument, i.e. -h.
712 33 restArgs := parseFlag(substring(inArg, 2, 2), inFlags, restArgs, flagtype);
713 elseif stringGetStringChar(inArg, 2) == "-" then
714
3/6
✓ Branch 0 taken 6555 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 6555 times.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 6555 times.
6555 if len < 4 or stringGetStringChar(inArg, 4) == "=" then
715 // Short flags may not be used with --, i.e. --h or --h=debug.
716 ✗ parseFlag(inArg, Flags.NO_FLAGS(), restArgs);
717 else
718 // Long flag, i.e. --help or --help=debug.
719 6555 restArgs := parseFlag(substring(inArg, 3, len), inFlags, restArgs, "--");
720 end if;
721 else
722
2/4
✓ Branch 1 taken 1791 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1791 times.
✗ Branch 6 not taken.
1791 if stringGetStringChar(inArg, 3) == "=" then
723 // Short flag with argument, i.e. -h=debug.
724 1791 restArgs := parseFlag(substring(inArg, 2, len), inFlags, restArgs, flagtype);
725 else
726 // Long flag used with -, i.e. -help, which is not allowed.
727 ✗ parseFlag(inArg, Flags.NO_FLAGS(), restArgs);
728 end if;
729 end if;
730 else
731 // Arguments that don't begin with + or - are not flags, ignore them.
732 nonFlags := inArg :: nonFlags;
733 end if;
734 end readArg;
735
736 protected function parseFlag
737 "Parses a single flag."
738 input String inFlag;
739 input Flags.Flag inFlags;
740 input output list<String> restArgs;
741 input String inFlagPrefix = "";
742 protected
743 String flag;
744 list<String> values;
745 String value;
746 Boolean missing_value;
747 algorithm
748
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11672 times.
11672 flag :: values := System.strtok(inFlag, "=");
749 11672 value := stringAppendList(values);
750
3/4
✓ Branch 0 taken 295 times.
✓ Branch 1 taken 11377 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 295 times.
11672 missing_value := stringEmpty(value) and not StringUtil.endsWith(inFlag, "=");
751 11672 restArgs := parseConfigFlag(flag, value, inFlags, restArgs, inFlagPrefix, missing_value);
752 end parseFlag;
753
754 protected function parseConfigFlag
755 "Tries to look up the flag with the given name, and set it to the given value."
756 input String inFlag;
757 input String inValue;
758 input Flags.Flag inFlags;
759 input output list<String> restArgs;
760 input String inFlagPrefix;
761 input Boolean missingValue;
762 protected
763 Flags.ConfigFlag config_flag;
764 String value;
765 algorithm
766 11672 config_flag := lookupConfigFlag(inFlag, inFlagPrefix);
767
768
5/8
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 11377 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 293 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
11671 if missingValue and flagRequiresValue(config_flag) and not listEmpty(restArgs)
769 and not StringUtil.startsWith(listHead(restArgs), "-") then
770 // If no value was given using = and the flag requires a value,
771 // use the next argument as the value unless the next argument is another
772 // flag (starts with -).
773 ✗ value := listHead(restArgs);
774 ✗ restArgs := listRest(restArgs);
775 else
776 value := inValue;
777 end if;
778
779 11671 evaluateConfigFlag(config_flag, value, inFlags);
780 end parseConfigFlag;
781
782 protected function lookupConfigFlag
783 "Lookup up the flag with the given name in the list of configuration flags."
784 input String inFlag;
785 input String inFlagPrefix;
786 output Flags.ConfigFlag outFlag;
787 algorithm
788 try
789 11672 outFlag := List.getMemberOnTrue(inFlag, allConfigFlags, matchConfigFlag);
790 else
791 2 Error.addMessage(Error.UNKNOWN_OPTION, {inFlagPrefix + inFlag});
792 1 fail();
793 end try;
794 end lookupConfigFlag;
795
796 protected function configFlagEq
797 input Flags.ConfigFlag inFlag1;
798 input Flags.ConfigFlag inFlag2;
799 output Boolean eq;
800 algorithm
801 eq := match(inFlag1, inFlag2)
802 local
803 Integer index1, index2;
804 case(Flags.CONFIG_FLAG(index=index1), Flags.CONFIG_FLAG(index=index2))
805 58849 then index1 == index2;
806 end match;
807 end configFlagEq;
808
809 protected function flagRequiresValue
810 input Flags.ConfigFlag flag;
811 output Boolean requiresValue;
812 algorithm
813 requiresValue := match flag
814 case Flags.CONFIG_FLAG(defaultValue = Flags.BOOL_FLAG()) then false;
815 else true;
816 end match;
817 end flagRequiresValue;
818
819 protected function setAdditionalOptModules
820 input Flags.ConfigFlag inFlag;
821 input Flags.ConfigFlag inOppositeFlag;
822 input list<String> inValues;
823 protected
824 list<String> values;
825 algorithm
826
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 81 times.
164 for value in inValues loop
827 // remove value from inOppositeFlag
828 83 values := Flags.getConfigStringList(inOppositeFlag);
829 83 values := List.removeOnTrue(value, stringEq, values);
830 83 setConfigStringList(inOppositeFlag, values);
831
832 // add value to inFlag
833 83 values := Flags.getConfigStringList(inFlag);
834 83 values := List.removeOnTrue(value, stringEq, values);
835 83 setConfigStringList(inFlag, value::values);
836 end for;
837 end setAdditionalOptModules;
838
839 protected function evaluateConfigFlag
840 "Evaluates a given flag and it's arguments."
841 input Flags.ConfigFlag inFlag;
842 input String inValue;
843 input Flags.Flag inFlags;
844 algorithm
845 () := match(inFlag, inFlags)
846 local
847 array<Boolean> debug_flags;
848 array<Flags.FlagData> config_flags;
849 list<String> values;
850
851 // Special case for +d, +debug, set the given debug flags.
852 case (Flags.CONFIG_FLAG(index = 1), Flags.FLAGS(debugFlags = debug_flags))
853 algorithm
854 1811 List.map1_0(splitCSV(inValue), setDebugFlag, debug_flags);
855 then
856 ();
857
858 // Special case for +h, +help, show help text.
859 case (Flags.CONFIG_FLAG(index = 2), _)
860 algorithm
861 ✗ values := splitCSV(System.tolower(inValue));
862 ✗ print(printHelp(values));
863 ✗ setConfigString(Flags.HELP, "omc");
864 then
865 ();
866
867 // Special case for --preOptModules+=<value>
868 case (_, _) guard(configFlagEq(inFlag, Flags.PRE_OPT_MODULES_ADD))
869 algorithm
870 30 setAdditionalOptModules(Flags.PRE_OPT_MODULES_ADD, Flags.PRE_OPT_MODULES_SUB, splitCSV(inValue));
871 then
872 ();
873
874 // Special case for --preOptModules-=<value>
875 case (_, _) guard(configFlagEq(inFlag, Flags.PRE_OPT_MODULES_SUB))
876 algorithm
877 18 setAdditionalOptModules(Flags.PRE_OPT_MODULES_SUB, Flags.PRE_OPT_MODULES_ADD, splitCSV(inValue));
878 then
879 ();
880
881 // Special case for --postOptModules+=<value>
882 case (_, _) guard(configFlagEq(inFlag, Flags.POST_OPT_MODULES_ADD))
883 algorithm
884 25 setAdditionalOptModules(Flags.POST_OPT_MODULES_ADD, Flags.POST_OPT_MODULES_SUB, splitCSV(inValue));
885 then
886 ();
887
888 // Special case for --postOptModules-=<value>
889 case (_, _) guard(configFlagEq(inFlag, Flags.POST_OPT_MODULES_SUB))
890 algorithm
891 6 setAdditionalOptModules(Flags.POST_OPT_MODULES_SUB, Flags.POST_OPT_MODULES_ADD, splitCSV(inValue));
892 then
893 ();
894
895 // Special case for --initOptModules+=<value>
896 case (_, _) guard(configFlagEq(inFlag, Flags.INIT_OPT_MODULES_ADD))
897 algorithm
898 2 setAdditionalOptModules(Flags.INIT_OPT_MODULES_ADD, Flags.INIT_OPT_MODULES_SUB, splitCSV(inValue));
899 then
900 ();
901
902 // Special case for --initOptModules-=<value>
903 case (_, _) guard(configFlagEq(inFlag, Flags.INIT_OPT_MODULES_SUB))
904 algorithm
905 ✗ setAdditionalOptModules(Flags.INIT_OPT_MODULES_SUB, Flags.INIT_OPT_MODULES_ADD, splitCSV(inValue));
906 then
907 ();
908
909 // All other configuration flags, set the flag to the given values.
910 case (_, Flags.FLAGS(configFlags = config_flags))
911 algorithm
912 9779 setConfigFlag(inFlag, config_flags, inValue);
913 then
914 ();
915
916 end match;
917 end evaluateConfigFlag;
918
919 protected function setDebugFlag
920 "Enables a debug flag given as a string, or disables it if it's prefixed with -."
921 input String inFlag;
922 input array<Boolean> inFlags;
923 protected
924 Boolean negated,neg1,neg2;
925 String flag_str;
926 algorithm
927
3/4
✓ Branch 1 taken 1905 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 724 times.
✓ Branch 6 taken 1181 times.
1905 neg1 := stringEq(stringGetStringChar(inFlag, 1), "-");
928 1905 neg2 := System.strncmp("no",inFlag,2) == 0;
929 1905 negated := neg1 or neg2;
930
2/2
✓ Branch 0 taken 1364 times.
✓ Branch 1 taken 541 times.
1905 flag_str := if negated then StringUtil.rest(inFlag) else inFlag;
931
2/2
✓ Branch 0 taken 183 times.
✓ Branch 1 taken 1722 times.
1905 flag_str := if neg2 then StringUtil.rest(flag_str) else flag_str;
932 1905 setDebugFlag2(flag_str, not negated, inFlags);
933 end setDebugFlag;
934
935 protected function setDebugFlag2
936 input String inFlag;
937 input Boolean inValue;
938 input array<Boolean> inFlags;
939 algorithm
940 () := matchcontinue inFlags
941 local
942 Flags.DebugFlag flag;
943
944 case _
945 algorithm
946 1905 flag := List.getMemberOnTrue(inFlag, allDebugFlags, matchDebugFlag);
947 1904 updateDebugFlagArray(inFlags, inValue, flag);
948 then
949 ();
950
951 else
952 algorithm
953 1 Error.addMessage(Error.UNKNOWN_DEBUG_FLAG, {inFlag});
954 1 then
955 fail();
956
957 end matchcontinue;
958 end setDebugFlag2;
959
960 protected function matchDebugFlag
961 "Returns true if the given flag has the given name, otherwise false."
962 input String inFlagName;
963 input Flags.DebugFlag inFlag;
964 output Boolean outMatches;
965 protected
966 String name;
967 algorithm
968 122111 Flags.DEBUG_FLAG(name = name) := inFlag;
969
4/4
✓ Branch 0 taken 6022 times.
✓ Branch 1 taken 116089 times.
✓ Branch 3 taken 4118 times.
✓ Branch 4 taken 1904 times.
122111 outMatches := stringEq(inFlagName, name);
970 end matchDebugFlag;
971
972 protected function matchConfigFlag
973 "Returns true if the given flag has the given name, otherwise false."
974 input String inFlagName;
975 input Flags.ConfigFlag inFlag;
976 output Boolean outMatches;
977 protected
978 Option<String> opt_shortname;
979 String name, shortname;
980 algorithm
981 // A configuration flag may have two names, one long and one short.
982 452273 Flags.CONFIG_FLAG(name = name, shortname = opt_shortname) := inFlag;
983 452273 shortname := Util.getOptionOrDefault(opt_shortname, "");
984
8/8
✓ Branch 0 taken 2759 times.
✓ Branch 1 taken 449514 times.
✓ Branch 3 taken 794 times.
✓ Branch 4 taken 1965 times.
✓ Branch 7 taken 21542 times.
✓ Branch 8 taken 428766 times.
✓ Branch 12 taken 9706 times.
✓ Branch 13 taken 11836 times.
452273 outMatches := stringEq(inFlagName, shortname) or
985 stringEq(System.tolower(inFlagName), System.tolower(name));
986 end matchConfigFlag;
987
988 protected function setConfigFlag
989 "Sets the value of a configuration flag, where the value is given as a list of
990 strings."
991 input Flags.ConfigFlag inFlag;
992 input array<Flags.FlagData> inConfigData;
993 input String inValue;
994 protected
995 Flags.FlagData data, default_value;
996 String name;
997 Option<Flags.ValidOptions> validOptions;
998 algorithm
999 9779 Flags.CONFIG_FLAG(name = name, defaultValue = default_value, validOptions = validOptions) := inFlag;
1000 9779 data := stringFlagData(inValue, default_value, validOptions, name);
1001 9779 updateConfigFlagArray(inConfigData, data, inFlag);
1002 end setConfigFlag;
1003
1004 protected function stringFlagData
1005 "Converts a list of strings into a FlagData value. The expected type is also
1006 given so that the value can be typechecked."
1007 input String inValue;
1008 input Flags.FlagData inExpectedType;
1009 input Option<Flags.ValidOptions> validOptions;
1010 input String inName;
1011 output Flags.FlagData outValue;
1012 algorithm
1013 outValue := matchcontinue(inValue, inExpectedType, validOptions)
1014 local
1015 Boolean b;
1016 Integer i;
1017 list<Integer> ilst;
1018 String et, at;
1019 list<tuple<String, Integer>> enums;
1020 list<String> flags;
1021 Flags.ValidOptions options;
1022
1023 // No value, but a boolean flag => enable the flag.
1024 case ("", Flags.BOOL_FLAG(), _) then Flags.BOOL_FLAG(true);
1025
1026 // A boolean value.
1027 case (_, Flags.BOOL_FLAG(), _)
1028 algorithm
1029 38 b := Util.stringBool(inValue);
1030
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 7 times.
69 then
1031 Flags.BOOL_FLAG(b);
1032
1033 // An integer value.
1034 case (_, Flags.INT_FLAG(), _)
1035 algorithm
1036 3021 i := stringInt(inValue);
1037
2/4
✓ Branch 1 taken 3021 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3021 times.
✗ Branch 6 not taken.
3021 true := stringEq(intString(i), inValue);
1038 3021 then
1039 Flags.INT_FLAG(i);
1040
1041 // integer list.
1042 case (_, Flags.INT_LIST_FLAG(), _)
1043 algorithm
1044
4/4
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2 times.
6 ilst := list(stringInt(v) for v in splitCSV(inValue));
1045 2 then
1046 Flags.INT_LIST_FLAG(ilst);
1047
1048 // A real value.
1049 case (_, Flags.REAL_FLAG(), _)
1050 3 then Flags.REAL_FLAG(stringReal(inValue));
1051
1052 // A string value with valid options specified.
1053 case (_, Flags.STRING_FLAG(), SOME(options))
1054 algorithm
1055 206 flags := getValidStringOptions(options);
1056
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 true := listMember(inValue,flags);
1057 206 then Flags.STRING_FLAG(inValue);
1058
1059 // A string value without valid options specified.
1060 case (_, Flags.STRING_FLAG(), NONE())
1061 guard not stringEmpty(inValue)
1062 6006 then Flags.STRING_FLAG(inValue);
1063
1064 // A multiple-string value.
1065 36 case (_, Flags.STRING_LIST_FLAG(), _) then Flags.STRING_LIST_FLAG(splitCSV(inValue));
1066
1067 // No value, and an enumeration that spells one of its values "true": the flag
1068 // used to be a boolean one, so keep --flag meaning --flag=true.
1069 case ("", Flags.ENUM_FLAG(validValues = enums), _)
1070 algorithm
1071 ✗ i := Util.assoc("true", enums);
1072 ✗ then
1073 Flags.ENUM_FLAG(i, enums);
1074
1075 // An enumeration value.
1076 case (_, Flags.ENUM_FLAG(validValues = enums), _)
1077 algorithm
1078 174 i := Util.assoc(inValue, enums);
1079 174 then
1080 Flags.ENUM_FLAG(i, enums);
1081
1082 // Type mismatch, print error.
1083 case (_, _, NONE())
1084 algorithm
1085 ✗ et := printExpectedTypeStr(inExpectedType);
1086 ✗ at := printActualTypeStr(inValue);
1087 ✗ Error.addMessage(Error.INVALID_FLAG_TYPE, {inName, et, at});
1088 ✗ then
1089 fail();
1090
1091 case (_, _, SOME(options))
1092 algorithm
1093 ✗ flags := getValidStringOptions(options);
1094 ✗ et := stringDelimitList(flags, ", ");
1095 ✗ at := printActualTypeStr(inValue);
1096 ✗ Error.addMessage(Error.INVALID_FLAG_TYPE_STRINGS, {inName, et, at});
1097 ✗ then
1098 fail();
1099
1100 end matchcontinue;
1101 end stringFlagData;
1102
1103 protected function printExpectedTypeStr
1104 "Prints the expected type as a string."
1105 input Flags.FlagData inType;
1106 output String outTypeStr;
1107 algorithm
1108 outTypeStr := match inType
1109 local
1110 list<tuple<String, Integer>> enums;
1111 list<String> enum_strs;
1112
1113 case Flags.BOOL_FLAG() then "a boolean value";
1114 case Flags.INT_FLAG() then "an integer value";
1115 case Flags.REAL_FLAG() then "a floating-point value";
1116 case Flags.STRING_FLAG() then "a string";
1117 case Flags.STRING_LIST_FLAG() then "a comma-separated list of strings";
1118 case Flags.ENUM_FLAG(validValues = enums)
1119 algorithm
1120 ✗ enum_strs := List.map(enums, Util.tuple21);
1121 ✗ then
1122 "one of the values {" + stringDelimitList(enum_strs, ", ") + "}";
1123 end match;
1124 end printExpectedTypeStr;
1125
1126 protected function printActualTypeStr
1127 "Prints the actual type as a string."
1128 input String inType;
1129 output String outTypeStr;
1130 algorithm
1131 outTypeStr := matchcontinue inType
1132 local
1133 Integer i;
1134
1135 case "" then "nothing";
1136 ✗ case _ algorithm Util.stringBool(inType); then "the boolean value " + inType;
1137 case _
1138 algorithm
1139 ✗ i := stringInt(inType);
1140 // intString returns 0 on failure, so this is to make sure that it
1141 // actually succeeded.
1142 ✗ true := stringEq(intString(i), inType);
1143 ✗ then
1144 "the number " + intString(i);
1145 //case {s}
1146 // equation
1147 // stringReal(s);
1148 // then
1149 // "the number " + intString(i);
1150 ✗ else "the string \"" + inType + "\"";
1151 end matchcontinue;
1152 end printActualTypeStr;
1153
1154 protected function configFlagsIsEqualIndex
1155 "Checks if two config flags have the same index."
1156 input Flags.ConfigFlag inFlag1;
1157 input Flags.ConfigFlag inFlag2;
1158 output Boolean outEqualIndex;
1159 protected
1160 Integer index1, index2;
1161 algorithm
1162 101339 Flags.CONFIG_FLAG(index = index1) := inFlag1;
1163 ✗ Flags.CONFIG_FLAG(index = index2) := inFlag2;
1164 ✗ outEqualIndex := intEq(index1, index2);
1165 end configFlagsIsEqualIndex;
1166
1167 protected function handleDeprecatedFlags
1168 "Gives warnings when deprecated flags are used. Sets newer flags if
1169 appropriate."
1170 protected
1171 list<String> remaining_flags;
1172 algorithm
1173 // At some point in the future remove all these flags and do the checks in
1174 // parseConfigFlag or something like that...
1175
1176 // DEBUG FLAGS
1177
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4513 times.
4513 if Flags.isSet(Flags.NF_UNITCHECK) then
1178 ✗ disableDebug(Flags.NF_UNITCHECK);
1179 ✗ setConfigBool(Flags.UNIT_CHECKING, true);
1180 ✗ Error.addMessage(Error.DEPRECATED_FLAG, {"-d=frontEndUnitCheck", "--unitChecking"});
1181 end if;
1182
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4513 times.
4513 if Flags.isSet(Flags.OLD_FE_UNITCHECK) then
1183 ✗ disableDebug(Flags.OLD_FE_UNITCHECK);
1184 ✗ setConfigBool(Flags.UNIT_CHECKING, true);
1185 ✗ Error.addMessage(Error.DEPRECATED_FLAG, {"-d=oldFrontEndUnitCheck", "--unitChecking"});
1186 end if;
1187
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4513 times.
4513 if Flags.isSet(Flags.INTERACTIVE_TCP) then
1188 ✗ disableDebug(Flags.INTERACTIVE_TCP);
1189 ✗ setConfigString(Flags.INTERACTIVE, "tcp");
1190 ✗ Error.addMessage(Error.DEPRECATED_FLAG, {"-d=interactive", "--interactive=tcp"});
1191 // The error message might get lost, so also print it directly here.
1192 ✗ print("The flag -d=interactive is depreciated. Please use --interactive=tcp instead.\n");
1193 end if;
1194 // add other deprecated flags here...
1195
1196 // CONFIG_FLAGS
1197
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 4513 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
4513 if Flags.getConfigString(Flags.TEARING_METHOD) == "noTearing" then
1198 ✗ setConfigString(Flags.TEARING_METHOD, "minimalTearing");
1199 ✗ Error.addMessage(Error.DEPRECATED_FLAG, {"--tearingMethod=noTearing", "--tearingMethod=minimalTearing"});
1200 end if;
1201 remaining_flags := {};
1202
2/2
✓ Branch 1 taken 63143 times.
✓ Branch 2 taken 4513 times.
67656 for flag in Flags.getConfigStringList(Flags.PRE_OPT_MODULES) loop
1203
3/4
✓ Branch 0 taken 4510 times.
✓ Branch 1 taken 58633 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4510 times.
63143 if flag == "unitChecking" then
1204 ✗ setConfigBool(Flags.UNIT_CHECKING, true);
1205 ✗ Error.addMessage(Error.DEPRECATED_FLAG, {"--preOptModules=unitChecking", "--unitChecking"});
1206 //elseif flag ==
1207 // add other deprecated flags here...
1208 else
1209 remaining_flags := flag :: remaining_flags;
1210 end if;
1211 end for;
1212 4513 setConfigStringList(Flags.PRE_OPT_MODULES, listReverse(remaining_flags));
1213 remaining_flags := {};
1214
2/2
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 4513 times.
4545 for flag in Flags.getConfigStringList(Flags.PRE_OPT_MODULES_ADD) loop
1215
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
32 if flag == "unitChecking" then
1216 ✗ setConfigBool(Flags.UNIT_CHECKING, true);
1217 ✗ Error.addMessage(Error.DEPRECATED_FLAG, {"--preOptModules+=unitChecking", "--unitChecking"});
1218 //elseif flag ==
1219 // add other deprecated flags here...
1220 else
1221 remaining_flags := flag :: remaining_flags;
1222 end if;
1223 end for;
1224 4513 setConfigStringList(Flags.PRE_OPT_MODULES_ADD, listReverse(remaining_flags));
1225 // add other deprecated flags here...
1226 end handleDeprecatedFlags;
1227
1228 protected function applySideEffects
1229 "Some flags have side effects, which are handled by this function."
1230 input Flags.ConfigFlag inFlag;
1231 input Flags.FlagData inValue;
1232 algorithm
1233 () := matchcontinue inValue
1234 local
1235 Boolean value;
1236
1237 // +showErrorMessages needs to be sent to the C runtime.
1238 case _
1239 algorithm
1240
1/2
✓ Branch 0 taken 101339 times.
✗ Branch 1 not taken.
101339 true := configFlagsIsEqualIndex(inFlag, Flags.SHOW_ERROR_MESSAGES);
1241 ✗ Flags.BOOL_FLAG(data = value) := inValue;
1242 ✗ ErrorExt.setShowErrorMessages(value);
1243 then
1244 ();
1245
1246 else ();
1247 end matchcontinue;
1248 end applySideEffects;
1249
1250 public function setConfigValue
1251 "Sets the value of a configuration flag."
1252 input Flags.ConfigFlag inFlag;
1253 input Flags.FlagData inValue;
1254 protected
1255 array<Boolean> debug_flags;
1256 array<Flags.FlagData> config_flags;
1257 Flags.Flag flags;
1258 algorithm
1259 91560 flags := loadFlags();
1260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 91560 times.
91560 Flags.FLAGS(debug_flags, config_flags) := flags;
1261 91560 config_flags := updateConfigFlagArray(config_flags, inValue, inFlag);
1262 91560 saveFlags(Flags.FLAGS(debug_flags, config_flags));
1263 end setConfigValue;
1264
1265 public function setConfigBool
1266 "Sets the value of a boolean configuration flag."
1267 input Flags.ConfigFlag inFlag;
1268 input Boolean inValue;
1269 algorithm
1270
2/2
✓ Branch 0 taken 74645 times.
✓ Branch 1 taken 6888 times.
156178 setConfigValue(inFlag, Flags.BOOL_FLAG(inValue));
1271 end setConfigBool;
1272
1273 public function setConfigInt
1274 "Sets the value of an integer configuration flag."
1275 input Flags.ConfigFlag inFlag;
1276 input Integer inValue;
1277 algorithm
1278 1 setConfigValue(inFlag, Flags.INT_FLAG(inValue));
1279 end setConfigInt;
1280
1281 public function setConfigReal
1282 "Sets the value of a real configuration flag."
1283 input Flags.ConfigFlag inFlag;
1284 input Real inValue;
1285 algorithm
1286 ✗ setConfigValue(inFlag, Flags.REAL_FLAG(inValue));
1287 end setConfigReal;
1288
1289 public function setConfigString
1290 "Sets the value of a string configuration flag."
1291 input Flags.ConfigFlag inFlag;
1292 input String inValue;
1293 algorithm
1294 206 setConfigValue(inFlag, Flags.STRING_FLAG(inValue));
1295 end setConfigString;
1296
1297 public function setConfigStringList
1298 "Sets the value of a multiple-string configuration flag."
1299 input Flags.ConfigFlag inFlag;
1300 input list<String> inValue;
1301 algorithm
1302 9280 setConfigValue(inFlag, Flags.STRING_LIST_FLAG(inValue));
1303 end setConfigStringList;
1304
1305 public function appendConfigStringList
1306 "Appends a value to a multiple-string configuration flag if the flag doesn't
1307 already contain it, and returns the old values of the flag."
1308 input Flags.ConfigFlag flag;
1309 input String value;
1310 output list<String> oldValues;
1311 algorithm
1312 ✗ oldValues := Flags.getConfigStringList(flag);
1313
1314 ✗ if not listMember(value, oldValues) then
1315 ✗ setConfigStringList(flag, value :: oldValues);
1316 end if;
1317 end appendConfigStringList;
1318
1319 public function setConfigEnum
1320 "Sets the value of an enumeration configuration flag."
1321 input Flags.ConfigFlag inFlag;
1322 input Integer inValue;
1323 protected
1324 list<tuple<String, Integer>> valid_values;
1325 algorithm
1326
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 540 times.
540 Flags.CONFIG_FLAG(defaultValue = Flags.ENUM_FLAG(validValues = valid_values)) := inFlag;
1327 540 setConfigValue(inFlag, Flags.ENUM_FLAG(inValue, valid_values));
1328 end setConfigEnum;
1329
1330 // Used by the print functions below to indent descriptions.
1331 protected constant String descriptionIndent = " ";
1332
1333 public function printHelp
1334 "Prints out help for the given list of topics."
1335 input list<String> inTopics;
1336 output String help;
1337 protected
1338 IOStream.IOStream s;
1339 algorithm
1340 help := matchcontinue inTopics
1341 local
1342 String desc;
1343 list<String> rest_topics, data;
1344 String str, name;
1345 Flags.ConfigFlag config_flag;
1346 list<tuple<String,String>> topics;
1347 Option<String> short_name;
1348
1349 ✗ case {} then printUsage();
1350
1351 ✗ case {"omc"} then printUsage();
1352
1353 ✗ case {"omcall-sphinxoutput"} then printUsageSphinxAll();
1354
1355 //case {"mos"} then "TODO: Write help-text";
1356
1357 case {"topics"}
1358 algorithm
1359 ✗ s := IOStream.create("topics");
1360 ✗ s := IOStream.append(s, "The available topics (help(\"topics\")) are as follows:\n");
1361
1362 topics := {
1363 //("mos","Help on the command-line and scripting environments, including OMShell and OMNotebook."),
1364 ("omc","The command-line options available for omc."),
1365 ("debug","Flags that enable debugging, diagnostics, and research prototypes."),
1366 ("optmodules","Flags that determine which symbolic methods are used to produce the causalized equation system."),
1367 ("simulation","The command-line options available for simulation executables generated by OpenModelica."),
1368 ("<flagname>","Displays option descriptions for flag <flagname>."),
1369 ("topics","This help-text.")
1370 };
1371
1372 ✗ s := IOStream.append(s, stringDelimitList(list(makeTopicString(t) for t in topics), "\n"));
1373 ✗ s := IOStream.append(s, "\n");
1374 ✗ then
1375 IOStream.string(s);
1376
1377 case {"simulation"}
1378 ✗ then "The simulation executable takes the following flags:\n\n" + System.getSimulationHelpText(true);
1379
1380 case {"simulation-sphinxoutput"}
1381 ✗ then "The simulation executable takes the following flags:\n\n" + System.getSimulationHelpText(true,sphinx=true);
1382
1383 case {"debug"}
1384 algorithm
1385 ✗ s := IOStream.create("debug");
1386 ✗ s := IOStream.append(s, "The debug flag takes a comma-separated list of flags which are used by the\ncompiler for debugging or experimental purposes.\nFlags prefixed with \"-\" or \"no\" will be disabled.\n");
1387 ✗ s := IOStream.append(s, "The available flags are (+ are enabled by default, - are disabled):\n\n");
1388 ✗ s := IOStream.appendList(s, list(printDebugFlag(flag) for flag in List.sort(allDebugFlags,compareDebugFlags)));
1389 ✗ then
1390 IOStream.string(s);
1391
1392 case {"optmodules"}
1393 algorithm
1394 ✗ s := IOStream.create("optmodules");
1395 // pre-optimization
1396 ✗ s := IOStream.append(s, wrapToTerminal("The --preOptModules flag sets the optimization modules which are used before the\nmatching and index reduction in the back end. These modules are specified as a comma-separated list."));
1397 Flags.CONFIG_FLAG(defaultValue=Flags.STRING_LIST_FLAG(data=data)) := Flags.PRE_OPT_MODULES;
1398 ✗ s := IOStream.append(s, "\n\nThe modules used by default are:\n--preOptModules=");
1399 ✗ s := IOStream.append(s, stringDelimitList(data, ","));
1400 ✗ s := IOStream.append(s, "\n\nThe valid modules are:\n");
1401 ✗ s := IOStream.append(s, printFlagValidOptionsDesc(Flags.PRE_OPT_MODULES));
1402 ✗ s := IOStream.append(s, "\n");
1403
1404 // matching
1405 ✗ s := IOStream.append(s, wrapToTerminal("\nThe --matchingAlgorithm sets the method that is used for the matching algorithm, after the pre optimization modules."));
1406 Flags.CONFIG_FLAG(defaultValue=Flags.STRING_FLAG(data=str)) := Flags.MATCHING_ALGORITHM;
1407 ✗ s := IOStream.append(s, "\n\nThe method used by default is:\n--matchingAlgorithm=");
1408 ✗ s := IOStream.append(s, str);
1409 ✗ s := IOStream.append(s, "\n\nThe valid methods are:\n");
1410 ✗ s := IOStream.append(s, printFlagValidOptionsDesc(Flags.MATCHING_ALGORITHM));
1411 ✗ s := IOStream.append(s, "\n");
1412
1413 // index reduction
1414 ✗ s := IOStream.append(s, wrapToTerminal("The --indexReductionMethod sets the method that is used for the index reduction, after the pre optimization modules."));
1415 Flags.CONFIG_FLAG(defaultValue=Flags.STRING_FLAG(data=str)) := Flags.INDEX_REDUCTION_METHOD;
1416 ✗ s := IOStream.append(s, "\n\nThe method used by default is:\n--indexReductionMethod=");
1417 ✗ s := IOStream.append(s, str);
1418 ✗ s := IOStream.append(s, "\n\nThe valid methods are:\n");
1419 ✗ s := IOStream.append(s, printFlagValidOptionsDesc(Flags.INDEX_REDUCTION_METHOD));
1420 ✗ s := IOStream.append(s, "\n");
1421
1422 // post-optimization (initialization)
1423 ✗ s := IOStream.append(s, wrapToTerminal("The --initOptModules then sets the optimization modules which are used after the index reduction to optimize the system for initialization, specified as a comma-separated list."));
1424 Flags.CONFIG_FLAG(defaultValue=Flags.STRING_LIST_FLAG(data=data)) := Flags.INIT_OPT_MODULES;
1425 ✗ s := IOStream.append(s, "\n\nThe modules used by default are:\n--initOptModules=" + stringDelimitList(data, ","));
1426 ✗ s := IOStream.append(s, "\n\nThe valid modules are:\n");
1427 ✗ s := IOStream.append(s, printFlagValidOptionsDesc(Flags.INIT_OPT_MODULES));
1428 ✗ s := IOStream.append(s, "\n");
1429
1430 // post-optimization (simulation)
1431 ✗ s := IOStream.append(s, wrapToTerminal("The --postOptModules then sets the optimization modules which are used after the index reduction to optimize the system for simulation, specified as a comma-separated list."));
1432 Flags.CONFIG_FLAG(defaultValue=Flags.STRING_LIST_FLAG(data=data)) := Flags.POST_OPT_MODULES;
1433 ✗ s := IOStream.append(s, "\n\nThe modules used by default are:\n--postOptModules=" + stringDelimitList(data, ","));
1434 ✗ s := IOStream.append(s, "\n\nThe valid modules are:\n");
1435 ✗ s := IOStream.append(s, printFlagValidOptionsDesc(Flags.POST_OPT_MODULES));
1436 ✗ s := IOStream.append(s, "\n");
1437 ✗ then
1438 IOStream.string(s);
1439
1440 case {str}
1441 algorithm
1442 ✗ s := IOStream.create("flag");
1443 ✗ config_flag as Flags.CONFIG_FLAG(name=name, shortname=short_name, description=desc) := List.getMemberOnTrue(str, allConfigFlags, matchConfigFlag);
1444
1445 ✗ if isSome(short_name) then
1446 ✗ s := IOStream.append(s, "-" + Util.getOption(short_name) + ", ");
1447 end if;
1448
1449 ✗ s := IOStream.append(s, "--" + name);
1450 ✗ s := IOStream.append(s, "\n");
1451 ✗ s := IOStream.append(s, wrapToTerminal(desc));
1452 ✗ s := IOStream.append(s, "\n\n");
1453 ✗ s := IOStream.append(s, "Valid arguments:\n");
1454 ✗ s := IOStream.append(s, printFlagValidOptionsDesc(config_flag));
1455 ✗ s := IOStream.append(s, "\n");
1456 ✗ then
1457 IOStream.string(s);
1458
1459 case {str}
1460 ✗ then "I'm sorry, I don't know what " + str + " is.\n";
1461
1462 case str :: (rest_topics as _::_)
1463 algorithm
1464 ✗ str := printHelp({str}) + "\n";
1465 ✗ help := printHelp(rest_topics);
1466 ✗ then str + help;
1467
1468 end matchcontinue;
1469 end printHelp;
1470
1471 public function getValidOptionsAndDescription
1472 input String flagName;
1473 output list<String> validStrings;
1474 output String mainDescriptionStr;
1475 output list<String> descriptions;
1476 protected
1477 Flags.ValidOptions validOptions;
1478 String mainDescription;
1479 algorithm
1480 ✗ Flags.CONFIG_FLAG(description=mainDescription,validOptions=SOME(validOptions)) := List.getMemberOnTrue(flagName, allConfigFlags, matchConfigFlag);
1481 mainDescriptionStr := mainDescription;
1482 ✗ (validStrings,descriptions) := getValidOptionsAndDescription2(validOptions);
1483 end getValidOptionsAndDescription;
1484
1485 protected function getValidOptionsAndDescription2
1486 input Flags.ValidOptions validOptions;
1487 output list<String> validStrings;
1488 output list<String> descriptions;
1489 algorithm
1490 (validStrings,descriptions) := match validOptions
1491 local
1492 list<tuple<String,String>> options;
1493 case Flags.STRING_OPTION(validStrings) then (validStrings,{});
1494 case Flags.STRING_DESC_OPTION(options)
1495 algorithm
1496 ✗ validStrings := List.map(options,Util.tuple21);
1497 ✗ descriptions := List.map(options,Util.tuple22);
1498 then (validStrings,descriptions);
1499 end match;
1500 end getValidOptionsAndDescription2;
1501
1502 protected function compareDebugFlags
1503 input Flags.DebugFlag flag1;
1504 input Flags.DebugFlag flag2;
1505 output Boolean b;
1506 protected
1507 String name1,name2;
1508 algorithm
1509 ✗ Flags.DEBUG_FLAG(name=name1) := flag1;
1510 ✗ Flags.DEBUG_FLAG(name=name2) := flag2;
1511 ✗ b := stringCompare(name1,name2) > 0;
1512 end compareDebugFlags;
1513
1514 protected function makeTopicString
1515 input tuple<String,String> topic;
1516 output String str;
1517 protected
1518 String str1,str2;
1519 algorithm
1520 ✗ (str1,str2) := topic;
1521 ✗ str1 := Util.stringPadRight(str1,13," ");
1522 ✗ str := stringAppendList(StringUtil.wordWrap(str1 + str2, System.getTerminalWidth(), "\n "));
1523 end makeTopicString;
1524
1525 public function printUsage
1526 "Prints out the usage text for the compiler."
1527 output String usage;
1528 algorithm
1529 ✗ Print.clearBuf();
1530 ✗ Print.printBuf("OpenModelica Compiler "); Print.printBuf(Settings.getVersionNr()); Print.printBuf("\n");
1531 ✗ Print.printBuf("Copyright © 2019 Open Source Modelica Consortium (OSMC)\n");
1532 ✗ Print.printBuf("Distributed under OSMC-PL and AGPL3, see www.openmodelica.org\n\n");
1533 //Print.printBuf("Please check the System Guide for full information about flags.\n");
1534 ✗ Print.printBuf("Usage: omc [Options] (Model.mo | Script.mos) [Libraries | .mo-files]\n* Libraries: Fully qualified names of libraries to load before processing Model or Script.\n The libraries should be separated by spaces: Lib1 Lib2 ... LibN.\n");
1535 ✗ Print.printBuf("\n* Options:\n");
1536 ✗ Print.printBuf(printAllConfigFlags());
1537 ✗ Print.printBuf("\nFor more details on a specific topic, use --help=topics or help(\"topics\")\n\n");
1538 ✗ Print.printBuf("* Examples:\n");
1539 ✗ Print.printBuf(" omc Model.mo will produce flattened Model on standard output.\n");
1540 ✗ Print.printBuf(" omc -s Model.mo will produce simulation code for the model:\n");
1541 ✗ Print.printBuf(" * Model.c The model C code.\n");
1542 ✗ Print.printBuf(" * Model_functions.c The model functions C code.\n");
1543 ✗ Print.printBuf(" * Model.makefile The makefile to compile the model.\n");
1544 ✗ Print.printBuf(" * Model_init.xml The initial values.\n");
1545 //Print.printBuf("\tomc Model.mof will produce flattened Model on standard output\n");
1546 ✗ Print.printBuf(" omc Script.mos will run the commands from Script.mos.\n");
1547 ✗ Print.printBuf(" omc Model.mo Modelica will first load the Modelica library and then produce\n flattened Model on standard output.\n");
1548 ✗ Print.printBuf(" omc Model1.mo Model2.mo will load both Model1.mo and Model2.mo, and produce\n flattened Model1 on standard output.\n");
1549 ✗ Print.printBuf(" omc --export-fmu -i MyPackage.Examples.Hello --fmiVersion=2.0\n ./MyPackage/package.mo\n will load the local package and export the model as an FMU.\n");
1550 ✗ Print.printBuf(" omc --export-fmu -i MyModel --fmiVersion=2.0 MyModel.mo Modelica\n will load MyModel.mo and the Modelica Standard Library,\n then export MyModel as an FMU.\n");
1551 ✗ Print.printBuf(" *.mo (Modelica files)\n");
1552 //Print.printBuf("\t*.mof (Flat Modelica files)\n");
1553 ✗ Print.printBuf(" *.mos (Modelica Script files)\n\n");
1554 ✗ Print.printBuf("For available simulation flags, use --help=simulation.\n\n");
1555 ✗ Print.printBuf("Documentation is available in the built-in package OpenModelica.Scripting or\nonline <https://build.openmodelica.org/Documentation/OpenModelica.Scripting.html>.\n");
1556 ✗ usage := Print.getString();
1557 ✗ Print.clearBuf();
1558 end printUsage;
1559
1560 public function printUsageSphinxAll
1561 "Prints out the usage text for the compiler."
1562 output String usage;
1563 protected
1564 String s;
1565 algorithm
1566 ✗ Print.clearBuf();
1567 s := "OpenModelica Compiler Flags";
1568 ✗ Print.printBuf("\n.. _openmodelica-compiler-flags :\n\n");
1569 ✗ Print.printBuf(s);
1570 ✗ Print.printBuf("\n");
1571 ✗ Print.printBuf(sum("=" for e in 1:stringLength(s)));
1572 ✗ Print.printBuf("\n");
1573 ✗ Print.printBuf("Usage: omc [Options] (Model.mo | Script.mos) [Libraries | .mo-files]\n\n* Libraries: Fully qualified names of libraries to load before processing Model or Script.\n The libraries should be separated by spaces: Lib1 Lib2 ... LibN.\n\n");
1574 ✗ Print.printBuf("\n.. _omcflags-options :\n\n");
1575 s := "Options";
1576 ✗ Print.printBuf(s);
1577 ✗ Print.printBuf("\n");
1578 ✗ Print.printBuf(sum("-" for e in 1:stringLength(s)));
1579 ✗ Print.printBuf("\n\n");
1580 ✗ for flag in allConfigFlags loop
1581 ✗ Print.printBuf(printConfigFlagSphinx(flag));
1582 end for;
1583
1584 ✗ Print.printBuf("\n.. _omcflag-debug-section:\n\n");
1585 s := "Debug flags";
1586 ✗ Print.printBuf(s);
1587 ✗ Print.printBuf("\n");
1588 ✗ Print.printBuf(sum("-" for e in 1:stringLength(s)));
1589 ✗ Print.printBuf("\n\n");
1590 ✗ Print.printBuf("The debug flag takes a comma-separated list of flags which are used by the\ncompiler for debugging or experimental purposes.\nFlags prefixed with \"-\" or \"no\" will be disabled.\n");
1591 ✗ Print.printBuf("The available flags are (+ are enabled by default, - are disabled):\n\n");
1592 ✗ for flag in List.sort(allDebugFlags,compareDebugFlags) loop
1593 ✗ Print.printBuf(printDebugFlag(flag, sphinx=true));
1594 end for;
1595
1596 ✗ Print.printBuf("\n.. _omcflag-optmodules-section:\n\n");
1597 s := "Flags for Optimization Modules";
1598 ✗ Print.printBuf(s);
1599 ✗ Print.printBuf("\n");
1600 ✗ Print.printBuf(sum("-" for e in 1:stringLength(s)));
1601 ✗ Print.printBuf("\n\n");
1602
1603 ✗ Print.printBuf("Flags that determine which symbolic methods are used to produce the causalized equation system.\n\n");
1604
1605 ✗ Print.printBuf("The :ref:`--preOptModules <omcflag-preOptModules>` flag sets the optimization modules which are used before the\nmatching and index reduction in the back end. These modules are specified as a comma-separated list.");
1606 ✗ Print.printBuf("\n\n");
1607 ✗ Print.printBuf("The :ref:`--matchingAlgorithm <omcflag-matchingAlgorithm>` sets the method that is used for the matching algorithm, after the pre optimization modules.");
1608 ✗ Print.printBuf("\n\n");
1609 ✗ Print.printBuf("The :ref:`--indexReductionMethod <omcflag-indexReductionMethod>` sets the method that is used for the index reduction, after the pre optimization modules.");
1610 ✗ Print.printBuf("\n\n");
1611 ✗ Print.printBuf("The :ref:`--initOptModules <omcflag-initOptModules>` then sets the optimization modules which are used after the index reduction to optimize the system for initialization, specified as a comma-separated list.");
1612 ✗ Print.printBuf("\n\n");
1613 ✗ Print.printBuf("The :ref:`--postOptModules <omcflag-postOptModules>` then sets the optimization modules which are used after the index reduction to optimize the system for simulation, specified as a comma-separated list.");
1614 ✗ Print.printBuf("\n\n");
1615
1616 ✗ usage := Print.getString();
1617 ✗ Print.clearBuf();
1618 end printUsageSphinxAll;
1619
1620 public function printAllConfigFlags
1621 "Prints all configuration flags to a string."
1622 output String outString;
1623 algorithm
1624 ✗ outString := stringAppendList(List.map(allConfigFlags, printConfigFlag));
1625 end printAllConfigFlags;
1626
1627 protected function printConfigFlag
1628 "Prints a configuration flag to a string."
1629 input Flags.ConfigFlag inFlag;
1630 output String outString;
1631 algorithm
1632 outString := match inFlag
1633 local
1634 String desc;
1635 String name, desc_str, flag_str, delim_str, opt_str;
1636 list<String> wrapped_str;
1637
1638 case Flags.CONFIG_FLAG(visibility = Flags.INTERNAL()) then "";
1639
1640 case Flags.CONFIG_FLAG(description = desc)
1641 algorithm
1642 desc_str := desc;
1643 ✗ name := Util.stringPadRight(printConfigFlagName(inFlag), 28, " ");
1644 ✗ flag_str := stringAppendList({name, " ", desc_str});
1645 delim_str := descriptionIndent + " ";
1646 ✗ wrapped_str := StringUtil.wordWrap(flag_str, System.getTerminalWidth(), delim_str);
1647 ✗ opt_str := printValidOptions(inFlag);
1648 ✗ flag_str := stringDelimitList(wrapped_str, "\n") + opt_str + "\n";
1649 then
1650 flag_str;
1651
1652 end match;
1653 end printConfigFlag;
1654
1655 protected function printConfigFlagSphinx
1656 "Prints a configuration flag to a restructured text string."
1657 input Flags.ConfigFlag inFlag;
1658 output String outString;
1659 algorithm
1660 outString := match inFlag
1661 local
1662 String desc;
1663 String name, longName, desc_str, flag_str, opt_str;
1664
1665 case Flags.CONFIG_FLAG(visibility = Flags.INTERNAL()) then "";
1666
1667 case Flags.CONFIG_FLAG(description = desc)
1668 algorithm
1669 desc_str := desc;
1670 ✗ desc_str := System.stringReplace(desc_str, "--help=debug", ":ref:`--help=debug <omcflag-debug-section>`");
1671 ✗ desc_str := System.stringReplace(desc_str, "--help=optmodules", ":ref:`--help=optmodules <omcflag-optmodules-section>`");
1672 ✗ (name,longName) := printConfigFlagName(inFlag,sphinx=true);
1673 ✗ opt_str := printValidOptionsSphinx(inFlag);
1674 ✗ flag_str := stringAppendList({".. _omcflag-", longName, ":\n\n:ref:`", name, "<omcflag-",longName,">`\n\n", desc_str, "\n", opt_str + "\n"});
1675 then flag_str;
1676
1677 end match;
1678 end printConfigFlagSphinx;
1679
1680 protected function printConfigFlagName
1681 "Prints out the name of a configuration flag, formatted for use by
1682 printConfigFlag."
1683 input Flags.ConfigFlag inFlag;
1684 input Boolean sphinx=false;
1685 output String outString;
1686 output String longName;
1687 algorithm
1688 (outString,longName) := match inFlag
1689 local
1690 String name, shortname;
1691
1692 case Flags.CONFIG_FLAG(name = name, shortname = SOME(shortname))
1693 algorithm
1694 ✗ shortname := if sphinx then "-" + shortname else Util.stringPadLeft("-" + shortname, 4, " ");
1695 ✗ then (stringAppendList({shortname, ", --", name}), name);
1696
1697 case Flags.CONFIG_FLAG(name = name, shortname = NONE())
1698 ✗ then ((if sphinx then "--" else " --") + name, name);
1699
1700 end match;
1701 end printConfigFlagName;
1702
1703 protected function printValidOptions
1704 "Prints out the valid options of a configuration flag to a string."
1705 input Flags.ConfigFlag inFlag;
1706 output String outString;
1707 algorithm
1708 outString := match inFlag
1709 local
1710 list<String> strl;
1711 String opt_str;
1712 list<tuple<String, String>> descl;
1713
1714 case Flags.CONFIG_FLAG(validOptions = NONE()) then "";
1715 case Flags.CONFIG_FLAG(validOptions = SOME(Flags.STRING_OPTION(options = strl)))
1716 algorithm
1717 ✗ opt_str := descriptionIndent + " " + "Valid options:" + " " +
1718 stringDelimitList(strl, ", ");
1719 ✗ strl := StringUtil.wordWrap(opt_str, System.getTerminalWidth(), descriptionIndent + " ");
1720 ✗ opt_str := stringDelimitList(strl, "\n");
1721 ✗ opt_str := "\n" + opt_str;
1722 then
1723 opt_str;
1724 case Flags.CONFIG_FLAG(validOptions = SOME(Flags.STRING_DESC_OPTION(options = descl)))
1725 algorithm
1726 ✗ opt_str := "\n" + descriptionIndent + " " + "Valid options:" + "\n" +
1727 stringAppendList(list(printFlagOptionDescShort(d) for d in descl));
1728 then
1729 opt_str;
1730 end match;
1731 end printValidOptions;
1732
1733 protected function printValidOptionsSphinx
1734 "Prints out the valid options of a configuration flag to a string."
1735 input Flags.ConfigFlag inFlag;
1736 output String outString;
1737 algorithm
1738 outString := match inFlag
1739 local
1740 list<String> strl;
1741 String opt_str;
1742 list<tuple<String, String>> descl;
1743
1744 ✗ case Flags.CONFIG_FLAG(validOptions = NONE()) then "\n" + defaultFlagSphinx(inFlag.defaultValue) + "\n";
1745 case Flags.CONFIG_FLAG(validOptions = SOME(Flags.STRING_OPTION(options = strl)))
1746 algorithm
1747 ✗ opt_str := "\n" + defaultFlagSphinx(inFlag.defaultValue) + " " + "Valid options" + ":\n\n" +
1748 sum("* " + s + "\n" for s in strl);
1749 then opt_str;
1750 case Flags.CONFIG_FLAG(validOptions = SOME(Flags.STRING_DESC_OPTION(options = descl)))
1751 algorithm
1752 ✗ opt_str := "\n" + defaultFlagSphinx(inFlag.defaultValue) + " " + "Valid options" + ":\n\n" +
1753 sum(printFlagOptionDesc(s, sphinx=true) for s in descl);
1754 then
1755 opt_str;
1756 end match;
1757 end printValidOptionsSphinx;
1758
1759 protected function defaultFlagSphinx
1760 input Flags.FlagData flag;
1761 output String str;
1762 algorithm
1763 str := match flag
1764 local
1765 Integer i;
1766 ✗ case Flags.BOOL_FLAG() then "Boolean (default"+" ``" + boolString(flag.data) + "``).";
1767 ✗ case Flags.INT_FLAG() then "Integer (default"+" ``" + intString(flag.data) + "``).";
1768 ✗ case Flags.REAL_FLAG() then "Real (default"+" ``" + realString(flag.data) + "``).";
1769 case Flags.STRING_FLAG("") then "String (default *empty*).";
1770 ✗ case Flags.STRING_FLAG() then "String (default"+" " + flag.data + ").";
1771 case Flags.STRING_LIST_FLAG(data={}) then "String list (default *empty*).";
1772 ✗ case Flags.STRING_LIST_FLAG() then "String list (default"+" " + stringDelimitList(flag.data, ",") + ").";
1773 case Flags.ENUM_FLAG()
1774 algorithm
1775 ✗ for f in flag.validValues loop
1776 ✗ (str,i) := f;
1777 ✗ if i==flag.data then
1778 ✗ str := "String (default "+" " + str + ").";
1779 ✗ return;
1780 end if;
1781 end for;
1782 ✗ then "#ENUM_FLAG Failed#" + anyString(flag);
1783 ✗ else "Unknown default value" + anyString(flag);
1784 end match;
1785 end defaultFlagSphinx;
1786
1787 protected function printFlagOptionDescShort
1788 "Prints out the name of a flag option."
1789 input tuple<String, String> inOption;
1790 input Boolean sphinx=false;
1791 output String outString;
1792 protected
1793 String name;
1794 algorithm
1795 ✗ (name, _) := inOption;
1796 ✗ outString := (if sphinx then "* " else descriptionIndent + " * ") + name + "\n";
1797 end printFlagOptionDescShort;
1798
1799 protected function printFlagValidOptionsDesc
1800 "Prints out the names and descriptions of the valid options for a
1801 configuration flag."
1802 input Flags.ConfigFlag inFlag;
1803 output String outString;
1804 protected
1805 list<tuple<String, String>> desc_options;
1806 list<String> str_options;
1807 list<tuple<String, Integer>> enum_options;
1808 algorithm
1809 outString := match inFlag
1810 // String flag with a description for each valid option.
1811 case Flags.CONFIG_FLAG(validOptions = SOME(Flags.STRING_DESC_OPTION(options = desc_options)))
1812 ✗ then stringAppendList(list(printFlagOptionDesc(o) for o in desc_options));
1813
1814 // String flag with valid options but no descriptions.
1815 case Flags.CONFIG_FLAG(validOptions = SOME(Flags.STRING_OPTION(options = str_options)))
1816 ✗ then stringDelimitList(str_options, ", ");
1817
1818 // Enum flag.
1819 case Flags.CONFIG_FLAG(defaultValue = Flags.FlagData.ENUM_FLAG(validValues = enum_options))
1820 ✗ then stringDelimitList(list(Util.tuple21(v) for v in enum_options), ", ");
1821
1822 // For other flags, give a generic description of the type of value they expect.
1823 else
1824 match inFlag.defaultValue
1825 case Flags.FlagData.BOOL_FLAG() then "false, true";
1826 case Flags.FlagData.INT_FLAG() then "An Integer value.";
1827 case Flags.FlagData.INT_LIST_FLAG() then "A comma-separated list of Integer values.";
1828 case Flags.FlagData.REAL_FLAG() then "A Real value.";
1829 case Flags.FlagData.STRING_FLAG() then "A String value";
1830 case Flags.FlagData.STRING_LIST_FLAG() then "A comma-separated list of String values.";
1831 else "Unknown";
1832 end match;
1833 end match;
1834 end printFlagValidOptionsDesc;
1835
1836 protected function sphinxMathMode
1837 input String s;
1838 output String o = s;
1839 protected
1840 Integer i;
1841 list<String> strs;
1842 String s1,s2,s3;
1843 algorithm
1844 ✗ (i,strs) := System.regex(o, "^(.*)[$]([^$]*)[$](.*)$", 4, extended=true);
1845 ✗ if i==4 then
1846 ✗ _::s1::s2::s3::_ := strs;
1847 ✗ o := s1 + " :math:`" + s2 + "` " + s3;
1848 end if;
1849 end sphinxMathMode;
1850
1851 protected function removeSphinxMathMode
1852 input String s;
1853 output String o = s;
1854 protected
1855 Integer i;
1856 list<String> strs;
1857 algorithm
1858 ✗ (i,strs) := System.regex(o, "^(.*):math:`([^`]*)[`](.*)$", 4, extended=true);
1859 ✗ if i==4 then
1860 ✗ o := removeSphinxMathMode(stringAppendList(listRest(strs)));
1861 end if;
1862 end removeSphinxMathMode;
1863
1864 protected function printFlagOptionDesc
1865 "Helper function to printFlagValidOptionsDesc."
1866 input tuple<String, String> inOption;
1867 input Boolean sphinx=false;
1868 output String outString;
1869 protected
1870 String desc;
1871 String name, desc_str, str;
1872 algorithm
1873 ✗ (name, desc) := inOption;
1874 desc_str := desc;
1875 ✗ if sphinx then
1876 ✗ desc_str := sum(System.trim(s) for s in System.strtok(desc_str, "\n"));
1877 ✗ outString := "* " + name + " (" + desc_str + ")\n";
1878 else
1879 ✗ str := Util.stringPadRight(" * " + name + " ", 30, " ") + removeSphinxMathMode(desc_str);
1880 ✗ outString := stringDelimitList(
1881 StringUtil.wordWrap(str, System.getTerminalWidth(), descriptionIndent + " "), "\n") + "\n";
1882 end if;
1883 end printFlagOptionDesc;
1884
1885 protected function printDebugFlag
1886 "Prints out name and description of a debug flag."
1887 input Flags.DebugFlag inFlag;
1888 input Boolean sphinx=false;
1889 output String outString;
1890 protected
1891 String desc;
1892 String name, desc_str;
1893 Boolean default;
1894 algorithm
1895 ✗ Flags.DEBUG_FLAG(default = default, name = name, description = desc) := inFlag;
1896 desc_str := desc;
1897 ✗ if sphinx then
1898 ✗ desc_str := stringDelimitList(list(System.trim(s) for s in System.strtok(desc_str, "\n")), "\n ");
1899 ✗ outString := "\n.. _omcflag-debug-"+name+":\n\n" +
1900 ":ref:`" + name + " <omcflag-debug-"+name+">`" +
1901 " (default: "+(if default then "on" else "off")+")\n " + desc_str + "\n";
1902 else
1903 ✗ outString := Util.stringPadRight((if default then " + " else " - ") + name + " ", 26, " ") + removeSphinxMathMode(desc_str);
1904 ✗ outString := stringDelimitList(StringUtil.wordWrap(outString, System.getTerminalWidth(),
1905 descriptionIndent), "\n") + "\n";
1906 end if;
1907 end printDebugFlag;
1908
1909 public function debugFlagName
1910 "Prints out name of a debug flag."
1911 input Flags.DebugFlag inFlag;
1912 output String name;
1913 algorithm
1914 ✗ Flags.DEBUG_FLAG(name = name) := inFlag;
1915 end debugFlagName;
1916
1917 public function configFlagName
1918 "Prints out name of a debug flag."
1919 input Flags.ConfigFlag inFlag;
1920 output String name;
1921 algorithm
1922 ✗ Flags.CONFIG_FLAG(name = name) := inFlag;
1923 end configFlagName;
1924
1925 protected function getValidStringOptions
1926 input Flags.ValidOptions inOptions;
1927 output list<String> validOptions;
1928 algorithm
1929 validOptions := match inOptions
1930 local
1931 list<tuple<String, String>> options;
1932 case Flags.STRING_OPTION(validOptions) then validOptions;
1933 142 case Flags.STRING_DESC_OPTION(options) then List.map(options,Util.tuple21);
1934 end match;
1935 end getValidStringOptions;
1936
1937 public
1938 function flagDataEq
1939 input Flags.FlagData data1;
1940 input Flags.FlagData data2;
1941 output Boolean eq;
1942 algorithm
1943 eq := match (data1, data2)
1944 case (Flags.EMPTY_FLAG(), Flags.EMPTY_FLAG()) then true;
1945 ✗ case (Flags.BOOL_FLAG(), Flags.BOOL_FLAG()) then data1.data == data2.data;
1946 ✗ case (Flags.INT_FLAG(), Flags.INT_FLAG()) then data1.data == data2.data;
1947 case (Flags.INT_LIST_FLAG(), Flags.INT_LIST_FLAG())
1948 ✗ then List.isEqualOnTrue(data1.data, data2.data, intEq);
1949 ✗ case (Flags.REAL_FLAG(), Flags.REAL_FLAG()) then data1.data == data2.data;
1950 ✗ case (Flags.STRING_FLAG(), Flags.STRING_FLAG()) then data1.data == data2.data;
1951 case (Flags.STRING_LIST_FLAG(), Flags.STRING_LIST_FLAG())
1952 ✗ then List.isEqualOnTrue(data1.data, data2.data, stringEq);
1953 case (Flags.ENUM_FLAG(), Flags.ENUM_FLAG())
1954 ✗ then referenceEq(data1.validValues, data2.validValues) and
1955 data1.data == data2.data;
1956 else false;
1957 end match;
1958 end flagDataEq;
1959
1960 function flagDataString
1961 input Flags.FlagData flagData;
1962 output String str;
1963 algorithm
1964 str := match flagData
1965 local
1966 Integer v;
1967
1968 ✗ case Flags.BOOL_FLAG() then boolString(flagData.data);
1969 ✗ case Flags.INT_FLAG() then intString(flagData.data);
1970 case Flags.INT_LIST_FLAG()
1971 ✗ then List.toStringCustom(flagData.data, intString, "", "", ",", "", false);
1972
1973 ✗ case Flags.REAL_FLAG() then realString(flagData.data);
1974 ✗ case Flags.STRING_FLAG() then flagData.data;
1975 ✗ case Flags.STRING_LIST_FLAG() then stringDelimitList(flagData.data, ",");
1976 case Flags.ENUM_FLAG()
1977 algorithm
1978 ✗ for vt in flagData.validValues loop
1979 ✗ (str, v) := vt;
1980 ✗ if v == flagData.data then
1981 ✗ return;
1982 end if;
1983 end for;
1984 then
1985 "";
1986
1987 else "";
1988 end match;
1989 end flagDataString;
1990
1991 function unparseFlags
1992 "Goes through all the existing flags, and returns a list of all flags with
1993 values that differ from the default. The format of each string is flag=value."
1994 output list<String> flagStrings = {};
1995 protected
1996 array<Boolean> debug_flags;
1997 array<Flags.FlagData> config_flags;
1998 String name;
1999 list<String> strl = {};
2000 Boolean fvalue;
2001 algorithm
2002 try
2003 ✗ Flags.FLAGS(debugFlags = debug_flags, configFlags = config_flags) := loadFlags(false);
2004 else
2005 ✗ return;
2006 end try;
2007
2008 ✗ for f in allConfigFlags loop
2009 ✗ if not flagDataEq(f.defaultValue, config_flags[f.index]) then
2010 name := match f.shortname
2011 ✗ case SOME(name) then "-" + name;
2012 ✗ else "--" + f.name;
2013 end match;
2014
2015 ✗ flagStrings := (name + "=" + flagDataString(config_flags[f.index])) :: flagStrings;
2016 end if;
2017 end for;
2018
2019 ✗ for f in allDebugFlags loop
2020 ✗ fvalue := debug_flags[f.index];
2021 ✗ if f.default <> fvalue then
2022 ✗ name := if fvalue then f.name else "no" + f.name;
2023 strl := name :: strl;
2024 end if;
2025 end for;
2026
2027 ✗ if not listEmpty(strl) then
2028 ✗ flagStrings := "-d=" + stringDelimitList(strl, ",") :: flagStrings;
2029 end if;
2030 end unparseFlags;
2031
2032 function splitCSV
2033 input String value;
2034 output list<String> outValues = System.strtok(value, ",");
2035 end splitCSV;
2036
2037 function wrapToTerminal
2038 input String str;
2039 output String outStr = stringAppendList(StringUtil.wordWrap(str, System.getTerminalWidth(), "\n"));
2040 end wrapToTerminal;
2041
2042 public function applyNumProcEnvironment
2043 "Bound OpenBLAS's thread pool, which it sizes from the environment when it
2044 loads and which costs 128 MiB of address space per thread. An OpenMP build
2045 (the MSYS2 package used on Windows) ignores OPENBLAS_NUM_THREADS and reads
2046 only OMP_NUM_THREADS, so both are set. Called wherever -n is applied rather
2047 than from Main.init alone: a setCommandLineOptions is still ahead of whatever
2048 first loads the library."
2049 algorithm
2050
2/2
✓ Branch 1 taken 3575 times.
✓ Branch 2 taken 4 times.
3579 if Flags.getConfigInt(Flags.NUM_PROC) == 1 then
2051 4 System.setEnv("OPENBLAS_NUM_THREADS", "1", false);
2052 4 System.setEnv("OMP_NUM_THREADS", "1", false);
2053 end if;
2054 end applyNumProcEnvironment;
2055
2056 annotation(__OpenModelica_Interface="util");
2057 end FlagsUtil;
2058