Skip to content

Commit

Permalink
Help for dealing with bugs: #1365 #1364
Browse files Browse the repository at this point in the history
- code for sharing crefs (too slow for now so disabled) in ComponentReference.mo
- use Expression.makeASUB everywhere where DAE.ASUB is created so we can check if
  the given expression is a cref and give a warning if +d=checkASUB is on.
- function Expression.makeCrefExp will display a warning if +d=checkDAECrefType 
  is ON and we give a *different* type than the one already present in the cref.
- flags +d=checkASUB and +d=checkDAECrefType should be used with -trace to see
  where the functions that are buggy are actually called!
- fix warning in Compiler/susan_codegen/SimCode/SimCodeC.tpl for equations:
  enum = pre(enum) by casting: enum = (modelica_integer)pre(enum)
  previously it only added cast for ET_INT, now it handles also ET_ENUMERATION
- maybe we should create *ALL* expressions via functions so we can easily check 
  if the typing is OK!



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7251 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Nov 30, 2010
1 parent 1801082 commit d5045e7
Show file tree
Hide file tree
Showing 19 changed files with 2,482 additions and 2,287 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackendDAEOptimize.mo
Expand Up @@ -2482,7 +2482,7 @@ algorithm

case(DAE.STMT_FOR(type_=type_, iterIsArray=iterIsArray, iter=ident, range=exp, statementLst=statementLst, source=source)::restStatements, var, functions, inputVars, paramVars, stateVars, controlVars)
equation
cref = DAE.CREF_IDENT(ident, DAE.ET_INT(), {});
cref = ComponentReference.makeCrefIdent(ident, DAE.ET_INT(), {});
controlVar = BackendDAE.VAR(cref, BackendDAE.VARIABLE(), DAE.BIDIR(), BackendDAE.REAL(), NONE(), NONE(), {}, -1, DAE.emptyElementSource, NONE(), NONE(), DAE.FLOW(), DAE.STREAM());
controlVars = listAppend(controlVars, {controlVar});
derivedStatements1 = differentiateAlgorithmStatements(statementLst, var, functions, inputVars, paramVars, stateVars, controlVars);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackendDAEUtil.mo
Expand Up @@ -1309,7 +1309,7 @@ algorithm
then
// adrpo: TODO! FIXME! check if this is TYPE correct!
// shouldn't we change the type using the subs?
DAE.ASUB(e, subs);
Expression.makeASUB(e, subs);

case (DAE.ASUB(exp = DAE.MATRIX(scalar = (((DAE.CREF(componentRef = cr, ty = ty), _) :: _) :: _)), sub = subs))
equation
Expand All @@ -1318,7 +1318,7 @@ algorithm
then
// adrpo: TODO! FIXME! check if this is TYPE correct!
// shouldn't we change the type using the subs?
DAE.ASUB(e, subs);
Expression.makeASUB(e, subs);

case (_) then arrayVar;
end matchcontinue;
Expand Down
8 changes: 4 additions & 4 deletions Compiler/Ceval.mo
Expand Up @@ -4295,7 +4295,7 @@ algorithm
case (cache,env,s1,impl,st,matrixDimension,row,{},msg)
equation
s2 = DAE.ICONST(row);
(cache,Values.REAL(rv2),_) = ceval(cache,env, DAE.ASUB(s1,{s2}), impl, st,NONE(), msg);
(cache,Values.REAL(rv2),_) = ceval(cache,env, Expression.makeASUB(s1,{s2}), impl, st,NONE(), msg);
correctDim = matrixDimension - 1;
zeroList = Util.listFill(Values.REAL(0.0), correctDim);
correctPlace = row - 1;
Expand All @@ -4309,7 +4309,7 @@ algorithm
case (cache,env,s1,impl,st,matrixDimension,row,listIN,msg)
equation
s2 = DAE.ICONST(row);
(cache,Values.REAL(rv2),_) = ceval(cache,env, DAE.ASUB(s1,{s2}), impl, st,NONE(), msg);
(cache,Values.REAL(rv2),_) = ceval(cache,env, Expression.makeASUB(s1,{s2}), impl, st,NONE(), msg);

