Skip to content

Commit

Permalink
Modelica State Machines module (not ready, yet). Module is not yet ac…
Browse files Browse the repository at this point in the history
…tivated (entry commented out in Flags.mo).

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23014 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
bernhard-thiele committed Oct 28, 2014
1 parent e09fc1a commit 4c603f1
Show file tree
Hide file tree
Showing 6 changed files with 870 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -103,6 +103,7 @@ protected import Tearing;
protected import Types;
protected import UnitCheck;
protected import Values;
protected import StateMachineFeatures;

protected
type Var = BackendDAE.Var;
Expand Down Expand Up @@ -8807,6 +8808,7 @@ algorithm
(BackendDAEOptimize.removeUnusedParameter, "removeUnusedParameter", false),
(BackendDAEOptimize.removeUnusedVariables, "removeUnusedVariables", false),
(SynchronousFeatures.clockPartitioning, "clockPartitioning", true),
(StateMachineFeatures.stateMachineElab, "stateMachineElab", true),
(BackendDAEOptimize.expandDerOperator, "expandDerOperator", false),
(IndexReduction.findStateOrder, "findStateOrder", false),
(BackendDAEOptimize.simplifyIfEquations, "simplifyIfEquations", false),
Expand Down
83 changes: 83 additions & 0 deletions Compiler/BackEnd/HashTableSM.mo
@@ -0,0 +1,83 @@
encapsulated package HashTableSM "
HashTable instance specific code "

public import BaseHashTable;
public import DAE;
protected import ComponentReference;
protected import StateMachineFeatures;
protected import HashSet;
protected import BaseHashSet;
protected import List;


public type Key = DAE.ComponentRef;
public type Value = StateMachineFeatures.Mode;

public type HashTableCrefFunctionsType = tuple<FuncHashCref, FuncCrefEqual, FuncCrefStr, FuncExpStr>;
public type HashTable = tuple<array<list<tuple<Key, Integer>>>,
tuple<Integer, Integer, array<Option<tuple<Key, Value>>>>,
Integer,
Integer,
HashTableCrefFunctionsType>;

partial function FuncHashCref
input Key cr;
input Integer mod;
output Integer res;
end FuncHashCref;

partial function FuncCrefEqual
input Key cr1;
input Key cr2;
output Boolean res;
end FuncCrefEqual;

partial function FuncCrefStr
input Key cr;
output String res;
end FuncCrefStr;

partial function FuncExpStr
input Value exp;
output String res;
end FuncExpStr;

public function emptyHashTable
"
Returns an empty HashTable.
Using the default bucketsize..
"
output HashTable hashTable;
algorithm
hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
end emptyHashTable;

public function emptyHashTableSized
"Returns an empty HashTable.
Using the bucketsize size"
input Integer size;
output HashTable hashTable;
algorithm
hashTable := BaseHashTable.emptyHashTableWork(size,(ComponentReference.hashComponentRefMod,ComponentReference.crefEqual,ComponentReference.printComponentRefStr,modeToString));
end emptyHashTableSized;

public function modeToString
input StateMachineFeatures.Mode mode;
output String s;
protected
String name;
Boolean isInitial;
HashSet.HashSet edges;
list<DAE.ComponentRef> crefs;
list<String> paths;
algorithm
StateMachineFeatures.MODE(name=name, isInitial=isInitial, edges=edges) := mode;
crefs := BaseHashSet.hashSetList(edges);
paths := List.map(crefs, ComponentReference.printComponentRefStr);
s := "MODE(" + stringDelimitList({name,boolString(isInitial)}, ",") + "), "
+ "EDGES(" + stringDelimitList(paths, ", ") +"))";
end modeToString;

annotation(__OpenModelica_Interface="backend");
end HashTableSM;

0 comments on commit 4c603f1

Please sign in to comment.