Skip to content

Commit

Permalink
+ Cleaned up ComponentReference handling in the code generators. Less…
Browse files Browse the repository at this point in the history
… clutter. Reuse functions as much as possible.

+ Now we can use offsetting to index arrays in generated code. works for qualified Crefs as well.
  - Some issues still remain (e.g. alias elimination) so we don't use offsetting by default.
    only used when the cref involves variable indexes for now. Still might give erroneous results if some array members are missing though. 
+ Improved handling of multi-variable return functions (*tuple returns). 
+ fix for a case where wrong types were used when creating crefs in front-end.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24578 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
mahge committed Feb 14, 2015
1 parent 674bc95 commit 99a799a
Show file tree
Hide file tree
Showing 7 changed files with 461 additions and 502 deletions.
64 changes: 64 additions & 0 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -1322,6 +1322,70 @@ algorithm
end matchcontinue;
end crefHasScalarSubscripts;

public function crefIsScalarWithAllConstSubs
""
input DAE.ComponentRef inCref;
output Boolean isScalar;
algorithm
isScalar := matchcontinue(inCref)
local
Boolean res;
list<DAE.Subscript> subs;
list<DAE.Dimension> dims;
list<DAE.ComponentRef> tempcrefs;
Integer ndim, nsub;

case _ equation {} = crefSubs(inCref); then true;

case _
equation
(subs as (_::_))= crefSubs(inCref);
dims = crefDims(inCref);
// Dimensions may be removed when a component is instantiated if it has
// constant subscripts though, so it may have more subscripts than
// dimensions.
// mahge: TODO: Does this still happen?
true = listLength(dims) <= listLength(subs);
true = Expression.subscriptConstants(subs);
then
true;

else false;

end matchcontinue;
end crefIsScalarWithAllConstSubs;

public function crefIsScalarWithVariableSubs
""
input DAE.ComponentRef inCref;
output Boolean isScalar;
algorithm
isScalar := matchcontinue(inCref)
local
Boolean res;
list<DAE.Subscript> subs;
list<DAE.Dimension> dims;
list<DAE.ComponentRef> tempcrefs;
Integer ndim, nsub;

case _
equation
(subs as (_::_))= crefSubs(inCref);
dims = crefDims(inCref);
// Dimensions may be removed when a component is instantiated if it has
// constant subscripts though, so it may have more subscripts than
// dimensions.
// mahge: TODO: Does this still happen?
true = listLength(dims) <= listLength(subs);
false = Expression.subscriptConstants(subs);
then
true;

else false;

end matchcontinue;
end crefIsScalarWithVariableSubs;

public function containWholeDim " A function to check if a cref contains a [:] wholedim element in the subscriptlist.
"
input DAE.ComponentRef inRef;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Static.mo
Expand Up @@ -11972,7 +11972,7 @@ algorithm
(cache,ss_1,const) = elabSubscriptsDims(cache, crefSubs, ss, sl, impl,
topPrefix, inComponentRef, info);
then
(cache,ComponentReference.makeCrefIdent(id,ty,ss_1),const,hasZeroSizeDim);
(cache,ComponentReference.makeCrefIdent(id,id_ty,ss_1),const,hasZeroSizeDim);

// QUAL,with no subscripts => looking for var in the top env!
case (cache,crefEnv,crefSubs,Absyn.CREF_QUAL(name = id,subscripts = {},componentRef = restCref),topPrefix,crefPrefix,impl,hasZeroSizeDim,_)
Expand Down
14 changes: 14 additions & 0 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -13924,6 +13924,20 @@ algorithm
end match;
end getVariableIndex;

public function generateSubPalceholders
input DAE.ComponentRef cr;
output String outdef;
protected
list<DAE.Dimension> dims;
Integer nrdims;
list<String> idxstrlst;
algorithm
dims := ComponentReference.crefDims(cr);
nrdims := listLength(dims);
idxstrlst := List.map(List.intRange(nrdims),intString);
outdef := stringDelimitList(List.threadMap(List.fill("i_", nrdims), idxstrlst, stringAppend), ",");
end generateSubPalceholders;

public function execStat
"Prints an execution stat on the format:
*** %name% -> time: %time%, memory %memory%
Expand Down

0 comments on commit 99a799a

Please sign in to comment.