Skip to content

Commit

Permalink
Split NFFlatten into multiple phases.
Browse files Browse the repository at this point in the history
- Split NFFlatten into NFFlatten, NFScalarize and NFConvertDAE.

Belonging to [master]:
  - OpenModelica/OMCompiler#1948
  - OpenModelica/OpenModelica-testsuite#753
  • Loading branch information
perost authored and OpenModelica-Hudson committed Oct 26, 2017
1 parent 43d3d5d commit 8abed04
Show file tree
Hide file tree
Showing 18 changed files with 2,134 additions and 1,182 deletions.
4 changes: 4 additions & 0 deletions Compiler/NFFrontEnd/NFBinding.mo
Expand Up @@ -67,6 +67,10 @@ public
SourceInfo info;
end TYPED_BINDING;

record FLAT_BINDING
Expression bindingExp;
end FLAT_BINDING;

public
function fromAbsyn
input Option<Absyn.Exp> bindingExp;
Expand Down
11 changes: 10 additions & 1 deletion Compiler/NFFrontEnd/NFClass.mo
Expand Up @@ -31,7 +31,6 @@

encapsulated package NFClass

import NFEquation.Equation;
import NFInstNode.InstNode;
import NFMod.Modifier;
import NFStatement.Statement;
Expand Down Expand Up @@ -290,6 +289,16 @@ uniontype Class
end match;
end getAttributes;

function getTypeAttributes
input Class cls;
output list<Modifier> attributes;
algorithm
attributes := match cls
case INSTANCED_BUILTIN() then cls.attributes;
else {};
end match;
end getTypeAttributes;

end Class;

annotation(__OpenModelica_Interface="frontend");
Expand Down
77 changes: 63 additions & 14 deletions Compiler/NFFrontEnd/NFComponentRef.mo
Expand Up @@ -71,17 +71,32 @@ public
output ComponentRef cref = CREF(node, subs, ty, origin, EMPTY());
end fromNode;

function prefixCref
input InstNode node;
input Type ty;
input list<Subscript> subs;
input ComponentRef restCref;
output ComponentRef cref = CREF(node, subs, ty, Origin.CREF, restCref);
end prefixCref;

function prefixScope
input InstNode node;
input Type ty;
input list<Subscript> subs;
input ComponentRef restCref;
output ComponentRef cref = CREF(node, subs, ty, Origin.SCOPE, restCref);
end prefixScope;

function fromAbsyn
input InstNode node;
input list<Absyn.Subscript> subs;
input Origin origin = Origin.CREF;
input ComponentRef restCref = EMPTY();
output ComponentRef cref;
protected
list<Subscript> sl;
algorithm
sl := list(Subscript.RAW_SUBSCRIPT(s) for s in subs);
cref := CREF(node, sl, Type.UNKNOWN(), origin, restCref);
cref := CREF(node, sl, Type.UNKNOWN(), Origin.CREF, restCref);
end fromAbsyn;

function fromBuiltin
Expand All @@ -90,6 +105,12 @@ public
output ComponentRef cref = CREF(node, {}, ty, Origin.SCOPE, EMPTY());
end fromBuiltin;

function makeIterator
input InstNode node;
input Type ty;
output ComponentRef cref = CREF(node, {}, ty, Origin.ITERATOR, EMPTY());
end makeIterator;

function isEmpty
input ComponentRef cref;
output Boolean isEmpty;
Expand Down Expand Up @@ -166,12 +187,10 @@ public
input Subscript subscript;
input output ComponentRef cref;
algorithm
() := match cref
cref := match cref
case CREF()
algorithm
cref.subscripts := listAppend(cref.subscripts, {subscript});
then
();
then CREF(cref.node, listAppend(cref.subscripts, {subscript}),
Type.unliftArray(cref.ty), cref.origin, cref.restCref);
end match;
end addSubscript;

Expand Down Expand Up @@ -204,6 +223,16 @@ public
function setSubscripts
input list<Subscript> subscripts;
input output ComponentRef cref;
algorithm
cref := match cref
case CREF()
then CREF(cref.node, subscripts, Type.arrayElementType(cref.ty), cref.origin, cref.restCref);
end match;
end setSubscripts;

function replaceSubscripts
input list<Subscript> subscripts;
input output ComponentRef cref;
algorithm
() := match cref
case CREF()
Expand All @@ -212,18 +241,36 @@ public
then
();
end match;
end setSubscripts;
end replaceSubscripts;

function allSubscripts
function subscriptsAll
"Returns all subscripts of a cref in reverse order.
Ex: a[1, 2].b[4].c[6, 3] => {{6,3}, {4}, {1,2}}"
input ComponentRef cref;
input list<list<Subscript>> accumSubs = {};
output list<list<Subscript>> subscripts;
algorithm
subscripts := match cref
case CREF() then allSubscripts(cref.restCref, cref.subscripts :: accumSubs);
case CREF() then subscriptsAll(cref.restCref, cref.subscripts :: accumSubs);
else accumSubs;
end match;
end allSubscripts;
end subscriptsAll;

function subscriptsN
"Returns the subscripts of the N first parts of a cref in reverse order.
Fails if the cref is fewer than N parts."
input ComponentRef cref;
input Integer n;
output list<list<Subscript>> subscripts = {};
protected
list<Subscript> subs;
ComponentRef rest = cref;
algorithm
for i in 1:n loop
CREF(subscripts = subs, restCref = rest) := rest;
subscripts := subs :: subscripts;
end for;
end subscriptsN;

function transferSubscripts
input ComponentRef srcCref;
Expand Down Expand Up @@ -346,7 +393,7 @@ public
end for;
end fromNodeList;

function vectorize
function scalarize
input ComponentRef cref;
output list<ComponentRef> crefs;
algorithm
Expand All @@ -358,6 +405,7 @@ public
list<list<Subscript>> subs;
list<list<Subscript>> new_subs;
Subscript sub;
ComponentRef scalar_cref;

case CREF()
algorithm
Expand All @@ -377,12 +425,13 @@ public
subs := new_subs;
end for;

scalar_cref := setType(Type.arrayElementType(cref.ty), cref);
then
listReverse(setSubscripts(s, cref) for s in subs);
listReverse(replaceSubscripts(s, scalar_cref) for s in subs);

else {cref};
end match;
end vectorize;
end scalarize;

annotation(__OpenModelica_Interface="frontend");
end NFComponentRef;

0 comments on commit 8abed04

Please sign in to comment.