Skip to content

Commit

Permalink
Revised createFunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored and OpenModelica-Hudson committed Aug 4, 2015
1 parent 228800e commit e427c5c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/OpenTURNS.mo
Expand Up @@ -117,7 +117,7 @@ algorithm
//print("strippedDae :");
//BackendDump.dump(strippedDae);
_ := System.realtimeTock(ClockIndexes.RT_CLOCK_BACKEND); // Is this necessary?
(_,libs,fileDir,_,_) := SimCodeMain.generateModelCode(strippedDae,inProgram,inDAElist,inPath,cname_str,SOME(simSettings),Absyn.FUNCTIONARGS({},{}));
(libs,fileDir,_,_) := SimCodeMain.generateModelCode(strippedDae,inProgram,inDAElist,inPath,cname_str,SOME(simSettings),Absyn.FUNCTIONARGS({},{}));

//print("..compiling, fileNamePrefix = "+fileNamePrefix+"\n");
CevalScript.compileModel(fileNamePrefix , libs);
Expand Down
39 changes: 18 additions & 21 deletions Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -122,7 +122,6 @@ protected function generateModelCodeFMU "
input String FMUType;
input String filenamePrefix;
input Option<SimCode.SimulationSettings> simSettingsOpt;
output BackendDAE.BackendDAE outIndexedBackendDAE;
output list<String> libs;
output String fileDir;
output Real timeSimCode;
Expand All @@ -141,9 +140,9 @@ algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE);
a_cref := Absyn.pathToCref(className);
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
(libs,libPaths,includes, includeDirs, recordDecls, functions, outIndexedBackendDAE, _, literals) :=
SimCodeUtil.createFunctions(p, dae, inBackendDAE, className);
simCode := createSimCode(outIndexedBackendDAE,
(libs,libPaths,includes, includeDirs, recordDecls, functions, literals) :=
SimCodeUtil.createFunctions(p, inBackendDAE);
simCode := createSimCode(inBackendDAE,
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, libPaths,simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{}));
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
SimCodeFunctionUtil.execStat("SimCode");
Expand All @@ -163,7 +162,6 @@ protected function generateModelCodeXML "
input Absyn.Path className;
input String filenamePrefix;
input Option<SimCode.SimulationSettings> simSettingsOpt;
output BackendDAE.BackendDAE outIndexedBackendDAE;
output list<String> libs;
output String fileDir;
output Real timeSimCode;
Expand All @@ -182,9 +180,9 @@ algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE);
a_cref := Absyn.pathToCref(className);
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
(libs, libPaths, includes, includeDirs, recordDecls, functions, outIndexedBackendDAE, _, literals) :=
SimCodeUtil.createFunctions(p, dae, inBackendDAE, className);
(simCode,_) := SimCodeUtil.createSimCode(outIndexedBackendDAE,
(libs, libPaths, includes, includeDirs, recordDecls, functions, literals) :=
SimCodeUtil.createFunctions(p, inBackendDAE);
(simCode,_) := SimCodeUtil.createSimCode(inBackendDAE,
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{}));
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
SimCodeFunctionUtil.execStat("SimCode");
Expand Down Expand Up @@ -222,7 +220,7 @@ algorithm
String FMUVersion,FMUType,filenameprefix,file_dir,resstr;
DAE.DAElist dae;
FCore.Graph graph;
BackendDAE.BackendDAE dlow,dlow_1,indexed_dlow_1;
BackendDAE.BackendDAE dlow,dlow_1;
list<String> libs;
GlobalScript.SymbolTable st;
Absyn.Program p;
Expand Down Expand Up @@ -258,7 +256,7 @@ algorithm
dlow_1 = BackendDAEUtil.getSolvedSystem(dlow,inFileNamePrefix);
timeBackend = System.realtimeTock(ClockIndexes.RT_CLOCK_BACKEND);

(indexed_dlow_1,libs,file_dir,timeSimCode,timeTemplates) =
(libs,file_dir,timeSimCode,timeTemplates) =
generateModelCodeFMU(dlow_1, p, dae, className, FMUVersion, FMUType, filenameprefix, inSimSettingsOpt);

