Skip to content

Commit

Permalink
- attempt to improve r20789 (don't handle impure functions as constant)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20848 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed May 27, 2014
1 parent 9f1818a commit e374b55
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/RemoveSimpleEquations.mo
Expand Up @@ -1542,7 +1542,7 @@ algorithm
// const
case (_, _, _, _, _, (vars, shared, eqns, seqns, index, mT, _))
equation
true = Expression.isConst(exp); // lochel: this is at least needed for impure functions
false = Expression.isImpure(exp); // lochel: this is at least needed for impure functions
Debug.fcall(Flags.DEBUG_ALIAS, BackendDump.debugStrCrefStrExpStr, ("Const Equation ", cr, " = ", exp, " found.\n"));
colum = mT[i];
_ = arrayUpdate(mT, i, index::colum);
Expand Down
30 changes: 30 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -7145,6 +7145,36 @@ algorithm
end match;
end isHalf;

public function isImpure "author: lochel
Returns true if an expression contains an impure function call."
input DAE.Exp inExp;
output Boolean outBoolean;
algorithm
outBoolean := isConstWork(inExp, true);
((_, outBoolean)) := traverseExp(inExp, isImpureWork, false);
end isImpure;

protected function isImpureWork "author: lochel"
input tuple<DAE.Exp, Boolean> inExp;
output tuple<DAE.Exp, Boolean> outExp;
algorithm
outExp := matchcontinue(inExp)
local
DAE.Exp e;
DAE.Type ty;
Boolean b;

case ((_, true))
then inExp;

case (((e as DAE.CALL(attr=DAE.CALL_ATTR(isImpure=true))), _))
then ((e, true));

else
then inExp;
end matchcontinue;
end isImpureWork;

public function isConst
"Returns true if an expression is constant"
input DAE.Exp inExp;
Expand Down

0 comments on commit e374b55

Please sign in to comment.