Skip to content

Commit

Permalink
NFFrontEnd improvments
Browse files Browse the repository at this point in the history
- Improved function call typing.
- Vectorization
- Record constructors
  • Loading branch information
mahge authored and OpenModelica-Hudson committed Feb 14, 2017
1 parent 6367803 commit 4af9b08
Show file tree
Hide file tree
Showing 8 changed files with 772 additions and 234 deletions.
53 changes: 53 additions & 0 deletions Compiler/NFFrontEnd/NFComponent.mo
Expand Up @@ -232,6 +232,16 @@ uniontype Component
end match;
end getBinding;

function hasBinding
input Component component;
output Boolean b;
algorithm
b := match getBinding(component)
case UNBOUND() then false;
else true;
end match;
end hasBinding;

function attr2DaeAttr
input Attributes attr;
output DAE.Attributes daeAttr;
Expand Down Expand Up @@ -278,6 +288,49 @@ uniontype Component
else false;
end match;
end isOutput;

function variability
input Component component;
output DAE.VarKind variability;
algorithm
variability := match component
case TYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(variability = variability)) then variability;
case UNTYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(variability = variability)) then variability;
else fail();
end match;
end variability;

function isConst
input Component component;
output Boolean isConst;
algorithm
isConst := match variability(component)
case DAE.VarKind.CONST() then true;
else false;
end match;
end isConst;

function visibility
input Component component;
output DAE.VarVisibility visibility;
algorithm
visibility := match component
case TYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(visibility = visibility)) then visibility;
case UNTYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(visibility = visibility)) then visibility;
else fail();
end match;
end visibility;

function isPublic
input Component component;
output Boolean isInput;
algorithm
isInput := match visibility(component)
case DAE.VarVisibility.PUBLIC() then true;
else false;
end match;
end isPublic;

end Component;

annotation(__OpenModelica_Interface="frontend");
Expand Down
17 changes: 17 additions & 0 deletions Compiler/NFFrontEnd/NFDimension.mo
Expand Up @@ -148,6 +148,23 @@ public
end match;
end isEqual;

public function allEqual
input list<Dimension> dims1;
input list<Dimension> dims2;
output Boolean allEqual;
algorithm
allEqual := match(dims1, dims2)
local
Dimension dim1, dim2;
list<Dimension> rest1, rest2;

case ({}, {}) then true;
case (dim1::rest1, dim2::rest2) guard isEqual(dim1, dim2)
then allEqual(rest1, rest2);
else false;
end match;
end allEqual;

function isEqualKnown
input Dimension dim1;
input Dimension dim2;
Expand Down
58 changes: 58 additions & 0 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -36,6 +36,7 @@ import NFInstNode.InstNode;
import NFPrefix.Prefix;
import Operator = NFOperator;
import Subscript = NFSubscript;
import Dimension = NFDimension;
import Type = NFType;

protected
Expand Down Expand Up @@ -105,6 +106,12 @@ uniontype Expression
Expression stop;
end RANGE;

record RECORD
Absyn.Path path; // Maybe not needed since the type contains the name. Prefix?
Type ty;
list<Expression> elements;
end RECORD;

record CALL
Absyn.Path path;
Expression cref "a pointer to the class of the function and the prefix, Expression.CREF";
Expand Down Expand Up @@ -513,6 +520,52 @@ uniontype Expression
end match;
end arrayElement;

function arrayFromList
input list<Expression> inExps;
input Type elemTy;
input list<Dimension> inDims;
output Expression outExp;
algorithm
outExp := arrayFromList_impl(inExps, elemTy, listReverse(inDims));
end arrayFromList;

function arrayFromList_impl
input list<Expression> inExps;
input Type elemTy;
input list<Dimension> inDims;
output Expression outExp;
protected
Dimension ldim;
list<Dimension> restdims;
Type ty;
list<Expression> newlst;
list<list<Expression>> partexps;
Integer dimsize;
algorithm

assert(listLength(inDims) > 0, "Empty dimension list given in arrayFromList.");

ldim::restdims := inDims;
dimsize := Dimension.size(ldim);
ty := Type.liftArrayLeft(elemTy, ldim);

if listLength(inDims) == 1 then
assert(dimsize == listLength(inExps), "Length mismatch in arrayFromList.");
outExp := ARRAY(ty,inExps);
return;
end if;

partexps := List.partition(inExps, dimsize);

newlst := {};
for arrexp in partexps loop
newlst := ARRAY(ty,arrexp)::newlst;
end for;

newlst := listReverse(newlst);
outExp := arrayFromList(newlst, ty, restdims);
end arrayFromList_impl;

function toInteger
input Expression exp;
output Integer i;
Expand Down Expand Up @@ -580,6 +633,7 @@ uniontype Expression
dexp := match exp
local
Type ty;
InstNode clsnode;

case INTEGER() then DAE.ICONST(exp.value);
case REAL() then DAE.RCONST(exp.value);
Expand All @@ -595,6 +649,10 @@ uniontype Expression
then DAE.ARRAY(Type.toDAE(exp.ty), Type.isScalarArray(exp.ty),
list(toDAE(e) for e in exp.elements));

case RECORD()
then DAE.RECORD(exp.path, list(toDAE(e) for e in exp.elements), {}, Type.toDAE(exp.ty));


case RANGE()
then DAE.RANGE(
Type.toDAE(exp.ty),
Expand Down

0 comments on commit 4af9b08

Please sign in to comment.