Skip to content

Commit

Permalink
Abstract naming of previous variables
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke committed Oct 10, 2015
1 parent 794b444 commit 5dfc9cd
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -2177,12 +2177,12 @@ algorithm
true = BackendVariable.varFixed(var);
isInput = BackendVariable.isVarOnTopLevelAndInput(var);
startValue_ = BackendVariable.varStartValue(var);
preUsed = BaseHashSet.has(cr, hs);
previousUsed = BaseHashSet.has(cr, clkHS);
preUsed = BaseHashSet.has(cr, hs) or previousUsed;

var = BackendVariable.setVarFixed(var, false);

preCR = if previousUsed then ComponentReference.crefPrefixString("$CLKPRE", cr) else ComponentReference.crefPrefixPre(cr); // cr => $PRE.cr
preCR = if previousUsed then ComponentReference.crefPrefixPrevious(cr) else ComponentReference.crefPrefixPre(cr); // cr => $PRE.cr
preVar = BackendVariable.copyVarNewName(preCR, var);
preVar = BackendVariable.setVarDirection(preVar, DAE.BIDIR());
preVar = BackendVariable.setBindExp(preVar, NONE());
Expand All @@ -2198,7 +2198,7 @@ algorithm

vars = if not isInput then BackendVariable.addVar(var, vars) else vars;
fixvars = if isInput then BackendVariable.addVar(var, fixvars) else fixvars;
vars = if preUsed then BackendVariable.addVar(preVar, vars) else vars;
vars = if preUsed or previousUsed then BackendVariable.addVar(preVar, vars) else vars;
eqns = BackendEquation.addEquation(eqn, eqns);

// Error.addCompilerNotification("VARIABLE (fixed=true): " + BackendDump.varString(var));
Expand Down Expand Up @@ -2279,7 +2279,7 @@ algorithm
then DAE.CREF(dummyder, ty);

case DAE.CALL(path = Absyn.IDENT(name="previous"), expLst = {DAE.CREF(componentRef=cr)}, attr=DAE.CALL_ATTR(ty=ty)) equation
dummyder = ComponentReference.crefPrefixString("$CLKPRE", cr);
dummyder = ComponentReference.crefPrefixPrevious(cr);
then DAE.CREF(dummyder, ty);

else inExp;
Expand Down
8 changes: 8 additions & 0 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -1927,6 +1927,14 @@ algorithm
outCref := makeCrefQual(DAE.preNamePrefix, DAE.T_UNKNOWN_DEFAULT, {}, inCref);
end crefPrefixPre;

public function crefPrefixPrevious "public function crefPrefixPrevious
Appends $CLKPRE to a cref, so a => $CLKPRE.a"
input DAE.ComponentRef inCref;
output DAE.ComponentRef outCref;
algorithm
outCref := makeCrefQual(DAE.previousNamePrefix, DAE.T_UNKNOWN_DEFAULT, {}, inCref);
end crefPrefixPrevious;

public function crefPrefixStart "public function crefPrefixStart
Appends $START to a cref, so a => $START.a"
input DAE.ComponentRef inCref;
Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -57,6 +57,7 @@ public constant String UNIQUEIO = "$unique$outer$";

public constant String derivativeNamePrefix = "$DER";
public constant String preNamePrefix = "$PRE";
public constant String previousNamePrefix = "$CLKPRE";
public constant String startNamePrefix = "$START";


Expand Down
2 changes: 1 addition & 1 deletion Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -580,7 +580,7 @@ algorithm
clockedVars := simVar::clockedVars;
if isPrevVar[i] then
cr := simVar.name;
simVar.name := ComponentReference.crefPrefixString("$CLKPRE", cr);
simVar.name := ComponentReference.crefPrefixPrevious(cr);
clockedVars := simVar::clockedVars;
simEq := SimCode.SES_SIMPLE_ASSIGN(ouniqueEqIndex, simVar.name, DAE.CREF(cr, simVar.type_), DAE.emptyElementSource);
equations := simEq::equations;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -5330,7 +5330,7 @@ template daeExpCall(Exp call, Context context, Text &preExp, Text &varDecls, Tex
daeExpCallPre(arg, context, preExp, varDecls, &auxFunction)

case CALL(path=IDENT(name="previous"), expLst={arg as CREF(__)}) then
'$P$CLKPRE<%cref(arg.componentRef)%>'
'<%cref(crefPrefixPrevious(arg.componentRef))%>'
case CALL(path=IDENT(name="$_clkfire"), expLst={arg as ICONST(__)}) then
'fireClock(data, threadData, <%arg.integer%> - 1, data->localData[0]->timeValue)'

Expand Down
2 changes: 1 addition & 1 deletion Compiler/Template/CodegenCppCommon.tpl
Expand Up @@ -1734,7 +1734,7 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/, Text &varD
'_discrete_events->pre(<%var1%>)'

case CALL(path=IDENT(name="previous"), expLst={arg as CREF(__)}) then
'_$CLKPRE_P<%cref(arg.componentRef, useFlatArrayNotation)%>'
'<%cref(crefPrefixPrevious(arg.componentRef), useFlatArrayNotation)%>'

case CALL(path=IDENT(name="$getPart"), expLst={e1}) then
daeExp(e1, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
Expand Down
5 changes: 5 additions & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -2987,6 +2987,11 @@ package ComponentReference
input DAE.ComponentRef inComponentRef;
output DAE.ComponentRef outComponentRef;
end crefArrayGetFirstCref;

function crefPrefixPrevious
input DAE.ComponentRef inCref;
output DAE.ComponentRef outCref;
end crefPrefixPrevious;
end ComponentReference;

package Expression
Expand Down

0 comments on commit 5dfc9cd

Please sign in to comment.