Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Implement missing case for SUB_SCALAR_ARRAY
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored and OpenModelica-Hudson committed Apr 6, 2017
1 parent 5124b80 commit 9b4cb3b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Compiler/Template/CodegenCFunctions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5014,7 +5014,11 @@ case BINARY(__) then
case T_ARRAY(ty=T_ENUMERATION(__)) then "integer_array"
else "real_array"
'add_alloc_scalar_<%type%>(<% if isArrayType(typeof(exp1)) then '<%e2%>, &<%e1%>' else '<%e1%>, &<%e2%>' %>)'
case SUB_SCALAR_ARRAY(__) then error(sourceInfo(),'Code generation does not support SUB_SCALAR_ARRAY <%ExpressionDumpTpl.dumpExp(exp,"\"")%>')
case SUB_SCALAR_ARRAY(__) then
let type = match ty case T_ARRAY(ty=T_INTEGER(__)) then "integer_array"
case T_ARRAY(ty=T_ENUMERATION(__)) then "integer_array"
else "real_array"
'sub_alloc_scalar_<%type%>(<% if isArrayType(typeof(exp1)) then '<%e2%>, &<%e1%>' else '<%e1%>, &<%e2%>' %>)'
case MUL_SCALAR_PRODUCT(__) then
let type = match ty case T_ARRAY(ty=T_INTEGER(__)) then "integer_scalar"
case T_ARRAY(ty=T_ENUMERATION(__)) then "integer_scalar"
Expand Down
13 changes: 13 additions & 0 deletions SimulationRuntime/c/util/real_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,19 @@ real_array_t add_alloc_scalar_real_array(modelica_real sc, const real_array_t *a
return dest;
}

real_array_t sub_alloc_scalar_real_array(modelica_real sc, const real_array_t *arr)
{
size_t nr_of_elements, i;
real_array_t dest;
clone_real_array_spec(arr, &dest);
alloc_real_array_data(&dest);
nr_of_elements = base_array_nr_of_elements(*arr);
for(i=0; i < nr_of_elements; ++i) {
real_set(&dest, i, sc - real_get(*arr, i));
}
return dest;
}

void usub_real_array(real_array_t* a)
{
size_t nr_of_elements, i;
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/util/real_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ extern void range_real_array(modelica_real start,modelica_real stop, modelica_re
extern real_array_t add_alloc_real_array(const real_array_t a, const real_array_t b);
extern void add_real_array(const real_array_t * a, const real_array_t * b, real_array_t* dest);
extern real_array_t add_alloc_scalar_real_array(const modelica_real sc, const real_array_t *arr);
extern real_array_t sub_alloc_scalar_real_array(const modelica_real sc, const real_array_t *arr);

/* Unary subtraction */
extern void usub_real_array(real_array_t* a);
Expand Down

0 comments on commit 9b4cb3b

Please sign in to comment.