Skip to content

Commit

Permalink
- Fixed codegen for reductions using guards (except for array-reducti…
Browse files Browse the repository at this point in the history
…ons)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8198 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Mar 12, 2011
1 parent 39fa6f6 commit f668356
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -5457,6 +5457,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp /*BUFP*/,
else tempDecl(arrayType,&tmpVarDecls)
let firstIndex = match identType case "modelica_metatype" then "" else tempDecl("int",&tmpVarDecls)
let arrIndex = match ri.path case IDENT(name="array") then tempDecl("int",&tmpVarDecls)
let foundFirst = if not ri.defaultValue then tempDecl("int",&tmpVarDecls)
let rangeExp = daeExp(r.range,context,&rangeExpPre,&tmpVarDecls)
let resType = expTypeArrayIf(typeof(exp))
let res = "_$reductionFoldTmpB"
Expand Down Expand Up @@ -5486,9 +5487,18 @@ template daeExpReduction(Exp exp, Context context, Text &preExp /*BUFP*/,
case IDENT(name="array") then
'*(<%arrayTypeResult%>_element_addr1(&<%res%>, 1, <%arrIndex%>++)) = <%reductionBodyExpr%>;'
else match ri.foldExp case SOME(fExp) then
let &foldExpPre = buffer ""
let fExpStr = daeExp(fExp, context, &bodyExpPre, &tmpVarDecls)
if not ri.defaultValue then
<<
<%res%> = <%daeExp(fExp, context, &bodyExpPre, &tmpVarDecls)%>;
if (<%foundFirst%>) {
<%res%> = <%fExpStr%>;
} else {
<%res%> = <%reductionBodyExpr%>;
<%foundFirst%> = 1;
}
>>
else '<%res%> = <%fExpStr%>;'
let firstValue = match ri.path
case IDENT(name="array") then
<<
Expand All @@ -5502,21 +5512,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp /*BUFP*/,
>>
else
<<
if (<%empty%>) MMC_THROW(); /* <%dotPath(ri.path)%> does not have a default value for empty ranges */
<% match identType
case "modelica_metatype" then
let &preUnbox = buffer ""
let unboxedVar = unboxVariable('MMC_CAR(<%loopVar%>)',typeof(exp),&preUnbox,&tmpVarDecls)
<<
<%&preUnbox%>
<%res%> = <%unboxedVar%>;
<%loopVar%> = MMC_CDR(<%loopVar%>);
>>
else
<<
<%res%> = *(<%arrayType%>_element_addr1(&<%loopVar%>, 1, <%firstIndex%>++));
>>
%>
<%foundFirst%> = 0; /* <%dotPath(ri.path)%> lacks default-value */
>>
let iteratorName = contextIteratorName(ri.ident, context)
let loopHead = match identType
Expand Down Expand Up @@ -5552,6 +5548,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp /*BUFP*/,
<%foldExp%>
}
<%loopTail%>
<% if not ri.defaultValue then 'if (!<%foundFirst%>) MMC_THROW();' %>
<% if resTail then '*<%resTail%> = mmc_mk_nil();' %>
<% resTmp %> = <% res %>;
}<%\n%>
Expand Down

0 comments on commit f668356

Please sign in to comment.