Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Handles some more things when dimension sizes are expressions.
  * One thing we now handle is matrix multiplication where dimensions are expressions.
  * We also make size(a,2) return the known size of size(a,2), which might be size(a,1). Might help with some matrix stuff in MSL that uses this idiom to tell the compiler the input is a square matrix.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15694 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Mar 28, 2013
1 parent d0c69bb commit 6472b18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Compiler/FrontEnd/Expression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,18 @@ algorithm
end liftArrayR;

public function dimensionSizeExp
"Converts a dimension to an integer expression."
"Converts a dimension to an expression."
input DAE.Dimension dim;
output DAE.Exp exp;
algorithm
exp := match(dim)
local
Integer i;
DAE.Exp e;

case DAE.DIM_INTEGER(integer = i) then DAE.ICONST(i);
case DAE.DIM_ENUM(size = i) then DAE.ICONST(i);
case DAE.DIM_EXP(exp = e) then e;
end match;
end dimensionSizeExp;

Expand Down Expand Up @@ -8285,7 +8287,7 @@ public function dimensionsKnownAndEqual
input DAE.Dimension dim2;
output Boolean res;
algorithm
res := intEq(dimensionSize(dim1), dimensionSize(dim2));
res := expEqual(dimensionSizeExp(dim1), dimensionSizeExp(dim2));
end dimensionsKnownAndEqual;

public function dimensionKnown
Expand Down
3 changes: 1 addition & 2 deletions Compiler/Template/CodegenC.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7750,8 +7750,7 @@ template daeExpSize(Exp exp, Context context, Text &preExp /*BUFP*/,
let expPart = daeExp(exp, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
let dimPart = daeExp(dim, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
let resVar = tempDecl("modelica_integer", &varDecls /*BUFD*/)
let typeStr = '<%expTypeArray(exp.ty)%>'
let &preExp += '<%resVar%> = size_of_dimension_<%typeStr%>(<%expPart%>, <%dimPart%>);<%\n%>'
let &preExp += '<%resVar%> = size_of_dimension_base_array(<%expPart%>, <%dimPart%>);<%\n%>'
resVar
case SIZE(exp=CREF(__)) then
let expPart = daeExp(exp, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
Expand Down

0 comments on commit 6472b18

Please sign in to comment.