Skip to content

Commit

Permalink
- Fix one of #3214 issues.
Browse files Browse the repository at this point in the history
- Fill in missing subs with whole dims when elaborating subs.
- Update overlooked array assignment case in code generation for arrays. 


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25108 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
mahge committed Mar 16, 2015
1 parent 02db2b2 commit c555854
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
16 changes: 15 additions & 1 deletion Compiler/FrontEnd/Static.mo
Expand Up @@ -11831,7 +11831,7 @@ algorithm
// false = Types.isUnknownType(t);
// print("elabCrefSubs type of: " + id + " is " + Types.printTypeStr(t) + "\n");
// Debug.traceln(" elabSucscriptsDims " + id + " got var");
_ = Types.simplifyType(t);
// _ = Types.simplifyType(t);
id_ty = Types.simplifyType(id_ty);
hasZeroSizeDim = Types.isZeroLengthArray(id_ty);
sl = Types.getDimensions(id_ty);
Expand Down Expand Up @@ -11961,6 +11961,7 @@ protected
DAE.Const const;
Option<DAE.Properties> prop;
String subl_str, diml_str, cref_str;
Integer nrdims, nrsubs;
algorithm
for asub in inSubscripts loop
if listEmpty(rest_dims) then
Expand All @@ -11984,6 +11985,19 @@ algorithm
outSubs := dsub :: outSubs;
end for;

nrsubs := listLength(outSubs);

// If there are subs and the number of subs is less than dims
// then fill in whole dims for the missing subs. i.e. We have a slice.
// If there are no subs then it is a whole array so we do nothing.
if nrsubs > 0 then
nrdims := listLength(inDimensions);
while nrsubs < nrdims loop
outSubs := DAE.WHOLEDIM()::outSubs;
nrsubs := nrsubs + 1;
end while;
end if;

outSubs := listReverse(outSubs);
end elabSubscriptsDims;

Expand Down
27 changes: 8 additions & 19 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -6964,10 +6964,17 @@ case STMT_ASSIGN_ARR(lhs=lhsexp as CREF(componentRef=cr), exp=RANGE(__), type_=t
case STMT_ASSIGN_ARR(lhs=lhsexp as CREF(componentRef=cr), exp=e as CALL(__), type_=t) then
let &preExp = buffer ""
let expPart = daeExp(e, context, &preExp, &varDecls, &auxFunction)
let type = expTypeArray(t)
if crefSubIsScalar(cr) then
let lhs = daeExpCrefLhs(lhsexp, context, &preExp, &varDecls, &auxFunction)
let freepararray = match context
case FUNCTION_CONTEXT(__) then
if acceptParModelicaGrammar() then 'free_device_array(&<%lhs%>)' else ''
else ''
<<
<%preExp%>
<%copyArrayDataAndFreeMemAfterCall(t, expPart, cr, context)%>
<%freepararray%>
copy_<%type%>_data(<%expPart%>, &<%lhs%>);
>>
else
let assign = indexedAssign(lhs, expPart, context, &preExp, &varDecls, &auxFunction)
Expand Down Expand Up @@ -7055,24 +7062,6 @@ template copyArrayData(DAE.Type ty, String exp, DAE.ComponentRef cr, Context con
'copy_<%type%>_data_mem(<%exp%>, &<%cref%>);'
end copyArrayData;

template copyArrayDataAndFreeMemAfterCall(DAE.Type ty, String exp, DAE.ComponentRef cr,

Context context)
::=
let type = expTypeArray(ty)
let cref = contextArrayCref(cr, context)
match context
case FUNCTION_CONTEXT(__) then
<<
<%if not acceptParModelicaGrammar() then 'copy_<%type%>_data(<%exp%>, &<%cref%>);'%>
<%if acceptParModelicaGrammar() then 'free_device_array(&<%cref%>); <%cref%> = <%exp%>;'%>
>>
case PARALLEL_FUNCTION_CONTEXT(__) then
'copy_<%type%>_data(<%exp%>, &<%cref%>);'
else
'/*that*/copy_<%type%>_data_mem(<%exp%>, &<%cref%>);'
end copyArrayDataAndFreeMemAfterCall;

template algStmtTupleAssign(DAE.Statement stmt, Context context, Text &varDecls, Text &auxFunction)
"Generates a tuple assigment algorithm statement."
::=
Expand Down

0 comments on commit c555854

Please sign in to comment.