Skip to content

Commit

Permalink
- Added simulate() option cflags = ""
Browse files Browse the repository at this point in the history
  - Also added a field for this in the OMEdit simulation widget


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8586 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Apr 11, 2011
1 parent 059b1a6 commit 772acb9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 29 deletions.
4 changes: 3 additions & 1 deletion Compiler/BackEnd/SimCode.mo
Expand Up @@ -467,6 +467,7 @@ uniontype SimulationSettings
String outputFormat;
String variableFilter;
Boolean measureTime;
String cflags;
end SIMULATION_SETTINGS;
end SimulationSettings;

Expand Down Expand Up @@ -844,6 +845,7 @@ public function createSimulationSettings
input String outputFormat;
input String variableFilter;
input Boolean measureTime;
input String cflags;
output SimulationSettings simSettings;
protected
Real stepSize;
Expand All @@ -852,7 +854,7 @@ algorithm
stepSize := (stopTime -. startTime) /. intReal(numberOfIntervals);
simSettings := SIMULATION_SETTINGS(
startTime, stopTime, numberOfIntervals, stepSize, tolerance,
method, options, outputFormat, variableFilter, measureTime);
method, options, outputFormat, variableFilter, measureTime, cflags);
end createSimulationSettings;


Expand Down
10 changes: 8 additions & 2 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -6672,7 +6672,7 @@ algorithm
Absyn.Info info;
String cname_str;
Absyn.Path className;
DAE.Exp startTime,stopTime,numberOfIntervals,tolerance,method;
DAE.Exp startTime,stopTime,numberOfIntervals,tolerance,method,cflags;
DAE.Exp fileNamePrefix,storeInTemp,options,noClean,outputFormat,variableFilter,measureTime;
CevalScript.SimulationOptions defaulSimOpt;
Env.Cache cache;
Expand Down Expand Up @@ -6734,6 +6734,11 @@ algorithm
getOptionalNamedArg(cache, env, SOME(st), impl, "measureTime", DAE.T_BOOL_DEFAULT,
args, CevalScript.getSimulationOption(defaulSimOpt, "measureTime"),
pre, info);

(cache,cflags) =
getOptionalNamedArg(cache, env, SOME(st), impl, "cflags", DAE.T_STRING_DEFAULT,
args, CevalScript.getSimulationOption(defaulSimOpt, "cflags"),
pre, info);
then
(cache,
{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER()),
Expand All @@ -6748,7 +6753,8 @@ algorithm
options,
outputFormat,
variableFilter,
measureTime});
measureTime,
cflags});

end match;
end getSimulationArguments;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Main/Main.mo
Expand Up @@ -878,7 +878,7 @@ algorithm
Print.clearErrorBuf();
Print.clearBuf();
cname_str = Absyn.pathString(classname);
simSettings = SimCode.createSimulationSettings(0.0, 1.0, 500, 1e-6,"dassl","","mat",".*",false);
simSettings = SimCode.createSimulationSettings(0.0, 1.0, 500, 1e-6,"dassl","","mat",".*",false,"");
(_,_,_,_,_,_) = SimCode.generateModelCode(dlow,functionTree,ap,dae,classname,cname_str,SOME(simSettings),m,mt,ass1,ass2,comps);
then
();
Expand Down
58 changes: 34 additions & 24 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -154,6 +154,7 @@ uniontype SimulationOptions "these are the simulation/buildModel* options"
DAE.Exp outputFormat "output format, default 'plt'";
DAE.Exp variableFilter "variable filter, regex does whole string matching, i.e. it becomes ^.*$ in the runtime";
DAE.Exp measureTime "Enables time measurements, default false";
DAE.Exp cflags "Compiler flags, in addition to MODELICAUSERCFLAGS";
end SIMULATION_OPTIONS;
end SimulationOptions;

Expand All @@ -170,6 +171,7 @@ public constant DAE.Exp defaultOptions = DAE.SCONST("") "default
public constant DAE.Exp defaultOutputFormat = DAE.SCONST("mat") "default outputFormat";
public constant DAE.Exp defaultVariableFilter = DAE.SCONST(".*") "default variableFilter; does whole string matching, i.e. it becomes ^.*$ in the runtime";
public constant DAE.Exp defaultMeasureTime = DAE.BCONST(false) "time measurement disabled by default";
public constant DAE.Exp defaultCflags = DAE.SCONST("") "default compiler flags";

public constant SimulationOptions defaultSimulationOptions =
SIMULATION_OPTIONS(
Expand All @@ -185,7 +187,8 @@ public constant SimulationOptions defaultSimulationOptions =
defaultOptions,
defaultOutputFormat,
defaultVariableFilter,
defaultMeasureTime
defaultMeasureTime,
defaultCflags
) "default simulation options";

public constant list<String> simulationOptionsNames =
Expand All @@ -201,7 +204,8 @@ public constant list<String> simulationOptionsNames =
"options",
"outputFormat",
"variableFilter",
"measureTime"
"measureTime",
"cflags"
} "names of simulation options";

