Skip to content

Commit

Permalink
Added package XMLDump and API function dumpXMLDAE to obtain flattened…
Browse files Browse the repository at this point in the history
…, index-reduced models in XML format

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@3643 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Filippo Donida committed Sep 15, 2008
1 parent 0f42c0c commit c6f7622
Show file tree
Hide file tree
Showing 5 changed files with 3,205 additions and 3 deletions.
125 changes: 124 additions & 1 deletion Compiler/Ceval.mo
Expand Up @@ -94,7 +94,7 @@ protected import Error;
protected import Settings;
protected import Refactor;
protected import DAEQuery;

protected import XMLDump;

protected function cevalBuiltin "function: cevalBuiltin
Expand Down Expand Up @@ -3109,6 +3109,51 @@ algorithm
setEcho(bval);
then
(cache,v,st);
case (cache,env,(exp as
Exp.CALL(
path = Absyn.IDENT(name = "dumpXMLDAE"),
expLst =
{Exp.CODE(Absyn.C_TYPENAME(className),_),
starttime,
stoptime,
interval,
tolerance,
method,
filenameprefix,
storeInTemp})),
(st_1 as Interactive.SYMBOLTABLE(
ast = p,
explodedAst = sp,
instClsLst = ic,
lstVarVal = iv,
compiledFunctions = cf)),msg)
local
String xml_filename,xml_contents;
equation
(cache,st,xml_filename,xml_contents) = dumpXMLDAE(cache,env, exp, st_1, msg);
then
(cache,Values.ARRAY({Values.STRING(xml_filename),Values.STRING(xml_contents)}),st);

case (cache,env,(exp as
Exp.CALL(
path = Absyn.IDENT(name = "dumpXMLDAE"),
expLst =
{
Exp.CODE(Absyn.C_TYPENAME(className),_),
starttime,
stoptime,
interval,
tolerance,
method,
filenameprefix,
storeInTemp})),
(st_1 as Interactive.SYMBOLTABLE(
ast = p,
explodedAst = sp,
instClsLst = ic,
lstVarVal = iv,
compiledFunctions = cf)),msg) /* failing build_model */
then (cache,Values.ARRAY({Values.STRING("Xml dump error"),Values.STRING("")}),st_1);
end matchcontinue;
end cevalInteractiveFunctions;

Expand Down Expand Up @@ -6694,5 +6739,83 @@ algorithm
end matchcontinue;
end cevalSubscript;

