Skip to content

Commit

Permalink
- do stream operators handling phase only if System.getHasStreamConne…
Browse files Browse the repository at this point in the history
…ctors() is true.

- tail recursive implementation of DAEUtil.traverseDAE2 to get rid of stack overflow for very large models.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7441 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Dec 16, 2010
1 parent d39745d commit e6623b8
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 101 deletions.
296 changes: 210 additions & 86 deletions Compiler/FrontEnd/DAEUtil.mo

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -3462,8 +3462,7 @@ public function traverseExp
output tuple<DAE.Exp, Type_a> outTpl;
end FuncExpType;
algorithm
outTplExpTypeA:=
matchcontinue (inExp,func,inTypeA)
outTplExpTypeA := matchcontinue (inExp,func,inTypeA)
local
DAE.Exp e1_1,e,e1,e2_1,e2,e3_1,e_1,e3;
Type_a ext_arg_1,ext_arg_2,ext_arg,ext_arg_3,ext_arg_4;
Expand Down
17 changes: 14 additions & 3 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -15122,11 +15122,22 @@ protected function handleStreamConnectors
output DAE.DAElist outDAE;
algorithm
outDAE := matchcontinue(isTopScope, inSets, inDAE)
case (false, _, _) then inDAE;

case (false, _, _)
then
inDAE;

// do not do this phase when getHasStreamConnectors() = false
case (true, _, _)
equation
false = System.getHasStreamConnectors();
then
inDAE;

// only do this phase when getHasStreamConnectors() = true
case (true, _, _)
equation
(inDAE, _, _) = DAEUtil.traverseDAE(inDAE, DAEUtil.emptyFuncTree,
handleStreamOperators, inSets);
(inDAE, _, _) = DAEUtil.traverseDAE(inDAE, DAEUtil.emptyFuncTree, handleStreamOperators, inSets);
then
inDAE;
end matchcontinue;
Expand Down
22 changes: 21 additions & 1 deletion Compiler/FrontEnd/SCodeUtil.mo
Expand Up @@ -94,6 +94,8 @@ algorithm
System.setHasInnerOuterDefinitions(false);
// set the external flag that signals the presence of expandable connectors in the model
System.setHasExpandableConnectors(false);
// set the external flag that signals the presence of expandable connectors in the model
System.setHasStreamConnectors(false);
sp = Util.listFold(inClasses, translate2, {});
sp = Util.listFold(initialClasses, translate2, sp);
sp = listReverse(sp);
Expand Down Expand Up @@ -1092,7 +1094,8 @@ algorithm
components = (Absyn.COMPONENTITEM(component = Absyn.COMPONENT(name = n,arrayDim = d,modification = m),comment = comment,condition=cond) :: xs)),info)
equation
// Debug.fprintln("translate", "translating component: " +& n);
setHasInnerOuterDefinitionsHandler(io);
setHasInnerOuterDefinitionsHandler(io); // signal the external flag that we have inner/outer definitions
setHasStreamConnectorsHandler(st); // signal the external flag that we have stream connectors
xs_1 = translateElementspec(cc, finalPrefix, io, repl, prot, Absyn.COMPONENTS(attr,t,xs), info);
mod = translateMod(m, false, Absyn.NON_EACH());
pa_1 = translateVariability(variability) "PR. This adds the arraydimension that may be specified together with the type of the component." ;
Expand Down Expand Up @@ -1127,6 +1130,23 @@ algorithm
end matchcontinue;
end setHasInnerOuterDefinitionsHandler;

protected function setHasStreamConnectorsHandler
"@author: adrpo
This function will set the external flag that signals
that a model has stream connectors"
input Boolean streamPrefix;
algorithm
_ := matchcontinue (streamPrefix)
// no stream prefix
case (false) then ();
// has stream prefix
case (true)
equation
System.setHasStreamConnectors(true);
then ();
end matchcontinue;
end setHasStreamConnectorsHandler;

protected function translateRedeclarekeywords
"function: translateRedeclarekeywords
author: PA
Expand Down
16 changes: 16 additions & 0 deletions Compiler/Util/System.mo
Expand Up @@ -518,6 +518,22 @@ public function getHasExpandableConnectors
external "C" System_getHasExpandableConnectors() annotation(Library = "omcruntime");
end getHasExpandableConnectors;

public function setHasStreamConnectors
"@author: adrpo
sets the external flag that signals the
presence of stream connectors in a model"
input Boolean hasStream;
external "C" System_setHasStreamConnectors(hasStream) annotation(Library = "omcruntime");
end setHasStreamConnectors;