public function getSimulationResultType
Expand Down Expand Up @@ -287,6 +291,7 @@ public function buildSimulationOptions
input DAE.Exp outputFormat "output format, default 'plt'";
input DAE.Exp variableFilter;
input DAE.Exp measureTime;
input DAE.Exp cflags;
output SimulationOptions outSimulationOptions;
algorithm
outSimulationOptions :=
Expand All @@ -303,7 +308,8 @@ algorithm
options,
outputFormat,
variableFilter,
measureTime
measureTime,
cflags
);
end buildSimulationOptions;

Expand Down Expand Up @@ -331,6 +337,7 @@ algorithm
case (SIMULATION_OPTIONS(outputFormat = e), "outputFormat") then e;
case (SIMULATION_OPTIONS(variableFilter = e), "variableFilter") then e;
case (SIMULATION_OPTIONS(measureTime = e), "measureTime") then e;
case (SIMULATION_OPTIONS(cflags = e), "cflags") then e;
case (_, name)
equation
msg = "Unknown simulation option: " +& name;
Expand Down Expand Up @@ -397,10 +404,10 @@ protected function setFileNamePrefixInSimulationOptions
input String inFileNamePrefix;
output SimulationOptions outSimOpt;
protected
DAE.Exp startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime;
DAE.Exp startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime, cflags;
algorithm
SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, _, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime) := inSimOpt;
outSimOpt := SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, DAE.SCONST(inFileNamePrefix), storeInTemp, noClean, options, outputFormat, variableFilter, measureTime);
SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, _, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime, cflags) := inSimOpt;
outSimOpt := SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, DAE.SCONST(inFileNamePrefix), storeInTemp, noClean, options, outputFormat, variableFilter, measureTime, cflags);
end setFileNamePrefixInSimulationOptions;

protected function getConst
Expand Down Expand Up @@ -452,64 +459,64 @@ algorithm
DAE.Exp noClean;
DAE.Exp options;
DAE.Exp outputFormat;
DAE.Exp variableFilter, measureTime;
DAE.Exp variableFilter, measureTime, cflags;
Real rStepSize, rStopTime, rStartTime;
Integer iNumberOfIntervals;
String name,msg;

case (inSimOpt, {}) then inSimOpt;

case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime),
case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime, cflags),
Absyn.NAMEDARG(argName = "Tolerance", argValue = exp)::rest)
equation
tolerance = getConst(exp, DAE.ET_REAL());
simOpt = populateSimulationOptions(
SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime),
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime,cflags),
rest);
then
simOpt;

case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime),
case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime, cflags),
Absyn.NAMEDARG(argName = "StartTime", argValue = exp)::rest)
equation
startTime = getConst(exp, DAE.ET_REAL());
simOpt = populateSimulationOptions(
SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime),
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime,cflags),
rest);
then
simOpt;

case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime),
case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime, cflags),
Absyn.NAMEDARG(argName = "StopTime", argValue = exp)::rest)
equation
stopTime = getConst(exp, DAE.ET_REAL());
simOpt = populateSimulationOptions(
SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime),
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime,cflags),
rest);
then
simOpt;

case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime),
case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime, cflags),
Absyn.NAMEDARG(argName = "NumberOfIntervals", argValue = exp)::rest)
equation
numberOfIntervals = getConst(exp, DAE.ET_INT());
simOpt = populateSimulationOptions(
SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime),
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime,cflags),
rest);
then
simOpt;

case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime),
case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime, cflags),
Absyn.NAMEDARG(argName = "Interval", argValue = exp)::rest)
equation
DAE.RCONST(rStepSize) = getConst(exp, DAE.ET_REAL());
// a bit different for Interval, handle it LAST!!!!
SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime) =
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime,cflags) =
populateSimulationOptions(inSimOpt, rest);

DAE.RCONST(rStartTime) = startTime;
Expand All @@ -521,11 +528,11 @@ algorithm
stepSize = DAE.RCONST(rStepSize);

simOpt = SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime);
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime,cflags);
then
simOpt;

