Skip to content

Commit

Permalink
Generate cleaner code for reinit statements
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed Jul 8, 2015
1 parent f186db9 commit d490ce2
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -2526,28 +2526,21 @@ template genreinits(SimWhenClause whenClauses, Text &varDecls, Text &auxFunction
::=
match whenClauses
case SIM_WHEN_CLAUSE(__) then
let helpIf = (conditions |> e => ' || (<%cref(e)%> && !$P$PRE<%cref(e)%> /* edge */)')
let ifthen = functionWhenReinitStatementThen(false, reinits, &varDecls, &auxFunction)
let initial_assign = match initialCall
case true then functionWhenReinitStatementThen(true, reinits, &varDecls, &auxFunction)
else '; /* nothing to do */'
let helpIf = (conditions |> e => '(<%cref(e)%> && !$P$PRE<%cref(e)%> /* edge */)';separator=" || ")
let ifthen = functionWhenReinitStatementThen(reinits, &varDecls, &auxFunction)

if reinits then
if boolAnd(intGt(listLength(conditions), 0), intGt(listLength(reinits), 0)) then
<<
/* for whenclause index <%int%> */
if(initial())
{
<%initial_assign%>
}
else if(0<%helpIf%>)
if(<%helpIf%>)
{
<%ifthen%>
}
>>
end genreinits;


template functionWhenReinitStatementThen(Boolean initialCall, list<WhenOperator> reinits, Text &varDecls, Text &auxFunction)
template functionWhenReinitStatementThen(list<WhenOperator> reinits, Text &varDecls, Text &auxFunction)
"Generates re-init statement for when equation."
::=
let body = (reinits |> reinit =>
Expand All @@ -2560,14 +2553,11 @@ template functionWhenReinitStatementThen(Boolean initialCall, list<WhenOperator>
'copy_real_array_data_mem(<%val%>, &<%cref(stateVar)%>);'
else
'<%cref(stateVar)%> = <%val%>;'
let needToIterate =
if not initialCall then
"data->simulationInfo.needToIterate = 1;"
<<
infoStreamPrint(LOG_EVENTS, 0, "reinit <%cref(stateVar)%> = %f", <%val%>);
<%preExp%>
<%lhs%>
<%needToIterate%>
infoStreamPrint(LOG_EVENTS, 0, "reinit <%cref(stateVar)%> = <%crefToPrintfArg(stateVar)%>", <%cref(stateVar)%>);
data->simulationInfo.needToIterate = 1;
>>
case TERMINATE(__) then
let &preExp = buffer ""
Expand Down

0 comments on commit d490ce2

Please sign in to comment.