Skip to content

Commit

Permalink
[NF] Clocked operators improvements.
Browse files Browse the repository at this point in the history
- Mark the parameter arguments of backSample, shiftSample, subSample,
  and superSample as structural so that they're evaluated by the
  frontend, since the clock partitioning in the backend expects this.
- Move the structural parameter utility functions from Inst to its own
  package, to avoid the need for other packages to depend on Inst when
  they just want to mark some parameters as structural.
  • Loading branch information
perost committed Jun 18, 2020
1 parent 1449ae6 commit 97bd8e7
Show file tree
Hide file tree
Showing 9 changed files with 513 additions and 386 deletions.
106 changes: 88 additions & 18 deletions OMCompiler/Compiler/NFFrontEnd/NFBuiltinCall.mo
Expand Up @@ -65,6 +65,7 @@ protected
import Component = NFComponent;
import NFPrefixes.ConnectorType;
import ClockKind = NFClockKind;
import Structural = NFStructural;

public
function needSpecialHandling
Expand Down Expand Up @@ -107,56 +108,56 @@ public
next_origin := ExpOrigin.setFlag(origin, ExpOrigin.SUBEXPRESSION);

(callExp, ty, variability) := match ComponentRef.firstName(cref)
case "String" then typeStringCall(call, next_origin, info);
//case "activeState" guard Config.synchronousFeaturesAllowed() then typeActiveStateCall(call, next_origin, info);
case "actualStream" then typeActualInStreamCall("actualStream", call, next_origin, info);
case "backSample" guard Config.synchronousFeaturesAllowed() then typeBackSampleCall(call, next_origin, info);
case "branch" then typeBranchCall(call, next_origin, info);
case "cardinality" then typeCardinalityCall(call, next_origin, info);
case "cat" then typeCatCall(call, next_origin, info);
case "change" then typeChangeCall(call, next_origin, info);
case "Clock" guard Config.synchronousFeaturesAllowed() then typeClockCall(call, next_origin, info);
case "der" then typeDerCall(call, next_origin, info);
case "diagonal" then typeDiagonalCall(call, next_origin, info);
case "DynamicSelect" then typeDynamicSelectCall("DynamicSelect", call, next_origin, info);
case "edge" then typeEdgeCall(call, next_origin, info);
case "fill" then typeFillCall(call, next_origin, info);
case "getInstanceName" then typeGetInstanceName(call);
//case "hold" guard Config.synchronousFeaturesAllowed() then typeHoldCall(call, next_origin, info);
//case "initialState" guard Config.synchronousFeaturesAllowed() then typeInitialStateCall(call, next_origin, info);
case "initial" then typeDiscreteCall(call, next_origin, info);
case "inStream" then typeActualInStreamCall("inStream", call, next_origin, info);
case "isRoot" then typeIsRootCall(call, next_origin, info);
case "matrix" then typeMatrixCall(call, next_origin, info);
case "max" then typeMinMaxCall("max", call, next_origin, info);
case "min" then typeMinMaxCall("min", call, next_origin, info);
case "ndims" then typeNdimsCall(call, next_origin, info);
//case "noClock" guard Config.synchronousFeaturesAllowed() then typeNoClockCall(call, next_origin, info);
case "noEvent" then typeNoEventCall(call, next_origin, info);
case "ones" then typeZerosOnesCall("ones", call, next_origin, info);
case "potentialRoot" then typePotentialRootCall(call, next_origin, info);
case "pre" then typePreCall(call, next_origin, info);
case "product" then typeProductCall(call, next_origin, info);
case "promote" then typePromoteCall(call, next_origin, info);
case "root" then typeRootCall(call, next_origin, info);
case "rooted" then typeRootedCall(call, next_origin, info);
case "uniqueRoot" then typeUniqueRootCall(call, next_origin, info);
case "uniqueRootIndices" then typeUniqueRootIndicesCall(call, next_origin, info);
case "root" then typeRootCall(call, next_origin, info);
case "sample" then typeSampleCall(call, next_origin, info);
case "scalar" then typeScalarCall(call, next_origin, info);
case "shiftSample" guard Config.synchronousFeaturesAllowed() then typeShiftSampleCall(call, next_origin, info);
case "smooth" then typeSmoothCall(call, next_origin, info);
case "String" then typeStringCall(call, next_origin, info);
case "subSample" guard Config.synchronousFeaturesAllowed() then typeSubSampleCall(call, next_origin, info);
case "sum" then typeSumCall(call, next_origin, info);
case "superSample" guard Config.synchronousFeaturesAllowed() then typeSuperSampleCall(call, next_origin, info);
case "symmetric" then typeSymmetricCall(call, next_origin, info);
case "terminal" then typeDiscreteCall(call, next_origin, info);
//case "ticksInState" guard Config.synchronousFeaturesAllowed() then typeTicksInStateCall(call, next_origin, info);
//case "timeInState" guard Config.synchronousFeaturesAllowed() then typeTimeInStateCall(call, next_origin, info);
//case "transition" guard Config.synchronousFeaturesAllowed() then typeTransitionCall(call, next_origin, info);
case "transpose" then typeTransposeCall(call, next_origin, info);
case "uniqueRootIndices" then typeUniqueRootIndicesCall(call, next_origin, info);
case "uniqueRoot" then typeUniqueRootCall(call, next_origin, info);
case "vector" then typeVectorCall(call, next_origin, info);
case "zeros" then typeZerosOnesCall("zeros", call, next_origin, info);
case "Clock" guard Config.synchronousFeaturesAllowed() then typeClockCall(call, next_origin, info);
case "sample" then typeSampleCall(call, next_origin, info);
case "DynamicSelect" then typeDynamicSelectCall("DynamicSelect", call, next_origin, info);
/*
case "hold" guard Config.synchronousFeaturesAllowed() then typeHoldCall(call, next_origin, info);
case "shiftSample" guard Config.synchronousFeaturesAllowed() then typeShiftSampleCall(call, next_origin, info);
case "backSample" guard Config.synchronousFeaturesAllowed() then typeBackSampleCall(call, next_origin, info);
case "noClock" guard Config.synchronousFeaturesAllowed() then typeNoClockCall(call, next_origin, info);
case "transition" guard Config.synchronousFeaturesAllowed() then typeTransitionCall(call, next_origin, info);
case "initialState" guard Config.synchronousFeaturesAllowed() then typeInitialStateCall(call, next_origin, info);
case "activeState" guard Config.synchronousFeaturesAllowed() then typeActiveStateCall(call, next_origin, info);
case "ticksInState" guard Config.synchronousFeaturesAllowed() then typeTicksInStateCall(call, next_origin, info);
case "timeInState" guard Config.synchronousFeaturesAllowed() then typeTimeInStateCall(call, next_origin, info);
*/
else
algorithm
Error.assertion(false, getInstanceName() + " got unhandled builtin function: " + Call.toString(call), sourceInfo());
Expand Down Expand Up @@ -2139,6 +2140,75 @@ protected
end if;
end typeDynamicSelectCall;

