Skip to content

Commit

Permalink
Fix indentation of 1c86d4e
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#2320
  • Loading branch information
lochel authored and OpenModelica-Hudson committed Mar 27, 2018
1 parent 1c86d4e commit 659bcbc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 58 deletions.
104 changes: 47 additions & 57 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -149,46 +149,36 @@ protected function simplifyInStreamWork2
output list<BackendDAE.Variables> outVars = inVars;
algorithm
outExp := match(inExp)
local DAE.Type tp;
DAE.ComponentRef cr;
DAE.Exp e, expr;
Option<DAE.Exp> eMin;
Option<DAE.Exp> eMax;
Boolean isZero;


case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e as DAE.CREF(componentRef=cr), expr})
algorithm
(eMin, eMax) := simplifyInStreamWorkExpresion(cr, outVars);
isZero := simplifyInStreamWorkSimplify(eMin, false);
tp := ComponentReference.crefTypeFull(cr);
then
if isZero then e else Expression.makePureBuiltinCall("max", {e, expr}, tp);

case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e as DAE.UNARY(DAE.UMINUS(tp), DAE.CREF(componentRef=cr)), expr})
algorithm
(eMin, eMax) := simplifyInStreamWorkExpresion(cr, outVars);
isZero := simplifyInStreamWorkSimplify(eMax, true);
then
if isZero then Expression.createZeroExpression(tp) else Expression.makePureBuiltinCall("max", {e, expr}, tp);

case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e, expr})
guard Expression.isZero(e)
then e;

case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e, expr})
//algorithm
//print("\nsimplifyInStreamWork: ");
//print(ExpressionDump.printExpStr(inExp));
//print(" <-> ");
//print(ExpressionDump.printExpStr(e));

then Expression.makePureBuiltinCall("max", {e, expr}, Expression.typeof(e));

case _
then inExp;
end match;
local
DAE.Type tp;
DAE.ComponentRef cr;
DAE.Exp e, expr;
Option<DAE.Exp> eMin, eMax;
Boolean isZero;

case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e as DAE.CREF(componentRef=cr), expr}) algorithm
(eMin, eMax) := simplifyInStreamWorkExpresion(cr, outVars);
isZero := simplifyInStreamWorkSimplify(eMin, false);
tp := ComponentReference.crefTypeFull(cr);
then if isZero then e else Expression.makePureBuiltinCall("max", {e, expr}, tp);

case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e as DAE.UNARY(DAE.UMINUS(tp), DAE.CREF(componentRef=cr)), expr}) algorithm
(eMin, eMax) := simplifyInStreamWorkExpresion(cr, outVars);
isZero := simplifyInStreamWorkSimplify(eMax, true);
then if isZero then Expression.createZeroExpression(tp) else Expression.makePureBuiltinCall("max", {e, expr}, tp);

case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e, expr}) guard Expression.isZero(e)
then e;

case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e, expr})
//print("\nsimplifyInStreamWork: ");
//print(ExpressionDump.printExpStr(inExp));
//print(" <-> ");
//print(ExpressionDump.printExpStr(e));
then Expression.makePureBuiltinCall("max", {e, expr}, Expression.typeof(e));

else inExp;
end match;
end simplifyInStreamWork2;

protected function simplifyInStreamWorkExpresion
Expand All @@ -199,32 +189,32 @@ protected function simplifyInStreamWorkExpresion
protected
BackendDAE.Var v;
algorithm
for vars in inVars loop
try
(v, _) := BackendVariable.getVarSingle(cr, vars);
(outMin, outMax) := BackendVariable.getMinMaxAttribute(v);
break;
else
// search
end try;
end for;

for vars in inVars loop
try
(v, _) := BackendVariable.getVarSingle(cr, vars);
(outMin, outMax) := BackendVariable.getMinMaxAttribute(v);
return;
else
// search
end try;
end for;
end simplifyInStreamWorkExpresion;

protected function simplifyInStreamWorkSimplify
input Option<DAE.Exp> bound;
input Boolean neg;
output Boolean isZero;
algorithm
isZero := match bound
local Real r;
case SOME(DAE.RCONST(r))
then if neg then r<= 0.0 else r >= 0.0;
case _
then false;
end match;
end simplifyInStreamWorkSimplify;
isZero := match bound
local
Real r;

case SOME(DAE.RCONST(r))
then if neg then r<= 0.0 else r >= 0.0;

else false;
end match;
end simplifyInStreamWorkSimplify;

// =============================================================================
// simplify time independent function calls
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -7623,7 +7623,7 @@ algorithm
preOptModules := Util.getOptionOrDefault(inPreOptModules, preOptModules);

if isSome(getGlobalRoot(Global.isInStream)) then
enabledModules := "simplifyInStream"::enabledModules;
enabledModules := "simplifyInStream"::enabledModules;
end if;

if Flags.getConfigBool(Flags.DEFAULT_OPT_MODULES_ORDERING) then
Expand Down

0 comments on commit 659bcbc

Please sign in to comment.