Skip to content

Commit

Permalink
Write the rest of init.xml as file
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 12, 2016
1 parent cc7a3c9 commit 7ce0918
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 11 deletions.
175 changes: 165 additions & 10 deletions Compiler/SimCode/SerializeInitXML.mo
Expand Up @@ -41,13 +41,16 @@ import BackendDAE.VarKind;
import CR=ComponentReference;
import CodegenC;
import CodegenUtil;
import DAE.{Exp,Type};
import Dump;
import ExpressionDump.printExpStr;
import File.Escape.XML;
import Settings;
import SimCode.{SimulationSettings,VarInfo};
import SimCodeVar.{AliasVariable,Causality,SimVar};
import SimCodeUtil;
import Tpl;
import Types;
import Util;

public
Expand Down Expand Up @@ -382,6 +385,144 @@ algorithm
File.write(file, "\">\n");
end scalarVariableAttribute;

function scalarVariableType "Generates code for ScalarVariable Type file for FMU target."
input File.File file;
input String unit, displayUnit;
input Option<Exp> minValue, maxValue, startValue, nominalValue;
input Boolean isFixed;
input Type t;
protected
Absyn.Path path;
algorithm
_ := match t
case Type.T_INTEGER(__)
algorithm
File.write(file, "<Integer ");
scalarVariableTypeUseAttribute(file, startValue, "useStart", "start");
scalarVariableTypeFixedAttribute(file, isFixed);
scalarVariableTypeAttribute(file, minValue, "min");
scalarVariableTypeAttribute(file, maxValue, "max");
scalarVariableTypeStringAttribute(file, unit, "unit");
scalarVariableTypeStringAttribute(file, displayUnit, "displayUnit");
File.write(file, " />");
then ();
case Type.T_REAL(__)
algorithm
File.write(file, "<Real ");
scalarVariableTypeUseAttribute(file, startValue, "useStart", "start");
scalarVariableTypeFixedAttribute(file, isFixed);
scalarVariableTypeUseAttribute(file, nominalValue, "useNominal", "nominal");
scalarVariableTypeAttribute(file, minValue, "min");
scalarVariableTypeAttribute(file, maxValue, "max");
scalarVariableTypeStringAttribute(file, unit, "unit");
scalarVariableTypeStringAttribute(file, displayUnit, "displayUnit");
then ();
case Type.T_BOOL(__)
algorithm
File.write(file, "<Boolean ");
scalarVariableTypeUseAttribute(file, startValue, "useStart", "start");
scalarVariableTypeFixedAttribute(file, isFixed);
scalarVariableTypeStringAttribute(file, unit, "unit");
scalarVariableTypeStringAttribute(file, displayUnit, "displayUnit");
then ();
case Type.T_STRING(__)
algorithm
File.write(file, "<String ");
scalarVariableTypeUseAttribute(file, startValue, "useStart", "start");
scalarVariableTypeFixedAttribute(file, isFixed);
scalarVariableTypeStringAttribute(file, unit, "unit");
scalarVariableTypeStringAttribute(file, displayUnit, "displayUnit");
then ();
case Type.T_ENUMERATION(__)
algorithm
File.write(file, "<Integer ");
scalarVariableTypeUseAttribute(file, startValue, "useStart", "start");
scalarVariableTypeFixedAttribute(file, isFixed);
scalarVariableTypeStringAttribute(file, unit, "unit");
scalarVariableTypeStringAttribute(file, displayUnit, "displayUnit");
then ();
case Type.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(path=path))
algorithm
File.write(file, "<ExternalObject path=\"");
Dump.writePath(file, path, XML);
File.write(file, "\"");
then ();
else
algorithm
Error.addInternalError("ScalarVariableType: "+Types.unparseType(t), sourceInfo());
then fail();
end match;
File.write(file, " />");
end scalarVariableType;

function scalarVariableTypeUseAttribute
input File.File file;
input Option<Exp> startValue;
input String use, name;
protected
Exp exp;
algorithm
File.write(file, use);
_ := match startValue
case SOME(exp)
algorithm
File.write(file, "=\"true\" ");
File.write(file, name);
File.write(file, "=\"");
writeExp(file, exp);
File.write(file, "\"");
then ();
else
algorithm
File.write(file, "=\"false\"");
then ();
end match;
end scalarVariableTypeUseAttribute;

function scalarVariableTypeFixedAttribute
input File.File file;
input Boolean isFixed;
algorithm
File.write(file, " fixed=\"");
File.write(file, String(isFixed));
File.write(file, "\"");
end scalarVariableTypeFixedAttribute;

function scalarVariableTypeAttribute
input File.File file;
input Option<Exp> attr;
input String name;
protected
Exp exp;
algorithm
_ := match attr
case SOME(exp)
algorithm
File.write(file, " ");
File.write(file, name);
File.write(file, "=\"");
writeExp(file, exp);
File.write(file, "\"");
then ();
else ();
end match;
end scalarVariableTypeAttribute;

