Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Fix codegeneration for reductions in simulation context


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13473 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 18, 2012
1 parent 166b767 commit 949be39
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -181,6 +181,14 @@ algorithm
outCrefIdent := DAE.CREF_IDENT(ident, identType, subscriptLst); // shareCref(DAE.CREF_IDENT(ident, identType, subscriptLst));
end makeCrefIdent;

public function makeUntypedCrefIdent
input DAE.Ident ident;
output ComponentRef outCrefIdent;
annotation(__OpenModelica_EarlyInline = true);
algorithm
outCrefIdent := DAE.CREF_IDENT(ident, DAE.T_UNKNOWN_DEFAULT, {});
end makeUntypedCrefIdent;

public function makeCrefQual
"@author: adrpo
This function creates a DAE.CREF_QUAL(ident, identType, subscriptLst, componentRef)"
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -7019,7 +7019,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp /*BUFP*/,
let foundFirst = if not ri.defaultValue then tempDecl("int",&tmpVarDecls)
let rangeExp = daeExp(iter.exp,context,&rangeExpPre,&tmpVarDecls)
let resType = expTypeArrayIf(typeof(exp))
let res = "_$reductionFoldTmpB"
let res = contextCref(makeUntypedCrefIdent("$reductionFoldTmpB"), context)
let &tmpVarDecls += '<%resType%> <%res%>;<%\n%>'
let resTmp = tempDecl(resType,&varDecls)
let &preDefault = buffer ""
Expand All @@ -7030,7 +7030,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp /*BUFP*/,
let guardCond = match iter.guardExp case SOME(grd) then daeExp(grd, context, &guardExpPre, &tmpVarDecls) else "1"
let empty = match identType case "modelica_metatype" then 'listEmpty(<%loopVar%>)' else '0 == size_of_dimension_base_array(<%loopVar%>, 1)'
let length = match identType case "modelica_metatype" then 'listLength(<%loopVar%>)' else 'size_of_dimension_base_array(<%loopVar%>, 1)'
let reductionBodyExpr = "_$reductionFoldTmpA"
let reductionBodyExpr = contextCref(makeUntypedCrefIdent("$reductionFoldTmpA"), context)
let bodyExprType = expTypeArrayIf(typeof(r.expr))
let reductionBodyExprWork = daeExp(r.expr, context, &bodyExpPre, &tmpVarDecls)
let &tmpVarDecls += '<%bodyExprType%> <%reductionBodyExpr%>;<%\n%>'
Expand Down
5 changes: 5 additions & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -2227,6 +2227,11 @@ end List;

package ComponentReference

function makeUntypedCrefIdent
input DAE.Ident ident;
output DAE.ComponentRef outCrefIdent;
end makeUntypedCrefIdent;

function crefStripLastSubs
input DAE.ComponentRef inComponentRef;
output DAE.ComponentRef outComponentRef;
Expand Down

0 comments on commit 949be39

Please sign in to comment.