Skip to content

Commit

Permalink
- Inline.mo: add inlineExpOpt and use it in inlineVar
Browse files Browse the repository at this point in the history
- BackendDump: add dumping of If equations

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12210 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jun 26, 2012
1 parent c10ebf0 commit 9e6d211
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 22 deletions.
40 changes: 40 additions & 0 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -1282,6 +1282,8 @@ algorithm
BackendDAE.WhenEquation weqn;
DAE.Algorithm alg;
DAE.ElementSource source;
list<list<BackendDAE.Equation>> eqnstrue;
list<BackendDAE.Equation> eqnsfalse,eqns;
case (BackendDAE.EQUATION(exp = e1,scalar = e2))
equation
s1 = ExpressionDump.printExpStr(e1);
Expand Down Expand Up @@ -1363,9 +1365,47 @@ algorithm
outsStr, ")" /*,"\n"*/});
then
res;
case (BackendDAE.IF_EQUATION(conditions=e1::expl, eqnstrue=eqns::eqnstrue, eqnsfalse=eqnsfalse, source=source))
equation
s1 = ExpressionDump.printExpStr(e1);
s2 = stringDelimitList(List.map(eqns,equationStr),"\n");
s3 = stringAppendList({"if ",s1," then\n",s2});
res = ifequationStr(expl,eqnstrue,eqnsfalse,s3);
then
res;
end matchcontinue;
end equationStr;

protected function ifequationStr
input list<DAE.Exp> conditions;
input list<list<BackendDAE.Equation>> eqnstrue;
input list<BackendDAE.Equation> eqnsfalse;
input String iString;
output String outString;
algorithm
outString := match(conditions,eqnstrue,eqnsfalse,iString)
local
list<list<BackendDAE.Equation>> eqnslst;
list<BackendDAE.Equation> eqns;
String seqns,s,se;
DAE.Exp e;
list<DAE.Exp> elst;
case ({},_,_,_)
equation
seqns = stringDelimitList(List.map(eqnsfalse,equationStr),"\n");
s = stringAppendList({"else\n",iString,seqns,"end if"});
then
s;
case(e::elst,eqns::eqnslst,_,_)
equation
se = ExpressionDump.printExpStr(e);
seqns = stringDelimitList(List.map(eqns,equationStr),"\n");
s = stringAppendList({"elseif ",se," then\n",seqns,"end if"});
then
ifequationStr(elst,eqnslst,eqnsfalse,s);
end match;
end ifequationStr;

protected function dumpExtObjCls "dump classes of external objects"
input BackendDAE.ExternalObjectClasses cls;
algorithm
Expand Down
17 changes: 16 additions & 1 deletion Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -1404,10 +1404,11 @@ algorithm
array<BackendDAE.MultiDimEquation> arrayEqs;
array<BackendDAE.ComplexEquation> complEqs;
list<tuple<Integer,list<list<DAE.Subscript>>>> entrylst,entrylst1;
list<DAE.Exp> explst;
list<DAE.Exp> explst,explst1;
list<DAE.ElementSource> sources;
DAE.ElementSource source;
String str;
list<list<DAE.Subscript>> subslst;

case ((eqn as BackendDAE.RESIDUAL_EQUATION(exp=e,source=source),(v, arrayEqs,complEqs,entrylst,explst,sources)))
equation
Expand All @@ -1422,6 +1423,20 @@ algorithm
rhs_exp_1 = Expression.negate(rhs_exp);
(rhs_exp_2,_) = ExpressionSimplify.simplify(rhs_exp_1);
then ((eqn,(v, arrayEqs,complEqs,entrylst,rhs_exp_2::explst,source::sources)));

case ((eqn as BackendDAE.ARRAY_EQUATION(dimSize=ds,left=e1, right=e2,source=source),(v, arrayEqs,complEqs,entrylst,explst,sources)))
equation
new_exp = Expression.expSub(e1,e2);
ad = List.map(ds,Util.makeOption);
subslst = BackendDAEUtil.arrayDimensionsToRange(ad);
subslst = BackendDAEUtil.rangesToSubscripts(subslst);
explst1 = List.map1r(subslst,Expression.applyExpSubscripts,new_exp);
explst1 = List.map1(explst1,BackendDAEUtil.getEqnsysRhsExp,v);
explst1 = List.map(explst1,Expression.negate);
explst1 = ExpressionSimplify.simplifyList(explst1, {});
explst = listAppend(explst1,explst);
sources = List.consN(equationSize(eqn), source, sources);
then ((eqn,(v, arrayEqs,complEqs,entrylst,explst,sources)));

