Skip to content

Commit

Permalink
- BackendVarTransform. add case for not Cr for when assigment
Browse files Browse the repository at this point in the history
- add case for jacobian for remove simple equations
- add case for not(not(exp)) -> exp 
- add case for not cr = ... for CodegenC.writeLhsCref

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14288 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Dec 7, 2012
1 parent bce7b1a commit 68368b7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Compiler/BackEnd/BackendVarTransform.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,7 @@ algorithm
String msg;
case(DAE.CREF(componentRef=cr),_,_) then (cr,inRhs);
case(DAE.UNARY(operator=op,exp=DAE.CREF(componentRef=cr)),_,_) then (cr,DAE.UNARY(op,inRhs));
case(DAE.LUNARY(operator=op,exp=DAE.CREF(componentRef=cr)),_,_) then (cr,DAE.LUNARY(op,inRhs));
else
equation
msg = "BackendVarTransform: failed to replace left hand side of when equation " +&
Expand Down Expand Up @@ -1805,6 +1806,7 @@ algorithm
true = b1 or b2;
(e1_2,_) = ExpressionSimplify.simplify(e1_1);
(e2_2,_) = ExpressionSimplify.simplify(e2_1);
(e1_2,e2_2) = moveNegateRhs(e1_2,e2_2);
source = DAEUtil.addSymbolicTransformationSubstitution(b1,source,e1,e1_2);
source = DAEUtil.addSymbolicTransformationSubstitution(b2,source,e2,e2_2);
(es_1,b) = replaceStatementLst(es, repl,inFuncTypeExpExpToBooleanOption,DAE.STMT_ASSIGN(type_,e1_2,e2_2,source)::inAcc,true);
Expand Down Expand Up @@ -1997,6 +1999,23 @@ algorithm
end matchcontinue;
end replaceStatementLst;

protected function moveNegateRhs
input DAE.Exp inLhs;
input DAE.Exp inRhs;
output DAE.Exp outLhs;
output DAE.Exp outRhs;
algorithm
(outLhs,outRhs) := match(inLhs,inRhs)
local
DAE.Exp e;
DAE.Type ty;
case (DAE.LUNARY(DAE.NOT(ty),e),_) then (e,DAE.LUNARY(DAE.NOT(ty),inRhs));
case (DAE.UNARY(DAE.UMINUS(ty),e),_) then (e,DAE.UNARY(DAE.UMINUS(ty),inRhs));
case (DAE.UNARY(DAE.UMINUS_ARR(ty),e),_) then (e,DAE.UNARY(DAE.UMINUS_ARR(ty),inRhs));
case (_,_) then (inLhs,inRhs);
end match;
end moveNegateRhs;

protected function validLhsArrayAssignSTMT "
function: validLhsArrayAssignSTMT
autor Frenkel TUD 2012-11
Expand Down
22 changes: 22 additions & 0 deletions Compiler/BackEnd/RemoveSimpleEquations.mo
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,19 @@ algorithm
BackendDAE.Variables vars,knvars;
list<Integer> ilst;
list<BackendDAE.Var> vlst;
// a = const
// wbraun:
// speacial case for Jacobains, since there are all known variablen
// time depending input variables
case (_,_,_,_,(vars,BackendDAE.SHARED(knownVars=knvars,backendDAEType = BackendDAE.JACOBIAN()),_,_,_,_,_))
equation
// collect vars and check if variable time not there
((_,(false,_,_,_,_,ilst))) = Expression.traverseExpTopDown(lhs, traversingTimeVarsFinder, (false,vars,knvars,true,false,{}));
((_,(false,_,_,_,_,ilst))) = Expression.traverseExpTopDown(rhs, traversingTimeVarsFinder, (false,vars,knvars,true,false,ilst));
ilst = List.uniqueIntN(ilst,BackendVariable.varsSize(vars));
vlst = List.map1r(ilst,BackendVariable.getVarAt,vars);
then
solveTimeIndependentAcausal(vlst,ilst,lhs,rhs,source,inTpl);
case (_,_,_,_,(vars,BackendDAE.SHARED(knownVars=knvars),_,_,_,_,_))
equation
// collect vars and check if variable time not there
Expand Down Expand Up @@ -892,6 +905,15 @@ algorithm
BackendDAE.Variables vars,knvars;
list<Integer> ilst;
list<BackendDAE.Var> vlst;
case (_,_,_,(vars,BackendDAE.SHARED(knownVars=knvars,backendDAEType = BackendDAE.JACOBIAN()),_,_,_,_,_))
equation
// collect vars and check if variable time not there
((_,(false,_,_,_,_,ilst))) = Expression.traverseExpTopDown(exp, traversingTimeVarsFinder, (false,vars,knvars,true,false,{}));
ilst = List.uniqueIntN(ilst,BackendVariable.varsSize(vars));
vlst = List.map1r(ilst,BackendVariable.getVarAt,vars);
then
// shoulde be ok since solve checks only for iszero
solveTimeIndependentAcausal(vlst,ilst,exp,DAE.RCONST(0.0),source,inTpl);
case (_,_,_,(vars,BackendDAE.SHARED(knownVars=knvars),_,_,_,_,_))
equation
// collect vars and check if variable time not there
Expand Down
5 changes: 5 additions & 0 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4214,6 +4214,11 @@ algorithm
b1 = not b1;
then
DAE.BCONST(b1);

// not(not(exp)) -> exp
case(DAE.NOT(_),DAE.LUNARY(DAE.NOT(_),e1))
then
e1;

// -x => 0 - x
case (DAE.UMINUS(ty = ty),DAE.ICONST(integer = i))
Expand Down
16 changes: 15 additions & 1 deletion Compiler/Template/CodegenC.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5373,6 +5373,15 @@ case UNARY(exp = e as CREF(ty= DAE.T_COMPLEX(varLst = varLst, complexClassType=R
; separator="\n"
%>
>>
case LUNARY(operator=NOT(__),exp = e as CREF(ty= DAE.T_COMPLEX(varLst = varLst, complexClassType=RECORD(__)))) then
let lhsStr = scalarLhsCref(e, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
<<
<%preExp%>
<% varLst |> var as TYPES_VAR(__) hasindex i1 fromindex 0 =>
'<%lhsStr%>$P<%var.name%> = !<%rhsStr%>.<%var.name%>;'
; separator="\n"
%>
>>
case CALL(path=path,expLst=expLst,attr=CALL_ATTR(ty= T_COMPLEX(varLst = varLst, complexClassType=RECORD(__)))) then
let &preExp = buffer ""
<<
Expand All @@ -5388,11 +5397,16 @@ case CREF(__) then
<<
<%lhsStr%> = <%rhsStr%>;
>>
case UNARY(exp = e as CREF(__)) then
case UNARY(operator=UMINUS(__),exp = e as CREF(__)) then
let lhsStr = scalarLhsCref(e, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
<<
<%lhsStr%> = -<%rhsStr%>;
>>
case LUNARY(operator=NOT(__),exp = e as CREF(__)) then
let lhsStr = scalarLhsCref(e, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
<<
<%lhsStr%> = !<%rhsStr%>;
>>
case ARRAY(array = {}) then
<<
>>
Expand Down

0 comments on commit 68368b7

Please sign in to comment.