Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit a8b251e

Browse files
adrpoOpenModelica-Hudson
authored andcommitted
experimental support for merging alg sections, ticket:4365
1 parent 935a1c9 commit a8b251e

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

Compiler/FrontEnd/DAEUtil.mo

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6445,6 +6445,64 @@ algorithm
64456445
end match;
64466446
end toSCodeConnectorType;
64476447

6448+
public function mergeAlgorithmSections
6449+
"@author: adrpo
6450+
experimental merging of all algorithm sections into:
6451+
- one for initial algorithms
6452+
- one for normal algorithms
6453+
- only happens on a flag (-d=mergeAlgSections)"
6454+
input DAE.DAElist inDae;
6455+
output DAE.DAElist outDae;
6456+
protected
6457+
list<DAE.Element> els, newEls = {}, dAElist;
6458+
list<DAE.Statement> istmts = {}, stmts = {}, s;
6459+
DAE.ElementSource source, src;
6460+
DAE.Ident ident;
6461+
Option<SCode.Comment> comment;
6462+
algorithm
6463+
// do nothing if the flag is not activated
6464+
if not Flags.isSet(Flags.MERGE_ALGORITHM_SECTIONS) then
6465+
outDae := inDae;
6466+
return;
6467+
end if;
6468+
6469+
DAE.DAE(els) := inDae;
6470+
for e in els loop
6471+
_ :=
6472+
match e
6473+
case DAE.COMP(ident, dAElist, src, comment)
6474+
equation
6475+
DAE.DAE(dAElist) = mergeAlgorithmSections(DAE.DAE(dAElist));
6476+
newEls = DAE.COMP(ident, dAElist, src, comment)::newEls;
6477+
then
6478+
();
6479+
6480+
case DAE.ALGORITHM(algorithm_ = DAE.ALGORITHM_STMTS(s), source = source)
6481+
equation
6482+
stmts = listAppend(stmts, s);
6483+
then ();
6484+
case DAE.INITIALALGORITHM(algorithm_ = DAE.ALGORITHM_STMTS(s), source = source)
6485+
equation
6486+
istmts = listAppend(istmts, s);
6487+
then ();
6488+
else
6489+
equation
6490+
newEls = e::newEls;
6491+
then ();
6492+
end match;
6493+
end for;
6494+
newEls := listReverse(newEls);
6495+
if not listEmpty(istmts) then
6496+
newEls := listAppend(newEls, {DAE.INITIALALGORITHM(DAE.ALGORITHM_STMTS(istmts), source)});
6497+
end if;
6498+
if not listEmpty(stmts) then
6499+
newEls := listAppend(newEls, {DAE.ALGORITHM(DAE.ALGORITHM_STMTS(stmts), source)});
6500+
end if;
6501+
6502+
outDae := DAE.DAE(newEls);
6503+
6504+
end mergeAlgorithmSections;
6505+
64486506
annotation(__OpenModelica_Interface="frontend");
64496507
end DAEUtil;
64506508

Compiler/Script/CevalScriptBackend.mo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,6 +2883,8 @@ algorithm
28832883
//print("\nInst.instantiateClass");
28842884
(cache,env,_,dae) = Inst.instantiateClass(cache,InnerOuter.emptyInstHierarchy,scodeP,className);
28852885

2886+
dae = DAEUtil.mergeAlgorithmSections(dae);
2887+
28862888
//FGraphDump.dumpGraph(env, "F:\\dev\\" + Absyn.pathString(className) + ".graph.graphml");
28872889

28882890
//System.stopTimer();

Compiler/Util/Flags.mo

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ constant DebugFlag NF_UNITCHECK = DEBUG_FLAG(168, "frontEndUnitCheck", false,
511511
Util.gettext("Checks the consistency of units in equation."));
512512
constant DebugFlag DISABLE_COLORING = DEBUG_FLAG(169, "disableColoring", false,
513513
Util.gettext("Disables coloring algorithm while spasity detection."));
514+
constant DebugFlag MERGE_ALGORITHM_SECTIONS = DEBUG_FLAG(170, "mergeAlgSections", false,
515+
Util.gettext("Disables coloring algorithm while spasity detection."));
514516

515517

516518
// This is a list of all debug flags, to keep track of which flags are used. A
@@ -687,7 +689,8 @@ constant list<DebugFlag> allDebugFlags = {
687689
PARTITION_INITIALIZATION,
688690
EVAL_PARAM_DUMP,
689691
NF_UNITCHECK,
690-
DISABLE_COLORING
692+
DISABLE_COLORING,
693+
MERGE_ALGORITHM_SECTIONS
691694
};
692695

693696
public

0 commit comments

Comments
 (0)