case ((eqn as BackendDAE.ARRAY_EQUATIONWRAPPER(index=index,source=source),(v, arrayEqs,complEqs,entrylst,explst,sources)))
equation
Expand Down
54 changes: 33 additions & 21 deletions Compiler/FrontEnd/Inline.mo
Expand Up @@ -182,7 +182,7 @@ function: inlineEqOpt
input Functiontuple inElementList;
output Option<BackendDAE.Equation> outEquationOption;
algorithm
outEquationOption := matchcontinue(inEquationOption,inElementList)
outEquationOption := match(inEquationOption,inElementList)
local
BackendDAE.Equation eqn;

Expand All @@ -192,12 +192,7 @@ algorithm
eqn = inlineEq(eqn,inElementList);
then
SOME(eqn);
case(_,_)
equation
Debug.fprintln(Flags.FAILTRACE,"Inline.inlineEqOpt failed");
then
fail();
end matchcontinue;
end match;
end inlineEqOpt;

public function inlineEq "
Expand Down Expand Up @@ -392,7 +387,7 @@ algorithm
DAE.VarDirection varDirection;
DAE.VarParallelism varParallelism;
BackendDAE.Type varType;
DAE.Exp e,e_1,startv,startv_1;
DAE.Exp startv,startv_1;
Option<Values.Value> bindValue;
DAE.InstDims arrayDim;
Integer index;
Expand All @@ -402,27 +397,21 @@ algorithm
DAE.Stream streamPrefix;
BackendDAE.Var var;
DAE.ElementSource source;
Option<DAE.Exp> bind;

case(BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,SOME(e),bindValue,arrayDim,index,source,values,comment,flowPrefix,streamPrefix),fns)
case(BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,index,source,values,comment,flowPrefix,streamPrefix),fns)
equation
(e_1,source) = inlineExp(e,fns,source);
(bind,source) = inlineExpOpt(bind,fns,source);
startv = DAEUtil.getStartAttrFail(values);
(startv_1,source) = inlineExp(startv,fns,source);
values1 = DAEUtil.setStartAttr(values,startv_1);
then
BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,SOME(e_1),bindValue,arrayDim,index,source,values1,comment,flowPrefix,streamPrefix);
case(BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,NONE(),bindValue,arrayDim,index,source,values,comment,flowPrefix,streamPrefix),fns)
BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,index,source,values1,comment,flowPrefix,streamPrefix);
case(BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,index,source,values,comment,flowPrefix,streamPrefix),fns)
equation
startv = DAEUtil.getStartAttrFail(values);
(startv_1,source) = inlineExp(startv,fns,source);
values1 = DAEUtil.setStartAttr(values,startv_1);
then
BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,NONE(),bindValue,arrayDim,index,source,values1,comment,flowPrefix,streamPrefix);
case(BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,SOME(e),bindValue,arrayDim,index,source,values,comment,flowPrefix,streamPrefix),fns)
equation
(e_1,source) = inlineExp(e,fns,source);
(bind,source) = inlineExpOpt(bind,fns,source);
then
BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,SOME(e_1),bindValue,arrayDim,index,source,values,comment,flowPrefix,streamPrefix);
BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,index,source,values,comment,flowPrefix,streamPrefix);
case(var,_) then var;
end matchcontinue;
end inlineVar;
Expand Down Expand Up @@ -1025,6 +1014,29 @@ algorithm
end matchcontinue;
end inlineElse;

public function inlineExpOpt "
function: inlineExpOpt
inlines calls in an DAE.Exp"
input Option<DAE.Exp> inExpOption;
input Functiontuple inElementList;
input DAE.ElementSource inSource;
output Option<DAE.Exp> outExpOption;
output DAE.ElementSource outSource;
algorithm
(outExpOption,outSource) := match(inExpOption,inElementList,inSource)
local
DAE.Exp exp;
DAE.ElementSource source;

case(NONE(),_,_) then (NONE(),inSource);
case(SOME(exp),_,_)
equation
(exp,source) = inlineExp(exp,inElementList,inSource);
then
(SOME(exp),source);
end match;
end inlineExpOpt;

public function inlineExp "
function: inlineExp
inlines calls in an DAE.Exp"
Expand Down

0 comments on commit 9e6d211

Please sign in to comment.