Skip to content

Commit c30ebad

Browse files
New Modelica state machine prototype
- Added DAE.FLAT_SM and DAE.SM_COMP to capture state machine composition - Most of the code for state machine instantiation is in the new package "InstStateMachineUtil.mo" - Transformation from state machines to data-flow is now triggered within the front-end function DAEUtil.transformationsBeforeBackend(..) - The state machine to data-flow transformation code is in the new package "StateMachineFlatten.mo" (stateMachineFlatten.stateMachineToDataFlow(..)) - The old back-end prototype in package "StateMachineFeatures.mo" is now obsolete Remaining issues: - Not yet implemented operators "ticksInState()" and "timeInState()" and MLS "17.3.6 Merging Connections to Multiple Outputs" - Equations in states need to confirm to the same requirements as when-equations (component ref to be assigned to must be at the LHS) - State machines are based on the synchronous elements features and in order simulate state-machines requires these to be working in OM - As a current workaround to simulate state machines is is possible to uncomment code that wraps all equations in "when-equations" and replaces "previous(x)" by "pre(x)", however, this is only intended for development purposes - The functionality provided by "StateMachineFlatten.mo" should be better adapted to a back-end implementation, however this will require to adapt the data structures used in the back-end (future work)
1 parent e8d65ec commit c30ebad

16 files changed

+2774
-175
lines changed

Compiler/BackEnd/StateMachineFeatures.mo

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ encapsulated package StateMachineFeatures
3333
" file: StateMachineFeatures.mo
3434
package: StateMachineFeatures
3535
description: Provides support for Modelica State Machines.
36-
37-
RCS: $Id$"
36+
"
3837

3938
public import Absyn;
4039
public import BackendDAE;
@@ -171,6 +170,18 @@ constant String SMS_PRE = "smOf" "prefix for crefs of fresh State Machine Semant
171170
constant Boolean DEBUG_SMDUMP = false "enable verbose stdout debug information during elaboration";
172171

173172
public function stateMachineElab
173+
"Deactived old module, since now implemented in frontend. See function 'stateMachineElabDEACTIVATED' for old code.
174+
175+
Might want to reactivate (and adapt) the module at a later time, particularly when state machine support is to be
176+
extended to support features that cannot be handled in a good way in the front-end.
177+
"
178+
input BackendDAE.BackendDAE inDAE;
179+
output BackendDAE.BackendDAE outDAE;
180+
algorithm
181+
outDAE := inDAE;
182+
end stateMachineElab;
183+
184+
public function stateMachineElabDEACTIVATED
174185
"Elaborate state machines and transform them in data-flow equations."
175186
input BackendDAE.BackendDAE inDAE;
176187
output BackendDAE.BackendDAE outDAE;
@@ -277,7 +288,7 @@ algorithm
277288
//BackendDump.printShared(shared);
278289
end if;
279290

280-
end stateMachineElab;
291+
end stateMachineElabDEACTIVATED;
281292

282293
protected function synthesizeAutomataEqs "
283294
Author: BTH
@@ -313,7 +324,7 @@ Synthesize Automaton/state machine relevant data-flow equations.
313324
output BackendDAE.EqSystem systOut;
314325
protected
315326
DAE.ComponentRef initRef, resetRef, stateRef, activeResetStateRef, activeStateRef, activeResetRef, activeRef;
316-
BackendDAE.Var initVar, resetVar, activePlotIndicatorVar;
327+
BackendDAE.Var initVar, activePlotIndicatorVar;
317328
DAE.ComponentRef preRef, refiningRef, refiningResetRef, refiningActiveRef;
318329
Composition refiningComp;
319330
list<Composition> stateRefiningComps, refiningComps;
@@ -2440,6 +2451,7 @@ algorithm
24402451
mode1 = MODE(name1, isInitial1, edges1, eqs1, outgoing1,os1,ol1,ps1);
24412452
modes = BaseHashTable.add((cstate1, mode1), inA);
24422453

