Skip to content

Commit

Permalink
- Fixed some code generation issues for subscripted crefs in tuples.
Browse files Browse the repository at this point in the history
- Code cleanup.
- Updated and enabled some MetaModelica tests which had started to work.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23319 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Nov 11, 2014
1 parent 6c836e6 commit 5cce585
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 113 deletions.
5 changes: 2 additions & 3 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -1801,13 +1801,12 @@ public function markZeroCrossingEquations "function: markStateEquations
protected
list<Integer> varindx_lst,eqns;
BackendDAE.IncidenceMatrix m;
BackendDAE.Variables v,v2;
BackendDAE.Variables v;
list<BackendDAE.Var> varlst;
algorithm
BackendDAE.EQSYSTEM(orderedVars = v,m=SOME(m)) := syst;
(_, (_, varlst)) := traverseZeroCrossingExps(inZeroCross, varsCollector, (v,{}), {});
v2 := BackendVariable.listVar(varlst);
varindx_lst := BackendVariable.getVarIndexFromVariables(v2, v);
varindx_lst := BackendVariable.getVarIndexFromVars(varlst, v);
eqns := List.map1r(varindx_lst,arrayGet,ass1);
eqns := List.select(eqns, Util.intPositive);
outIntegerArray := markStateEquationsWork(eqns,{},m,ass1,arr);
Expand Down
82 changes: 31 additions & 51 deletions Compiler/BackEnd/BackendInline.mo
Expand Up @@ -87,41 +87,29 @@ public function inlineCalls
input BackendDAE.BackendDAE inBackendDAE;
output BackendDAE.BackendDAE outBackendDAE;
algorithm
outBackendDAE := matchcontinue(inITLst,inBackendDAE)
outBackendDAE := matchcontinue(inBackendDAE)
local
list<DAE.InlineType> itlst;
BackendDAE.Variables knownVars;
BackendDAE.Variables externalObjects,aliasVars "alias-variables' hashtable";
BackendDAE.EquationArray removedEqs;
BackendDAE.EquationArray initialEqs;
list<DAE.Constraint> constrs;
list<DAE.ClassAttributes> clsAttrs;
BackendDAE.EventInfo eventInfo;
BackendDAE.ExternalObjectClasses extObjClasses;
Inline.Functiontuple tpl;
BackendDAE.EqSystems eqs;
BackendDAE.BackendDAEType btp;
BackendDAE.SymbolicJacobians symjacs;
DAE.FunctionTree functionTree;
FCore.Cache cache;
FCore.Graph graph;
BackendDAE.ExtraInfo ei;

case (itlst,BackendDAE.DAE(eqs,BackendDAE.SHARED(knownVars=knownVars,externalObjects=externalObjects,aliasVars=aliasVars,initialEqs=initialEqs,removedEqs=removedEqs,constraints=constrs,classAttrs=clsAttrs,cache=cache,graph=graph,functionTree=functionTree,eventInfo=eventInfo,extObjClasses=extObjClasses,backendDAEType=btp,symjacs=symjacs,info=ei)))
equation
tpl = (SOME(functionTree),itlst);
eqs = List.map1(eqs,inlineEquationSystem,tpl);
(knownVars,_) = inlineVariables(knownVars,tpl);
(externalObjects,_) = inlineVariables(externalObjects,tpl);
(initialEqs,_) = inlineEquationArray(initialEqs,tpl);
(removedEqs,_) = inlineEquationArray(removedEqs,tpl);
eventInfo = inlineEventInfo(eventInfo,tpl);
BackendDAE.Shared shared;

case BackendDAE.DAE(eqs, shared as BackendDAE.SHARED())
algorithm
tpl := (SOME(shared.functionTree), inITLst);
eqs := List.map1(eqs, inlineEquationSystem, tpl);
shared.knownVars := inlineVariables(shared.knownVars, tpl);
shared.externalObjects := inlineVariables(shared.externalObjects, tpl);
shared.initialEqs := inlineEquationArray(shared.initialEqs, tpl);
shared.removedEqs := inlineEquationArray(shared.removedEqs, tpl);
shared.eventInfo := inlineEventInfo(shared.eventInfo, tpl);
then
BackendDAE.DAE(eqs,BackendDAE.SHARED(knownVars,externalObjects,aliasVars,initialEqs,removedEqs,constrs,clsAttrs,cache,graph,functionTree,eventInfo,extObjClasses,btp,symjacs,ei));
BackendDAE.DAE(eqs, shared);

