Skip to content

Commit

Permalink
added generation of script file for windows to run cpp simulation wit…
Browse files Browse the repository at this point in the history
…h simulation parameter

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18543 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Dec 20, 2013
1 parent 5a09ffa commit ffcb55f
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Compiler/BackEnd/SimCode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ uniontype SimCode
end SIMCODE;
end SimCode;



uniontype DelayedExpression
"Delayed expressions type"
record DELAYED_EXPRESSIONS
Expand Down Expand Up @@ -507,6 +509,7 @@ uniontype MakefileParams
list<String> includes;
list<String> libs;
String platform;
String compileDir;
end MAKEFILE_PARAMS;
end MakefileParams;

Expand Down
5 changes: 3 additions & 2 deletions Compiler/BackEnd/SimCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -5776,7 +5776,7 @@ public function createMakefileParams
input Boolean isFunction;
output SimCode.MakefileParams makefileParams;
protected
String omhome, ccompiler, cxxcompiler, linker, exeext, dllext, cflags, ldflags, rtlibs, platform, fopenmp;
String omhome, ccompiler, cxxcompiler, linker, exeext, dllext, cflags, ldflags, rtlibs, platform, fopenmp,compileDir;
algorithm
ccompiler := Util.if_(stringEq(Config.simCodeTarget(),"JavaScript"),"emcc",
Util.if_(Flags.isSet(Flags.OPENMP) or Flags.isSet(Flags.HPCOM),System.getOMPCCompiler(),
Expand All @@ -5792,8 +5792,9 @@ algorithm
ldflags := System.getLDFlags();
rtlibs := Util.if_(isFunction, System.getRTLibs(), System.getRTLibsSim());
platform := System.modelicaPlatform();
compileDir := System.pwd() +& System.pathDelimiter();
makefileParams := SimCode.MAKEFILE_PARAMS(ccompiler, cxxcompiler, linker, exeext, dllext,
omhome, cflags, ldflags, rtlibs, includes, libs, platform);
omhome, cflags, ldflags, rtlibs, includes, libs, platform,compileDir);
end createMakefileParams;

protected function elaborateRecordDeclarationsFromTypes
Expand Down
101 changes: 99 additions & 2 deletions Compiler/Template/CodegenCpp.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ template translateModel(SimCode simCode) ::=
let()= textFile(simulationFunctionsHeaderFile(simCode,modelInfo.functions,literals), 'OMCpp<%lastIdentOfPath(modelInfo.name)%>Functions.h')
let()= textFile(simulationFunctionsFile(simCode, modelInfo.functions,literals), 'OMCpp<%lastIdentOfPath(modelInfo.name)%>Functions.cpp')
let()= textFile(simulationMakefile(target,simCode), '<%fileNamePrefix%>.makefile')
let()= textFile(simulationMainRunScrip(simCode), 'OMCpp<%fileNamePrefix%>Run<%simulationMainRunScripSuffix(simCode)%>')
algloopfiles(listAppend(allEquations,initialEquations),simCode)
// empty result of the top-level template .., only side effects
end translateModel;



template translateFunctions(FunctionCode functionCode)
"Generates C code and Makefile for compiling and calling Modelica and
MetaModelica functions."
Expand All @@ -44,6 +43,104 @@ case SIMCODE(__) then
end simulationHeaderFile;


template simulationMainRunScrip(SimCode simCode)
"Generates code for header file for simulation target."
::=
match simCode
case SIMCODE(makefileParams=MAKEFILE_PARAMS(__)) then
<<
<%simulationMainRunScrip2(makefileParams.platform,simCode)%>
>>
end simulationMainRunScrip;


template simulationMainRunScrip2(String platform, SimCode simCode)
"Generates code for header file for simulation target."
::=
match platform
case "linux64"
case "linux32" then
match simCode
case SIMCODE(modelInfo=MODELINFO(__),makefileParams=MAKEFILE_PARAMS(__)) then
<<

>>
end match
case "win32"
case "win64" then
match simCode
case SIMCODE(modelInfo=MODELINFO(__),makefileParams=MAKEFILE_PARAMS(__),simulationSettingsOpt = SOME(settings as SIMULATION_SETTINGS(__))) then
let start = settings.startTime
let end = settings.stopTime
let stepsize = settings.stepSize
let intervals = settings.numberOfIntervals
let tol = settings.tolerance
let solver = settings.method
let moLib = makefileParams.compileDir
let home = makefileParams.omhome
<<
set PATHTMP=%PATH%
set PATH = %PATH%;<%home%>/bin
OMCpp<%fileNamePrefix%>.exe -s <%start%> -e <%end%> -f <%stepsize%> -v <%intervals%> -y <%tol%> -i <%solver%> -r <%simulationLibDir(simulationCodeTarget(),simCode)%> -m <%moLib%> -R <%simulationResults(getRunningTestsuite(),simCode)%>
set PATH = %PATHTMP%
>>
end match
end simulationMainRunScrip2;


template simulationLibDir(String target, SimCode simCode)
"Generates code for header file for simulation target."
::=
match target
case "msvc" then
match simCode
case SIMCODE(makefileParams=MAKEFILE_PARAMS(__)) then
<< <%makefileParams.omhome%>/lib/omc/cpp/msvc >>
end match
else
match simCode
case SIMCODE(makefileParams=MAKEFILE_PARAMS(__)) then
<<<%makefileParams.omhome%>/lib/omc/cpp/ >>
end match
end simulationLibDir;


template simulationResults(Boolean test, SimCode simCode)
"Generates code for header file for simulation target."
::=
match simCode
case SIMCODE(modelInfo=MODELINFO(__),makefileParams=MAKEFILE_PARAMS(__),simulationSettingsOpt = SOME(settings as SIMULATION_SETTINGS(__))) then
let results = if test then "" else '<%makefileParams.omhome%>/'
<<
<%results%><%lastIdentOfPath(modelInfo.name)%>res_.<%settings.outputFormat%>
>>
end simulationResults;


template simulationMainRunScripSuffix(SimCode simCode)
"Generates code for header file for simulation target."
::=
match simCode
case SIMCODE( makefileParams=MAKEFILE_PARAMS(__)) then
<<<%simulationMainRunScripSuffix2(makefileParams.platform,simCode)%>>>
end simulationMainRunScripSuffix;



template simulationMainRunScripSuffix2(String platform,SimCode simCode)
"Generates code for header file for simulation target."
::=
match platform
case "linux64"
case "linux32" then
<<.sh>>
case "win32"
case "win64" then
<<.bat>>
end simulationMainRunScripSuffix2;



template simulationMainFile(SimCode simCode)
"Generates code for header file for simulation target."
::=
Expand Down
1 change: 1 addition & 0 deletions Compiler/Template/SimCodeTV.mo
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ package SimCode
list<String> includes;
list<String> libs;
String platform;
String compileDir;
end MAKEFILE_PARAMS;
end MakefileParams;

Expand Down

0 comments on commit ffcb55f

Please sign in to comment.