Skip to content

Commit

Permalink
Reactivate Cpp code generation for SimCode.SES_FOR_LOOP
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Oct 4, 2018
1 parent 6952465 commit 3f4c043
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
27 changes: 4 additions & 23 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -11577,34 +11577,15 @@ template equationForLoop(SimEqSystem eq, Context context, Text &varDecls, SimCod
let endExp = daeExp(endIt, context, preExp, varDecls, simCode, extraFuncs, extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, false)
let expPart = daeExp(exp, context, preExp, varDecls, simCode, extraFuncs, extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, false)
let crefPart = daeExp(crefExp(cref), context, preExp, varDecls, simCode, extraFuncs, extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, false)
let crefWithIdx = crefWithIndex(cref, context, varDecls, simCode, extraFuncs, extraFuncsDecl, extraFuncsNamespace, stateDerVectorName /*=__zDot*/, useFlatArrayNotation)
let lhs = getLHS(cref, startExp, useFlatArrayNotation)
<<
<%preExp%>
//double *result = &<%cref(cref, false)%>[0];
double *result = &<%lhs%>;
for(int <%iterExp%> = <%startExp%>; <%iterExp%> != <%endExp%>+1; <%iterExp%>++)
result[i] = <%expPart%>;
for (int <%iterExp%> = <%startExp%>; <%iterExp%> <= <%endExp%>; <%iterExp%>++) {
<%preExp%>
<%crefPart%> = <%expPart%>;
}
>>
end equationForLoop;


template getLHS(ComponentRef cr, Text startExp, Boolean useFlatArrayNotation)
"Returns the left hand side of a for loop with the right var index, e.g., _resistor1_P_i.
Assumption: lhs = 'cref' + 'startIndex of for loop'."
::=
match cr
case CREF_QUAL(__) then
//"_" + '<%ident%><%startExp%><%subscriptsToCStrForArray(subscriptLst)%>_P_<%crefToCStr(componentRef,useFlatArrayNotation)%>'
"_" + '<%crefAppendedSubs(cr)%>'
else "CREF_NOT_QUAL"
end match
end getLHS;





template testDaeDimensionExp(Exp exp)
"Generates code for an expression."
::=
Expand Down
1 change: 1 addition & 0 deletions Compiler/Template/CodegenCppCommon.tpl
Expand Up @@ -53,6 +53,7 @@ template subscriptToCStr(Subscript subscript)
match exp
case ICONST(integer=i) then i
case ENUM_LITERAL(index=i) then i
case CREF(componentRef=cr) then crefToCStr(cr, false)
end match
else "UNKNOWN_SUBSCRIPT"
end subscriptToCStr;
Expand Down
3 changes: 2 additions & 1 deletion Compiler/Template/CodegenUtil.tpl
Expand Up @@ -124,12 +124,13 @@ end subscriptsStr;

template subscriptStr(Subscript subscript)
"Generates a single subscript.
Only works for constant integer indicies."
Only works for constant integer and cref indicies."

::=
match subscript
case INDEX(exp=ICONST(integer=i)) then i
case INDEX(exp=ENUM_LITERAL(name=n)) then dotPath(n)
case INDEX(exp=CREF()) then printExpStr(exp)
case SLICE(exp=ICONST(integer=i)) then i
case INDEX(__)
case SLICE(__) then 'UNKNOWN_SUBSCRIPT /* <%escapeCComments(printExpStr(exp))%> */'
Expand Down

0 comments on commit 3f4c043

Please sign in to comment.