Skip to content

Commit

Permalink
[NF] Various fixes.
Browse files Browse the repository at this point in the history
- Unpack input arrays that have been packed after an external call.
- Fix ordering of initial algorithm sections.
- Type cast the branches of an if-expression instead of the whole
  expression.
- Fix expansion of cast expressions.

Belonging to [master]:
  - OpenModelica/OMCompiler#2906
  - OpenModelica/OpenModelica-testsuite#1116
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 29, 2019
1 parent 9a35199 commit 38fd61a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFConvertDAE.mo
Expand Up @@ -875,7 +875,7 @@ function convertInitialAlgorithms
input list<Algorithm> algorithms;
input output list<DAE.Element> elements;
algorithm
for alg in algorithms loop
for alg in listReverse(algorithms) loop
elements := convertInitialAlgorithm(alg, elements);
end for;
end convertInitialAlgorithms;
Expand Down
4 changes: 1 addition & 3 deletions Compiler/NFFrontEnd/NFExpandExp.mo
Expand Up @@ -943,13 +943,11 @@ public
input Type ty;
output Expression outExp;
output Boolean expanded;
protected
Type ety = Type.arrayElementType(ty);
algorithm
(outExp, expanded) := expand(exp);

if expanded then
outExp := Expression.mapArrayElements(outExp, function Expression.typeCast(castTy = ety));
outExp := Expression.typeCastElements(outExp, ty);
else
outExp := exp;
end if;
Expand Down
10 changes: 8 additions & 2 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -817,7 +817,7 @@ public
algorithm
exp := match (exp, ty)
local
Type t;
Type t, ety;
list<Expression> el;

case (INTEGER(), Type.REAL())
Expand All @@ -827,14 +827,20 @@ public

case (ARRAY(ty = t, elements = el), _)
algorithm
el := list(typeCastElements(e, ty) for e in el);
ety := Type.arrayElementType(ty);
el := list(typeCastElements(e, ety) for e in el);
t := Type.setArrayElementType(t, ty);
then
ARRAY(t, el, exp.literal);

case (UNARY(), _)
then UNARY(exp.operator, typeCastElements(exp.exp, ty));

case (IF(), _)
then IF(exp.condition,
typeCastElements(exp.trueBranch, ty),
typeCastElements(exp.falseBranch, ty));

else
algorithm
t := typeOf(exp);
Expand Down
8 changes: 7 additions & 1 deletion Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -2193,7 +2193,7 @@ template extFunCallVardecl(SimExtArg arg, Text &varDecls, Text &auxFunction, Boo
case SIMEXTARG(isInput = true, isArray = true, type_ = ty, cref = c) then
match expTypeShort(ty)
case "integer" then
'pack_integer_array(&<%contextCref(c,contextFunction,&auxFunction)%>);'
'pack_integer_array(&<%contextCref(c,contextFunction,&auxFunction)%>);<%\n%>'
else ""
case SIMEXTARG(isInput = false, isArray = true, type_ = ty, cref = c) then
match expTypeShort(ty)
Expand Down Expand Up @@ -2315,6 +2315,12 @@ template extFunCallVarcopy(SimExtArg arg, Text &auxFunction)
"Helper to extFunCall."
::=
match arg
case SIMEXTARG(isInput = true, isArray = true, type_ = ty, cref = c) then
// Inputs that have been packed should be unpacked after the external call.
match expTypeShort(ty)
case "integer" then
'unpack_integer_array(&<%contextCref(c,contextFunction,&auxFunction)%>);'
else ""
case SIMEXTARG(outputIndex=0) then ""
case SIMEXTARG(outputIndex=oi, isArray=true, cref=c, type_=ty) then
match expTypeShort(ty)
Expand Down

0 comments on commit 38fd61a

Please sign in to comment.