Skip to content

Commit 1054196

Browse files
author
Willi Braun
committed
[newSimulationRuntime]
- added and adjusted FMU export for new simulation runtime(need more work) git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10622 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 1ac926d commit 1054196

File tree

13 files changed

+1249
-116
lines changed

13 files changed

+1249
-116
lines changed

Compiler/BackEnd/SimCode.mo

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ protected import Builtin;
8383
protected import CevalScript;
8484
protected import ClassInf;
8585
protected import CodegenC;
86+
protected import CodegenFMU;
8687
protected import ComponentReference;
8788
protected import Config;
8889
protected import DAEDump;
@@ -954,7 +955,7 @@ algorithm
954955
Debug.execStat("SimCode",CevalScript.RT_CLOCK_BUILD_MODEL);
955956

956957
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
957-
Tpl.tplNoret(SimCodeFMU.translateModel, simCode);
958+
callTargetTemplatesFMU(simCode, Config.simCodeTarget());
958959
timeTemplates := System.realtimeTock(CevalScript.RT_CLOCK_BUILD_MODEL);
959960
end generateModelCodeFMU;
960961

@@ -1139,6 +1140,39 @@ algorithm
11391140
end match;
11401141
end callTargetTemplates;
11411142

1143+
protected function callTargetTemplatesFMU
1144+
"Generate target code by passing the SimCode data structure to templates."
1145+
input SimCode simCode;
1146+
input String target;
1147+
algorithm
1148+
_ := match (simCode,target)
1149+
local
1150+
BackendDAE.BackendDAE outIndexedBackendDAE;
1151+
array<Integer> equationIndices, variableIndices;
1152+
BackendDAE.IncidenceMatrix incidenceMatrix;
1153+
BackendDAE.IncidenceMatrixT incidenceMatrixT;
1154+
BackendDAE.StrongComponents strongComponents;
1155+
1156+
case (simCode,"C")
1157+
equation
1158+
Tpl.tplNoret(SimCodeFMU.translateModel, simCode);
1159+
then ();
1160+
case (simCode,"c")
1161+
equation
1162+
Tpl.tplNoret(CodegenFMU.translateModel, simCode);
1163+
then ();
1164+
case (simCode,"Dump")
1165+
equation
1166+
// Yes, do this better later on...
1167+
print(Tpl.tplString(SimCodeDump.dumpSimCode, simCode));
1168+
then ();
1169+
case (_,target)
1170+
equation
1171+
target = "Unknown template target: " +& target;
1172+
Error.addMessage(Error.INTERNAL_ERROR, {target});
1173+
then fail();
1174+
end match;
1175+
end callTargetTemplatesFMU;
11421176

11431177

11441178
public function translateModel
@@ -5732,7 +5766,7 @@ algorithm
57325766

57335767
e = Expression.crefExp(cref);
57345768
tp = Expression.typeof(e);
5735-
startExp = Expression.makeBuiltinCall("start", {e}, tp);
5769+
startExp = Expression.makeBuiltinCall("$_start", {e}, tp);
57365770
e2 = DAE.BINARY(crefExp, DAE.SUB(DAE.T_REAL_DEFAULT), startExp);
57375771

57385772
e1 = DAE.BINARY(e1, DAE.MUL(DAE.T_REAL_DEFAULT), e2);
@@ -7626,7 +7660,7 @@ algorithm
76267660
//startv = DAEUtil.getStartAttr(attr);
76277661
e = Expression.crefExp(cr);
76287662
tp = Expression.typeof(e);
7629-
startv = Expression.makeBuiltinCall("start", {e}, tp);
7663+
startv = Expression.makeBuiltinCall("$_start", {e}, tp);
76307664
then
76317665
((v,(BackendDAE.EQUATION(e,startv,source)::eqns,av)));
76327666
case (((v as BackendDAE.VAR(varName = cr,varKind = BackendDAE.STATE(),values = attr,source=source)),(eqns,av))) /* add equations for variables with fixed = true */
@@ -7637,7 +7671,7 @@ algorithm
76377671
//startv = DAEUtil.getStartAttr(attr);
76387672
e = Expression.crefExp(cr);
76397673
tp = Expression.typeof(e);
7640-
startv = Expression.makeBuiltinCall("start", {e}, tp);
7674+
startv = Expression.makeBuiltinCall("$_start", {e}, tp);
76417675
then
76427676
((v,(BackendDAE.EQUATION(e,startv,source)::eqns,av)));
76437677
case ((inTpl)) then inTpl;