//reset config flag
Expand All @@ -274,7 +272,7 @@ algorithm
resstr = Absyn.pathStringNoQual(className);
resstr = stringAppendList({"SimCode: The model ",resstr," has been translated to FMU"});
then
(cache,Values.STRING(resstr),st,indexed_dlow_1,libs,file_dir, resultValues);
(cache,Values.STRING(resstr),st,dlow_1,libs,file_dir, resultValues);
case (_,_,_,_,_,_,_,_,_)
equation
resstr = Absyn.pathStringNoQual(className);
Expand Down Expand Up @@ -311,7 +309,7 @@ algorithm
String filenameprefix,file_dir,resstr,description;
DAE.DAElist dae;
FCore.Graph graph;
BackendDAE.BackendDAE dlow,dlow_1,indexed_dlow_1;
BackendDAE.BackendDAE dlow,dlow_1;
list<String> libs;
GlobalScript.SymbolTable st;
Absyn.Program p;
Expand All @@ -334,7 +332,7 @@ algorithm
dlow_1 = BackendDAEUtil.getSolvedSystem(dlow,inFileNamePrefix);
timeBackend = System.realtimeTock(ClockIndexes.RT_CLOCK_BACKEND);

(indexed_dlow_1,libs,file_dir,timeSimCode,timeTemplates) =
(libs,file_dir,timeSimCode,timeTemplates) =
generateModelCodeXML(dlow_1, p, dae, className, filenameprefix, inSimSettingsOpt);
resultValues =
{("timeTemplates",Values.REAL(timeTemplates)),
Expand All @@ -345,7 +343,7 @@ algorithm
resstr = Absyn.pathStringNoQual(className);
resstr = stringAppendList({"SimCode: The model ",resstr," has been translated to XML"});
then
(cache,Values.STRING(resstr),st,indexed_dlow_1,libs,file_dir, resultValues);
(cache,Values.STRING(resstr),st,dlow_1,libs,file_dir, resultValues);
case (_,_,_,_,_,_, _)
equation
resstr = Absyn.pathStringNoQual(className);
Expand All @@ -368,7 +366,6 @@ public function generateModelCode "
input String filenamePrefix;
input Option<SimCode.SimulationSettings> simSettingsOpt;
input Absyn.FunctionArgs args;
output BackendDAE.BackendDAE outIndexedBackendDAE;
output list<String> libs;
output String fileDir;
output Real timeSimCode;
Expand All @@ -382,13 +379,13 @@ protected
tuple<Integer, HashTableExpToIndex.HashTable, list<DAE.Exp>> literals;
algorithm
if Flags.isSet(Flags.GRAPHML) then
HpcOmTaskGraph.dumpTaskGraph(inBackendDAE,filenamePrefix);
HpcOmTaskGraph.dumpTaskGraph(inBackendDAE, filenamePrefix);
end if;
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE);
a_cref := Absyn.pathToCref(className);
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
(libs, libPaths,includes, includeDirs, recordDecls, functions, outIndexedBackendDAE, _, literals) := SimCodeUtil.createFunctions(p, dae, inBackendDAE, className);
simCode := createSimCode(outIndexedBackendDAE, className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, simSettingsOpt, recordDecls, literals, args);
(libs, libPaths,includes, includeDirs, recordDecls, functions, literals) := SimCodeUtil.createFunctions(p, inBackendDAE);
simCode := createSimCode(inBackendDAE, className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, simSettingsOpt, recordDecls, literals, args);
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
SimCodeFunctionUtil.execStat("SimCode");

Expand Down Expand Up @@ -625,7 +622,7 @@ algorithm
String filenameprefix, file_dir, resstr, description;
DAE.DAElist dae;
FCore.Graph graph;
BackendDAE.BackendDAE dlow, dlow_1, indexed_dlow_1;
BackendDAE.BackendDAE dlow, dlow_1;
list<String> libs;
GlobalScript.SymbolTable st;
Absyn.Program p;
Expand All @@ -651,14 +648,14 @@ algorithm
dlow_1 = BackendDAEUtil.getSolvedSystem(dlow,inFileNamePrefix);
timeBackend = System.realtimeTock(ClockIndexes.RT_CLOCK_BACKEND);

(indexed_dlow_1, libs, file_dir, timeSimCode, timeTemplates) =
(libs, file_dir, timeSimCode, timeTemplates) =
generateModelCode(dlow_1, p, dae, className, filenameprefix, inSimSettingsOpt, args);

