Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 7f3aeef

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Update NFModelicaBuiltin.
- Use the same inline definition of 'rem' as in the old frontend, since inlining now works and the backend doesn't handle 'rem'. - Port recent changes of ModelicaBuiltin to NFModelicaBuiltin. Belonging to [master]: - #2523
1 parent a107bb4 commit 7f3aeef

File tree

1 file changed

+89
-59
lines changed

1 file changed

+89
-59
lines changed

Compiler/NFFrontEnd/NFModelicaBuiltin.mo

Lines changed: 89 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,16 +1044,18 @@ package Internal "Contains internal implementations, e.g. overloaded builtin fun
10441044
input Integer x;
10451045
input Integer y;
10461046
output Integer z;
1047-
external "builtin" z=rem(x,y);
1048-
annotation(preferredView="text");
1047+
algorithm
1048+
z := x - (div(x, y) * y);
1049+
annotation(preferredView="text", __OpenModelica_EarlyInline=true);
10491050
end intRem;
10501051

10511052
function realRem
10521053
input Real x;
10531054
input Real y;
10541055
output Real z;
1055-
external "builtin" z=rem(x,y);
1056-
annotation(preferredView="text");
1056+
algorithm
1057+
z := x - (div(x, y) * y);
1058+
annotation(preferredView="text", __OpenModelica_EarlyInline=true);
10571059
end realRem;
10581060

10591061
/*
@@ -1116,47 +1118,6 @@ package Internal "Contains internal implementations, e.g. overloaded builtin fun
11161118
</html>"));
11171119
end arrayMax;
11181120

1119-
/*
1120-
function intMin
1121-
input Integer i1;
1122-
input Integer i2;
1123-
output Integer i;
1124-
algorithm
1125-
i := if i1 < i2 then i1 else i2;
1126-
annotation(__OpenModelica_EarlyInline = true, __OpenModelica_BuiltinPtr = true);
1127-
end intMin;
1128-
1129-
function realMin
1130-
input Real r1;
1131-
input Real r2;
1132-
output Real r;
1133-
algorithm
1134-
r := if r1 < r2 then r1 else r2;
1135-
annotation(__OpenModelica_EarlyInline = true, __OpenModelica_BuiltinPtr = true);
1136-
end realMin;
1137-
1138-
function boolMin
1139-
input Boolean b1;
1140-
input Boolean b2;
1141-
output Boolean b;
1142-
algorithm
1143-
b := if b1 then b1 else b2;
1144-
annotation(__OpenModelica_EarlyInline = true, __OpenModelica_BuiltinPtr = true);
1145-
end boolMin;
1146-
1147-
function enumMin<enumType>
1148-
"Returns the smallest element of two enums.
1149-
This will need special handling internaly"
1150-
input enumType s1;
1151-
input enumType s2;
1152-
output enumType s;
1153-
external "builtin" s = min(s1,s2);
1154-
annotation(Documentation(info="<html>
1155-
See <a href=\"modelica://ModelicaReference.Operators.'min()'\">min()</a>
1156-
</html>"));
1157-
end enumMin;
1158-
*/
1159-
11601121
function scalarMin<ScalarBasicType> "Returns the smallest element of two scalar basic types"
11611122
input ScalarBasicType a;
11621123
input ScalarBasicType b;
@@ -1314,6 +1275,16 @@ external "builtin";
13141275
annotation(preferredView="text");
13151276
end loadFiles;
13161277