false = intEq(matrixDimension, row);

Expand All @@ -4327,7 +4327,7 @@ algorithm
case (cache,env,s1,impl,st,matrixDimension,row,{},msg)
equation
s2 = DAE.ICONST(row);
(cache,Values.INTEGER(iv2),_) = ceval(cache,env, DAE.ASUB(s1,{s2}), impl, st,NONE(), msg);
(cache,Values.INTEGER(iv2),_) = ceval(cache,env, Expression.makeASUB(s1,{s2}), impl, st,NONE(), msg);
correctDim = matrixDimension - 1;
zeroList = Util.listFill(Values.INTEGER(0), correctDim);
correctPlace = row - 1;
Expand All @@ -4341,7 +4341,7 @@ algorithm
case (cache,env,s1,impl,st,matrixDimension,row,listIN,msg)
equation
s2 = DAE.ICONST(row);
(cache,Values.INTEGER(iv2),_) = ceval(cache,env, DAE.ASUB(s1,{s2}), impl, st,NONE(), msg);
(cache,Values.INTEGER(iv2),_) = ceval(cache,env, Expression.makeASUB(s1,{s2}), impl, st,NONE(), msg);

false = intEq(matrixDimension, row);

Expand Down
111 changes: 105 additions & 6 deletions Compiler/ComponentReference.mo
Expand Up @@ -58,18 +58,113 @@ protected import Util;
// do not make this public. instead use the function below.
protected constant DAE.ComponentRef dummyCref = DAE.CREF_IDENT("dummy", DAE.ET_OTHER(), {});

public function makeDummyCref
// global root index for cref memory
public
constant Integer crefMemoryIndex = 2;

public function createEmptyCrefMemory
"@author: adrpo
This function creates a dummy component reference"
output DAE.ComponentRef outCrefIdent;
creates an array, with one element for each record in DAE.ComponentRef!"
output array<list<DAE.ComponentRef>> crefMemory;
algorithm
outCrefIdent := dummyCref;
end makeDummyCref;
crefMemory := arrayCreate(3, {});
end createEmptyCrefMemory;

protected function searchInMememoryLst
"@author: adrpo
This function searches in memory for already existing DAE.ComponentRef"
input DAE.ComponentRef inCref;
input list<DAE.ComponentRef> inMem;
output DAE.ComponentRef outCref;
algorithm
outCref := matchcontinue (inCref, inMem)
local
list<DAE.ComponentRef> rest;
DAE.ComponentRef cref;

// fail if we couldn't find it
case (inCref, {}) then fail();

// see if we have it in memory, return the already existing!
case (inCref, cref::rest)
equation
equality(inCref = cref);
then
cref;

// try the next
case (inCref, cref::rest)
equation
failure(equality(inCref = cref));
cref = searchInMememoryLst(inCref, rest);
then
cref;
end matchcontinue;
end searchInMememoryLst;

protected function shareCref
"@author: adrpo
searches in the global cache for the given cref and if
there is one, returns that pointer, otherwise adds it"
input DAE.ComponentRef inCref;
output DAE.ComponentRef outCref;
algorithm
outCref := matchcontinue (inCref)
local
array<list<DAE.ComponentRef>> crefMem;
list<DAE.ComponentRef> crefLst;
DAE.ComponentRef cref;
Integer indexBasedOnValueConstructor;

// see if we have it in memory
case (inCref) then inCref;

// see if we have it in memory
case (inCref)
equation
// oh the horror. if you don't understand this, contact adrpo
// get from global roots
crefMem = getGlobalRoot(crefMemoryIndex);
// select a list based on the constructor of DAE.ComponentRef value
indexBasedOnValueConstructor = valueConstructor(inCref);
crefLst = arrayGet(crefMem, indexBasedOnValueConstructor + 1);
// search in the list for already existing one
cref = searchInMememoryLst(inCref, crefLst);

