Skip to content

Commit

Permalink
- support for non constant array-indices added to variable - memory -…
Browse files Browse the repository at this point in the history
… mapping

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25816 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Marcus Walther committed Apr 29, 2015
1 parent dbedd11 commit 55d8775
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 3 additions & 4 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -6998,19 +6998,18 @@ algorithm
end getAssertConditionCrefs;

public function getSubscriptIndex "author: marcusw
Get the index of the given subscript as Integer. If the subscript is not a constant integer, the function returns 0."
Get the index of the given subscript as Integer. If the subscript is not a constant integer, the function returns -1."
input DAE.Subscript iSubscript;
output Integer oIndex;
protected
Integer index;
DAE.Exp exp;
algorithm
oIndex := match(iSubscript)
case(DAE.INDEX(DAE.ICONST(integer=index)))
then index;
else
equation
Error.addMessage(Error.INTERNAL_ERROR, {"GetSubscriptIndex: Only constant index subsripts are supported at the moment!."});
then 0;
then -1;
end match;
end getSubscriptIndex;

Expand Down
16 changes: 15 additions & 1 deletion Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -12570,7 +12570,7 @@ algorithm
//print("Adding variable " + ComponentReference.printComponentRefStr(name) + " to map with index " + intString(varIdx) + "\n");
tmpVarToIndexMapping = BaseHashTable.add((name, {varIdx}), tmpVarToIndexMapping);
arraySubscripts = ComponentReference.crefLastSubs(name);
if(listEmpty(numArrayElement)) then
if(boolOr(listEmpty(numArrayElement), checkIfSubscriptsContainsUnhandlableIndices(arraySubscripts))) then
arrayName = name;
else
arrayName = ComponentReference.crefStripLastSubs(name);
Expand Down Expand Up @@ -12603,6 +12603,20 @@ algorithm
end match;
end createVarToArrayIndexMapping1;

protected function checkIfSubscriptsContainsUnhandlableIndices "author: marcusw
Returns false if at least one subscript can not be handled as constant index."
input list<DAE.Subscript> iSubscripts;
output Boolean oContainsUnhandledSubscripts;
protected
Boolean containsUnhandledSubscripts = false;
DAE.Subscript subscript;
algorithm
for subscript in iSubscripts loop
containsUnhandledSubscripts := boolOr(containsUnhandledSubscripts, intLt(DAEUtil.getSubscriptIndex(subscript), 0));
end for;
oContainsUnhandledSubscripts := containsUnhandledSubscripts;
end checkIfSubscriptsContainsUnhandlableIndices;

protected function getArrayIdxByVar "author: marcusw
Get the storage-index of the given variable. If the variable is an alias, the storage position of the alias variable is returned.
If the variable is a negated alias, then the negated storage position of the alias variable is returned."
Expand Down

0 comments on commit 55d8775

Please sign in to comment.