else
equation
true = Flags.isSet(Flags.FAILTRACE);
Debug.trace("Inline.inlineCalls failed\n");
algorithm
true := Flags.isSet(Flags.FAILTRACE);
Debug.traceln("Inline.inlineCalls failed");
then
fail();
end matchcontinue;
Expand All @@ -141,6 +129,7 @@ algorithm
Boolean b1,b2;
BackendDAE.StateSets stateSets;
BackendDAE.BaseClockPartitionKind partitionKind;

case (syst as BackendDAE.EQSYSTEM(orderedVars=orderedVars,orderedEqs=orderedEqs,matching=matching,stateSets=stateSets,partitionKind=partitionKind),_)
equation
(orderedVars,b1) = inlineVariables(orderedVars,tpl);
Expand All @@ -166,7 +155,7 @@ algorithm
array<Option<BackendDAE.Equation>> eqarr;
case(BackendDAE.EQUATION_ARRAY(size,i1,i2,eqarr),fns)
equation
oInlined = inlineEquationOptArray(1,eqarr,i2,fns,false);
oInlined = inlineEquationOptArray(eqarr,i2,fns);
then
(BackendDAE.EQUATION_ARRAY(size,i1,i2,eqarr),oInlined);
else
Expand All @@ -181,31 +170,22 @@ end inlineEquationArray;
protected function inlineEquationOptArray
"functio: inlineEquationrOptArray
inlines calls in a equation option"
input Integer Index;
input array<Option<BackendDAE.Equation>> inEqnArray;
input Integer arraysize;
input Inline.Functiontuple fns;
input Boolean iInlined;
output Boolean oInlined;
output Boolean oInlined := false;
protected
Option<BackendDAE.Equation> eqn;
Boolean inlined;
algorithm
oInlined := matchcontinue(Index,inEqnArray,arraysize,fns,iInlined)
local
Option<BackendDAE.Equation> eqn;
Boolean b;
case(_,_,_,_,_)
equation
true = intLe(Index,arraysize);
eqn = inEqnArray[Index];
(eqn,b) = inlineEqOpt(eqn,fns);
updateArrayCond(b,inEqnArray,Index,eqn);
then
inlineEquationOptArray(Index+1,inEqnArray,arraysize,fns,b or iInlined);
else
equation
false = intLe(Index,arraysize);
then
iInlined;
end matchcontinue;
for i in 1:arraysize loop
(eqn, inlined) := inlineEqOpt(inEqnArray[i], fns);

if inlined then
arrayUpdate(inEqnArray, i, eqn);
oInlined := true;
end if;
end for;
end inlineEquationOptArray;

protected function inlineEqOpt "
Expand Down
77 changes: 25 additions & 52 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -3181,70 +3181,43 @@ algorithm
outMatch := ComponentReference.crefEqualNoStringCompare(cr, inCref);
end crefIndexEqualCref;

public function getVarIndexFromVariables
public function getVarIndexFromVars
input list<BackendDAE.Var> inVars;
input BackendDAE.Variables inVariables;
input BackendDAE.Variables inVariables2;
output list<Integer> v_lst;
algorithm
((_,v_lst)) := traverseBackendDAEVars(inVariables,traversingisVarIndexVarFinder,(inVariables2,{}));
end getVarIndexFromVariables;

protected function traversingisVarIndexVarFinder
"author: Frenkel TUD 2010-11"
input BackendDAE.Var inVar;
input tuple<BackendDAE.Variables, list<Integer>> inTpl;
output BackendDAE.Var outVar;
output tuple<BackendDAE.Variables, list<Integer>> outTpl;
output list<Integer> outIndices := {};
algorithm
(outVar,outTpl) := matchcontinue (inVar,inTpl)
local
BackendDAE.Var v;
BackendDAE.Variables vars;
list<Integer> v_lst;
DAE.ComponentRef cr;
list<Integer> indxlst;
case (v,(vars,v_lst))
equation
cr = varCref(v);
(_,indxlst) = getVar(cr, vars);
v_lst = listAppend(v_lst,indxlst);
then (v,(vars,v_lst));
else (inVar,inTpl);
end matchcontinue;
end traversingisVarIndexVarFinder;

for var in inVars loop
(_, outIndices) := traversingVarIndexFinder(var, inVariables, outIndices);
end for;
end getVarIndexFromVars;

public function getVarIndexFromVar
public function getVarIndexFromVariables
input BackendDAE.Variables inVariables;
input BackendDAE.Variables inVariables2;
output list<Integer> v_lst;
algorithm
((_, v_lst)) := traverseBackendDAEVars(inVariables, traversingVarIndexFinder, (inVariables2, {}));
end getVarIndexFromVar;
v_lst := traverseBackendDAEVars(inVariables,
function traversingVarIndexFinder(inVars = inVariables2), {});
end getVarIndexFromVariables;

