@@ -48,10 +48,6 @@ package CodegenC
4848import interface SimCodeTV;
4949import CodegenUtil.*;
5050
51- template escapeCComments(String stringWithCComments)
52- "escape the C comments inside a string, replaces them with /* */->(* *)"
53- ::= '<%System.stringReplace(System.stringReplace(stringWithCComments, "/*", "(*"), "*/", "*)")%>'
54- end escapeCComments;
5551
5652template translateModel(SimCode simCode, String guid)
5753 "Generates C code and Makefile for compiling and running a simulation of a
@@ -3482,127 +3478,6 @@ template intArr(list<Integer> values)
34823478 >>
34833479end intArr;
34843480
3485- template equationIndex(SimEqSystem eq)
3486- "Generates an equation."
3487- ::=
3488- match eq
3489- case SES_RESIDUAL(__)
3490- case SES_SIMPLE_ASSIGN(__)
3491- case SES_ARRAY_CALL_ASSIGN(__)
3492- case SES_IFEQUATION(__)
3493- case SES_ALGORITHM(__)
3494- case SES_LINEAR(__)
3495- case SES_NONLINEAR(__)
3496- case SES_MIXED(__)
3497- case SES_WHEN(__)
3498- then index
3499- end equationIndex;
3500-
3501- template dumpEqs(list<SimEqSystem > eqs)
3502- ::= eqs |> eq hasindex i0 =>
3503- match eq
3504- case e as SES_RESIDUAL(__) then
3505- <<
3506- equation index: <%equationIndex(eq)%>
3507- type: RESIDUAL
3508-
3509- <%escapeCComments(printExpStr(e.exp))%>
3510- >>
3511- case e as SES_SIMPLE_ASSIGN(__) then
3512- <<
3513- equation index: <%equationIndex(eq)%>
3514- type: SIMPLE_ASSIGN
3515- <%crefStr(e.cref)%> = <%escapeCComments(printExpStr(e.exp))%>
3516- >>
3517- case e as SES_ARRAY_CALL_ASSIGN(__) then
3518- <<
3519- equation index: <%equationIndex(eq)%>
3520- type: ARRAY_CALL_ASSIGN
3521-
3522- <%crefStr(e.componentRef)%> = <%escapeCComments(printExpStr(e.exp))%>
3523- >>
3524- case e as SES_ALGORITHM(statements={ } ) then
3525- <<
3526- empty algorithm
3527- >>
3528- case e as SES_ALGORITHM(statements=first::_) then
3529- <<
3530- equation index: <%equationIndex(eq)%>
3531- type: ALGORITHM
3532-
3533- <%e.statements |> stmt => escapeCComments(ppStmtStr(stmt,2))%>
3534- >>
3535- case e as SES_LINEAR(__) then
3536- <<
3537- equation index: <%equationIndex(eq)%>
3538- type: LINEAR
3539-
3540- <%e.vars |> SIMVAR(name=cr) => '<var ><%crefStr(cr)%></var >' ; separator = "\n" %>
3541- <row >
3542- <%beqs |> exp => '<cell ><%escapeCComments(printExpStr(exp))%></cell >' ; separator = "\n" %><%\n%>
3543- </row >
3544- <matrix >
3545- <%simJac |> (i1,i2,eq) =>
3546- <<
3547- <cell row =" <%i1%>" col =" <%i2%>" >
3548- <%match eq case e as SES_RESIDUAL(__) then
3549- <<
3550- <residual ><%escapeCComments(printExpStr(e.exp))%></residual >
3551- >>
3552- %>
3553- </cell >
3554- >>
3555- %>
3556- </matrix >
3557- >>
3558- case e as SES_NONLINEAR(__) then
3559- <<
3560- equation index: <%equationIndex(eq)%>
3561- indexNonlinear: <%indexNonLinearSystem%>
3562- type: NONLINEAR
3563-
3564- vars: { <% e.crefs |> cr => ' <%crefStr(cr)%>' ; separator = " , " %> }
3565- eqns: { <% e.eqs |> eq => ' <%equationIndex(eq)%>' ; separator = " , " %> }
3566- >>
3567- case e as SES_MIXED(__) then
3568- <<
3569- equation index: <%equationIndex(eq)%>
3570- type: MIXED
3571-
3572- <%dumpEqs(fill(e.cont,1))%>
3573- <%dumpEqs(e.discEqs)%><%\n%>
3574-
3575- <mixed >
3576- <continuous index =" <%equationIndex(e.cont)%>" />
3577- <%e.discVars |> SIMVAR(name=cr) => '<var ><%crefStr(cr)%></var >' ; separator = ","%>
3578- <%e.discEqs |> eq => '<discrete index =" <%equationIndex(eq)%>" />'%>
3579- </mixed >
3580- >>
3581- case e as SES_WHEN(__) then
3582- <<
3583- equation index: <%equationIndex(eq)%>
3584- type: WHEN
3585-
3586- when { <% conditions |> cond => ' <%crefStr(cond)%>' ; separator= " , " %> } then
3587- <%crefStr(e.left)%> = <%escapeCComments(printExpStr(e.right))%>;
3588- end when;
3589- >>
3590- case e as SES_IFEQUATION(__) then
3591- let branches = ifbranches |> (_,eqs) => dumpEqs(eqs)
3592- let elsebr = dumpEqs(elsebranch)
3593- <<
3594- equation index: <%equationIndex(eq)%>
3595- type: IFEQUATION
3596-
3597- <%branches%>
3598- <%elsebr%>
3599- >>
3600- else
3601- <<
3602- unknown equation
3603- >>
3604- end dumpEqs;
3605-
36063481template equation_arrayFormat(SimEqSystem eq, String name, Context context, Integer arrayIndex, Text &varDecls /*BUFP*/, Text &eqArray, Text &eqfuncs, String modelNamePrefix)
36073482 "Generates an equation.
36083483 This template should not be used for a SES_RESIDUAL.
0 commit comments