// print("Lst: " +& intString(listLength(crefLst)) +&
// " Shared: " +& printComponentRefStr(cref) +& "\n");
then
cref;

// we didn't find it, add it
case (inCref)
equation
// oh the horror. if you don't understand this, contact adrpo
// get from global roots
crefMem = getGlobalRoot(crefMemoryIndex);
// select a list based on the constructor of DAE.ComponentRef value
indexBasedOnValueConstructor = valueConstructor(inCref);
crefLst = arrayGet(crefMem, indexBasedOnValueConstructor + 1);
// add the translation to the list and set the array
crefMem = arrayUpdate(crefMem, indexBasedOnValueConstructor + 1, inCref::crefLst);
// set the global cache with the new value
setGlobalRoot(crefMemoryIndex, crefMem);
then
inCref;
end matchcontinue;
end shareCref;

/***************************************************/
/* generate a ComponentRef */
/***************************************************/

public function makeDummyCref
"@author: adrpo
This function creates a dummy component reference"
output DAE.ComponentRef outCrefIdent;
algorithm
outCrefIdent := dummyCref; // shareCref(dummyCref);
end makeDummyCref;

public function makeCrefIdent
"@author: adrpo
Expand All @@ -79,7 +174,7 @@ public function makeCrefIdent
input list<DAE.Subscript> subscriptLst;
output DAE.ComponentRef outCrefIdent;
algorithm
outCrefIdent := DAE.CREF_IDENT(ident, identType, subscriptLst);
outCrefIdent := DAE.CREF_IDENT(ident, identType, subscriptLst); // shareCref(DAE.CREF_IDENT(ident, identType, subscriptLst));
end makeCrefIdent;

public function makeCrefQual
Expand All @@ -90,7 +185,11 @@ public function makeCrefQual
input list<DAE.Subscript> subscriptLst;
input DAE.ComponentRef componentRef;
output DAE.ComponentRef outCrefQual;
protected
DAE.ComponentRef subCref;
algorithm
// subCref := shareCref(componentRef);
// outCrefQual := shareCref(DAE.CREF_QUAL(ident, identType, subscriptLst, subCref));
outCrefQual := DAE.CREF_QUAL(ident, identType, subscriptLst, componentRef);
end makeCrefQual;

Expand Down
4 changes: 2 additions & 2 deletions Compiler/DAE.mo
Expand Up @@ -1345,8 +1345,8 @@ end Operator;
public
uniontype ComponentRef "- Component references
CREF_QUAL(...) is used for qualified component names, e.g. a.b.c
CREF_IDENT(..) is used for non-qualifed component names, e.g. x
"
CREF_IDENT(..) is used for non-qualifed component names, e.g. x"
record CREF_QUAL
Ident ident;
ExpType identType "type of the identifier, without considering the subscripts";
Expand Down
2 changes: 1 addition & 1 deletion Compiler/DAEUtil.mo
Expand Up @@ -2049,7 +2049,7 @@ algorithm
equation
e_1 = toModelicaFormExp(e);
then
DAE.ASUB(e_1,expl);
Expression.makeASUB(e_1,expl);
case (DAE.SIZE(exp = e,sz = eopt))
equation
e_1 = toModelicaFormExp(e);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Derive.mo
Expand Up @@ -699,7 +699,7 @@ algorithm
equation
e_1 = differentiateExpTime(e, (timevars,functions));
then
DAE.ASUB(e,sub);
Expression.makeASUB(e,sub);

case (DAE.REDUCTION(path = a,expr = e1,ident = str,range = e2),(timevars,functions))
equation
Expand Down Expand Up @@ -1561,7 +1561,7 @@ algorithm
equation
e_1 = differentiateExp(e, tv, differentiateIfExp);
then
DAE.ASUB(e,sub);
Expression.makeASUB(e,sub);

case (DAE.REDUCTION(path = a,expr = e1,ident = str,range = e2),tv,differentiateIfExp)
equation
Expand Down

0 comments on commit d5045e7

Please sign in to comment.