Skip to content

Commit

Permalink
Filter constant when conditions
Browse files Browse the repository at this point in the history
* Adjust dump of when clauses
* Simplify initial stuff in removed equations
  • Loading branch information
lochel committed Sep 25, 2015
1 parent aca0480 commit 88a65ee
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 58 deletions.
38 changes: 17 additions & 21 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -5830,27 +5830,22 @@ public function traverseBackendDAEExpsNoCopyWithUpdate<A>
output DAE.Exp outExp;
output A outA;
end FuncExpType;
protected
list<BackendDAE.EqSystem> systs;
BackendDAE.Shared shared;
String name;
algorithm
outTypeA := matchcontinue inBackendDAE
local
list<BackendDAE.EqSystem> systs;
BackendDAE.Shared shared;
String name;

case BackendDAE.DAE(systs, shared)
equation
outTypeA = List.fold1(systs, traverseBackendDAEExpsEqSystemWithUpdate, func, inTypeA);
outTypeA = traverseBackendDAEExpsVarsWithUpdate(shared.knownVars, func, outTypeA);
outTypeA = traverseBackendDAEExpsEqnsWithUpdate(shared.initialEqs, func, outTypeA);
outTypeA = traverseBackendDAEExpsEqnsWithUpdate(shared.removedEqs, func, outTypeA);
then
outTypeA;

else equation
(_, _, name) = System.dladdr(func);
Error.addInternalError("traverseBackendDAEExpsNoCopyWithUpdate failed for " + name, sourceInfo());
then fail();
end matchcontinue;
try
BackendDAE.DAE(systs, shared) := inBackendDAE;
outTypeA := List.fold1(systs, traverseBackendDAEExpsEqSystemWithUpdate, func, inTypeA);
outTypeA := traverseBackendDAEExpsVarsWithUpdate(shared.knownVars, func, outTypeA);
outTypeA := traverseBackendDAEExpsEqnsWithUpdate(shared.initialEqs, func, outTypeA);
outTypeA := traverseBackendDAEExpsEqnsWithUpdate(shared.removedEqs, func, outTypeA);
else
(_, _, name) := System.dladdr(func);
Error.addInternalError("traverseBackendDAEExpsNoCopyWithUpdate failed for " + name, sourceInfo());
fail();
end try;
end traverseBackendDAEExpsNoCopyWithUpdate;

public function traverseBackendDAEExpsEqSystem "This function goes through the BackendDAE structure and finds all the
Expand Down Expand Up @@ -7697,7 +7692,8 @@ algorithm
case {}
then (inConditionVarList, inInitialCall);

case DAE.BCONST(false)::conditionList equation
// filter constant conditions
case exp::conditionList guard(Expression.isConst(exp)) equation
(conditionVarList, initialCall) = getConditionList1(conditionList, inConditionVarList, inInitialCall);
then (conditionVarList, initialCall);

Expand Down
59 changes: 22 additions & 37 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -1402,47 +1402,32 @@ algorithm
end match;
end strongComponentString;

public function whenEquationString "Helper function to equationString"
public function whenEquationString
input BackendDAE.WhenEquation inWhenEqn;
input Boolean inStart;
output String outString;
algorithm
outString := match (inWhenEqn, inStart)
local
String s1,s2,res,s3,cs;
DAE.Exp e2,cond;
DAE.ComponentRef cr;
BackendDAE.WhenEquation weqn;
Option<BackendDAE.WhenEquation> oweqn;
list<BackendDAE.WhenOperator> whenStmtLst;
case (BackendDAE.WHEN_STMTS(condition=cond, whenStmtLst = whenStmtLst, elsewhenPart = oweqn), true)
equation
s1 = ExpressionDump.printExpStr(cond);
s2 = stringDelimitList(List.map(whenStmtLst, dumpWhenOperatorStr), " ");
if isSome(oweqn) then
SOME(weqn) = oweqn;
s3 = whenEquationString(weqn, false);
else
s3 = "";
end if;
res = stringAppendList({"when ",s1," then\n ",s2,"\n",s3,"\nend when"});
then
res;
protected
String conditionStr, whenStmtStr, elseWhenStr;
DAE.Exp cond;
BackendDAE.WhenEquation weqn;
Option<BackendDAE.WhenEquation> oweqn;
list<BackendDAE.WhenOperator> whenStmtLst;
algorithm
BackendDAE.WHEN_STMTS(condition=cond, whenStmtLst=whenStmtLst, elsewhenPart=oweqn) := inWhenEqn;
conditionStr := ExpressionDump.printExpStr(cond);
whenStmtStr := stringDelimitList(List.map(whenStmtLst, dumpWhenOperatorStr), ";\n ") + ";\n";
if isSome(oweqn) then
SOME(weqn) := oweqn;
elseWhenStr := whenEquationString(weqn, false);
else
elseWhenStr := "";
end if;

case (BackendDAE.WHEN_STMTS(condition=cond, whenStmtLst = whenStmtLst, elsewhenPart = oweqn), false)
equation
s1 = ExpressionDump.printExpStr(cond);
s2 = stringDelimitList(List.map(whenStmtLst, dumpWhenOperatorStr), " ");
if isSome(oweqn) then
SOME(weqn) = oweqn;
s3 = whenEquationString(weqn, false);
else
s3 = "";
end if;
res = stringAppendList({"elsewhen ",s1," then\n ",s2,"\n",s3});
then
res;
end match;
if inStart then
outString := "when " + conditionStr + " then\n " + whenStmtStr + elseWhenStr + "end when;";
else
outString := "elsewhen " + conditionStr + " then\n " + whenStmtStr + elseWhenStr;
end if;
end whenEquationString;

public function equationString "Helper function to e.g. dump."
Expand Down
1 change: 1 addition & 0 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -2333,6 +2333,7 @@ protected
algorithm
for eqs in outDAE.eqs loop
_ := BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(eqs.orderedEqs, removeInitializationStuff1, false);
_ := BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(eqs.removedEqs, removeInitializationStuff1, false);
end for;

for eq in BackendEquation.equationList(shared.removedEqs) loop
Expand Down

0 comments on commit 88a65ee

Please sign in to comment.