protected function traversingVarIndexFinder
"author: Frenkel TUD 2010-11"
input BackendDAE.Var inVar;
input tuple<BackendDAE.Variables, list<Integer>> inTpl;
output BackendDAE.Var outVar;
output tuple<BackendDAE.Variables, list<Integer>> outTpl;
input BackendDAE.Variables inVars;
input list<Integer> inIndices;
output BackendDAE.Var outVar := inVar;
output list<Integer> outIndices;
protected
DAE.ComponentRef cr;
list<Integer> indices;
algorithm
(outVar,outTpl) := matchcontinue (inVar,inTpl)
local
BackendDAE.Var v;
list<BackendDAE.Var> vlst;
BackendDAE.Variables vars;
list<Integer> v_lst;
DAE.ComponentRef cr;
list<Integer> indxlst;
case (v,(vars,v_lst))
equation
cr = varCref(v);
(_,indxlst) = getVar(cr, vars);
v_lst = listAppend(v_lst,indxlst);
then (v,(vars,v_lst));
else (inVar,inTpl);
end matchcontinue;
try
cr := varCref(inVar);
(_, indices) := getVar(cr, inVars);
outIndices := listAppend(inIndices, indices);
else
outIndices := inIndices;
end try;
end traversingVarIndexFinder;

public function mergeVariables
Expand Down
5 changes: 2 additions & 3 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -1196,7 +1196,7 @@ protected function fixInitialSystem "author: lochel
output list<BackendDAE.Var> outDumpVars;
output list<BackendDAE.Equation> outRemovedEqns;
protected
Integer nVars, nEqns, nInitEqs, nInitVars, nAddEqs, nAddVars;
Integer nVars, nEqns, nInitEqs, nAddEqs, nAddVars;
list<Integer> stateIndices, range, unassigned, initEqsIndices, redundantEqns;
list<BackendDAE.Var> initVarList;
array<Integer> vec1, vec2;
Expand All @@ -1218,8 +1218,7 @@ algorithm
//BackendDump.dumpIncidenceMatrix(m_);

// get state-index list
stateIndices := BackendVariable.getVarIndexFromVar(inInitVars, inVars);
nInitVars := listLength(stateIndices);
stateIndices := BackendVariable.getVarIndexFromVariables(inInitVars, inVars);
//print("{" + stringDelimitList(List.map(stateIndices, intString),",") + "}\n");

// get initial equation-index list
Expand Down
5 changes: 2 additions & 3 deletions Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -675,7 +675,7 @@ algorithm
list<Integer> nodesList, nodesEqnsIndex;
list<list<Integer>> sparsepattern,sparsepatternT, coloredlist;
list<BackendDAE.Var> jacDiffVars, indiffVars, indiffedVars;
BackendDAE.Variables diffedVars, varswithDiffs;
BackendDAE.Variables varswithDiffs;
BackendDAE.EquationArray orderedEqns;
array<Option<list<Integer>>> forbiddenColor;
array<Integer> colored, colored1, ass1, ass2;
Expand Down Expand Up @@ -720,8 +720,7 @@ algorithm
end if;

// get indexes of diffed vars (rows)
diffedVars = BackendVariable.listVar1(indiffedVars);
nodesEqnsIndex = BackendVariable.getVarIndexFromVariables(diffedVars,varswithDiffs);
nodesEqnsIndex = BackendVariable.getVarIndexFromVars(indiffedVars,varswithDiffs);
nodesEqnsIndex = List.map1(nodesEqnsIndex, Array.getIndexFirst, ass1);

// debug dump
Expand Down
4 changes: 3 additions & 1 deletion Compiler/Template/CodegenC.tpl
Expand Up @@ -4853,7 +4853,9 @@ template contextArrayReferenceCrefAndCopy(ComponentRef cr, Exp e, Type ty, Conte
let &varCopy += if lhs then '<%lhs%><%\n%>' else error(sourceInfo(), 'Got empty statement from writeLhsCref(<%printExpStr(e)%>)')
let &varCopy += varCopyAfter
var
else contextCref(cr,context,&auxFunction)
else
let &preExp = buffer ""
scalarLhsCref(e, context, &preExp, &varDecls, &auxFunction)
end contextArrayReferenceCrefAndCopy;

template contextArrayCref(ComponentRef cr, Context context)
Expand Down

0 comments on commit 5cce585

Please sign in to comment.