diff --git a/Compiler/SimCode/SerializeInitXML.mo b/Compiler/SimCode/SerializeInitXML.mo index cc7c0c92416..6fee8a6cf57 100644 --- a/Compiler/SimCode/SerializeInitXML.mo +++ b/Compiler/SimCode/SerializeInitXML.mo @@ -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 @@ -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 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, ""); + then (); + case Type.T_REAL(__) + algorithm + File.write(file, ""); +end scalarVariableType; + +function scalarVariableTypeUseAttribute + input File.File file; + input Option 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 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; @@ -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; @@ -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; @@ -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; diff --git a/Compiler/SimCode/SimCodeMain.mo b/Compiler/SimCode/SimCodeMain.mo index 660bf660fa6..d315fc09c73 100644 --- a/Compiler/SimCode/SimCodeMain.mo +++ b/Compiler/SimCode/SimCodeMain.mo @@ -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 { @@ -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