Compiler/Makefile.common

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ Ceval.mo \
4040
CevalFunction.mo \
4141
ClassInf.mo \
4242
ClassLoader.mo \
43-
CodegenC.mo \
4443
ComponentReference.mo \
4544
Connect.mo \
4645
ConnectUtil.mo \
@@ -127,6 +126,8 @@ GLOBAL = \
127126
Global.mo
128127

129128
TEMPLATE = \
129+
CodegenC.mo \
130+
CodegenFMU.mo \
130131
SCodeDumpTpl.mo \
131132
SimCodeC.mo \
132133
SimCodeCSharp.mo \

Compiler/susan_codegen/SimCode/CodegenC.tpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ case simCode as SIMCODE(modelInfo=MODELINFO(__)) then
110110
>>
111111
end simulationHeaderFile;
112112

113+
113114
template simulationFile(SimCode simCode, String guid)
114115
"Generates code for main C file for simulation target."
115116
::=
@@ -118,6 +119,7 @@ case simCode as SIMCODE(__) then
118119
<<
119120
<%simulationFileHeader(simCode)%>
120121
<%externalFunctionIncludes(externalFunctionIncludes)%>
122+
#include "<%fileNamePrefix%>.h"
121123
#include "<%fileNamePrefix%>_functions.c"
122124
#define _OMC_SEED_HACK char* _omc_hack
123125
#define _OMC_SEED_HACK_2 NULL
@@ -215,8 +217,6 @@ case SIMCODE(modelInfo=MODELINFO(__), extObjInfo=EXTOBJINFO(__)) then
215217

216218
#include "<%fileNamePrefix%>_functions.h"
217219

218-
#include "<%fileNamePrefix%>.h"
219-
220220
>>
221221
end simulationFileHeader;
222222

@@ -2049,7 +2049,7 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
20492049
CFLAGS_BASED_ON_INIT_FILE=<%extraCflags%>
20502050
CFLAGS=$(CFLAGS_BASED_ON_INIT_FILE) <%makefileParams.cflags%> <%match sopt case SOME(s as SIMULATION_SETTINGS(__)) then s.cflags /* From the simulate() command */%>
20512051
CPPFLAGS=-I"<%makefileParams.omhome%>/include/omc2" -I. <%dirExtra%> <%makefileParams.includes ; separator=" "%>
2052-
LDFLAGS=-L"<%makefileParams.omhome%>/lib/omc2" -lSimulationRuntimeC <%makefileParams.ldflags%>
2052+
LDFLAGS=-L"<%makefileParams.omhome%>/lib/omc2" -lSimulationRuntimeC <%makefileParams.ldflags%> -ldl
20532053
SENDDATALIBS=<%makefileParams.senddatalibs%>
20542054
PERL=perl
20552055
MAINFILE=<%fileNamePrefix%><% if acceptMetaModelicaGrammar() then ".conv"%>.c
@@ -5145,7 +5145,8 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/,
51455145
error(sourceInfo(), 'Code generation does not support der(<%printExpStr(exp)%>)')
51465146
case CALL(path=IDENT(name="pre"), expLst={arg}) then
51475147
daeExpCallPre(arg, context, preExp, varDecls)
5148-
case CALL(path=IDENT(name="start"), expLst={arg}) then
5148+
// a $_start is used to get get start value of a variable
5149+
case CALL(path=IDENT(name="$_start"), expLst={arg}) then
51495150
daeExpCallStart(arg, context, preExp, varDecls)
51505151
case CALL(path=IDENT(name="edge"), expLst={arg as CREF(__)}) then
51515152
'(<%cref(arg.componentRef)%> && !$P$PRE<%cref(arg.componentRef)%>)'

0 commit comments

Comments
 (0)