Skip to content

Commit

Permalink
Do not generate defines for value references
Browse files Browse the repository at this point in the history
Use a lookup table for value references instead of letting the C
preprocessor do all the work.

Belonging to [master]:
  - OpenModelica/OMCompiler#1884
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Oct 11, 2017
1 parent 88845bb commit a603749
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 154 deletions.
2 changes: 2 additions & 0 deletions Compiler/SimCode/SimCode.mo
Expand Up @@ -52,6 +52,7 @@ encapsulated package SimCode

// public imports
import Absyn;
import AvlTreeCRToInt;
import BackendDAE;
import DAE;
import HashTable;
Expand Down Expand Up @@ -136,6 +137,7 @@ uniontype SimCode
String fileNamePrefix, fullPathPrefix "Used in FMI where files are generated in a special directory";
String fmuTargetName;
HpcOmSimCode.HpcOmData hpcomData;
AvlTreeCRToInt.Tree valueReferences "Used in FMI";
//maps each variable to an array of storage indices (with this information, arrays must not be unrolled) and a list for the array-dimensions
//if the variable is not part of an array (if it is a scalar value), then the array has size 1
HashTableCrIListArray.HashTable varToArrayIndexMapping;
Expand Down
52 changes: 52 additions & 0 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -563,6 +563,7 @@ algorithm
if isFMU then (filenamePrefix+".fmutmp/sources/") else "",
fmuTargetName,
HpcOmSimCode.emptyHpcomData,
if isFMU then getValueReferenceMapping(modelInfo) else AvlTreeCRToInt.EMPTY(),
varToArrayIndexMapping,
varToIndexMapping,
crefToSimVarHT,
Expand Down Expand Up @@ -13440,5 +13441,56 @@ algorithm
else t1>t2;
end simvarGraterThan;

public function lookupVR
input DAE.ComponentRef cr;
input SimCode.SimCode simCode;
output Integer vr;
algorithm
print("LookupVR " + ComponentReference.printComponentRefStr(cr) + "\n");
vr := AvlTreeCRToInt.get(simCode.valueReferences, cr);
print("LookupVR " + ComponentReference.printComponentRefStr(cr) + " OK\n");
end lookupVR;

protected function getValueReferenceMapping
input SimCode.ModelInfo modelInfo;
output AvlTreeCRToInt.Tree tree;
protected
Integer i;
SimCodeVar.SimVars vars;
algorithm
tree := AvlTreeCRToInt.EMPTY();
vars := modelInfo.vars;
(i,tree) := getValueReferenceMapping2(vars.stateVars, 0, tree);
(i,tree) := getValueReferenceMapping2(vars.derivativeVars, i, tree);
(i,tree) := getValueReferenceMapping2(vars.algVars, i, tree);
(i,tree) := getValueReferenceMapping2(vars.discreteAlgVars, i, tree);
(i,tree) := getValueReferenceMapping2(vars.aliasVars, i, tree);
(i,tree) := getValueReferenceMapping2(vars.paramVars, i, tree);

(i,tree) := getValueReferenceMapping2(vars.intAlgVars, 0, tree);
(i,tree) := getValueReferenceMapping2(vars.intParamVars, i, tree);
(i,tree) := getValueReferenceMapping2(vars.intAliasVars, i, tree);

(i,tree) := getValueReferenceMapping2(vars.boolAlgVars, 0, tree);
(i,tree) := getValueReferenceMapping2(vars.boolParamVars, i, tree);
(i,tree) := getValueReferenceMapping2(vars.boolAliasVars, i, tree);

(i,tree) := getValueReferenceMapping2(vars.stringAlgVars, 0, tree);
(i,tree) := getValueReferenceMapping2(vars.stringParamVars, i, tree);
(i,tree) := getValueReferenceMapping2(vars.stringAliasVars, i, tree);
end getValueReferenceMapping;

protected function getValueReferenceMapping2
input list<SimCodeVar.SimVar> vars;
input output Integer i;
input output AvlTreeCRToInt.Tree tree;
algorithm
for v in vars loop
tree := AvlTreeCRToInt.add(tree, v.name, i);
i := i + 1;
end for;
end getValueReferenceMapping2;


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

0 comments on commit a603749

Please sign in to comment.