Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 44.9% 127 / 0 / 283
Functions: 41.4% 108 / 1 / 262
Branches: 18.2% 8 / 0 / 44

OMCompiler/Compiler/Util/System.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 System
37 " file: System.mo
38 package: System
39 description: This file contains runtime system specific function, which are implemented in C.
40
41
42 This module contain a set of system calls, for e.g. compiling and
43 executing stuff, reading and writing files and so on."
44
45 protected
46 import Autoconf;
47 import Error;
48 import Settings;
49
50 1340234 public function trim
51 "removes chars in charsToRemove from begin and end of inString"
52 input String inString;
53 input String charsToRemove = " \f\n\r\t\v";
54 output String outString;
55
56 external "C" outString=System_trim(inString,charsToRemove) annotation(Library = "omcruntime");
57 end trim;
58
59 public function trimWhitespace
60 "removes chars in ' \f\n\r\t\v' from begin and end of inString"
61 input String inString;
62 output String outString;
63 algorithm
64 1295280 outString := trim(inString);
65 end trimWhitespace;
66
67 1298302 public function trimChar
68 input String inString1;
69 input String inString2;
70 output String outString;
71
72 external "C" outString=System_trimChar(inString1,inString2) annotation(Library = "omcruntime");
73 end trimChar;
74
75 3022 public function strcmp
76 "This function returns:
77 0 if inString1 == inString2
78 1 if inString1 > inString2
79 -1 if inString1 < inString2
80 This is different from what C strcmp
81 returns (negative values if <, positive values if >).
82 We fix negative values to -1 and positive to +1 so
83 we can pattern match on them directly in MetaModelica!"
84 input String inString1;
85 input String inString2;
86 output Integer outInteger;
87
88 external "C" outInteger=System_strcmp(inString1,inString2) annotation(Library = "omcruntime");
89 end strcmp;
90
91 ✗ public function strcmp_offset
92 "Like strcmp, but also takes offset and lengths of the strings in order to avoid building them through substring"
93 input String string1;
94 input Integer offset1;
95 input Integer length1;
96 input String string2;
97 input Integer offset2;
98 input Integer length2;
99 output Integer outInteger;
100
101 external "C" outInteger=System_strcmp_offset(string1,offset1,length1,string2,offset2,length2) annotation(Library = "omcruntime");
102 end strcmp_offset;
103
104 586071 public function stringFind "locates substring searchStr in str. If succeeds return position (starting from 0), otherwise return -1"
105 input String str;
106 input String searchStr;
107 output Integer outInteger;
108
109 external "C" outInteger=System_stringFind(str,searchStr) annotation(Library = "omcruntime");
110 end stringFind;
111
112 36374494 public function stringFindString "locates substring searchStr in str. If succeeds return the string, otherwise fail"
113 input String str;
114 input String searchStr;
115 output String outString;
116
117 external "C" outString=System_stringFindString(str,searchStr) annotation(Library = "omcruntime");
118 end stringFindString;
119
120 ✗ public function regex "Fails and sets Error.mo if the regex does not compile.
121
122 The returned result is the same as POSIX regex():
123 The first value is the complete matched string
124 The rest are the substrings that you wanted.
125 For example:
126 regex(lorem,\" \\([A-Za-z]*\\) \\([A-Za-z]*\\) \",maxMatches=3)
127 => {\" ipsum dolor \",\"ipsum\",\"dolor\"}
128 This means if you have n groups, you want maxMatches=n+1
129 "
130 input String str;
131 input String re;
132 input Integer maxMatches "The maximum number of matches that will be returned";
133 input Boolean extended=false "Use POSIX extended or regular syntax";
134 input Boolean ignoreCase=false;
135 output Integer numMatches "0 means no match, else returns a number 1..maxMatches (1 if maxMatches<0)";
136 output list<String> strs "This list has length = maxMatches. Substrings that did not match are filled with the empty string";
137
138 external "C" strs=System_regex(str,re,maxMatches,extended,ignoreCase,numMatches) annotation(Library = "omcruntime");
139 end regex;
140
141 2826104 public function strncmp
142 input String inString1;
143 input String inString2;
144 input Integer len;
145 output Integer outInteger;
146
147 external "C" outInteger=System_strncmp(inString1,inString2,len) annotation(Library = "omcruntime");
148 end strncmp;
149
150 8504901 public function stringReplace
151 input String str;
152 input String source;
153 input String target;
154 output String res;
155
156 external "C" res=System_stringReplace(str,source,target) annotation(Library = "omcruntime");
157 end stringReplace;
158
159 7559236 public function makeC89Identifier "Replaces unknown characters with _"
160 input String str;
161 output String res;
162
163 external "C" res=System_makeC89Identifier(str) annotation(Library = "omcruntime");
164 end makeC89Identifier;
165
166 45439 public function toupper
167 input String inString;
168 output String outString;
169
170 external "C" outString=System_toupper(inString) annotation(Library = "omcruntime");
171 end toupper;
172
173 946633 public function tolower
174 input String inString;
175 output String outString;
176
177 external "C" outString=System_tolower(inString) annotation(Library = "omcruntime");
178 end tolower;
179
180 946017 public function strtok
181 "Break string into a series of tokens using the delimiter token.
182 See strtok from C standard."
183 input String string;
184 input String token;
185 output list<String> strings;
186
187 external "C" strings=System_strtok(string,token) annotation(Library = "omcruntime");
188 end strtok;
189
190 217387 public function strtokIncludingDelimiters
191 "as strtok but also includes *all* delimiters
192 split the string at delimiters into a list of strings including *all* delimiters
193 stringSplitInTokens(*a**b*, *) => {*, a, *, *, b, *}"
194 input String string;
195 input String token;
196 output list<String> strings;
197
198 external "C" strings=System_strtokIncludingDelimiters(string,token) annotation(Library = "omcruntime");
199 end strtokIncludingDelimiters;
200
201 3 public function splitOnNewline
202 "Splits a string on new lines (\n and \r\n). If includeDelimiter is true then
203 the new line delimiters are included in the list as separate tokens.
204 splitOnNewline(a\nb\r\nc) = {a, b, c}
205 splitOnNewline(a\nb\r\nc, true) = {a, \n, b, \r\n, c}"
206 input String str;
207 input Boolean includeDelimiter = false;
208 output list<String> strings;
209
210 external "C" strings=System_splitOnNewline(str, includeDelimiter) annotation(Library = "omcruntime");
211 end splitOnNewline;
212
213 272505 public function setCCompiler
214 input String inString;
215
216 external "C" SystemImpl__setCCompiler(inString) annotation(Library = "omcruntime");
217 end setCCompiler;
218
219 1479 public function getCCompiler
220 output String outString;
221
222 external "C" outString=System_getCCompiler() annotation(Library = "omcruntime");
223 end getCCompiler;
224
225 1478 public function setCFlags
226 input String inString;
227
228 external "C" SystemImpl__setCFlags(inString) annotation(Library = "omcruntime");
229 end setCFlags;
230
231 1490 public function getCFlags
232 output String outString;
233
234 external "C" outString=System_getCFlags() annotation(Library = "omcruntime");
235 end getCFlags;
236
237 1488 public function setCXXCompiler
238 input String inString;
239
240 external "C" SystemImpl__setCXXCompiler(inString) annotation(Library = "omcruntime");
241 end setCXXCompiler;
242
243 1487 public function getCXXCompiler
244 output String outString;
245
246 external "C" outString=System_getCXXCompiler() annotation(Library = "omcruntime");
247 end getCXXCompiler;
248
249 1494 public function getOMPCCompiler
250 output String outString;
251
252 external "C" outString=System_getOMPCCompiler() annotation(Library = "omcruntime");
253 end getOMPCCompiler;
254
255 8 public function setLinker
256 input String inString;
257
258 external "C" SystemImpl__setLinker(inString) annotation(Library = "omcruntime");
259 end setLinker;
260
261 1486 public function getLinker
262 output String outString;
263
264 external "C" outString=System_getLinker() annotation(Library = "omcruntime");
265 end getLinker;
266
267 1486 public function setLDFlags
268 input String inString;
269
270 external "C" SystemImpl__setLDFlags(inString) annotation(Library = "omcruntime");
271 end setLDFlags;
272
273 1486 public function getLDFlags
274 output String outString;
275
276 external "C" outString=System_getLDFlags() annotation(Library = "omcruntime");
277 end getLDFlags;
278
279 1486 public function loadLibrary
280 "Loads and returns a handle to the library given by the filename. If the
281 filename is empty the returned handle will be for the whole program."
282 input String inLib;
283 input Boolean relativePath "If the path is relative or absolute";
284 input Boolean printDebug;
285 output Integer outLibHandle;
286
287 external "C" outLibHandle=System_loadLibrary(inLib, relativePath, printDebug) annotation(Library = "omcruntime");
288 end loadLibrary;
289
290 2037 public function loadLibraryLazy
291 "As loadLibrary, but binds symbols when they are used instead of when the
292 library is loaded, so a library that has an unresolvable symbol somewhere
293 else in it can still be asked for a function."
294 input String inLib;
295 input Boolean relativePath "If the path is relative or absolute";
296 input Boolean printDebug;
297 output Integer outLibHandle;
298
299 external "C" outLibHandle=System_loadLibraryLazy(inLib, relativePath, printDebug) annotation(Library = "omcruntime");
300 end loadLibraryLazy;
301
302 1877 public function getLoadLibraryError
303 "Why the last loadLibrary/loadLibraryLazy failed. Empty if it succeeded."
304 output String outError;
305
306 external "C" outError=System_getLoadLibraryError() annotation(Library = "omcruntime");
307 end getLoadLibraryError;
308
309 1870 public function lookupFunction
310 input Integer inLibHandle;
311 input String inFunc;
312 output Integer outFuncHandle;
313
314 external "C" outFuncHandle=System_lookupFunction(inLibHandle,inFunc) annotation(Library = "omcruntime");
315 end lookupFunction;
316
317 418 public function freeFunction
318 input Integer inFuncHandle;
319 input Boolean inPrintDebug;
320
321 external "C" System_freeFunction(inFuncHandle, inPrintDebug) annotation(Library = "omcruntime");
322 end freeFunction;
323
324 262 public function freeLibrary
325 input Integer inLibHandle;
326 input Boolean inPrintDebug;
327
328 external "C" System_freeLibrary(inLibHandle, inPrintDebug) annotation(Library = "omcruntime");
329 end freeLibrary;
330
331 165 public function writeFile
332 "This function will write to the file given by first argument the given string"
333 input String fileNameToWrite "a filename where to write the data";
334 input String stringToBeWritten "the data";
335 external "C" System_writeFile(fileNameToWrite,stringToBeWritten) annotation(Library = "omcruntime");
336 end writeFile;
337
338 4764 public function appendFile
339 input String file;
340 input String data;
341 external "C" System_appendFile(file,data) annotation(Library = "omcruntime");
342 end appendFile;
343
344 233642 public function readFile
345 "Does not fail. Returns strings describing the error instead."
346 input String inString;
347 output String outString;
348 external "C" outString = System_readFile(inString) annotation(Library = "omcruntime");
349 end readFile;
350
351 public function systemCallRestrictedEnv
352 "@author: adrpo
353 This function will call system with restricted environment to make sure we do not pick executables or dlls from the PATH.
354 Only keep the OM or OMDev directories and the Windows ones in the PATH for the system call.
355 After the execution the PATH will be set back."
356 input String command;
357 input String outFile = "" "empty file means no redirection unless it is part of the command";
358 output Integer outInteger;
359 protected
360 String savedPATH = "", newPATH = "", windowsPath = "", omInstallPath = "", omDevPath = "", pfix = "";
361 algorithm
362 if Autoconf.os == "Windows_NT" then
363 // save path
364 try
365 savedPATH := readEnv("PATH");
366 else
367 savedPATH := "";
368 Error.addInternalError(getInstanceName() + " failed for: " + command + "! Could not read PATH environment variable.", sourceInfo());
369 fail();
370 end try;
371 // construct restricted path
372 newPATH := "";
373 // keep the OM or OMDev directories and the Windows ones
374 windowsPath := System.stringReplace(winGetSystemDirectory(), "\\", "/");
375 omInstallPath := System.stringReplace(Settings.getInstallationDirectoryPath(), "\\", "/");
376 try
377 omDevPath := System.stringReplace(readEnv("OMDEV"), "\\", "/");
378 else
379 omDevPath := "";
380 end try;
381 for p in listReverse(strtok(savedPATH, ";")) loop
382 pfix := System.stringReplace(p, "\\", "/");
383 if (0 == stringFind(pfix, windowsPath)) or
384 (0 == stringFind(pfix, omInstallPath)) or
385 (0 == stringFind(pfix, omDevPath))
386 then
387 newPATH := p + ";" + newPATH;
388 end if;
389 end for;
390 if stringEqual(newPATH, "") then
391 Error.addInternalError(getInstanceName() + " failed for: " + command + "! Failed to filter the PATH: " + savedPATH, sourceInfo());
392 fail();
393 end if;
394 setEnv("PATH", newPATH, true);
395 try
396 outInteger := systemCall(command, outFile);
397 else
398 Error.addInternalError(getInstanceName() + " failed for: " + command + "! Failed in the system call with restricted PATH: " + newPATH, sourceInfo());
399 setEnv("PATH", savedPATH, true);
400 fail();
401 end try;
402 setEnv("PATH", savedPATH, true);
403 else
404 1367 outInteger := systemCall(command, outFile);
405 end if;
406 end systemCallRestrictedEnv;
407
408 public function winGetSystemDirectory "returns the Windows system directory on Windows and empty string on Linux"
409 output String outDirectory = "";
410 algorithm
411 outDirectory := "";
412 if Autoconf.os == "Windows_NT" then
413 outDirectory := winGetSystemDirectoryA();
414 end if;
415 end winGetSystemDirectory;
416
417 ✗ protected function winGetSystemDirectoryA
418 output String str;
419 external "C" str=SystemImpl__winGetSystemDirectoryA() annotation(Library = "omcruntime");
420 end winGetSystemDirectoryA;
421
422 ✗ public function systemCall
423 input String command;
424 input String outFile = "" "empty file means no redirection unless it is part of the command";
425 output Integer outInteger;
426 external "C" outInteger=SystemImpl__systemCall(command,outFile) annotation(Library = "omcruntime");
427 end systemCall;
428
429
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
3008 public function popen "Run the command and return the stdout as a string"
430 input String command;
431 output String contents;
432 output Integer status;
433 external "C" contents=System_popen(OpenModelica.threadData(), command, status) annotation(Library = "omcruntime");
434 end popen;
435
436 ✗ public function systemCallParallel
437 input list<String> inStrings;
438 input Integer numThreads;
439 output list<Integer> outIntegers;
440 external "C" outIntegers=SystemImpl__systemCallParallel(inStrings,numThreads) annotation(Library = "omcruntime");
441 end systemCallParallel;
442
443 ✗ public function spawnCall
444 input String path "The absolute path to the executable";
445 input String str "The list of arguments with executable";
446 output Integer outInteger;
447 external "C" outInteger=SystemImpl__spawnCall(path,str) annotation(Library = "omcruntime");
448 end spawnCall;
449
450 ✗ public function plotCallBackDefined
451 output Boolean outBoolean;
452 external "C" outBoolean=SystemImpl__plotCallBackDefined(OpenModelica.threadData()) annotation(Library = "omcruntime");
453 end plotCallBackDefined;
454
455 ✗ public function plotCallBack
456 input Boolean externalWindow;
457 input String filename;
458 input String title;
459 input String grid;
460 input String plotType;
461 input String logX;
462 input String logY;
463 input String xLabel;
464 input String yLabel;
465 input String x1;
466 input String x2;
467 input String y1;
468 input String y2;
469 input String curveWidth;
470 input String curveStyle;
471 input String legendPosition;
472 input String footer;
473 input String autoScale;
474 input String variables;
475 external "C" SystemImpl__plotCallBack(OpenModelica.threadData(), externalWindow, filename, title, grid, plotType, logX, logY, xLabel, yLabel, x1, x2, y1, y2, curveWidth, curveStyle, legendPosition, footer, autoScale, variables) annotation(Library = "omcruntime");
476 end plotCallBack;
477
478 ✗ public function loadModelCallBackDefined
479 output Boolean isDefined;
480 external "C"
481 isDefined=SystemImpl__loadModelCallBackDefined(OpenModelica.threadData()) annotation(Library = "omcruntime");
482 end loadModelCallBackDefined;
483
484 ✗ public function loadModelCallBack
485 input String modelName;
486 external "C" SystemImpl__loadModelCallBack(OpenModelica.threadData(), modelName) annotation(Library = "omcruntime");
487 end loadModelCallBack;
488
489 215 public function cd
490 input String inString;
491 output Integer outInteger;
492 external "C" outInteger=SystemImpl__chdir(inString) annotation(Library = "omcruntime");
493 end cd;
494
495 9 public function createDirectory
496 input String inString;
497 output Boolean outBool;
498 external "C" outBool=SystemImpl__createDirectory(inString) annotation(Library = "omcruntime");
499 end createDirectory;
500
501 1363 public function createTemporaryDirectory
502 input String inPrefix;
503 output String outName;
504 external "C" outName=SystemImpl__createTemporaryDirectory(inPrefix) annotation(Library = "omcruntime");
505 end createTemporaryDirectory;
506
507 4195 public function pwd
508 output String outString;
509 external "C" outString=SystemImpl__pwd() annotation(Library = "omcruntime");
510 end pwd;
511
512 4713 public function readEnv "Reads the environment variable given as string, fails if variable not found"
513 input String inString;
514 output String outString;
515 external "C" outString=System_readEnv(inString) annotation(Library = "omcruntime");
516 end readEnv;
517
518 3334 public function setEnv ""
519 input String varName;
520 input String value;
521 input Boolean overwrite "is always true on Windows, so recommended to always call it using true";
522 output Integer outInteger;
523 external "C" outInteger=setenv(varName,value,overwrite) annotation(Library = "omcruntime");
524 end setEnv;
525
526 2685 public function subDirectories
527 input String inString;
528 output list<String> outStringLst;
529 external "C" outStringLst=System_subDirectories(inString) annotation(Library = "omcruntime");
530 end subDirectories;
531
532 195647 public function moFiles
533 input String inString;
534 output list<String> outStringLst;
535 external "C" outStringLst=System_moFiles(inString) annotation(Library = "omcruntime");
536 end moFiles;
537
538 189608 public function mocFiles
539 input String inString;
540 output list<String> outStringLst;
541 external "C" outStringLst=System_mocFiles(inString) annotation(Library = "omcruntime");
542 end mocFiles;
543
544 ✗ public function getLoadModelPath
545 input String className;
546 input list<String> prios;
547 input list<String> mps;
548 input Boolean requireExactVersion = false;
549 output String dir;
550 output String name;
551 output Boolean isDir;
552 external "C" System_getLoadModelPath(className,prios,mps,requireExactVersion,dir,name,isDir) annotation(Library = "omcruntime");
553 end getLoadModelPath;
554
555 1912 public function time
556 output Real outReal;
557 external "C" outReal=SystemImpl__time() annotation(Library = "omcruntime");
558 end time;
559
560 ✗ public function regularFileExists
561 input String inString;
562 output Boolean outBool;
563 external "C" outBool = SystemImpl__regularFileExists(inString) annotation(Library = "omcruntime");
564 end regularFileExists;
565
566 2948115 public function regularFileReadable
567 input String inString;
568 output Boolean outBool;
569 external "C" outBool = SystemImpl__regularFileReadable(inString) annotation(Library = "omcruntime");
570 end regularFileReadable;
571
572 2024 public function regularFileWritable
573 input String inString;
574 output Boolean outBool;
575 external "C" outBool = SystemImpl__regularFileWritable(inString) annotation(Library = "omcruntime");
576 end regularFileWritable;
577
578 ✗ public function removeFile "Removes a file, returns 0 if suceeds, implemented using remove() in stdio.h"
579 input String fileName;
580 output Integer res;
581 external "C" res=SystemImpl__removeFile(fileName) annotation(Library = "omcruntime");
582 end removeFile;
583
584 1650 public function directoryExists
585 input String inString;
586 output Boolean outBool;
587 external "C" outBool=SystemImpl__directoryExists(inString) annotation(Library = "omcruntime");
588 end directoryExists;
589
590 2525189 public function copyFile
591 input String source;
592 input String destination;
593 output Boolean outBool;
594 external "C" outBool=SystemImpl__copyFile(source, destination) annotation(Library = "omcruntime");
595 end copyFile;
596
597 12579 public function copyPath "Copies a file, or a directory with everything in it, to destination, the path of the copy. An existing directory there is merged into."
598 input String source;
599 input String destination;
600 output Boolean success;
601 external "C" success=SystemImpl__copyPath(source, destination) annotation(Library = "omcruntime");
602 end copyPath;
603
604
605 public function removeDirectory
606 input String inString;
607 output Boolean outBool;
608 algorithm
609 outBool := System.removeDirectory_dispatch(inString);
610 // oh Windows crap: stat fails on very long paths!
611 if (not outBool) then
612 if Autoconf.os == "Windows_NT" then
613 // try rm as that somehow works on long paths
614 outBool := (0 == System.systemCall("rm -r " + inString));
615 end if;
616 end if;
617 end removeDirectory;
618
619 330 protected function removeDirectory_dispatch
620 input String inString;
621 output Boolean outBool;
622 external "C" outBool=SystemImpl__removeDirectory(inString) annotation(Library = "omcruntime");
623 end removeDirectory_dispatch;
624
625 ✗ public function getClassnamesForSimulation
626 output String outString;
627 external "C" outString=System_getClassnamesForSimulation() annotation(Library = "omcruntime");
628 end getClassnamesForSimulation;
629
630 ✗ public function setClassnamesForSimulation
631 input String inString;
632 external "C" System_setClassnamesForSimulation(inString) annotation(Library = "omcruntime");
633 end setClassnamesForSimulation;
634
635 ✗ public function getVariableValue
636 input Real timeStamp;
637 input list<Real> timeValues;
638 input list<Real> varValues;
639 output Real outValue;
640 external "C" outValue=System_getVariableValue(timeStamp,timeValues,varValues) annotation(Library = "omcruntime");
641 end getVariableValue;
642
643 ✗ public function getFileModificationTime
644 "@author adrpo
645 this system function returns the modification time of a file as a
646 SOME(Real) which represents the time elapsed since the
647 Epoch (00:00:00 UTC, January 1, 1970).
648 If the file does not exist or if there is an error the returned value
649 will be NONE.
650 "
651 input String fileName;
652 output Option<Real> outValue;
653 external "C" outValue=System_getFileModificationTime(fileName) annotation(Library = "omcruntime");
654 end getFileModificationTime;
655
656 16 public function getCurrentTime
657 "@author adrpo
658 this system function returns current time elapsed
659 since the Epoch (00:00:00 UTC, January 1, 1970)."
660 output Real outValue;
661 external "C" outValue=SystemImpl__getCurrentTime() annotation(Library = "omcruntime");
662 end getCurrentTime;
663
664 ✗ public function getCurrentDateTime
665 "@author Frenkel TUD
666 this system function returns current time elapsed
667 since the Epoch (00:00:00 UTC, January 1, 1970)."
668 output Integer sec;
669 output Integer min;
670 output Integer hour;
671 output Integer mday;
672 output Integer mon;
673 output Integer year;
674 external "C" System_getCurrentDateTime(sec,min,hour,mday,mon,year) annotation(Library = "omcruntime");
675 end getCurrentDateTime;
676
677 1218 public function getCurrentTimeStr "
678 returns current time in format Www Mmm dd hh:mm:ss yyyy
679 using the asctime() function in time.h (libc)
680 "
681 output String timeStr;
682 external "C" timeStr=System_getCurrentTimeStr() annotation(Library = "omcruntime");
683 end getCurrentTimeStr;
684
685 1 public function setHasExpandableConnectors
686 "@author: adrpo
687 sets the external flag that signals the
688 presence of expandable connectors in a model"
689 input Boolean hasExpandable;
690 external "C" System_setHasExpandableConnectors(hasExpandable) annotation(Library = "omcruntime");
691 end setHasExpandableConnectors;
692
693 44401 public function getHasExpandableConnectors
694 "@author: adrpo
695 retrieves the external flag that signals the
696 presence of expandable connectors in a model"
697 output Boolean hasExpandable;
698 external "C" hasExpandable = System_getHasExpandableConnectors() annotation(Library = "omcruntime");
699 end getHasExpandableConnectors;
700
701 11445 public function setHasOverconstrainedConnectors
702 "@author: adrpo
703 sets the external flag that signals the
704 presence of overconstrained connectors in a model"
705 input Boolean hasOverconstrained;
706 external "C" System_setHasOverconstrainedConnectors(hasOverconstrained) annotation(Library = "omcruntime");
707 end setHasOverconstrainedConnectors;
708
709 61631 public function getHasOverconstrainedConnectors
710 "@author: adrpo
711 retrieves the external flag that signals the
712 presence of overconstrained connectors in a model"
713 output Boolean hasOverconstrained;
714 external "C" hasOverconstrained = System_getHasOverconstrainedConnectors() annotation(Library = "omcruntime");
715 end getHasOverconstrainedConnectors;
716
717 7937 public function setPartialInstantiation
718 "@author: adrpo
719 sets the external flag that signals the
720 presence of expandable connectors in a model"
721 input Boolean isPartialInstantiation;
722 external "C" System_setPartialInstantiation(isPartialInstantiation) annotation(Library = "omcruntime");
723 end setPartialInstantiation;
724
725 84912 public function getPartialInstantiation
726 "@author: adrpo
727 retrieves the external flag that signals the
728 presence of expandable connectors in a model"
729 output Boolean isPartialInstantiation;
730 external "C" isPartialInstantiation=System_getPartialInstantiation() annotation(Library = "omcruntime");
731 end getPartialInstantiation;
732
733 80965 public function setHasStreamConnectors
734 "@author: adrpo
735 sets the external flag that signals the
736 presence of stream connectors in a model"
737 input Boolean hasStream;
738 external "C" System_setHasStreamConnectors(hasStream) annotation(Library = "omcruntime");
739 end setHasStreamConnectors;
740
741 45612 public function getHasStreamConnectors
742 "@author: adrpo
743 retrieves the external flag that signals the
744 presence of stream connectors in a model"
745 output Boolean hasStream;
746 external "C" hasStream=System_getHasStreamConnectors() annotation(Library = "omcruntime");
747 end getHasStreamConnectors;
748
749 7374 public function setUsesCardinality
750 "Sets the external flag that signals the use of the cardinality operator."
751 input Boolean inUses;
752 external "C" System_setUsesCardinality(inUses) annotation(Library = "omcruntime");
753 end setUsesCardinality;
754
755 7237 public function getUsesCardinality
756 "Retrieves the external flag that signals the use of the cardinality operator."
757 output Boolean outUses;
758 external "C" outUses=System_getUsesCardinality() annotation(Library = "omcruntime");
759 end getUsesCardinality;
760
761 12960 public function setHasInnerOuterDefinitions
762 "@author: adrpo
763 sets the external flag that signals the presence
764 of inner/outer comoponent definitions in a model"
765 input Boolean hasInnerOuterDefinitions;
766 external "C" System_setHasInnerOuterDefinitions(hasInnerOuterDefinitions) annotation(Library = "omcruntime");
767 end setHasInnerOuterDefinitions;
768
769 103046 public function getHasInnerOuterDefinitions
770 "@author: adrpo
771 retrieves the external flag that signals the presence
772 of inner/outer comoponent definitions in a model"
773 output Boolean hasInnerOuterDefinitions;
774 external "C" hasInnerOuterDefinitions=System_getHasInnerOuterDefinitions() annotation(Library = "omcruntime");
775 end getHasInnerOuterDefinitions;
776
777 public function tmpTick
778 "returns a tick that can be reset"
779 output Integer tickNo;
780 algorithm
781 511077 tickNo := tmpTickIndex(index=0);
782 end tmpTick;
783
784 511077 public function tmpTickReset
785 "resets the tick so it restarts on start"
786 input Integer start;
787 external "C" SystemImpl_tmpTickReset(OpenModelica.threadData(),start) annotation(Library = "omcruntime");
788 end tmpTickReset;
789
790 86790 public function tmpTickIndex
791 "returns a tick that can be reset. TODO: remove me when bootstrapped (default argument index=0)"
792 input Integer index;
793 output Integer tickNo;
794 external "C" tickNo = SystemImpl_tmpTickIndex(OpenModelica.threadData(),index) annotation(Library = "omcruntime");
795 end tmpTickIndex;
796
797 13945572 public function tmpTickIndexReserve
798 "returns a tick that can be reset and reserves N values in it.
799 TODO: remove me when bootstrapped (default argument index=0)"
800 input Integer index;
801 input Integer reserve "current tick + reserve";
802 output Integer tickNo;
803 external "C" tickNo = SystemImpl_tmpTickIndexReserve(OpenModelica.threadData(),index,reserve) annotation(Library = "omcruntime");
804 end tmpTickIndexReserve;
805
806 128568 public function tmpTickResetIndex
807 "resets the tick so it restarts on start. TODO: remove me when bootstrapped (default argument index=0)"
808 input Integer start;
809 input Integer index;
810 external "C" SystemImpl_tmpTickResetIndex(OpenModelica.threadData(),start,index) annotation(Library = "omcruntime");
811 end tmpTickResetIndex;
812
813 245884 public function tmpTickSetIndex
814 "sets the index, like tmpTickResetIndex, but does not reset the maximum counter"
815 input Integer start;
816 input Integer index;
817 external "C" SystemImpl_tmpTickSetIndex(OpenModelica.threadData(),start,index) annotation(Library = "omcruntime");
818 end tmpTickSetIndex;
819
820 143208 public function tmpTickMaximum
821 "returns the max tick since the last reset"
822 input Integer index;
823 output Integer maxIndex;
824 external "C" maxIndex=SystemImpl_tmpTickMaximum(OpenModelica.threadData(),index) annotation(Library = "omcruntime");
825 end tmpTickMaximum;
826
827 235427 public function userIsRoot
828 "Returns true if the current user is root.
829 Used by main to disable running omc as root as it is very dangerous.
830 Consider opening a socket and letting anyone run system() commands without authentication. As root."
831 output Boolean isRoot;
832 external "C" isRoot=System_userIsRoot() annotation(Library = "omcruntime");
833 end userIsRoot;
834
835 2677 public function getuid
836 output Integer uid;
837 external "C" uid=System_getuid() annotation(Library = "omcruntime");
838 end getuid;
839
840 ✗ public function realtimeTick
841 "Store current time in timer.
842 The clock index is 0-31. The function fails if the number is out of range."
843 input Integer clockIndex;
844 external "C" System_realtimeTick(clockIndex) annotation(Library = "omcruntime");
845 end realtimeTick;
846
847 26895 public function realtimeTock
848 "Tock returns the time since the last tick, undefined if tick was never called.
849 The clock index is 0-31. The function fails if the number is out of range."
850 input Integer clockIndex;
851 output Real outTime;
852 external "C" outTime = System_realtimeTock(clockIndex) annotation(Library = "omcruntime");
853 end realtimeTock;
854
855 52145 public function realtimeClear
856 "Clears the timer.
857 The clock index is 0-31. The function fails if the number is out of range."
858 input Integer clockIndex;
859 external "C" System_realtimeClear(clockIndex) annotation(Library = "omcruntime");
860 end realtimeClear;
861
862 33649 public function realtimeAccumulate
863 "Accumulates the timer.
864 The clock index is 0-31. The function fails if the number is out of range."
865 input Integer clockIndex;
866 output Real outTime;
867 external "C" outTime = System_realtimeAccumulate(clockIndex) annotation(Library = "omcruntime");
868 end realtimeAccumulate;
869
870 249 public function realtimeAccumulated
871 "Returns the time accumulated from intervals between ticks and tocks.
872 The clock index is 0-31. The function fails if the number is out of range."
873 input Integer clockIndex;
874 output Real outTime;
875 external "C" outTime = System_realtimeAccumulated(clockIndex) annotation(Library = "omcruntime");
876 end realtimeAccumulated;
877
878 ✗ public function realtimeNtick
879 "Returns the number of ticks since last clear.
880 The clock index is 0-31. The function fails if the number is out of range."
881 input Integer clockIndex;
882 output Integer n;
883 external "C" n = System_realtimeNtick(clockIndex) annotation(Library = "omcruntime");
884 end realtimeNtick;
885
886 ✗ function resetTimer
887 "@autor: adrpo
888 this function will reset the timer to 0."
889 external "C" System_resetTimer() annotation(Library = "omcruntime");
890 end resetTimer;
891
892 ✗ function startTimer
893 "@autor: adrpo
894 this function will start counting the time
895 that should be aggregated."
896 external "C" System_startTimer() annotation(Library = "omcruntime");
897 end startTimer;
898
899 ✗ function stopTimer
900 "@autor: adrpo
901 this function will stop counting the time
902 that should be aggregated."
903 external "C" System_stopTimer() annotation(Library = "omcruntime");
904 end stopTimer;
905
906 ✗ function getTimerIntervalTime
907 "@autor: adrpo
908 this function will return the time that
909 passed between the last [startTimer,stopTimer] interval.
910 Notice that if start/stop are called recursively this
911 function will return the time passed between the
912 corresponding intervals.
913 Example:
914 (start1,
915 (start2,
916 (start3, stop3) call getTimerIntervalTime -> (stop3-start3)
917 stop2) call getTimerIntervalTime -> (stop2-start2)
918 stop1) call getTimerIntervalTime -> (stop1-start1)"
919 output Real timerIntervalTime;
920 external "C" timerIntervalTime=System_getTimerIntervalTime() annotation(Library = "omcruntime");
921 end getTimerIntervalTime;
922
923 ✗ function getTimerCummulatedTime
924 "@autor: adrpo
925 this function will return the cummulated time
926 by adding all the interval times [startTimer,stopTimer].
927 Note that if you have recursive calls to start/stop
928 this function will not return the *correct* time.
929 Example:
930 Recursive:
931 (start1, (start2, (start3, stop3) stop2) stop1)
932 getTimerCummulatedTime =
933 stop3-start3 + stop2-start2 + stop1-start1.
934 Serial:
935 (start1, stop1) (start2, stop2) (start3, stop3)
936 getTimerCummulatedTime =
937 stop3-start3 + stop2-start2 + stop1-start1."
938 output Real timerCummulatedTime;
939 external "C" timerCummulatedTime=System_getTimerCummulatedTime() annotation(Library = "omcruntime");
940 end getTimerCummulatedTime;
941
942 ✗ function getTimerElapsedTime
943 "@autor: adrpo
944 this function will return the time
945 passed since the first call to startTimeer
946 Example:
947 (start1, (start2, (start3, stop3), stop2) ...
948 getTimerSinceFirstStartTime = timeNow-start1."
949 output Real timerElapsedTime;
950 external "C" timerElapsedTime=System_getTimerElapsedTime() annotation(Library = "omcruntime");
951 end getTimerElapsedTime;
952
953 ✗ function getTimerStackIndex
954 "@autor: adrpo
955 this function will return number of
956 times start/stop was called recursively.
957 You can use this function for pretty printing.
958 Example:
959 index 0
960 (start1, index 1
961 (start2, index 2
962 (start3, index 3
963 stop3), index 2
964 stop2) index 1
965 stop1) index 0"
966 output Integer stackIndex;
967 external "C" stackIndex=System_getTimerStackIndex() annotation(Library = "omcruntime");
968 end getTimerStackIndex;
969
970
971 1217 public function getUUIDStr "creates the Globally Unique IDentifier and return it as String"
972 output String uuidStr;
973 external "C" uuidStr=System_getUUIDStr() annotation(Library = "omcruntime");
974 end getUUIDStr;
975
976 17529 public function basename
977 "Returns the name of the file without any leading directory path.
978 See man 3 basename."
979 input String filename;
980 output String base;
981 // We need to strdup the input, so we can't use basename() directly
982 external "C" base = System_basename(filename) annotation(Library = "omcruntime");
983 end basename;
984
985 46509 public function dirname
986 "Returns the name of the file without any leading directory path.
987 See man 3 dirname."
988 input String filename;
989 output String base;
990 // We need to strdup the input, so we can't use basename() directly
991 external "C" base = System_dirname(filename) annotation(Library = "omcruntime");
992 end dirname;
993
994 30197 public function escapedString
995 "Because list() requires escape-sequences to be in the AST, we need to be
996 able to unescape them in some places of the code."
997 input String unescapedString;
998 input Boolean unescapeNewline;
999 output String escapedString;
1000 external "C" escapedString=System_escapedString(unescapedString,unescapeNewline) annotation(Library = "omcruntime");
1001 end escapedString;
1002
1003 21673277 public function unescapedString
1004 "Because list() requires escape-sequences to be in the AST, we need to be
1005 able to unescape them in some places of the code."
1006 input String escapedString;
1007 output String unescapedString;
1008 external "C" unescapedString=System_unescapedString(escapedString) annotation(Library = "omcruntime");
1009 end unescapedString;
1010
1011 21129171 public function unescapedStringLength
1012 "Calculates the C string length of the input, if the input was used as a string
1013 literal in C. For example unescapedStringLength('\"')=1, unescapedStringLength('ab')=2."
1014 input String unescapedString;
1015 output Integer length;
1016 external "C" length=SystemImpl__unescapedStringLength(unescapedString) annotation(Library = "omcruntime");
1017 end unescapedStringLength;
1018
1019 5744039 public function unquoteIdentifier
1020 "Quoted identifiers, for example 'xyz' need to be translated into canonical form; for example _omcQ_27xyz_27
1021
1022 The prefix is _omcQ, there is no suffix. The escape character is _ (an identifier with _ would be _5F)
1023
1024 This name presents a unique mapping that is also reversible (so the debugger can show the quoted identifier's nam.
1025 The returned name is a valid C89 identifier."
1026 input String str;
1027 output String outStr;
1028 external "C" outStr=System_unquoteIdentifier(str) annotation(Library = "omcruntime");
1029 end unquoteIdentifier;
1030
1031 5697518 public function intMaxLit "Returns the maximum integer that can be represent using this version of the compiler"
1032 output Integer outInt;
1033 external "builtin" outInt=intMaxLit();
1034 end intMaxLit;
1035
1036 ✗ public function realMaxLit "Returns the maximum real that can be represent using this version of the compiler"
1037 output Real outReal;
1038 external "builtin" outReal=realMaxLit();
1039 end realMaxLit;
1040
1041
2/4
✓ Branch 4 taken 1771 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1771 times.
✗ Branch 7 not taken.
1771 public function uriToClassAndPath "Handles modelica:// and file:// URI's. The result is an absolute path on the local system.
1042 The result depends on the current OPENMODELICALIBRARY (MODELICAPATH in the language specification). Sets the error buffer on failure."
1043 input String uri;
1044 output String scheme "file:// or modelica://, in lower-case";
1045 output String classname "empty if file:// is used";
1046 output String pathname;
1047 external "C" System_uriToClassAndPath(uri,scheme,classname,pathname) annotation(Library = "omcruntime");
1048 end uriToClassAndPath;
1049
1050 5384 public function modelicaPlatform "Returns the standardized platform name according to the Modelica specification:
1051 win32 [Microsoft Windows 32 bit]
1052 win64 [Microsoft Windows 64 bit]
1053 i386-pc-linux [Linux Intel 32 bit]
1054 x64_86-linux [Linux Intel 64 bit]
1055 Else, the openModelicaPlatform() is returned
1056 "
1057 output String platform;
1058 external "C" platform=System_modelicaPlatform() annotation(Library = "omcruntime");
1059 end modelicaPlatform;
1060
1061 7374 public function openModelicaPlatform "
1062 Returns uname -sm (with spaces replaced by dashes and only lower-case letters) on Unix platforms
1063 ucrt64 or mingw32 or mingw64 is returned for OMDev mingw
1064 "
1065 output String platform;
1066 external "C" platform=System_openModelicaPlatform() annotation(Library = "omcruntime");
1067 end openModelicaPlatform;
1068
1069 4845 public function openModelicaPlatformAlternative "
1070 in case openModelicaPlatform is ucrt64 then mingw64 is returned, else nothing
1071 "
1072 output String platform;
1073 external "C" platform=System_openModelicaPlatformAlternative() annotation(Library = "omcruntime");
1074 end openModelicaPlatformAlternative;
1075
1076 1084 public function gccDumpMachine "
1077 Returns gcc -dumpmachine
1078 "
1079 output String machine;
1080 external "C" machine=System_gccDumpMachine() annotation(Library = "omcruntime");
1081 end gccDumpMachine;
1082
1083 ✗ public function gccVersion "
1084 Returns gcc --version
1085 "
1086 output String version;
1087 external "C" version=System_gccVersion() annotation(Library = "omcruntime");
1088 end gccVersion;
1089
1090 ✗ public function dgesv
1091 "# dgesv from LAPACK
1092
1093 ## Purpose
1094 DGESV computes the solution to a real system of linear equations
1095 A * X = B,
1096 where A is an N-by-N matrix and X and B are N-by-NRHS matrices.
1097
1098 The LU decomposition with partial pivoting and row interchanges is
1099 used to factor A as
1100 A = P * L * U,
1101 where P is a permutation matrix, L is unit lower triangular, and U is
1102 upper triangular. The factored form of A is then used to solve the
1103 system of equations A * X = B.
1104
1105 ## Return values
1106 ### output list<Real> X
1107 On exit, if info = 0, the N-by-NRHS solution matrix X.
1108
1109 ### output Integer info
1110 = 0: successful exit
1111 < 0: if INFO = -i, the i-th argument had an illegal value
1112 > 0: if INFO = i, U(i,i) is exactly zero. The factorization
1113 has been completed, but the factor U is exactly
1114 singular, so the solution could not be computed.
1115 "
1116 input list<list<Real>> A;
1117 input list<Real> B;
1118 output list<Real> X;
1119 output Integer info;
1120 external "C" info=SystemImpl__dgesv(A,B,X) annotation(Library = {"omcruntime","Lapack"});
1121 end dgesv;
1122
1123 269 public function reopenStandardStream
1124 input Integer _stream "stdin,stdout,stderr";
1125 input String filename;
1126 output Boolean success;
1127 external "C" success=SystemImpl__reopenStandardStream(_stream,filename) annotation(Library = {"omcruntime"});
1128 end reopenStandardStream;
1129
1130 2995 function iconv "The iconv() function converts one multibyte characters from one character
1131 set to another.
1132 See man (3) iconv for more information.
1133 "
1134 input String string;
1135 input String from;
1136 input String to;
1137 output String result;
1138 external "C" result=SystemImpl__iconv(string,from,to,true /* Print errors */) annotation(Library = {"omcruntime"});
1139 end iconv;
1140
1141 2995 function snprintff
1142 "snprintf format string that takes one double as argument
1143 and the maximum length of the formatted string as another argument."
1144 input String format;
1145 input Integer maxlen;
1146 input Real val;
1147 output String str;
1148 external "C" str=System_snprintff(format,maxlen,val) annotation(Library = {"omcruntime"});
1149 end snprintff;
1150
1151 22708 function sprintff
1152 "sprintf format string that takes one double as argument,
1153 but unlike snprintff it takes no string length as argument.
1154
1155 NOTE: This function doesn't actually call sprintf, since that would be unsafe.
1156 It instead calls snprintf with a fixed buffer size that should be enough
1157 for most cases, and if that fails it resizes the buffer to the size
1158 snprintf said it needed and calls snprintf again."
1159 input String format;
1160 input Real val;
1161 output String str;
1162 external "C" str = System_sprintff(format, val) annotation(Library = {"omcruntime"});
1163 end sprintff;
1164
1165 821 public function realRand
1166 "Returns a value in the intervals (0,1]"
1167 output Real r;
1168
1169 external "C" r = SystemImpl__realRand() annotation(Library = {"omcruntime"});
1170 end realRand;
1171
1172 public function intRand
1173 "Returns a integer value in the interval (0,n].
1174 The number of possible values is n, the maximum value n-1."
1175 input Integer n;
1176 output Integer i;
1177 algorithm
1178 ✗ i := integer(realRand()*n);
1179 end intRand;
1180
1181 public function intRandom
1182 "Returns a value in the interval [0,n)"
1183 input Integer n;
1184 output Integer ret;
1185 algorithm
1186 ret := intMod(intRandom0(), n);
1187 end intRandom;
1188
1189 ✗ protected function intRandom0
1190 "Returns a value in the intervals [0,RAND_MAX) using the C method rand()."
1191 output Integer ret;
1192
1193 external "C" ret = rand() annotation(Include = "#include <stdlib.h>");
1194 end intRandom0;
1195
1196 ✗ public function anyStringCode
1197 "Takes any boxed input"
1198 input Any any;
1199 output String str;
1200 replaceable type Any subtypeof Any;
1201 external "C" str = anyStringCode(any);
1202 end anyStringCode;
1203
1204 ✗ public function numBits
1205 output Integer n;
1206 external "C" n=architecture_numbits() annotation(Include="#define architecture_numbits() (8*sizeof(void*))");
1207 end numBits;
1208
1209 public function realpath
1210 "Return the canonicalized absolute pathname"
1211 input String path;
1212 output String fullpath;
1213 protected
1214 2542866 function system_realpath
1215 input String path;
1216 output String fullpath;
1217 external "C" fullpath = System_realpath(path) annotation(Library = {"omcruntime"});
1218 end system_realpath;
1219 algorithm
1220 try
1221 fullpath := system_realpath(path);
1222 else
1223 ✗ Error.addInternalError(getInstanceName() + " failed for " + path, sourceInfo());
1224 ✗ fail();
1225 end try;
1226 end realpath;
1227
1228 ✗ public function getSimulationHelpText
1229 input Boolean detailed=false;
1230 input Boolean sphinx=false;
1231 output String text;
1232 external "C" text = System_getSimulationHelpTextSphinx(detailed,sphinx) annotation(Library = {"omcruntime"});
1233 end getSimulationHelpText;
1234
1235 ✗ public function getTerminalWidth
1236 output Integer width;
1237 external "C" width = System_getTerminalWidth() annotation(Library = {"omcruntime"});
1238 end getTerminalWidth;
1239
1240 ✗ public function fileIsNewerThan
1241 input String file1;
1242 input String file2;
1243 output Boolean result;
1244 external "C" result = System_fileIsNewerThan(file1,file2) annotation(Library = {"omcruntime"});
1245 end fileIsNewerThan;
1246
1247 ✗ public function fileContentsEqual
1248 input String file1;
1249 input String file2;
1250 output Boolean result;
1251 external "C" result = SystemImpl__fileContentsEqual(file1,file2) annotation(Library = {"omcruntime"});
1252 end fileContentsEqual;
1253
1254 1 public function rename "returns true if success, false otherwise"
1255 input String source;
1256 input String dest;
1257 output Boolean result;
1258 external "C" result = SystemImpl__rename(source,dest) annotation(Library = {"omcruntime"});
1259 end rename;
1260
1261 106 public function numProcessors
1262 output Integer result;
1263 external "C" result = System_numProcessors() annotation(Library = {"omcruntime"});
1264 end numProcessors;
1265
1266 3249 public function launchParallelTasks "Takes a list of inputs and produces a list of Boolean (true if the function call was successful). The function is called by not using forks (experimental version using threads because fork doesn't play nice). Only returns if all functions return."
1267 input Integer numThreads;
1268 input list<AnyInput> inData;
1269 input ForkFunction func;
1270 output list<AnyOutput> result;
1271 partial function ForkFunction
1272 input AnyInput inData;
1273 output AnyOutput outData;
1274 end ForkFunction;
1275 replaceable type AnyInput subtypeof Any;
1276 replaceable type AnyOutput subtypeof Any;
1277 external "C" result = System_launchParallelTasks(OpenModelica.threadData(), numThreads, inData, func) annotation(Library = {"omcruntime"});
1278 end launchParallelTasks;
1279
1280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1122 times.
1122 public function launchParallelTasksThreaded "Like launchParallelTasks, but only for call sites whose task input/output are safe to move across OS threads. In the classic runtime this is an alias for launchParallelTasks; the Rust port uses it to opt a call site into real (rayon) threading."
1281 input Integer numThreads;
1282 input list<AnyInput> inData;
1283 input ForkFunction func;
1284 output list<AnyOutput> result;
1285 partial function ForkFunction
1286 input AnyInput inData;
1287 output AnyOutput outData;
1288 end ForkFunction;
1289 replaceable type AnyInput subtypeof Any;
1290 replaceable type AnyOutput subtypeof Any;
1291 external "C" result = System_launchParallelTasks(OpenModelica.threadData(), numThreads, inData, func) annotation(Library = {"omcruntime"});
1292 end launchParallelTasksThreaded;
1293
1294 ✗ public function exit "Exits the compiler at this point with the given exit status."
1295 input Integer status;
1296 external "C" exit(status) annotation(Include = "#include <stdlib.h>");
1297 end exit;
1298
1299 ✗ public function threadWorkFailed "Exits the current thread with a failure."
1300 external "C" System_threadFail(OpenModelica.threadData());
1301 end threadWorkFailed;
1302
1303 ✗ public function isCancelled "True if the user has requested cancellation of the running operation."
1304 output Boolean cancelled;
1305 external "C" cancelled = System_isCancelled() annotation(Library = "omcruntime");
1306 end isCancelled;
1307
1308 2600813 public function alarmExpired "True if the cancellation being reported came from the alarm running out rather than from a user."
1309 output Boolean expired;
1310 external "C" expired = System_alarmExpired() annotation(Library = "omcruntime");
1311 end alarmExpired;
1312
1313 ✗ public function reportProgress "Report progress of the running operation to the host UI. permille is 0..1000 or -1 (indeterminate); phase is one of the metamodelica::cancel PHASE_* constants (2 parse, 3 instantiate, 4 backend, 5 simulate)."
1314 input Integer permille;
1315 input Integer phase;
1316 external "C" System_reportProgress(permille, phase) annotation(Library = "omcruntime");
1317 end reportProgress;
1318
1319 4195 public function reportProgressMessage "Label the step in progress for the host UI, which shows it instead of the generic phase label. Cleared by the next reportProgress call, so report it after that one."
1320 input String message;
1321 external "C" System_reportProgressMessage(message) annotation(Library = "omcruntime");
1322 end reportProgressMessage;
1323
1324 162 public function getMemorySize
1325 output Real memory(unit="MB");
1326 external "C" memory=System_getMemorySize() annotation(Library = {"omcruntime"});
1327 end getMemorySize;
1328
1329 ✗ public function initGarbageCollector "this needs to be called first in Main.mo"
1330 external "C" System_initGarbageCollector() annotation(Library = {"omcruntime"});
1331 end initGarbageCollector;
1332
1333 2677 public function ctime
1334 input Real t;
1335 output String str;
1336 external "C" str=SystemImpl__ctime(t) annotation(Library = {"omcruntime"},Documentation(info="<html>
1337 <p>Like <a href=\"http://linux.die.net/man/3/ctime\">ctime(3)</a>, except the input is of type real because of limited precision of Integer.</p>
1338 </html>"));
1339 end ctime;
1340
1341 type StatFileType = enumeration(NoFile, RegularFile, Directory, SpecialFile);
1342
1343 ✗ public function stat
1344 input String filename;
1345 output Boolean success;
1346 output Real st_size; /* An integer stored as double for higher precision */
1347 output Real st_mtime; /* An integer stored as double for higher precision */
1348 output StatFileType fileType;
1349 external "C" success=SystemImpl__stat(filename,st_size,st_mtime,fileType) annotation(Library = {"omcruntime"},Documentation(info="<html>
1350 <p>Like <a href=\"http://linux.die.net/man/2/stat\">stat(2)</a>, except the output is of type real because of limited precision of Integer.</p>
1351 </html>"));
1352 end stat;
1353
1354 567 public function alarm
1355 input Integer seconds;
1356 output Integer previousAlarm;
1357 external "C" previousAlarm=SystemImpl__alarm(seconds) annotation(Library = {"omcruntime"},Documentation(info="<html>
1358 <p>Like <a href=\"http://linux.die.net/man/2/alarm\">alarm(2)</a>.</p>
1359 </html>"));
1360 end alarm;
1361
1362 2814 public function covertTextFileToCLiteral
1363 input String textFile;
1364 input String outFile;
1365 input String target "this would be what is set for +target=msvc|gcc";
1366 output Boolean success;
1367 external "C" success=SystemImpl__covertTextFileToCLiteral(textFile, outFile, target);
1368 end covertTextFileToCLiteral;
1369
1370 public function dladdr<T>
1371 input T symbol "Function pointer";
1372 output String info;
1373 output String file;
1374 output String name;
1375 algorithm
1376 ✗ (file,name) := _dladdr(symbol);
1377 ✗ info := file + ": " + name;
1378 protected
1379
1380 ✗ function _dladdr<T>
1381 input T symbol "Function pointer";
1382 output String file;
1383 output String name;
1384 external "C" SystemImpl__dladdr(symbol, file, name) annotation(Library = {"omcruntime"},Documentation(info="<html>
1385 <p>Like <a href=\"http://linux.die.net/man/3/dladdr\">dladdr(3)</a>.</p>
1386 <p>Only works on Linux. Other platforms return dummy strings.</p>.
1387 </html>"));
1388 end _dladdr;
1389 annotation(Documentation(info="<html>
1390 <p>Like <a href=\"http://linux.die.net/man/3/dladdr\">dladdr(3)</a>.</p>
1391 <p>Only works on Linux. Other platforms return dummy strings.</p>.
1392 </html>"));
1393 end dladdr;
1394
1395 class StringAllocator
1396 extends ExternalObject;
1397 2166602 function constructor
1398 input Integer sz;
1399 output StringAllocator str;
1400 external "C" str=StringAllocator_constructor(sz) annotation(Include="
1401 2166602 void* StringAllocator_constructor(int sz)
1402 {
1403 void *res;
1404
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2166602 times.
2166602 if (sz < 0) {
1405 ✗ MMC_THROW();
1406 }
1407 2166602 res = mmc_alloc_scon(sz);
1408
2/2
✓ Branch 0 taken 2166596 times.
✓ Branch 1 taken 6 times.
2166602 if (sz > 0) {
1409 /* mmc_alloc_scon does not terminate the string and the copies below do not either */
1410 2166596 ((char*)MMC_STRINGDATA(res))[sz] = '\\0';
1411 }
1412 2166602 return res;
1413 }
1414 ");
1415 end constructor;
1416 function destructor
1417 input StringAllocator str;
1418 algorithm
1419 /* Nothing */
1420 end destructor;
1421 end StringAllocator;
1422
1423 2166602 function stringAllocatorStringCopy
1424 input StringAllocator dest;
1425 input String source;
1426 input Integer destOffset=0;
1427 external "C" om_stringAllocatorStringCopy(dest,source,destOffset) annotation(Include="
1428 13648004 void om_stringAllocatorStringCopy(void *dest, char *source, int destOffset) {
1429 /* memcpy without the terminator so copies at later offsets are not clobbered when filling the string in reverse order */
1430 13648004 size_t n = strlen(source);
1431
2/2
✓ Branch 0 taken 13639211 times.
✓ Branch 1 taken 8793 times.
13648004 if (n > 0) {
1432 13639211 memcpy(MMC_STRINGDATA(dest)+destOffset, source, n);
1433 }
1434 13648004 }
1435 ", Documentation(info="<html>
1436 <p>Copies the source string (without its terminator) into the (input) destination at the given offset. This is dangerous and not valid Modelica.</p>
1437 <p>Make sure the String has been allocated properly and is not shared. The input lengths are not validated, so this function can write out of bounds if called incorrectly.</p>
1438 </html>"));
1439 end stringAllocatorStringCopy;
1440
1441 13648004 function stringAllocatorResult<T>
1442 input StringAllocator sa;
1443 input T dummy "This is just added so we do not make an extra allocation for the string" annotation(__OpenModelica_UnusedVariable=true);
1444 output T res;
1445 external "C" res=om_stringAllocatorResult(sa) annotation(Include="
1446 ✗ void* om_stringAllocatorResult(void *sa) {
1447 ✗ return sa;
1448 }
1449 ");
1450 end stringAllocatorResult;
1451
1452 2166602 function relocateFunctions
1453 input String fileName "shared object";
1454 input list<tuple<String,String>> names "tuple of names to relocate; first is the local name and second is the name in the shared object";
1455 output Boolean res;
1456 external "C" res=SystemImpl__relocateFunctions(fileName, names) annotation(Library = {"omcruntime"},Documentation(info="<html>
1457 <p>Update symbols in the running program to ones defined in the given shared object.</p>
1458 <p>This will hot-swap the functions at run-time, enabling a smart build system to do some incremental compilation
1459 (as long as the function interfaces are the same).</p>
1460 </html>"));
1461 end relocateFunctions;
1462
1463 ✗ function fflush
1464 external "C" SystemImpl__fflush() annotation(Include = "
1465 #include <stdio.h>
1466 ✗ void SystemImpl__fflush(void)
1467 {
1468 ✗ fflush(NULL);
1469 ✗ }
1470 ",Documentation(info="<html>
1471 <p>This function will call fflush(NULL) to flush all buffers.</p>
1472 </html>"));
1473 end fflush;
1474
1475 3355 function updateUriMapping
1476 input array<String> namesAndDirs;
1477 external "C" OpenModelica_updateUriMapping(OpenModelica.threadData(), namesAndDirs) annotation(include="#include \"util/utility.h\"", Documentation(info="<html>
1478 <p>Used to set the mapping from package names to directories, for loadResource. Part of the C runtime.</p>
1479 <p>Odd indexes are names and even indexes are the corresponding directory.</p>
1480 </html>"));
1481 end updateUriMapping;
1482
1483
0/4
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
6054 function getSizeOfData<T>
1484 input T data;
1485 output Real sz;
1486 output Real raw_sz "The size without granule overhead";
1487 output Real nonSharedStringSize "The size that could be saved if String sharing was enabled";
1488 external "C" sz=SystemImpl__getSizeOfData(data, raw_sz, nonSharedStringSize) annotation(Library = {"omcruntime"}, Documentation(info="<html>
1489 Counts the number of bytes that were allocated to hold the given data structure.
1490 Includes constant data and handles cycles.
1491 </html>"));
1492 end getSizeOfData;
1493
1494 type StreamType = enumeration(STDOUT, STDERR);
1495
1496 ✗ function fputs
1497 input String str;
1498 input StreamType streamType;
1499 output Integer res "Nonnegative on success, EOF on error";
1500 external "C" res=SystemImpl__fputs(str, streamType) annotation(Library = "omcruntime", Documentation(info="<html>
1501 Outputs a string using the C function fputs.
1502 </html>"));
1503 end fputs;
1504
1505 744 function waitForInput
1506 external "C" SystemImpl__waitForInput() annotation(Library = "omcruntime", Documentation(info="<html>
1507 Waits for input, useful for e.g. pausing the compiler in order to turn valgrind instrumentation on/off.
1508 </html>"));
1509 end waitForInput;
1510
1511 annotation(__OpenModelica_Interface="util");
1512 end System;
1513