//Functions added by fildo:
public function dumpXMLDAE "function buildModel
author: x02lucpo
translates and builds the model by running compiler script on the generated makefile"
input Env.Cache inCache;
input Env.Env inEnv;
input Exp.Exp inExp;
input Interactive.InteractiveSymbolTable inInteractiveSymbolTable;
input Msg inMsg;
output Env.Cache outCache;
output Interactive.InteractiveSymbolTable outInteractiveSymbolTable3;
output String xml_filename "initFileName";
output String xml_contents;
algorithm
(outCache,outInteractiveSymbolTable3,xml_filename,xml_contents):=
matchcontinue (inCache,inEnv,inExp,inInteractiveSymbolTable,inMsg)
local
Values.Value ret_val;
Interactive.InteractiveSymbolTable st,st_1;
DAELow.DAELow indexed_dlow_1;
list<String> libs;
String file_dir,cname_str,init_filename,method_str,filenameprefix,makefilename,oldDir,tempDir;
Absyn.Path classname;
Real starttime_r,stoptime_r,interval_r,tolerance_r;
list<Env.Frame> env;
Exp.Exp exp,starttime,stoptime,interval,tolerance,method,fileprefix,storeInTemp;
Exp.ComponentRef cr;
Absyn.Program p;
list<SCode.Class> sp;
list<Interactive.InstantiatedClass> ic;
list<Interactive.InteractiveVariable> iv;
list<Interactive.CompiledCFunction> cf;
Msg msg;
Env.Cache cache;
Boolean cdToTemp;
case (cache,env,(exp as Exp.CALL(path = Absyn.IDENT(name = _),
expLst = {Exp.CODE(Absyn.C_TYPENAME(classname),_),starttime,stoptime,interval,tolerance,method,fileprefix,storeInTemp})),
(st_1 as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
equation
_ = Error.getMessagesStr() "Clear messages";
(cache,Values.BOOL(cdToTemp),SOME(st)) = ceval(cache,env, storeInTemp, true, SOME(st_1), NONE, msg);
oldDir = System.pwd();
changeToTempDirectory(cdToTemp);
(cache,ret_val,st,indexed_dlow_1,libs,file_dir) = translateModel(cache,env, classname, st_1, msg, fileprefix);
cname_str = Absyn.pathString(classname);
(cache,init_filename,starttime_r,stoptime_r,interval_r,tolerance_r,method_str) = calculateSimulationSettings(cache,env, exp, st, msg, cname_str);
(cache,filenameprefix) = extractFilePrefix(cache,env, fileprefix, st, msg);

(cache,init_filename,starttime_r,stoptime_r,interval_r,tolerance_r,method_str) = calculateSimulationSettings(cache,env, exp, st, msg, cname_str);

xml_filename = Util.stringAppendList({filenameprefix,"_dump.xml"});
Print.clearBuf();
XMLDump.dumpDAELow(indexed_dlow_1);
xml_contents = Print.getString();
Print.clearBuf();
System.writeFile(xml_filename,xml_contents);

/*
cname_str = Absyn.pathString(classname);
(cache,init_filename,starttime_r,stoptime_r,interval_r,tolerance_r,method_str) = calculateSimulationSettings(cache,env, exp, st, msg, cname_str);
(cache,filenameprefix) = extractFilePrefix(cache,env, fileprefix, st, msg);
SimCodegen.generateInitData(indexed_dlow_1, classname, filenameprefix, init_filename,
starttime_r, stoptime_r, interval_r, tolerance_r, method_str);
makefilename = generateMakefilename(filenameprefix);
Debug.fprintln("dynload", "buildModel: about to compile model " +& filenameprefix +& ", " +& file_dir);
compileModel(filenameprefix, libs, file_dir);
Debug.fprintln("dynload", "buildModel: Compiling done.");
_ = System.cd(oldDir);
*/
// s_call = Util.stringAppendList({"make -f ",cname_str, ".makefile\n"});
then

(cache,st,xml_filename,xml_contents);
case (_,_,_,_,_)
then
fail();
end matchcontinue;
end dumpXMLDAE;
end Ceval;

3 changes: 2 additions & 1 deletion Compiler/Makefile.common
Expand Up @@ -62,7 +62,8 @@ SRCMO= Absyn.mo \
Values.mo \
VarTransform.mo \
Refactor.mo \
DAEQuery.mo
DAEQuery.mo \
XMLDump.mo

ALLMO = $(SRCMO) DAEEXT.mo Print.mo RTOpts.mo System.mo Parser.mo \
TaskGraphExt.mo Corba.mo Socket.mo ErrorExt.mo Settings.mo
Expand Down
3 changes: 2 additions & 1 deletion Compiler/Makefile.common.w32
Expand Up @@ -37,7 +37,8 @@ SRCMO= Absyn.mo \
Values.mo \
VarTransform.mo \
Refactor.mo \
DAEQuery.mo
DAEQuery.mo \
XMLDump.mo

ALLMO = $(SRCMO) \
DAEEXT.mo \
Expand Down
26 changes: 26 additions & 0 deletions Compiler/Static.mo
Expand Up @@ -5798,6 +5798,32 @@ algorithm
(cache,bool_exp_1,prop,st_1) = elabExp(cache,env, bool_exp, impl, SOME(st),true);
then
(cache,Exp.CALL(Absyn.IDENT("echo"),{bool_exp_1},false,true,Exp.STRING()),Types.PROP((Types.T_BOOL({}),NONE),Types.C_CONST()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "dumpXMLDAE"),{Absyn.CREF(componentReg = cr)},args,impl,SOME(st))
local Absyn.Path className; Exp.Exp storeInTemp;
equation
className = Absyn.crefToPath(cr);
(cache,startTime) = getOptionalNamedArg(cache,env, SOME(st), impl, "startTime", (Types.T_REAL({}),NONE),
args, Exp.RCONST(0.0));
(cache,stopTime) = getOptionalNamedArg(cache,env, SOME(st), impl, "stopTime", (Types.T_REAL({}),NONE),
args, Exp.RCONST(1.0));
(cache,numberOfIntervals) = getOptionalNamedArg(cache,env, SOME(st), impl, "numberOfIntervals",
(Types.T_INTEGER({}),NONE), args, Exp.ICONST(500));
(cache,tolerance) = getOptionalNamedArg(cache,env, SOME(st), impl, "tolerance", (Types.T_REAL({}),NONE),
args, Exp.RCONST(1e-10));
(cache,method) = getOptionalNamedArg(cache,env, SOME(st), impl, "method", (Types.T_STRING({}),NONE),
args, Exp.SCONST("dassl"));
cname_str = Absyn.pathString(className);
(cache,filenameprefix) = getOptionalNamedArg(cache,env, SOME(st), impl, "fileNamePrefix",
(Types.T_STRING({}),NONE), args, Exp.SCONST(cname_str));
(cache,storeInTemp) = getOptionalNamedArg(cache,env, SOME(st), impl, "storeInTemp",
(Types.T_BOOL({}),NONE), args, Exp.BCONST(false));
then
(cache,Exp.CALL(Absyn.IDENT("dumpXMLDAE"),
{Exp.CODE(Absyn.C_TYPENAME(className),Exp.OTHER()),startTime,stopTime,
numberOfIntervals,tolerance,method,filenameprefix,storeInTemp},false,true,Exp.OTHER()),Types.PROP(
(
Types.T_ARRAY(Types.DIM(SOME(2)),(Types.T_STRING({}),NONE)),NONE),Types.C_VAR()),SOME(st));
end matchcontinue;
end elabCallInteractive;

Expand Down

0 comments on commit c6f7622

Please sign in to comment.