Skip to content

Commit

Permalink
- support noretcall in when equation, add example but still not work …
Browse files Browse the repository at this point in the history
…because of undefined reference to `Modelica_Utilities_Streams_print'

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13351 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Oct 12, 2012
1 parent 39c18aa commit 1da8fc3
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 5 deletions.
9 changes: 9 additions & 0 deletions Compiler/BackEnd/BackendDAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ uniontype WhenOperator "- Reinit Statement"
.DAE.Exp message;
.DAE.ElementSource source "the origin of the component/equation/algorithm";
end TERMINATE;

record NORETCALL "call with no return value, i.e. no equation.
Typically sideeffect call of external function but also
Connections.* i.e. Connections.root(...) functions."
Absyn.Path functionName;
list<DAE.Exp> functionArgs;
DAE.ElementSource source "the origin of the component/equation/algorithm";
end NORETCALL;

end WhenOperator;

public
Expand Down
8 changes: 8 additions & 0 deletions Compiler/BackEnd/BackendDAECreate.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,7 @@ algorithm
list<list<DAE.Element>> eqnslst;
Boolean b;
String s;
Absyn.Path functionName;

case ({},_,_,_,_) then (iEquationLst,iReinitStatementLst);
case (DAE.EQUATION(exp = (cre as DAE.CREF(componentRef = cr)),scalar = e, source = source) :: xs,_,_,_,_)
Expand Down Expand Up @@ -1391,6 +1392,13 @@ algorithm
then
(eqnl,reinit);

case (DAE.NORETCALL(functionName = functionName,functionArgs=expl,source=source) :: xs,_,_,_,_)
equation
(expl,source,_) = Inline.inlineExps(expl,(SOME(functionTree),{DAE.NORM_INLINE()}),source);
(eqnl,reinit) = lowerWhenEqn2(xs,inCond, functionTree, iEquationLst, BackendDAE.NORETCALL(functionName,expl,source) :: iReinitStatementLst);
then
(eqnl,reinit);

// failure
case (el::_,_,_,_,_)
equation
Expand Down
9 changes: 9 additions & 0 deletions Compiler/BackEnd/BackendDAETransform.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3303,6 +3303,8 @@ algorithm
DAE.ComponentRef cr;
DAE.ElementSource source;
Type_a ext_arg_1,ext_arg_2;
Absyn.Path functionName;
list<DAE.Exp> functionArgs,functionArgs1;

case ({},_,_) then ({},inTypeA);

Expand All @@ -3320,6 +3322,13 @@ algorithm
then
(BackendDAE.ASSERT(cond1,msg,level,source)::res1,ext_arg_2);

case (BackendDAE.NORETCALL(functionName=functionName,functionArgs=functionArgs,source=source)::res,_,_)
equation
(res1,ext_arg_1) = traverseBackendDAEExpsWhenOperator(res,func,inTypeA);
((functionArgs,ext_arg_2)) = Expression.traverseExpList(functionArgs,func,ext_arg_1);
then
(BackendDAE.NORETCALL(functionName,functionArgs,source)::res1,ext_arg_2);

case (wop::res,_,_)
equation
(res1,ext_arg_1) = traverseBackendDAEExpsWhenOperator(res,func,inTypeA);
Expand Down
13 changes: 11 additions & 2 deletions Compiler/BackEnd/BackendDump.mo
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ algorithm
String scr,se,se1,str;
DAE.ComponentRef cr;
DAE.Exp e,e1;
Absyn.Path functionName;
list<DAE.Exp> functionArgs;
case BackendDAE.REINIT(stateVar=cr,value=e)
equation
scr = ComponentReference.printComponentRefStr(cr);
Expand All @@ -550,13 +552,20 @@ algorithm
se1 = ExpressionDump.printExpStr(e1);
str = stringAppendList({"assert(",se,",",se1,")"});
then
str;
str;
case BackendDAE.TERMINATE(message=e)
equation
se = ExpressionDump.printExpStr(e);
str = stringAppendList({"terminate(",se,")"});
then
str;
str;
case BackendDAE.NORETCALL(functionName=functionName,functionArgs=functionArgs)
equation
se = Absyn.pathString(functionName);
se1 = stringDelimitList(List.map(functionArgs,ExpressionDump.printExpStr),", ");
str = stringAppendList({se,"(",se1,")"});
then
str;
end match;
end dumpWhenOperatorStr;

Expand Down
12 changes: 12 additions & 0 deletions Compiler/BackEnd/BackendVarTransform.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,9 @@ algorithm
DAE.ComponentRef cr,cr1;
DAE.ElementSource source;
Boolean b,b1,b2;
Absyn.Path functionName;
list<DAE.Exp> functionArgs,functionArgs1;
list<Boolean> blst;

case ({},_,_,_,_) then (listReverse(iAcc),replacementPerformed);

Expand Down Expand Up @@ -1518,6 +1521,15 @@ algorithm
(res1,b) = replaceWhenOperator(res,repl,inFuncTypeExpExpToBooleanOption,replacementPerformed,wop::iAcc);
then
(res1,b);
case ((wop as BackendDAE.NORETCALL(functionName=functionName,functionArgs=functionArgs,source=source))::res,_,_,_,_)
equation
(functionArgs1,blst) = replaceExpList1(functionArgs, repl, inFuncTypeExpExpToBooleanOption, {}, {});
b = Util.boolOrList(blst);
source = DAEUtil.addSymbolicTransformationSubstitutionLst(blst,source,functionArgs,functionArgs1);
wop1 = Util.if_(b,BackendDAE.NORETCALL(functionName,functionArgs1,source),wop);
(res1,b) = replaceWhenOperator(res,repl,inFuncTypeExpExpToBooleanOption,replacementPerformed or b,wop1::iAcc);
then
(res1,b);
end match;
end replaceWhenOperator;

Expand Down
12 changes: 10 additions & 2 deletions Compiler/Template/CodegenC.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,16 @@ template functionWhenReinitStatementThen(list<WhenOperator> reinits, Text &varDe
FILE_INFO info = {<%infoArgs(getElementSourceFileInfo(source))%>};
omc_terminate(<%msgVar%>, info);
>>
case ASSERT(source=SOURCE(info=info)) then
assertCommon(condition, message, level, contextSimulationDiscrete, &varDecls, info)
case ASSERT(source=SOURCE(info=info)) then
assertCommon(condition, message, level, contextSimulationDiscrete, &varDecls, info)
case NORETCALL(__) then
let &preExp = buffer "" /*BUFD*/
let argStr = (functionArgs |> exp => '<%daeExp(exp, contextSimulationDiscrete, &preExp /*BUFC*/, &varDecls /*BUFD*/)%>' ;separator=", ")
let funName = '<%underscorePath(functionName)%>'
<<
<%preExp%>
<%funName%>(<%argStr%>);
>>
;separator="\n")
<<
<%body%>
Expand Down
10 changes: 9 additions & 1 deletion Compiler/Template/SimCodeTV.mo
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,15 @@ package BackendDAE
record TERMINATE " The Modelica builtin terminate(msg)"
DAE.Exp message;
DAE.ElementSource source "the origin of the component/equation/algorithm";
end TERMINATE;
end TERMINATE;

record NORETCALL "call with no return value, i.e. no equation.
Typically sideeffect call of external function but also
Connections.* i.e. Connections.root(...) functions."
Absyn.Path functionName;
list<DAE.Exp> functionArgs;
DAE.ElementSource source "the origin of the component/equation/algorithm";
end NORETCALL;
end WhenOperator;

uniontype WhenEquation
Expand Down

0 comments on commit 1da8fc3

Please sign in to comment.