Skip to content

Commit

Permalink
Merge branch 'master' into clocks
Browse files Browse the repository at this point in the history
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
  • Loading branch information
niklwors committed Apr 26, 2016
1 parent fde84cd commit 4f37b92
Show file tree
Hide file tree
Showing 70 changed files with 2,877 additions and 2,070 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Expand Up @@ -10,5 +10,6 @@ configure.ac text eol=native
Makefile* text eol=native
*.pro text eol=native
*.mo eol=lf
*.tpl eol=lf
*.po eol=lf
*.g text eol=lf
13 changes: 3 additions & 10 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -2394,15 +2394,13 @@ algorithm

case DAE.ALGORITHM(algorithm_=alg, source=source) equation
// calculate the size of the algorithm by collecting the left hand sites of the statemens
(alg, _) = Inline.inlineAlgorithm(alg, (SOME(functionTree), {DAE.NORM_INLINE()}));
crefLst = CheckModel.checkAndGetAlgorithmOutputs(alg, source, inCrefExpansion);
size = listLength(crefLst);
(eqns, reqns) = List.consOnBool(intGt(size, 0), BackendDAE.ALGORITHM(size, alg, source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC), inEquations, inREquations);
then (eqns, reqns, inIEquations);

case DAE.INITIALALGORITHM(algorithm_=alg, source=source) equation
// calculate the size of the algorithm by collecting the left hand sites of the statemens
(alg, _) = Inline.inlineAlgorithm(alg, (SOME(functionTree), {DAE.NORM_INLINE()}));
crefLst = CheckModel.checkAndGetAlgorithmOutputs(alg, source, inCrefExpansion);
size = listLength(crefLst);
then (inEquations, inREquations, BackendDAE.ALGORITHM(size, alg, source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_INITIAL)::inIEquations);
Expand All @@ -2412,9 +2410,6 @@ algorithm
then (inEquations, inREquations, inIEquations);