1278+
function loadEncryptedPackage
1279+
input String fileName;
1280+
input String workdir = "<default>" "The output directory for imported encrypted files. <default> will put the files to current working directory.";
1281+
output Boolean success;
1282+
external "builtin";
1283+
annotation(Documentation(info="<html>
1284+
<p>Loads the given encrypted package.</p>
1285+
</html>"), preferredView="text");
1286+
end loadEncryptedPackage;
1287+
13171288
function reloadClass "reloads the file associated with the given (loaded class)"
13181289
input TypeName name;
13191290
input String encoding = "UTF-8";
@@ -1668,15 +1639,15 @@ function setPreOptModules "example input: removeFinalParameters,removeSimpleEqua
16681639
input String modules;
16691640
output Boolean success;
16701641
algorithm
1671-
success := setCommandLineOptions("+preOptModules=" + modules);
1642+
success := setCommandLineOptions("--preOptModules=" + modules);
16721643
annotation(__OpenModelica_EarlyInline = true, preferredView="text");
16731644
end setPreOptModules;
16741645

16751646
function setCheapMatchingAlgorithm "example input: 3"
16761647
input Integer matchingAlgorithm;
16771648
output Boolean success;
16781649
algorithm
1679-
success := setCommandLineOptions("+cheapmatchingAlgorithm=" + String(matchingAlgorithm));
1650+
success := setCommandLineOptions("--cheapmatchingAlgorithm=" + String(matchingAlgorithm));
16801651
annotation(__OpenModelica_EarlyInline = true, preferredView="text");
16811652
end setCheapMatchingAlgorithm;
16821653

@@ -1695,7 +1666,7 @@ function setMatchingAlgorithm "example input: omc"
16951666
input String matchingAlgorithm;
16961667
output Boolean success;
16971668
algorithm
1698-
success := setCommandLineOptions("+matchingAlgorithm=" + matchingAlgorithm);
1669+
success := setCommandLineOptions("--matchingAlgorithm=" + matchingAlgorithm);
16991670
annotation(__OpenModelica_EarlyInline = true, preferredView="text");
17001671
end setMatchingAlgorithm;
17011672

@@ -1714,15 +1685,15 @@ function setIndexReductionMethod "example input: dynamicStateSelection"
17141685
input String method;
17151686
output Boolean success;
17161687
algorithm
1717-
success := setCommandLineOptions("+indexReductionMethod=" + method);
1688+
success := setCommandLineOptions("--indexReductionMethod=" + method);
17181689
annotation(__OpenModelica_EarlyInline = true, preferredView="text");
17191690
end setIndexReductionMethod;
17201691

17211692
function setPostOptModules "example input: lateInline,inlineArrayEqn,removeSimpleEquations."
17221693
input String modules;
17231694
output Boolean success;
17241695
algorithm
1725-
success := setCommandLineOptions("+postOptModules=" + modules);
1696+
success := setCommandLineOptions("--postOptModules=" + modules);
17261697
annotation(__OpenModelica_EarlyInline = true, preferredView="text");
17271698
end setPostOptModules;
17281699

@@ -1741,7 +1712,7 @@ function setTearingMethod "example input: omcTearing"
17411712
input String tearingMethod;
17421713
output Boolean success;
17431714
algorithm
1744-
success := setCommandLineOptions("+tearingMethod=" + tearingMethod);
1715+
success := setCommandLineOptions("--tearingMethod=" + tearingMethod);
17451716
annotation(__OpenModelica_EarlyInline = true, preferredView="text");
17461717
end setTearingMethod;
17471718

@@ -1911,7 +1882,7 @@ external "builtin";
19111882
annotation(preferredView="text");
19121883
end readFileNoNumeric;
19131884

1914-
function getErrorString "Returns the current error message. [file.mo:n:n-n:n:b] Error: message"
1885+
impure function getErrorString "Returns the current error message. [file.mo:n:n-n:n:b] Error: message"
19151886
input Boolean warningsAsErrors = false;
19161887
output String errorString;
19171888
external "builtin";
@@ -1981,7 +1952,7 @@ external "builtin";
19811952
annotation(preferredView="text");
19821953
end clearMessages;
19831954

1984-
function runScript "Runs the mos-script specified by the filename."
1955+
impure function runScript "Runs the mos-script specified by the filename."
19851956
input String fileName "*.mos";
19861957
output String result;
19871958
external "builtin";
@@ -2024,7 +1995,7 @@ function setAnnotationVersion "Sets the annotation version."
20241995
input String annotationVersion;
20251996
output Boolean success;
20261997
algorithm
2027-
success := setCommandLineOptions("+annotationVersion=" + annotationVersion);
1998+
success := setCommandLineOptions("--annotationVersion=" + annotationVersion);
20281999
annotation(__OpenModelica_EarlyInline = true, preferredView="text");
20292000
end setAnnotationVersion;
20302001

@@ -2051,7 +2022,7 @@ function setVectorizationLimit
20512022
input Integer vectorizationLimit;
20522023
output Boolean success;
20532024
algorithm
2054-
success := setCommandLineOptions("+v=" + String(vectorizationLimit));
2025+
success := setCommandLineOptions("-v=" + String(vectorizationLimit));
20552026
annotation(__OpenModelica_EarlyInline = true, preferredView="text");
20562027
end setVectorizationLimit;
20572028

@@ -2067,7 +2038,7 @@ public function setDefaultOpenCLDevice
20672038
input Integer defdevid;
20682039
output Boolean success;
20692040
algorithm
2070-
success := setCommandLineOptions("+o=" + String(defdevid));
2041+
success := setCommandLineOptions("-o=" + String(defdevid));
20712042
annotation(__OpenModelica_EarlyInline = true, preferredView="text");
20722043
end setDefaultOpenCLDevice;
20732044

@@ -2088,7 +2059,7 @@ function setOrderConnections "Sets the orderConnection flag."
20882059
input Boolean orderConnections;
20892060
output Boolean success;
20902061
algorithm
2091-
success := setCommandLineOptions("+orderConnections=" + String(orderConnections));
2062+
success := setCommandLineOptions("--orderConnections=" + String(orderConnections));
20922063
annotation(__OpenModelica_EarlyInline = true, preferredView="text");
20932064
end setOrderConnections;
20942065

@@ -2102,7 +2073,7 @@ function setLanguageStandard "Sets the Modelica Language Standard."
21022073
input String inVersion;
21032074
output Boolean success;
21042075
algorithm
2105-
success := setCommandLineOptions("+std=" + inVersion);
2076+
success := setCommandLineOptions("--std=" + inVersion);
21062077
annotation(__OpenModelica_EarlyInline = true, preferredView="text");
21072078
end setLanguageStandard;
21082079

@@ -2258,6 +2229,8 @@ end saveModel;
22582229
function saveTotalModel
22592230
input String fileName;
22602231
input TypeName className;
2232+
input Boolean stripAnnotations = false;
2233+
input Boolean stripComments = false;
22612234
output Boolean success;
22622235
external "builtin";
22632236
annotation(preferredView="text");
@@ -2602,13 +2575,21 @@ The only required argument is the className, while all others have some default
26022575
input String version = "2.0" "FMU version, 1.0 or 2.0.";
26032576
input String fmuType = "me" "FMU type, me (model exchange), cs (co-simulation), me_cs (both model exchange and co-simulation)";
26042577
input String fileNamePrefix = "<default>" "fileNamePrefix. <default> = \"className\"";
2605-
input String platforms[:] = {"dynamic"} "The list of platforms to generate code for. \"dynamic\"=current platform, dynamically link the runtime. \"static\"=current platform, statically link everything. Else, use a host triple, e.g. \"x86_64-linux-gnu\" or \"x86_64-w64-mingw32\"";
2578+
input String platforms[:] = {"static"} "The list of platforms to generate code for. \"dynamic\"=current platform, dynamically link the runtime. \"static\"=current platform, statically link everything. Else, use a host triple, e.g. \"x86_64-linux-gnu\" or \"x86_64-w64-mingw32\"";
26062579
input Boolean includeResources = false "include Modelica based resources via loadResource or not";
26072580
output String generatedFileName "Returns the full path of the generated FMU.";
26082581
external "builtin";
26092582
annotation(preferredView="text");
26102583
end buildModelFMU;
26112584

2585+
function buildEncryptedPackage
2586+
input TypeName className "the class that should encrypted";
2587+
output Boolean success;
2588+
output String commandOutput "Output of the packagetool executable";
2589+
external "builtin";
2590+
annotation(preferredView="text");
2591+
end buildEncryptedPackage;
2592+
26122593
function simulate "simulates a modelica model by generating c code, build it and run the simulation executable.
26132594
The only required argument is the className, while all others have some default values.
26142595
simulate(className, [startTime], [stopTime], [numberOfIntervals], [tolerance], [method], [fileNamePrefix], [options], [outputFormat], [variableFilter], [cflags], [simflags])
@@ -2668,6 +2649,43 @@ external "builtin";
26682649
annotation(preferredView="text");
26692650
end buildModel;
26702651

2652+
function buildLabel "builds Label."
2653+
input TypeName className "the class that should be built";
2654+
input Real startTime = 0.0 "the start time of the simulation. <default> = 0.0";
2655+
input Real stopTime = 1.0 "the stop time of the simulation. <default> = 1.0";
2656+
input Integer numberOfIntervals = 500 "number of intervals in the result file. <default> = 500";
2657+
input Real tolerance = 1e-6 "tolerance used by the integration method. <default> = 1e-6";
2658+
input String method = "dassl" "integration method used for simulation. <default> = dassl";
2659+
input String fileNamePrefix = "" "fileNamePrefix. <default> = \"\"";
2660+
input String options = "" "options. <default> = \"\"";
2661+
input String outputFormat = "mat" "Format for the result file. <default> = \"mat\"";
2662+
input String variableFilter = ".*" "Filter for variables that should store in result file. <default> = \".*\"";
2663+
input String cflags = "" "cflags. <default> = \"\"";
2664+
input String simflags = "" "simflags. <default> = \"\"";
2665+
output String[2] buildModelResults;
2666+
external "builtin";
2667+
annotation(preferredView="text");
2668+
end buildLabel;
2669+
2670+
function reduceTerms "reduce terms."
2671+
input TypeName className "the class that should be built";
2672+
input Real startTime = 0.0 "the start time of the simulation. <default> = 0.0";
2673+
input Real stopTime = 1.0 "the stop time of the simulation. <default> = 1.0";
2674+
input Integer numberOfIntervals = 500 "number of intervals in the result file. <default> = 500";
2675+
input Real tolerance = 1e-6 "tolerance used by the integration method. <default> = 1e-6";
2676+
input String method = "dassl" "integration method used for simulation. <default> = dassl";
2677+
input String fileNamePrefix = "" "fileNamePrefix. <default> = \"\"";
2678+
input String options = "" "options. <default> = \"\"";
2679+
input String outputFormat = "mat" "Format for the result file. <default> = \"mat\"";
2680+
input String variableFilter = ".*" "Filter for variables that should store in result file. <default> = \".*\"";
2681+
input String cflags = "" "cflags. <default> = \"\"";
2682+
input String simflags = "" "simflags. <default> = \"\"";
2683+
input String labelstoCancel="";
2684+
output String[2] buildModelResults;
2685+
external "builtin";
2686+
annotation(preferredView="text");
2687+
end reduceTerms;
2688+
26712689
function moveClass
26722690
"Moves a class up or down depending on the given offset, where a positive
26732691
offset moves the class down and a negative offset up. The offset is truncated
@@ -2970,6 +2988,7 @@ public function filterSimulationResults
29702988
input String outFile;
29712989
input String[:] vars;
29722990
input Integer numberOfIntervals = 0 "0=Do not resample";
2991+
input Boolean removeDescription = false;
29732992
output Boolean success;
29742993
external "builtin";
29752994
annotation(Documentation(info="<html>
@@ -3158,6 +3177,17 @@ annotation(
31583177
preferredView="text");
31593178
end getComponentModifierValues;
31603179

3180+
function getInstantiatedParametersAndValues
3181+
input TypeName cls;
3182+
output String[:] values;
3183+
external "builtin";
3184+
annotation(
3185+
Documentation(info="<html>
3186+
<p>Returns the parameter names and values from the DAE.</p>
3187+
</html>"),
3188+
preferredView="text");
3189+
end getInstantiatedParametersAndValues;
3190+
31613191
function removeComponentModifiers
31623192
input TypeName class_;
31633193
input String componentName;

0 commit comments

Comments
 (0)