function typeBackSampleCall
input Call call;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
output Variability var;
protected
Call ty_call;
Expression counter, resolution;
algorithm
ty_call as Call.TYPED_CALL(arguments = {_, counter, resolution}, ty = ty, var = var) :=
Call.typeMatchNormalCall(call, origin, info);
Structural.markExp(counter);
Structural.markExp(resolution);
callExp := Expression.CALL(Call.unboxArgs(ty_call));
end typeBackSampleCall;

function typeShiftSampleCall
input Call call;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
output Variability var;
protected
Call ty_call;
Expression counter, resolution;
algorithm
ty_call as Call.TYPED_CALL(arguments = {_, counter, resolution}, ty = ty, var = var) :=
Call.typeMatchNormalCall(call, origin, info);
Structural.markExp(counter);
Structural.markExp(resolution);
callExp := Expression.CALL(Call.unboxArgs(ty_call));
end typeShiftSampleCall;

function typeSubSampleCall
input Call call;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
output Variability var;
protected
Call ty_call;
Expression factor;
algorithm
ty_call as Call.TYPED_CALL(arguments = {_, factor}, ty = ty, var = var) :=
Call.typeMatchNormalCall(call, origin, info);
Structural.markExp(factor);
callExp := Expression.CALL(Call.unboxArgs(ty_call));
end typeSubSampleCall;

function typeSuperSampleCall
input Call call;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
output Variability var;
protected
Call ty_call;
Expression factor;
algorithm
ty_call as Call.TYPED_CALL(arguments = {_, factor}, ty = ty, var = var) :=
Call.typeMatchNormalCall(call, origin, info);
Structural.markExp(factor);
callExp := Expression.CALL(Call.unboxArgs(ty_call));
end typeSuperSampleCall;