case DAE.ASSERT(condition=cond, message=msg, level=level, source=source) equation
(cond, source, _,_) = Inline.inlineExp(cond, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
(msg, source, _,_) = Inline.inlineExp(msg, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
(level, source, _,_) = Inline.inlineExp(level, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
BackendDAEUtil.checkAssertCondition(cond, msg, level, ElementSource.getElementSourceFileInfo(source));
alg = DAE.ALGORITHM_STMTS({DAE.STMT_ASSERT(cond, msg, level, source)});
then (inEquations, BackendDAE.ALGORITHM(0, alg, source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC)::inREquations, inIEquations);
Expand All @@ -2423,12 +2418,10 @@ algorithm
then (inEquations, BackendDAE.ALGORITHM(0, DAE.ALGORITHM_STMTS({DAE.STMT_TERMINATE(msg, source)}), source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC)::inREquations, inIEquations);

case DAE.NORETCALL(exp=e, source=source) equation
(e, source, _, _) = Inline.inlineExp(e, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
alg = DAE.ALGORITHM_STMTS({DAE.STMT_NORETCALL(e, source)});
then (inEquations, BackendDAE.ALGORITHM(0, alg, source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC)::inREquations, inIEquations);

case DAE.INITIAL_NORETCALL(exp=e, source=source) equation
(e, source, _, _) = Inline.inlineExp(e, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
alg = DAE.ALGORITHM_STMTS({DAE.STMT_NORETCALL(e, source)});
then (inEquations, BackendDAE.ALGORITHM(0, alg, source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_INITIAL)::inREquations, inIEquations);

Expand Down Expand Up @@ -2680,17 +2673,17 @@ algorithm
Integer i;
case(_, _, _, _)
equation
(v::{}, i::{}) = BackendVariable.getVar(cr, iVars);
(v, i) = BackendVariable.getVarSingle(cr, iVars);
then
(v, i, 1);
case(_, _, _, _)
equation
(v::{}, i::{}) = BackendVariable.getVar(cr, iKnVars);
(v, i) = BackendVariable.getVarSingle(cr, iKnVars);
then
(v, i, 2);
case(_, _, _, _)
equation
(v::{}, i::{}) = BackendVariable.getVar(cr, iExtVars);
(v, i) = BackendVariable.getVarSingle(cr, iExtVars);
then
(v, i, 3);
end matchcontinue;
Expand Down
24 changes: 12 additions & 12 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -172,17 +172,17 @@ algorithm
Boolean negate;

case (DAE.CALL(path=Absyn.IDENT(name="der"), expLst={DAE.CREF(componentRef=cr, ty=tp)}), (knvars, aliasvars, _)) equation
(var::{}, _) = BackendVariable.getVar(cr, knvars);
(var, _) = BackendVariable.getVarSingle(cr, knvars);
false = BackendVariable.isVarOnTopLevelAndInput(var);
(zero, _) = Expression.makeZeroExpression(Expression.arrayDimension(tp));
then (zero, (knvars, aliasvars, true));

case (DAE.CALL(path=Absyn.IDENT(name="pre"), expLst={e as DAE.CREF(componentRef=cr)}), (knvars, aliasvars, _)) equation
(_::{}, _) = BackendVariable.getVar(cr, knvars);
(_, _) = BackendVariable.getVarSingle(cr, knvars);
then(e, (knvars, aliasvars, true));

case (DAE.CALL(path=Absyn.IDENT(name="previous"), expLst={e as DAE.CREF(componentRef=cr)}), (knvars, aliasvars, _)) equation
(_::{}, _) = BackendVariable.getVar(cr, knvars);
(_, _) = BackendVariable.getVarSingle(cr, knvars);
then(e, (knvars, aliasvars, true));

case (DAE.CALL(path=Absyn.IDENT(name="pre"), expLst={e as DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time"))}), (knvars, aliasvars, _))
Expand All @@ -198,7 +198,7 @@ algorithm
then (e, (knvars, aliasvars, true));

case (DAE.CALL(path=Absyn.IDENT(name="pre"), expLst={DAE.CREF(componentRef=cr, ty=tp)}, attr=attr), (knvars, aliasvars, _)) equation
(var::{}, _) = BackendVariable.getVar(cr, aliasvars);
(var, _) = BackendVariable.getVarSingle(cr, aliasvars);
(cr, negate) = BackendVariable.getAlias(var);
e = DAE.CREF(cr, tp);
e = if negate then Expression.negate(e) else e;
Expand All @@ -207,7 +207,7 @@ algorithm
then (e, (knvars, aliasvars, true));

case (DAE.CALL(path=Absyn.IDENT(name="previous"), expLst={DAE.CREF(componentRef=cr, ty=tp)}, attr=attr), (knvars, aliasvars, _)) equation
(var::{}, _) = BackendVariable.getVar(cr, aliasvars);
(var, _) = BackendVariable.getVarSingle(cr, aliasvars);
(cr, negate) = BackendVariable.getAlias(var);
e = DAE.CREF(cr, tp);
e = if negate then Expression.negate(e) else e;
Expand All @@ -229,7 +229,7 @@ algorithm
then (DAE.BCONST(false), (knvars, aliasvars, true));

case (DAE.CALL(path=Absyn.IDENT(name="change"), expLst={DAE.CREF(componentRef=cr, ty=tp)}, attr=attr), (knvars, aliasvars, _)) equation
(var::{}, _) = BackendVariable.getVar(cr, aliasvars);
(var, _) = BackendVariable.getVarSingle(cr, aliasvars);
(cr, negate) = BackendVariable.getAlias(var);
e = DAE.CREF(cr, tp);
e = if negate then Expression.negate(e) else e;
Expand All @@ -238,15 +238,15 @@ algorithm
then (e, (knvars, aliasvars, true));

case (DAE.CALL(path=Absyn.IDENT(name="edge"), expLst={DAE.CREF(componentRef=cr, ty=tp)}), (knvars, aliasvars, _)) equation
(_::{}, _) = BackendVariable.getVar(cr, knvars);
(_, _) = BackendVariable.getVarSingle(cr, knvars);
zero = Expression.arrayFill(Expression.arrayDimension(tp), DAE.BCONST(false));
then (zero, (knvars, aliasvars, true));

case (DAE.CALL(path=Absyn.IDENT(name="edge"), expLst={DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time"))}), (knvars, aliasvars, _))
then (DAE.BCONST(false), (knvars, aliasvars, true));

case (DAE.CALL(path=Absyn.IDENT(name="edge"), expLst={DAE.CREF(componentRef=cr, ty=tp)}, attr=attr), (knvars, aliasvars, _)) equation
(var::{}, _) = BackendVariable.getVar(cr, aliasvars);
(var, _) = BackendVariable.getVarSingle(cr, aliasvars);
(cr, negate) = BackendVariable.getAlias(var);
e = DAE.CREF(cr, tp);
e = if negate then Expression.negate(e) else e;
Expand Down Expand Up @@ -2323,7 +2323,7 @@ algorithm
DAE.Exp e;
case (DAE.CREF(componentRef = cr),(knvars,_))
equation
(v::{},_::{}) = BackendVariable.getVar(cr,knvars);
(v,_) = BackendVariable.getVarSingle(cr,knvars);
true = BackendVariable.isFinalVar(v);
e = BackendVariable.varBindExpStartValue(v);
then (e,(knvars,true));
Expand Down Expand Up @@ -3810,7 +3810,7 @@ algorithm
then (exp,vars);
case (e1 as DAE.CALL(path=Absyn.IDENT(name = "der"), expLst={DAE.CREF(componentRef=cr)}))
equation
({v}, _) = BackendVariable.getVar(cr, vars);
(v, _) = BackendVariable.getVarSingle(cr, vars);
(vars, e1) = updateStatesVar(vars, v, e1);
then (e1, vars);
case (e1 as DAE.CALL(path=Absyn.IDENT(name = "der"), expLst={DAE.CREF(componentRef=cr)}))
Expand Down Expand Up @@ -3844,7 +3844,7 @@ algorithm
DAE.Exp e;
case (e as DAE.CALL(path = Absyn.IDENT(name = "der"), expLst = {DAE.CREF(componentRef = cr)}), vars)
equation
({v}, _) = BackendVariable.getVar(cr, vars);
(v, _) = BackendVariable.getVarSingle(cr, vars);
(vars, e) = updateStatesVar(vars, v, e);
then (e, vars);
case (e as DAE.CALL(path = Absyn.IDENT(name = "der"), expLst = {DAE.CREF(componentRef = cr)}), vars)
Expand Down Expand Up @@ -5268,7 +5268,7 @@ algorithm
String str;

case (DAE.CALL(path=Absyn.IDENT(name="der"), expLst={DAE.CREF(componentRef=cr, ty=ty)}), (vars, eqnLst, shared, addVar, _)) equation
({v}, _) = BackendVariable.getVar(cr, vars);
(v, _) = BackendVariable.getVarSingle(cr, vars);
cref = BackendVariable.varCref(v);
v1 = BackendVariable.createAliasDerVar(cref);
v1 = BackendVariable.mergeNominalAttribute(v, v1, false);
Expand Down
26 changes: 15 additions & 11 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -358,17 +358,21 @@ algorithm
List.map_0(stateSets, printStateSet);
end printStateSets;

protected function printStateSet "author: Frenkel TUD"
input BackendDAE.StateSet statSet;
protected
Integer rang;
list<BackendDAE.Var> states;
list<DAE.ComponentRef> crstates;
algorithm
BackendDAE.STATESET(rang=rang,statescandidates=states) := statSet;
crstates := List.map(states,BackendVariable.varCref);
print("StateSet: select " + intString(rang) + " from\n");
debuglst(crstates,ComponentReference.printComponentRefStr,"\n","\n");
protected function printStateSet "author: lochel"
input BackendDAE.StateSet inStateSet;
algorithm
print("StateSet \"" + ComponentReference.printComponentRefStr(ComponentReference.crefFirstCref(inStateSet.crA)) + "\" (rang " + intString(inStateSet.rang) + ")\n");

dumpVarList(inStateSet.statescandidates, "state candidates");
dumpEquationList(inStateSet.eqns, "eqns");

dumpVarList(inStateSet.ovars, "ovars");
dumpEquationList(inStateSet.oeqns, "oeqns");

dumpVarList(inStateSet.varA, "varA");
dumpVarList(inStateSet.varJ, "varJ");

//print(jacobianString(inStateSet.jacobian));
end printStateSet;

public function printVar
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -2375,9 +2375,9 @@ algorithm

case(_,e1 as DAE.CREF(componentRef = cr)) algorithm
try
({v}, _) := BackendVariable.getVar(cr, inVars);
(v, _) := BackendVariable.getVarSingle(cr, inVars);
else
({v}, _) := BackendVariable.getVar(cr, knvars);
(v, _) := BackendVariable.getVarSingle(cr, knvars);
end try;

lhs := ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
Expand Down
113 changes: 97 additions & 16 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -773,7 +773,7 @@ public function isDiscrete
protected
BackendDAE.Var v;
algorithm
({v},_) := getVar(cr,vars);
(v,_) := getVarSingle(cr,vars);
outBoolean := isVarDiscrete(v);
end isDiscrete;

Expand Down Expand Up @@ -1426,7 +1426,7 @@ algorithm

case (_) guard(ComponentReference.traverseCref(inCref, ComponentReference.crefIsRec, false)) equation
DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(path), source=typeLst) = inType;
source = DAE.SOURCE(Absyn.dummyInfo, {}, NONE(), {}, path::typeLst, {}, {});
source = DAE.SOURCE(Absyn.dummyInfo, {}, Prefix.NOCOMPPRE(), {}, path::typeLst, {}, {});
varKind = if Types.isDiscreteType(inType) then BackendDAE.DISCRETE() else BackendDAE.VARIABLE();
outVar = BackendDAE.VAR(inCref, varKind, DAE.BIDIR(), DAE.NON_PARALLEL(), inType, NONE(), NONE(), {}, source, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true);
then outVar;
Expand Down Expand Up @@ -1506,7 +1506,7 @@ algorithm

case (_) guard(ComponentReference.traverseCref(inCref, ComponentReference.crefIsRec, false)) equation
DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(path), source=typeLst) = inType;
source = DAE.SOURCE(Absyn.dummyInfo, {}, NONE(), {}, path::typeLst, {}, {});
source = DAE.SOURCE(Absyn.dummyInfo, {}, Prefix.NOCOMPPRE(), {}, path::typeLst, {}, {});
varKind = if Types.isDiscreteType(inType) then BackendDAE.DISCRETE() else BackendDAE.VARIABLE();
outVar = BackendDAE.VAR(inCref, varKind, DAE.BIDIR(), DAE.NON_PARALLEL(), inType, NONE(), NONE(), inArryDim, source, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true);
then outVar;
Expand Down Expand Up @@ -2722,11 +2722,16 @@ algorithm
equation
(v,indx) = getVar2(cr, inVariables) "if scalar found, return it";
then
({v},{indx});
({v},if isPresent(outIntegerLst) then {indx} else {});
case (_,_) /* check if array or record */
equation
crlst = ComponentReference.expandCref(cr,true);
(vLst as _::_,indxs) = getVarLst(crlst,inVariables);
if isPresent(outIntegerLst) then
(vLst as _::_,indxs) = getVarLst(crlst,inVariables);
else
(vLst as _::_,_) = getVarLst(crlst,inVariables);
indxs = {};
end if;
then
(vLst,indxs);
// try again check if variable indexes used
Expand All @@ -2735,7 +2740,12 @@ algorithm
// replace variables with WHOLEDIM()
(cr1,true) = replaceVarWithWholeDim(cr, false);
crlst = ComponentReference.expandCref(cr1,true);
(vLst as _::_,indxs) = getVarLst(crlst,inVariables);
if isPresent(outIntegerLst) then
(vLst as _::_,indxs) = getVarLst(crlst,inVariables);
else
(vLst as _::_,_) = getVarLst(crlst,inVariables);
indxs = {};
end if;
then
(vLst,indxs);
/* failure
Expand All @@ -2748,6 +2758,66 @@ algorithm
end matchcontinue;
end getVar;

public function getVarSingle
" Return a variable and its index in the vector.
The indexes is enumerated from 1..n
Normally a variable has only one index, but in case of an array variable
it may have several indexes and several scalar variables,
therefore a list of variables and a list of indexes is returned.

This function fails if there are more than a single returned value"
input DAE.ComponentRef cr;
input BackendDAE.Variables inVariables;
output BackendDAE.Var outVar;
output Integer outInteger;
algorithm
(outVar,outInteger) := matchcontinue (cr,inVariables)
local
BackendDAE.Var v;
Integer indx;
list<Integer> indxs;
list<BackendDAE.Var> vLst;
list<DAE.ComponentRef> crlst;
DAE.ComponentRef cr1;
case (_,_)
equation
(v,indx) = getVar2(cr, inVariables) "if scalar found, return it";
then (v,indx);
case (_,_) /* check if array or record */
equation
// TODO: Don't expand if > length 1
crlst = ComponentReference.expandCref(cr,true);
if isPresent(outInteger) then
({v},{indx}) = getVarLst(crlst,inVariables);
else
({v},_) = getVarLst(crlst,inVariables);
indx = 0;
end if;
then (v,indx);
// try again check if variable indexes used
case (_,_)
equation
// TODO: Don't expand if > length 1
// replace variables with WHOLEDIM()
(cr1,true) = replaceVarWithWholeDim(cr, false);
crlst = ComponentReference.expandCref(cr1,true);
if isPresent(outInteger) then
({v},{indx}) = getVarLst(crlst,inVariables);
else
({v},_) = getVarLst(crlst,inVariables);
indx = 0;
end if;
then (v,indx);
/* failure
case (_,_)
equation
fprintln(Flags.DAE_LOW, "- getVar failed on component reference: " + ComponentReference.printComponentRefStr(cr));
then
fail();
*/
end matchcontinue;
end getVarSingle;

protected function replaceVarWithWholeDim
"Helper function to traverseExp. Traverses any expressions in a
component reference (i.e. in it's subscripts)."
Expand Down Expand Up @@ -2862,15 +2932,26 @@ protected
BackendDAE.Var v;
Integer indx;
algorithm
for cr in inComponentRefLst loop
try
(v,indx) := getVar2(cr, inVariables);
outVarLst := v::outVarLst;
outIntegerLst := indx::outIntegerLst;
else
// skip this element
end try;
end for;
if isPresent(outIntegerLst) then
for cr in inComponentRefLst loop
try
(v,indx) := getVar2(cr, inVariables);
outVarLst := v::outVarLst;
outIntegerLst := indx::outIntegerLst;
else
// skip this element
end try;
end for;
else
for cr in inComponentRefLst loop
try
(v,indx) := getVar2(cr, inVariables);
outVarLst := v::outVarLst;
else
// skip this element
end try;
end for;
end if;
end getVarLst;

public function getVar2
Expand Down Expand Up @@ -3550,7 +3631,7 @@ algorithm
equation
// check for cyclic bindings in start value
false = BaseHashSet.has(cr, hs);
({BackendDAE.VAR(bindExp = SOME(e))}, _) = getVar(cr, vars);
(BackendDAE.VAR(bindExp = SOME(e)), _) = getVarSingle(cr, vars);
hs = BaseHashSet.add(cr,hs);
(e, (_,_,hs)) = Expression.traverseExpBottomUp(e, replaceCrefWithBindExp, (vars,false,hs));
then (e, (vars,true,hs));
Expand Down

0 comments on commit 4f37b92

Please sign in to comment.