2454+
// FIXME: I should just update the mode1 and not create a mode2???
24432455
mode2 = if BaseHashTable.hasKey(cstate2, modes)
24442456
then BaseHashTable.get(cstate2, modes)
24452457
else MODE(ComponentReference.crefLastIdent(cstate1), false, HashSet.emptyHashSet(),

Compiler/FrontEnd/DAE.mo

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,17 @@ public uniontype Element
337337
ClassAttributes classAttrs;
338338
end CLASS_ATTRIBUTES;
339339

340+
record FLAT_SM "Flat state machine section"
341+
Ident ident;
342+
list<Element> dAElist "The states/modes transitions and variable
343+
merging equations within the the flat state machine";
344+
end FLAT_SM;
345+
346+
record SM_COMP "A state/mode component in a state machine"
347+
ComponentRef componentRef;
348+
list<Element> dAElist "a component with subelements";
349+
end SM_COMP;
350+
340351

341352
end Element;
342353

@@ -1031,7 +1042,6 @@ end EvaluateSingletonTypeFunction;
10311042
public constant FunctionAttributes FUNCTION_ATTRIBUTES_BUILTIN = FUNCTION_ATTRIBUTES(NO_INLINE(),true,false,false,FUNCTION_BUILTIN(NONE()),FP_NON_PARALLEL());
10321043
public constant FunctionAttributes FUNCTION_ATTRIBUTES_DEFAULT = FUNCTION_ATTRIBUTES(NO_INLINE(),true,false,false,FUNCTION_NOT_BUILTIN(),FP_NON_PARALLEL());
10331044
public constant FunctionAttributes FUNCTION_ATTRIBUTES_IMPURE = FUNCTION_ATTRIBUTES(NO_INLINE(),false,true,false,FUNCTION_NOT_BUILTIN(),FP_NON_PARALLEL());
1034-
//BTH
10351045
public constant FunctionAttributes FUNCTION_ATTRIBUTES_BUILTIN_IMPURE = FUNCTION_ATTRIBUTES(NO_INLINE(),false,true,false,FUNCTION_BUILTIN(NONE()),FP_NON_PARALLEL());
10361046

10371047
public

Compiler/FrontEnd/DAEDump.mo

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public uniontype splitElements
7777
list<DAE.Element> co;
7878
list<DAE.Element> o;
7979
list<DAE.Element> ca;
80+
list<compWithSplitElements> sm;
8081
end SPLIT_ELEMENTS;
8182
end splitElements;
8283

@@ -2170,6 +2171,24 @@ algorithm
21702171
Print.printBuf("NORETCALL()");
21712172
then
21722173
();
2174+
case DAE.SM_COMP(componentRef = cr,dAElist = l)
2175+
equation
2176+
Print.printBuf("SM_COMP(");
2177+
ComponentReference.printComponentRef(cr);
2178+
Print.printBuf(",");
2179+
dumpDebugElist(l);
2180+
Print.printBuf(")");
2181+
then
2182+
();
2183+
case DAE.FLAT_SM(ident = n,dAElist = l)
2184+
equation
2185+
Print.printBuf("FLAT_SM(");
2186+
Print.printBuf(n);
2187+
Print.printBuf(",");
2188+
dumpDebugElist(l);
2189+
Print.printBuf(")");
2190+
then
2191+
();
21732192
case _
21742193
equation
21752194
Print.printBuf("UNKNOWN ");
@@ -2620,20 +2639,17 @@ algorithm
26202639
list<DAE.Element> co;
26212640
list<DAE.Element> o;
26222641
list<DAE.Element> ca;
2642+
list<compWithSplitElements> sm;
26232643
splitElements loc_splelem;
26242644

26252645
compWithSplitElements compWSplElem;
26262646

26272647

26282648
case (DAE.COMP(ident = n,dAElist = l,comment = c))
26292649
equation
2630-
2631-
(v,ie,ia,e,a,ca,co,o) = DAEUtil.splitElements(l);
2632-
2633-
loc_splelem = SPLIT_ELEMENTS(v,ie,ia,e,a,ca,co,o);
2634-
2650+
(v,ie,ia,e,a,ca,co,o,sm) = DAEUtil.splitElements(l);
2651+
loc_splelem = SPLIT_ELEMENTS(v,ie,ia,e,a,ca,co,o,sm);
26352652
compWSplElem = COMP_WITH_SPLIT(n, loc_splelem, c);
2636-
26372653
then
26382654
(compWSplElem);
26392655

0 commit comments

Comments
 (0)