resultValues = {("timeTemplates", Values.REAL(timeTemplates)),
("timeSimCode", Values.REAL(timeSimCode)),
("timeBackend", Values.REAL(timeBackend)),
("timeFrontend", Values.REAL(timeFrontend))};
then (cache, st, indexed_dlow_1, libs, file_dir, resultValues);
then (cache, st, dlow_1, libs, file_dir, resultValues);

case (_, _, _, _, _, _, _, _) equation
true = Flags.isSet(Flags.FAILTRACE);
Expand Down
62 changes: 23 additions & 39 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -477,47 +477,31 @@ end createSimCode;

public function createFunctions
input Absyn.Program inProgram;
input DAE.DAElist inDAElist;
input BackendDAE.BackendDAE inBackendDAE;
input Absyn.Path inPath;
output list<String> libs;
output list<String> libPaths;
output list<String> includes;
output list<String> includeDirs;
output list<SimCode.RecordDeclaration> recordDecls;
output list<SimCode.Function> functions;
output BackendDAE.BackendDAE outBackendDAE;
output DAE.DAElist outDAE;
output tuple<Integer, HashTableExpToIndex.HashTable, list<DAE.Exp>> literals;
output list<String> outLibs;
output list<String> outLibPaths;
output list<String> outIncludes;
output list<String> outIncludeDirs;
output list<SimCode.RecordDeclaration> outRecordDecls;
output list<SimCode.Function> outFunctions;
output tuple<Integer, HashTableExpToIndex.HashTable, list<DAE.Exp>> outLiterals;
protected
list<DAE.Function> funcelems;
DAE.FunctionTree functionTree;
list<DAE.Exp> lits;
algorithm
(libs,libPaths, includes, includeDirs, recordDecls, functions, outBackendDAE, outDAE, literals) :=
matchcontinue (inProgram, inDAElist, inBackendDAE, inPath)
local
list<String> libs2,libpaths2, includes2, includeDirs2;
list<DAE.Function> funcelems, part_func_elems, recFuncs;
DAE.DAElist dae;
BackendDAE.BackendDAE dlow;
DAE.FunctionTree functionTree;
Absyn.Path path;
list<SimCode.Function> fns;
list<DAE.Exp> lits;

case (_, dae, dlow as BackendDAE.DAE(shared=BackendDAE.SHARED(functionTree=functionTree)), _)
equation
// get all the used functions from the function tree
funcelems = DAEUtil.getFunctionList(functionTree);
funcelems = setRecordVariability(funcelems,inBackendDAE);
funcelems = Inline.inlineCallsInFunctions(funcelems, (NONE(), {DAE.NORM_INLINE(), DAE.AFTER_INDEX_RED_INLINE()}), {});
(funcelems, literals as (_, _, lits)) = simulationFindLiterals(dlow, funcelems);
(fns, recordDecls, includes2, includeDirs2, libs2,libpaths2) = SimCodeFunctionUtil.elaborateFunctions(inProgram, funcelems, {}, lits, {}); // Do we need metarecords here as well?
then
(libs2, libpaths2,includes2, includeDirs2, recordDecls, fns, dlow, dae, literals);
else
equation
Error.addInternalError("Creation of Modelica functions failed.", sourceInfo());
then
fail();
end matchcontinue;
try
BackendDAE.DAE(shared=BackendDAE.SHARED(functionTree=functionTree)) := inBackendDAE;
// get all the used functions from the function tree
funcelems := DAEUtil.getFunctionList(functionTree);
funcelems := setRecordVariability(funcelems, inBackendDAE);
funcelems := Inline.inlineCallsInFunctions(funcelems, (NONE(), {DAE.NORM_INLINE(), DAE.AFTER_INDEX_RED_INLINE()}), {});
(funcelems, outLiterals as (_, _, lits)) := simulationFindLiterals(inBackendDAE, funcelems);
(outFunctions, outRecordDecls, outIncludes, outIncludeDirs, outLibs, outLibPaths) := SimCodeFunctionUtil.elaborateFunctions(inProgram, funcelems, {}, lits, {}); // Do we need metarecords here as well?
else
Error.addInternalError("Creation of Modelica functions failed.", sourceInfo());
fail();
end try;
end createFunctions;

protected function getParamAsserts"splits the equationArray in variable-dependent and parameter-dependent equations.
Expand Down

0 comments on commit e427c5c

Please sign in to comment.