Skip to content

Commit

Permalink
- remove alias variables: merge var direction
Browse files Browse the repository at this point in the history
- BackendVariable.mo add functions etVarDirection, used for merge var direction

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8286 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Mar 17, 2011
1 parent b4b62eb commit a8484fb
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
34 changes: 31 additions & 3 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -1000,9 +1000,9 @@ algorithm
matchcontinue (inAVar,inCref,inVars,negate)
local
DAE.ComponentRef name,cr;
BackendDAE.Var v,var,var1,var2,var3;
BackendDAE.Var v,var,var1,var2,var3,var4;
BackendDAE.Variables vars;
Boolean fixeda, fixedb,starta,startb;
Boolean fixeda, fixedb;
case (v as BackendDAE.VAR(varName=name),cr,inVars,negate)
equation
((var :: _),_) = BackendVariable.getVar(cr,inVars);
Expand All @@ -1014,8 +1014,10 @@ algorithm
var2 = mergeStartAttribute(v,var1,negate);
// nominal
var3 = mergeNomnialAttribute(v,var2,negate);
// direction
var4 = mergeDirection(v,var3);
// update vars
vars = BackendVariable.addVar(var3,inVars);
vars = BackendVariable.addVar(var4,inVars);
then vars;
case(_,_,inVars,negate) then inVars;
end matchcontinue;
Expand Down Expand Up @@ -1097,6 +1099,32 @@ algorithm
end matchcontinue;
end mergeNomnialAttribute;

protected function mergeDirection
input BackendDAE.Var inAVar;
input BackendDAE.Var inVar;
output BackendDAE.Var outVar;
algorithm
outVar :=
matchcontinue (inAVar,inVar)
local
BackendDAE.Var v,var,var1;
Option<DAE.VariableAttributes> attr,attr1;
DAE.Exp e,e1;
case (v as BackendDAE.VAR(varDirection = DAE.INPUT()),var as BackendDAE.VAR(varDirection = DAE.OUTPUT()))
equation
var1 = BackendVariable.setVarDirection(var,DAE.INPUT());
then var1;
case (v as BackendDAE.VAR(varDirection = DAE.INPUT()),var as BackendDAE.VAR(varDirection = DAE.BIDIR()))
equation
var1 = BackendVariable.setVarDirection(var,DAE.INPUT());
then var1;
case (v as BackendDAE.VAR(varDirection = DAE.OUTPUT()),var as BackendDAE.VAR(varDirection = DAE.BIDIR()))
equation
var1 = BackendVariable.setVarDirection(var,DAE.OUTPUT());
then var1;
case(_,inVar) then inVar;
end matchcontinue;
end mergeDirection;

/*
* remove parameter equations
Expand Down
39 changes: 39 additions & 0 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -1151,6 +1151,45 @@ algorithm
end match;
end setBindValue;

public function setVarDirection
"function setVarDirection
author: Frenkel TUD 17-03-11
Sets the DAE.VarDirection of a variable"
input BackendDAE.Var inVar;
input DAE.VarDirection varDirection;
output BackendDAE.Var outVar;
algorithm
outVar := match (inVar,varDirection)
local
DAE.ComponentRef cr;
BackendDAE.VarKind kind;
BackendDAE.Type tp;
Option<DAE.Exp> bind;
Option<Values.Value> v;
list<DAE.Subscript> dim;
BackendDAE.Value i;
DAE.ElementSource source;
Option<DAE.VariableAttributes> attr;
Option<SCode.Comment> comment;
DAE.Flow flowPrefix;
DAE.Stream streamPrefix;

case (BackendDAE.VAR(varName = cr,
varKind = kind,
varType = tp,
bindExp = bind,
bindValue = v,
arryDim = dim,
index = i,
source = source,
values = attr,
comment = comment,
flowPrefix = flowPrefix,
streamPrefix = streamPrefix),varDirection)
then BackendDAE.VAR(cr,kind,varDirection,tp,bind,v,dim,i,source,attr,comment,flowPrefix,streamPrefix);
end match;
end setVarDirection;

public function isVarOnTopLevelAndOutput
"function isVarOnTopLevelAndOutput
this function checks if the provided cr is from a var that is on top model
Expand Down

0 comments on commit a8484fb

Please sign in to comment.