case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime),
case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime, cflags),
Absyn.NAMEDARG(argName = name, argValue = exp)::rest)
equation
msg = "Ignoring unknown experiment annotation option: " +& name +& " = " +& Dump.printExpStr(exp);
Expand Down Expand Up @@ -2147,13 +2154,14 @@ algorithm
Ceval.Msg msg;
Env.Cache cache;
Boolean measureTime;
case (cache,env,{Values.CODE(Absyn.C_TYPENAME(_)),starttime_v,stoptime_v,Values.INTEGER(interval_i),tolerance_v,Values.STRING(method_str),_,_,_,Values.STRING(options_str),Values.STRING(outputFormat_str),Values.STRING(variableFilter_str),Values.BOOL(measureTime)},
String cflags;
case (cache,env,{Values.CODE(Absyn.C_TYPENAME(_)),starttime_v,stoptime_v,Values.INTEGER(interval_i),tolerance_v,Values.STRING(method_str),_,_,_,Values.STRING(options_str),Values.STRING(outputFormat_str),Values.STRING(variableFilter_str),Values.BOOL(measureTime),Values.STRING(cflags)},
(st as Interactive.SYMBOLTABLE(ast = _)),msg)
equation
starttime_r = ValuesUtil.valueReal(starttime_v);
stoptime_r = ValuesUtil.valueReal(stoptime_v);
tolerance_r = ValuesUtil.valueReal(tolerance_v);
outSimSettings = SimCode.createSimulationSettings(starttime_r,stoptime_r,interval_i,tolerance_r,method_str,options_str,outputFormat_str,variableFilter_str,measureTime);
outSimSettings = SimCode.createSimulationSettings(starttime_r,stoptime_r,interval_i,tolerance_r,method_str,options_str,outputFormat_str,variableFilter_str,measureTime,cflags);
then
(cache, outSimSettings);
else
Expand Down Expand Up @@ -2207,7 +2215,7 @@ algorithm
Absyn.TimeStamp ts;

// do not recompile.
case (cache,env,{Values.CODE(Absyn.C_TYPENAME(classname)),starttime,stoptime,interval,tolerance,Values.STRING(method_str),Values.STRING(filenameprefix),Values.BOOL(cdToTemp),_,options,Values.STRING(outputFormat_str),_},
case (cache,env,{Values.CODE(Absyn.C_TYPENAME(classname)),starttime,stoptime,interval,tolerance,Values.STRING(method_str),Values.STRING(filenameprefix),Values.BOOL(cdToTemp),_,options,Values.STRING(outputFormat_str),_,_},
(st as Interactive.SYMBOLTABLE(ast = p as Absyn.PROGRAM(globalBuildTimes=Absyn.TIMESTAMP(_,edit)),explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
// If we already have an up-to-date version of the binary file, we don't need to recompile.
equation
Expand All @@ -2227,7 +2235,7 @@ algorithm
(cache,filenameprefix,method_str,outputFormat_str,st,init_filename,zeroAdditionalSimulationResultValues);

// compile the model
case (cache,env,vals as {Values.CODE(Absyn.C_TYPENAME(classname)),starttime,stoptime,interval,tolerance,method,Values.STRING(filenameprefix),Values.BOOL(cdToTemp),noClean,options,outputFormat,variableFilter,_},(st_1 as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
case (cache,env,vals as {Values.CODE(Absyn.C_TYPENAME(classname)),starttime,stoptime,interval,tolerance,method,Values.STRING(filenameprefix),Values.BOOL(cdToTemp),noClean,options,outputFormat,variableFilter,_,_},(st_1 as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
equation
(cdef as Absyn.CLASS(info = Absyn.INFO(buildTimes=ts as Absyn.TIMESTAMP(_,globalEdit)))) = Interactive.getPathedClassInProgram(classname,p);
Absyn.PROGRAM(_,_,Absyn.TIMESTAMP(globalBuild,_)) = p;
Expand Down Expand Up @@ -2261,7 +2269,9 @@ algorithm
(cache,filenameprefix,method_str,outputFormat_str,st2,init_filename,resultValues);

// failure
case (_,_,_,_,_)
case (_,_,vals,_,_)
equation
Error.assertion(listLength(vals) == 14, "buildModel failure, length = " +& intString(listLength(vals)), Absyn.dummyInfo);
then
fail();
end matchcontinue;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -2292,7 +2292,7 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
EXEEXT=<%makefileParams.exeext%>
DLLEXT=<%makefileParams.dllext%>
CFLAGS_BASED_ON_INIT_FILE=<%extraCflags%>
CFLAGS=$(CFLAGS_BASED_ON_INIT_FILE) -I"<%makefileParams.omhome%>/include/omc" <%makefileParams.cflags%>
CFLAGS=$(CFLAGS_BASED_ON_INIT_FILE) -I"<%makefileParams.omhome%>/include/omc" <%makefileParams.cflags%> <%match sopt case SOME(s as SIMULATION_SETTINGS(__)) then s.cflags /* From the simulate() command */%>
LDFLAGS=-L"<%makefileParams.omhome%>/lib/omc" <%makefileParams.ldflags%>
SENDDATALIBS=<%makefileParams.senddatalibs%>
PERL=perl
Expand Down
1 change: 1 addition & 0 deletions Compiler/susan_codegen/SimCode/SimCodeTV.mo
Expand Up @@ -110,6 +110,7 @@ package SimCode
String outputFormat;
String variableFilter;
Boolean measureTime;
String cflags;
end SIMULATION_SETTINGS;
end SimulationSettings;

Expand Down

0 comments on commit 772acb9

Please sign in to comment.