annotation(__OpenModelica_Interface="frontend");
end NFBuiltinCall;
35 changes: 29 additions & 6 deletions OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo
Expand Up @@ -360,15 +360,15 @@ public
end match;
end addSubscript;

function applySubscripts
function mergeSubscripts
input list<Subscript> subscripts;
input output ComponentRef cref;
input Boolean applyToScope = false;
algorithm
({}, cref) := applySubscripts2(subscripts, cref, applyToScope);
end applySubscripts;
({}, cref) := mergeSubscripts2(subscripts, cref, applyToScope);
end mergeSubscripts;

function applySubscripts2
function mergeSubscripts2
input output list<Subscript> subscripts;
input output ComponentRef cref;
input Boolean applyToScope;
Expand All @@ -381,7 +381,7 @@ public
case CREF(subscripts = cref_subs)
guard applyToScope or cref.origin == Origin.CREF
algorithm
(subscripts, rest_cref) := applySubscripts2(subscripts, cref.restCref, applyToScope);
(subscripts, rest_cref) := mergeSubscripts2(subscripts, cref.restCref, applyToScope);

if not listEmpty(subscripts) then
(cref_subs, subscripts) :=
Expand All @@ -392,7 +392,7 @@ public

else (subscripts, cref);
end match;
end applySubscripts2;
end mergeSubscripts2;

function hasSubscripts
input ComponentRef cref;
Expand Down Expand Up @@ -526,6 +526,29 @@ public
end match;
end transferSubscripts;

function applySubscripts
input ComponentRef cref;
input FuncT func;

partial function FuncT
input Subscript subscript;
end FuncT;
algorithm
() := match cref
case CREF(origin = Origin.CREF)
algorithm
for sub in cref.subscripts loop
func(sub);
end for;

applySubscripts(cref.restCref, func);
then
();

else ();
end match;
end applySubscripts;

function foldSubscripts<ArgT>
input ComponentRef cref;
input FuncT func;
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -1060,7 +1060,7 @@ public
ComponentRef cr;
Type ty;
algorithm
cr := ComponentRef.applySubscripts(subscript :: restSubscripts, cref);
cr := ComponentRef.mergeSubscripts(subscript :: restSubscripts, cref);
ty := ComponentRef.getSubscriptedType(cr);
outExp := CREF(ty, cr);
end applySubscriptCref;
Expand Down
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -54,7 +54,6 @@ import ExecStat.execStat;
import ExpressionIterator = NFExpressionIterator;
import Expression = NFExpression;
import Flags;
import Inst = NFInst;
import List;
import Call = NFCall;
import Class = NFClass;
Expand Down Expand Up @@ -92,6 +91,7 @@ import InstNodeType = NFInstNode.InstNodeType;
import ExpandableConnectors = NFExpandableConnectors;
import SCodeUtil;
import DAE;
import Structural = NFStructural;

public
type FunctionTree = FunctionTreeImpl.Tree;
Expand Down Expand Up @@ -747,7 +747,7 @@ algorithm
algorithm
restString := ComponentRef.toString(restCref);
if prefixLength <= stringLength(restString) and prefixString == substring(restString, 1, prefixLength) then
exp.cref := ComponentRef.applySubscripts({subscript}, exp.cref, applyToScope = true);
exp.cref := ComponentRef.mergeSubscripts({subscript}, exp.cref, applyToScope = true);
end if;
then
exp;
Expand Down Expand Up @@ -957,7 +957,7 @@ algorithm
cond_var := Expression.variability(cond);

if Expression.variability(cond) == Variability.PARAMETER then
Inst.markStructuralParamsExp(cond);
Structural.markExp(cond);
end if;
end flattenConditionalArrayIfExp;

Expand Down
4 changes: 4 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFFunction.mo
Expand Up @@ -1467,6 +1467,7 @@ uniontype Function
// Can have variable number of arguments.
case "array" then true;
case "actualStream" then true;
case "backSample" then true;
case "branch" then true;
case "cardinality" then true;
case "cat" then true;
Expand Down Expand Up @@ -1516,10 +1517,13 @@ uniontype Function
case "scalar" then true;
// First argument can have any number of dimensions.
case "size" then true;
case "shiftSample" then true;
// Needs to check that second argument is real or array of real or record of reals.
case "smooth" then true;
case "subSample" then true;
// needs unboxing and return type fix.
case "sum" then true;
case "superSample" then true;
// unbox args and set return type.
case "symmetric" then true;
// Always discrete.
Expand Down

0 comments on commit 97bd8e7

Please sign in to comment.