Skip to content

Commit

Permalink
[NF] Translate more binary vector operations to DAE
Browse files Browse the repository at this point in the history
There are still some operators in there that I do not know if they work
properly. They now give internal errors and continue translation so we
can check which models are affected easier.

Belonging to [master]:
  - OpenModelica/OMCompiler#2350
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 10, 2018
1 parent e84261d commit 5e99e61
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
9 changes: 8 additions & 1 deletion Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -921,6 +921,9 @@ public
dexp := match exp
local
Type ty;
DAE.Operator daeOp;
Boolean swap;
DAE.Exp dae1, dae2;

case INTEGER() then DAE.ICONST(exp.value);
case REAL() then DAE.RCONST(exp.value);
Expand Down Expand Up @@ -963,7 +966,11 @@ public
// END() doesn't have a DAE representation.

case BINARY()
then DAE.BINARY(toDAE(exp.exp1), Operator.toDAE(exp.operator), toDAE(exp.exp2));
algorithm
(daeOp, swap) := Operator.toDAE(exp.operator);
dae1 := toDAE(exp.exp1);
dae2 := toDAE(exp.exp2);
then DAE.BINARY(if swap then dae2 else dae1, daeOp, if swap then dae1 else dae2);

case UNARY()
then DAE.UNARY(Operator.toDAE(exp.operator), toDAE(exp.exp));
Expand Down
21 changes: 11 additions & 10 deletions Compiler/NFFrontEnd/NFOperator.mo
Expand Up @@ -139,6 +139,7 @@ public
function toDAE
input Operator op;
output DAE.Operator daeOp;
output Boolean swapArguments=false "The DAE structure only has array*scalar, not scalar*array, etc";
protected
DAE.Type ty;
algorithm
Expand All @@ -150,18 +151,18 @@ public
case Op.MUL then DAE.MUL(ty);
case Op.DIV then DAE.DIV(ty);
case Op.POW then DAE.POW(ty);
case Op.ADD_SCALAR_ARRAY then DAE.ADD(ty);
case Op.ADD_ARRAY_SCALAR then DAE.ADD(ty);
case Op.SUB_SCALAR_ARRAY then DAE.SUB(ty);
case Op.SUB_ARRAY_SCALAR then DAE.SUB(ty);
case Op.MUL_SCALAR_ARRAY then DAE.MUL(ty);
case Op.MUL_ARRAY_SCALAR then DAE.MUL(ty);
case Op.MUL_VECTOR_MATRIX then DAE.MUL(ty);
case Op.MUL_MATRIX_VECTOR then DAE.MUL(ty);
case Op.ADD_SCALAR_ARRAY algorithm swapArguments := true; then DAE.ADD_ARRAY_SCALAR(ty);
case Op.ADD_ARRAY_SCALAR then DAE.ADD_ARRAY_SCALAR(ty);
case Op.SUB_SCALAR_ARRAY then DAE.SUB_SCALAR_ARRAY(ty);
case Op.SUB_ARRAY_SCALAR algorithm Error.addInternalError(getInstanceName() + ": Don't know how to handle " + String(op.op), sourceInfo()); then DAE.SUB(ty);
case Op.MUL_SCALAR_ARRAY algorithm swapArguments := true; then DAE.MUL_ARRAY_SCALAR(ty);
case Op.MUL_ARRAY_SCALAR then DAE.MUL_ARRAY_SCALAR(ty);
case Op.MUL_VECTOR_MATRIX algorithm Error.addInternalError(getInstanceName() + ": Don't know how to handle " + String(op.op), sourceInfo()); then DAE.MUL(ty);
case Op.MUL_MATRIX_VECTOR algorithm Error.addInternalError(getInstanceName() + ": Don't know how to handle " + String(op.op), sourceInfo()); then DAE.MUL(ty);
case Op.SCALAR_PRODUCT then DAE.MUL_SCALAR_PRODUCT(ty);
case Op.MATRIX_PRODUCT then DAE.MUL_MATRIX_PRODUCT(ty);
case Op.DIV_SCALAR_ARRAY then DAE.DIV(ty);
case Op.DIV_ARRAY_SCALAR then DAE.DIV(ty);
case Op.DIV_SCALAR_ARRAY then DAE.DIV_SCALAR_ARRAY(ty);
case Op.DIV_ARRAY_SCALAR then DAE.DIV_ARRAY_SCALAR(ty);
case Op.POW_SCALAR_ARRAY then DAE.POW_SCALAR_ARRAY(ty);
case Op.POW_ARRAY_SCALAR then DAE.POW_ARRAY_SCALAR(ty);
case Op.POW_MATRIX then DAE.POW_ARR(ty);
Expand Down

0 comments on commit 5e99e61

Please sign in to comment.