Skip to content

Commit

Permalink
- extend var replacement to substitute partial function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich authored and OpenModelica-Hudson committed Jun 15, 2015
1 parent 810b701 commit 96c3492
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
20 changes: 19 additions & 1 deletion Compiler/BackEnd/BackendVarTransform.mo
Expand Up @@ -1123,7 +1123,13 @@ algorithm
case ((e as DAE.CALL(path = path,expLst = expl,attr = attr)),repl,cond)
equation
true = replaceExpCond(cond, e);
(expl_1,true) = replaceExpList(expl, repl, cond, {}, false);
cr = ComponentReference.toExpCref(Absyn.pathToCref(path));
if hasReplacement(repl,cr) then
e1_1 = getReplacement(repl,cr);
DAE.PARTEVALFUNCTION(path=path,expList = expl_1) = e1_1;
expl = listAppend(expl_1,expl);
end if;
(expl_1,_) = replaceExpList(expl, repl, cond, {}, false);
then
(DAE.CALL(path,expl_1,attr),true);
case ((e as DAE.PARTEVALFUNCTION(path,expl,tp,t)),repl,cond)
Expand Down Expand Up @@ -1205,6 +1211,18 @@ algorithm
(e1_1,_) = replaceExp(e1, repl, cond);
(iters,true) = replaceExpIters(iters, repl, cond, {}, false);
then (DAE.REDUCTION(reductionInfo,e1_1,iters),true);
case ((e as DAE.BOX(exp = e1)),repl,cond)
equation
true = replaceExpCond(cond, e);
(e1_1,true) = replaceExp(e1, repl, cond);
then
(DAE.BOX(e1_1),true);
case ((e as DAE.UNBOX(ty=tp, exp = e1)),repl,cond)
equation
true = replaceExpCond(cond, e);
(e1_1,true) = replaceExp(e1, repl, cond);
then
(DAE.UNBOX(e1_1,tp),true);
case (e,_,_)
then (e,false);
end matchcontinue;
Expand Down
36 changes: 29 additions & 7 deletions Compiler/BackEnd/EvaluateFunctions.mo
Expand Up @@ -1579,6 +1579,21 @@ algorithm
end matchcontinue;
end evaluateFunctions_updateAlgElements;

protected function unboxExp
"takes an expression and unboxes it if it is boxed"
input DAE.Exp ie;
input Boolean bIn;
output DAE.Exp outExp;
output Boolean bOut;
algorithm
(outExp, bOut) := match (ie,bIn)
local
DAE.Exp e;
case (DAE.BOX(e),_) then unboxExp(e,true);
else (ie,bIn);
end match;
end unboxExp;

protected function evaluateFunctions_updateStatement "replaces the statements with regards to the given varReplacements and check for constant assignments.
if there are constant assignments add this replacement rule
author:Waurich TUD 2014-03"
Expand Down Expand Up @@ -1621,10 +1636,13 @@ algorithm
cref = Expression.expCref(exp1);
scalars = getRecordScalars(cref);
(exp2,_) = BackendVarTransform.replaceExp(exp2,replIn,NONE());
(exp2,_) = ExpressionSimplify.simplify(exp2);

(exp2,(exp1,funcTree,idx,addStmts)) = Expression.traverseExpTopDown(exp2,evaluateConstantFunctionWrapper,(exp1,funcTree,idx,{}));

// (exp2,changed) = bcallret1_2(changed,ExpressionSimplify.simplify,exp2,exp2,changed); This does nothing useful with the statement below...
(exp2,_) = ExpressionSimplify.simplify(exp2);
//(exp2,_) = ExpressionSimplify.simplify(exp2);
(exp2,_) = Expression.traverseExpBottomUp(exp2,unboxExp,false);// for metamodelica/meta/omc
expLst = Expression.getComplexContents(exp2);

// add the replacements for the addStmts and remove the replacements for the variable outputs
Expand Down Expand Up @@ -2330,17 +2348,21 @@ algorithm
Integer idx;
DAE.Exp rhs, lhs;
DAE.FunctionTree funcs;
DAE.Type ty;
list<BackendDAE.Equation> addEqs;
list<DAE.Statement> stmts,stmtsIn;
case (rhs,(lhs,funcs,idx,stmtsIn))
equation
DAE.CALL() = rhs;
((rhs,lhs,addEqs,funcs,idx,_)) = evaluateConstantFunction(rhs,lhs,funcs,idx);

case (DAE.CALL(),(lhs,funcs,idx,stmtsIn))
equation
((rhs,lhs,addEqs,funcs,idx,_)) = evaluateConstantFunction(inExp,lhs,funcs,idx);
stmts = List.map(addEqs,equationToStmt);

stmts = listAppend(stmts,stmtsIn);
then (rhs,true,(lhs,funcs,idx,stmts));

case (DAE.UNBOX(exp=rhs, ty=ty),(lhs,funcs,idx,stmts))
equation
(rhs,_,(lhs,funcs,idx,stmts)) = evaluateConstantFunctionWrapper(rhs,inTpl);
then (rhs,true,(lhs,funcs,idx,stmts));

case (rhs,(lhs,funcs,idx,stmtsIn))
then (rhs,false,(lhs,funcs,idx,stmtsIn));
end matchcontinue;
Expand Down
2 changes: 2 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -7297,6 +7297,8 @@ algorithm
/*TODO:Make this work for multiple iters, guard exps*/
case (DAE.REDUCTION(expr=e1,iterators={DAE.REDUCTIONITER(exp=e2)}),_)
then isConstWork(e1,isConstWork(e2,true));

case(DAE.BOX(exp=e),_) then isConstWork(e,true);

else false;
end match;
Expand Down

0 comments on commit 96c3492

Please sign in to comment.