Skip to content

Commit

Permalink
- SimCode.mo
Browse files Browse the repository at this point in the history
  -collate crefs of arrays before template code generation 
- DAELow.mo
  -add function collateAlgorithm, collateArrExpm, traversingcollateArrExp
- SimCode/SimCodeC.tpl
  - improve template algStmtTupleAssign to generate code for functions return arrays

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5865 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jul 18, 2010
1 parent f46d1cc commit 5982a41
Show file tree
Hide file tree
Showing 4 changed files with 588 additions and 370 deletions.
79 changes: 79 additions & 0 deletions Compiler/DAELow.mo
Expand Up @@ -6014,6 +6014,85 @@ algorithm
end matchcontinue;
end makeMatrix;

public function collateAlgorithm "
Author: Frenkel TUD 2010-07"
input DAE.Algorithm inAlg;
input Option<DAE.FunctionTree> infuncs;
output DAE.Algorithm outAlg;
algorithm
outAlg := matchcontinue(inAlg,infuncs)
local list<DAE.Statement> statementLst;
case(DAE.ALGORITHM_STMTS(statementLst=statementLst),infuncs)
equation
(statementLst,_) = DAEUtil.traverseDAEEquationsStmts(statementLst, collateArrExp, infuncs);
then
DAE.ALGORITHM_STMTS(statementLst);
case(inAlg,infuncs) then inAlg;
end matchcontinue;
end collateAlgorithm;

public function collateArrExp "
Author: Frenkel TUD 2010-07"
input DAE.Exp inExp;
input Option<DAE.FunctionTree> infuncs;
output DAE.Exp outExp;
output Option<DAE.FunctionTree> outfuncs;
algorithm
(outExp,outfuncs) := matchcontinue(inExp,infuncs)
local DAE.Exp e;
case(inExp,infuncs)
equation
((e,outfuncs)) = Exp.traverseExp(inExp, traversingcollateArrExp, infuncs);
then
(e,outfuncs);
case(inExp,infuncs) then (inExp,infuncs);
end matchcontinue;
end collateArrExp;

protected function traversingcollateArrExp "
Author: Frenkel TUD 2010-07."
input tuple<DAE.Exp, Option<DAE.FunctionTree> > inExp;
output tuple<DAE.Exp, Option<DAE.FunctionTree> > outExp;
algorithm outExp := matchcontinue(inExp)
local
Option<DAE.FunctionTree> funcs;
DAE.ComponentRef cr;
DAE.ExpType ty;
Integer i;
DAE.Exp e,e1,e1_1,e1_2;
Boolean b;
case ((e as DAE.MATRIX(ty=ty,integer=i,scalar=(((e1 as DAE.CREF(componentRef = cr)),_)::_)::_),funcs))
equation
e1_1 = Exp.expStripLastSubs(e1);
(e1_2,_) = extendArrExp(e1_1,funcs);
true = Exp.expEqual(e,e1_2);
then
((e1_1,funcs));
case ((e as DAE.MATRIX(ty=ty,integer=i,scalar=(((e1 as DAE.UNARY(exp = DAE.CREF(componentRef = cr))),_)::_)::_),funcs))
equation
e1_1 = Exp.expStripLastSubs(e1);
(e1_2,_) = extendArrExp(e1_1,funcs);
true = Exp.expEqual(e,e1_2);
then
((e1_1,funcs));
case ((e as DAE.ARRAY(ty=ty,scalar=b,array=(e1 as DAE.CREF(componentRef = cr))::_),funcs))
equation
e1_1 = Exp.expStripLastSubs(e1);
(e1_2,_) = extendArrExp(e1_1,funcs);
true = Exp.expEqual(e,e1_2);
then
((e1_1,funcs));
case ((e as DAE.ARRAY(ty=ty,scalar=b,array=(e1 as DAE.UNARY(exp = DAE.CREF(componentRef = cr)))::_),funcs))
equation
e1_1 = Exp.expStripLastSubs(e1);
(e1_2,_) = extendArrExp(e1_1,funcs);
true = Exp.expEqual(e,e1_2);
then
((e1_1,funcs));
case(inExp) then inExp;
end matchcontinue;
end traversingcollateArrExp;

protected function lowerComplexEqn
"function: lowerComplexEqn
Helper function to lower2.
Expand Down
4 changes: 2 additions & 2 deletions Compiler/SimCode.mo
Expand Up @@ -3697,7 +3697,7 @@ algorithm
DAELow.EquationArray eqns,se,ie;
DAELow.MultiDimEquation[:] ae;
Algorithm.Algorithm[:] al;
Algorithm.Algorithm alg;
Algorithm.Algorithm alg,alg1;
DAELow.EventInfo ev;
list<Exp.ComponentRef> solvedVars,algOutVars;
list<Exp.Exp> algOutExpVars;
Expand All @@ -3714,7 +3714,7 @@ algorithm
algOutVars = Util.listMap(algOutExpVars,Exp.expCref);
// The variables solved for and the output variables of the algorithm must be the same.
true = Util.listSetEqualOnTrue(solvedVars,algOutVars,Exp.crefEqual);
DAE.ALGORITHM_STMTS(algStatements) = alg;
DAE.ALGORITHM_STMTS(algStatements) = DAELow.collateAlgorithm(alg,NONE());
equation_ = SES_ALGORITHM(algStatements);
then equation_;
/* Error message, inverse algorithms not supported yet */
Expand Down

0 comments on commit 5982a41

Please sign in to comment.