function scalarVariableTypeStringAttribute
input File.File file;
input String attr;
input String name;
algorithm
if attr=="" then
return;
end if;
File.write(file, " ");
File.write(file, name);
File.write(file, "=\"");
File.writeEscape(file, attr, XML);
File.write(file, "\"");
end scalarVariableTypeStringAttribute;

function getCausality "Returns the Causality Attribute of ScalarVariable."
input Causality c;
output String str;
Expand All @@ -399,10 +540,10 @@ function getVariablity "Returns the variablity Attribute of ScalarVariable."
output String str;
algorithm
str := match varKind
case VarKind.DISCRETE(__) then "discrete";
case VarKind.PARAM(__) then "parameter";
case VarKind.CONST(__) then "constant";
else "continuous";
case VarKind.DISCRETE(__) then "discrete";
case VarKind.PARAM(__) then "parameter";
case VarKind.CONST(__) then "constant";
else "continuous";
end match;
end getVariablity;

Expand All @@ -411,12 +552,12 @@ function getAliasVar "Returns the alias Attribute of ScalarVariable."
input AliasVariable aliasvar;
algorithm
_ := match aliasvar
case AliasVariable.ALIAS()
algorithm File.write(file, "\"alias\" aliasVariable=\""); CR.writeCref(file, aliasvar.varName); File.write(file, "\""); then ();
case AliasVariable.NEGATEDALIAS()
algorithm File.write(file, "\"negatedAlias\" aliasVariable=\""); CR.writeCref(file, aliasvar.varName); File.write(file, "\""); then ();
else
algorithm File.write(file, "\"noAlias\""); then ();
case AliasVariable.ALIAS()
algorithm File.write(file, "\"alias\" aliasVariable=\""); CR.writeCref(file, aliasvar.varName); File.write(file, "\""); then ();
case AliasVariable.NEGATEDALIAS()
algorithm File.write(file, "\"negatedAlias\" aliasVariable=\""); CR.writeCref(file, aliasvar.varName); File.write(file, "\""); then ();
else
algorithm File.write(file, "\"noAlias\""); then ();
end match;
end getAliasVar;

Expand All @@ -432,5 +573,19 @@ algorithm
File.writeInt(file, dt.sec, ":%02dZ");
end xsdateTime;

function writeExp
input File.File file;
input Exp exp;
algorithm
_ := match exp
case Exp.ICONST(__) algorithm File.writeInt(file, exp.integer); then ();
case Exp.RCONST(__) algorithm File.writeReal(file, exp.real); then ();
case Exp.SCONST(__) algorithm File.writeEscape(file, exp.string, XML); then ();
case Exp.BCONST(__) algorithm File.write(file, String(exp.bool)); then ();
case Exp.ENUM_LITERAL(__) algorithm File.writeInt(file, exp.index); then ();
else algorithm Error.addInternalError("initial value of unknown type: " + printExpStr(exp), sourceInfo()); then fail();
end match;
end writeExp;

annotation(__OpenModelica_Interface="backend");
end SerializeInitXML;
2 changes: 1 addition & 1 deletion Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -604,6 +604,7 @@ algorithm

System.realtimeTick(ClockIndexes.RT_PROFILER0);
codegenFuncs := {};
codegenFuncs := (function SerializeInitXML.simulationInitFileReturnBool(simCode=simCode, guid=guid)) :: codegenFuncs;
dumpTaskSystemIfFlag(simCode);
codegenFuncs := (function runTpl(func=function CodegenC.translateModel(in_a_simCode=simCode))) :: codegenFuncs;
for f in {
Expand Down Expand Up @@ -631,7 +632,6 @@ algorithm
end for;
codegenFuncs := (function runTpl(func=function CodegenC.simulationFile_mixAndHeader(a_simCode=simCode, a_modelNamePrefix=simCode.fileNamePrefix))) :: codegenFuncs;
codegenFuncs := (function runTplWriteFile(func=function CodegenC.simulationFile(in_a_simCode=simCode, in_a_guid=guid, in_a_isModelExchangeFMU=false), file=simCode.fileNamePrefix + ".c")) :: codegenFuncs;
codegenFuncs := (function SerializeInitXML.simulationInitFileReturnBool(simCode=simCode, guid=guid)) :: codegenFuncs;
if Flags.isSet(Flags.MODEL_INFO_JSON) then
codegenFuncs := (function runToStr(func=function SerializeModelInfo.serialize(code=simCode, withOperations=Flags.isSet(Flags.INFO_XML_OPERATIONS)))) :: codegenFuncs;
else
Expand Down

0 comments on commit 7ce0918

Please sign in to comment.