public function getHasStreamConnectors
"@author: adrpo
retrieves the external flag that signals the
presence of stream connectors in a model"
output Boolean hasStream;
external "C" System_getHasStreamConnectors() annotation(Library = "omcruntime");
end getHasStreamConnectors;

public function setHasInnerOuterDefinitions
"@author: adrpo
sets the external flag that signals the presence
Expand Down
15 changes: 13 additions & 2 deletions Compiler/runtime/System_omc.cpp
Expand Up @@ -189,12 +189,12 @@ extern int System_strcmp(const char *str1, const char *str2)

extern int System_getHasExpandableConnectors()
{
return hasExpandableConnector;
return hasExpandableConnectors;
}

extern void System_setHasExpandableConnectors(int b)
{
hasExpandableConnector = b;
hasExpandableConnectors = b;
}

extern int System_getHasInnerOuterDefinitions()
Expand All @@ -207,6 +207,17 @@ extern void System_setHasInnerOuterDefinitions(int b)
hasInnerOuterDefinitions = b;
}

extern int System_getHasStreamConnectors()
{
return hasStreamConnectors;
}

extern void System_setHasStreamConnectors(int b)
{
hasStreamConnectors = b;
}


extern void* System_strtok(const char *str0, const char *delimit)
{
char *s;
Expand Down
34 changes: 28 additions & 6 deletions Compiler/runtime/System_rml.c
Expand Up @@ -713,28 +713,28 @@ RML_END_LABEL

/*
* @author: adrpo
* side effect to set if we have expandable conenctors in a program
* side effect to set if we have expandable connectors in a program
*/
RML_BEGIN_LABEL(System__getHasExpandableConnectors)
{
rmlA0 = hasExpandableConnector ? RML_TRUE : RML_FALSE;
rmlA0 = hasExpandableConnectors ? RML_TRUE : RML_FALSE;
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
/*
* @author: adrpo
* side effect to get if we have expandable conenctors in a program
* side effect to get if we have expandable connectors in a program
*/
RML_BEGIN_LABEL(System__setHasExpandableConnectors)
{
hasExpandableConnector = (RML_UNTAGFIXNUM(rmlA0)) ? 1 : 0;
hasExpandableConnectors = (RML_UNTAGFIXNUM(rmlA0)) ? 1 : 0;
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

/*
* @author: adrpo
* side effect to set if we have expandable conenctors in a program
* side effect to set if we have expandable connectors in a program
*/
RML_BEGIN_LABEL(System__getHasInnerOuterDefinitions)
{
Expand All @@ -744,7 +744,7 @@ RML_BEGIN_LABEL(System__getHasInnerOuterDefinitions)
RML_END_LABEL
/*
* @author: adrpo
* side effect to get if we have expandable conenctors in a program
* side effect to get if we have expandable connectors in a program
*/
RML_BEGIN_LABEL(System__setHasInnerOuterDefinitions)
{
Expand All @@ -753,6 +753,28 @@ RML_BEGIN_LABEL(System__setHasInnerOuterDefinitions)
}
RML_END_LABEL

/*
* @author: adrpo
* side effect to set if we have stream connectors in a program
*/
RML_BEGIN_LABEL(System__getHasStreamConnectors)
{
rmlA0 = hasStreamConnectors ? RML_TRUE : RML_FALSE;
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
/*
* @author: adrpo
* side effect to get if we have stream connectors in a program
*/
RML_BEGIN_LABEL(System__setHasStreamConnectors)
{
hasStreamConnectors = (RML_UNTAGFIXNUM(rmlA0)) ? 1 : 0;
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL


/*
* @author ppriv
*/
Expand Down
3 changes: 2 additions & 1 deletion Compiler/runtime/systemimpl.c
Expand Up @@ -105,8 +105,9 @@ static char *linker = (char*) DEFAULT_LINKER;
static char *cflags = (char*) DEFAULT_CFLAGS;
static char *ldflags= (char*) DEFAULT_LDFLAGS;

static int hasExpandableConnector = 0;
static int hasExpandableConnectors = 0;
static int hasInnerOuterDefinitions = 0;
static int hasStreamConnectors = 0;
static char* class_names_for_simulation = NULL;
static const char *select_from_dir = NULL;

Expand Down

0 comments on commit e6623b8

Please sign in to comment.