Skip to content

Commit

Permalink
Handle preExp and varDecls for crefs with subs. (OpenModelica#923)
Browse files Browse the repository at this point in the history
* Handle preExp and varDecls for crefs with subs.

  - We used to throw away any extra expressions and variable declarations
    needed for it, i.e., if it has some complicated subscript that can not
    be generated inline.

  - If you are sure you have a path (a cref with no subs) then you can use
    contextCrefNoPrevExp (e.g variable names are just paths. They are just
    represented as cref). Otherwise contextCref now needs a preEx and varDecls
    buffer passed to it.

* Fix wrong ordering of buffer arguments.

* Avoid unnecessary code generation.

  - This fixes ticket:5994.

  - The path we took for crefs with subscripts in function context
    used to create unnecessary temporaries and exps which we did
    not notice because they were were thrown away after being created.

  - Split up the function to take different paths for normal and parallel
    functions.

* Add a test case for Ticket:5994.
  • Loading branch information
mahge authored and adrpo committed Sep 28, 2020
1 parent a749b62 commit 7d8bd2d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion OMCompiler/Compiler/Template/CodegenCFunctions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,27 @@ template recordModelicaCallConstrctor(String rec_name, list<Variable> variables)
}
*/
>>
end recordModelicaCallConstrctor;
end recordCopyFromVarsDef;

template recordCopyToVarsDef(String rec_name, list<Variable> variables)
"Generates structs for a record declaration."
::=
let &varCopies = buffer ""
let &auxFunction = buffer ""
let dst_pref = ' *in'
let src_pref = 'src->'
let _ = (variables |> var => recordMemberCopy(var, src_pref, dst_pref, &varCopies, &auxFunction) ;separator="\n")
let inputs = (variables |> var as VARIABLE(__) =>
(", " + varType(var) + " " + dst_pref + contextCrefNoPrevExp(var.name, contextFunction, &auxFunction))
)

<<
void <%rec_name%>_copy_to_vars_p(void* v_src <%inputs%>) {
<%rec_name%>* src = (<%rec_name%>*)(v_src);
<%varCopies%>
}
>>
end recordCopyToVarsDef;

template recordMemberCopy(Variable var, String src_pref, String dst_pref, Text &varCopies, Text &auxFunction)
"Generates code for copying memembers of a record during a record copy operation.
Expand Down

0 comments on commit 7d8bd2d

Please sign in to comment.