Skip to content

Commit

Permalink
- Moved global root indices to Global.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10433 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Nov 11, 2011
1 parent b029013 commit 69c783c
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 58 deletions.
25 changes: 14 additions & 11 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -69,6 +69,7 @@ protected import Error;
protected import Expression;
protected import ExpressionSimplify;
protected import ExpressionDump;
protected import Global;
protected import HashTable2;
protected import HashTable4;
protected import List;
Expand Down Expand Up @@ -6713,21 +6714,21 @@ end selectOptModules1;

public function profilerinit
algorithm
setGlobalRoot(5, 0.0);
setGlobalRoot(6, 0.0);
System.realtimeTick(8);
setGlobalRoot(Global.profilerTime1Index, 0.0);
setGlobalRoot(Global.profilerTime2Index, 0.0);
System.realtimeTick(8);
end profilerinit;

public function profilerresults
protected
Real tg,t1,t2;
algorithm
tg := System.realtimeTock(8);
t1 := getGlobalRoot(5);
t2 := getGlobalRoot(6);
print("Time all: "); print(realString(tg)); print("\n");
print("Time t1: "); print(realString(t1)); print("\n");
print("Time t2: "); print(realString(t2)); print("\n");
tg := System.realtimeTock(8);
t1 := getGlobalRoot(Global.profilerTime1Index);
t2 := getGlobalRoot(Global.profilerTime2Index);
print("Time all: "); print(realString(tg)); print("\n");
print("Time t1: "); print(realString(t1)); print("\n");
print("Time t2: "); print(realString(t2)); print("\n");
end profilerresults;

public function profilerstart1
Expand All @@ -6745,15 +6746,17 @@ protected
Real t;
algorithm
t := System.realtimeTock(9);
setGlobalRoot(5, realAdd(getGlobalRoot(5),t));
setGlobalRoot(Global.profilerTime1Index,
realAdd(getGlobalRoot(Global.profilerTime1Index),t));
end profilerstop1;

public function profilerstop2
protected
Real t;
algorithm
t := System.realtimeTock(10);
setGlobalRoot(6, realAdd(getGlobalRoot(6),t));
setGlobalRoot(Global.profilerTime2Index,
realAdd(getGlobalRoot(Global.profilerTime2Index),t));
end profilerstop2;

public function mapEqSystem1
Expand Down
13 changes: 6 additions & 7 deletions Compiler/FrontEnd/Builtin.mo
Expand Up @@ -53,6 +53,7 @@ public import SCode;
// protected imports
protected import ClassInf;
protected import Debug;
protected import Global;
protected import List;
protected import Parser;
protected import SCodeUtil;
Expand Down Expand Up @@ -546,8 +547,6 @@ algorithm
end matchcontinue;
end initialEnvMetaModelica;

protected constant Integer memoryIndex = 3;

public function getInitialFunctions
"Fetches the Absyn.Program representation of the functions (and other classes) in the initial environment"
output Absyn.Program initialProgram;
Expand All @@ -560,12 +559,12 @@ algorithm
Option<Absyn.Program> optProgram;
case ()
equation
failure(_ = getGlobalRoot(memoryIndex));
setGlobalRoot(memoryIndex,{});
failure(_ = getGlobalRoot(Global.builtinIndex));
setGlobalRoot(Global.builtinIndex,{});
then fail();
case ()
equation
assocLst = getGlobalRoot(memoryIndex);
assocLst = getGlobalRoot(Global.builtinIndex);
then Util.assoc(RTOpts.acceptMetaModelicaGrammar(), assocLst);
case ()
equation
Expand All @@ -575,8 +574,8 @@ algorithm
initialFunctionStr = System.readFile(fileModelica);
initialFunctionStrMM = Debug.bcallret1(b, System.readFile, fileMetaModelica, "");
initialProgram = Parser.parsestring(initialFunctionStr +& initialFunctionStrMM, fileModelica);
assocLst = getGlobalRoot(memoryIndex);
setGlobalRoot(memoryIndex, (b,initialProgram)::assocLst);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, (b,initialProgram)::assocLst);
then initialProgram;
else
equation
Expand Down
11 changes: 4 additions & 7 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -50,6 +50,7 @@ protected import Debug;
protected import Dump;
protected import Expression;
protected import ExpressionDump;
protected import Global;
protected import List;
protected import Print;
protected import RTOpts;
Expand All @@ -59,10 +60,6 @@ protected import Util;
// do not make this public. instead use the function below.
protected constant DAE.ComponentRef dummyCref = DAE.CREF_IDENT("dummy", DAE.ET_OTHER(), {});

// global root index for cref memory
public
constant Integer crefMemoryIndex = 2;

public function createEmptyCrefMemory
"@author: adrpo
creates an array, with one element for each record in DAE.ComponentRef!"
Expand Down Expand Up @@ -125,7 +122,7 @@ algorithm
equation
// oh the horror. if you don't understand this, contact adrpo
// get from global roots
crefMem = getGlobalRoot(crefMemoryIndex);
crefMem = getGlobalRoot(Global.crefIndex);
// select a list based on the constructor of DAE.ComponentRef value
indexBasedOnValueConstructor = valueConstructor(inCref);
crefLst = arrayGet(crefMem, indexBasedOnValueConstructor + 1);
Expand All @@ -142,14 +139,14 @@ algorithm
equation
// oh the horror. if you don't understand this, contact adrpo
// get from global roots
crefMem = getGlobalRoot(crefMemoryIndex);
crefMem = getGlobalRoot(Global.crefIndex);
// select a list based on the constructor of DAE.ComponentRef value
indexBasedOnValueConstructor = valueConstructor(inCref);
crefLst = arrayGet(crefMem, indexBasedOnValueConstructor + 1);
// add the translation to the list and set the array
crefMem = arrayUpdate(crefMem, indexBasedOnValueConstructor + 1, inCref::crefLst);
// set the global cache with the new value
setGlobalRoot(crefMemoryIndex, crefMem);
setGlobalRoot(Global.crefIndex, crefMem);
then
inCref;
end matchcontinue;
Expand Down
42 changes: 20 additions & 22 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -98,9 +98,6 @@ constant Boolean neverUnroll = false;

constant Integer RT_CLOCK_EXECSTAT_MAIN = 11;

// the index of the inst hash table in the global table
constant Integer instHashIndex = 0;

// **
// These type aliases are introduced to make the code a little more readable.
// **
Expand Down Expand Up @@ -137,6 +134,7 @@ protected import ErrorExt;
protected import Expression;
protected import ExpressionDump;
protected import ExpressionSimplify;
protected import Global;
protected import Graph;
protected import HashTable;
protected import HashTable5;
Expand Down Expand Up @@ -315,8 +313,8 @@ algorithm
dae2 = DAE.DAE({DAE.COMP(name2,daeElts,source,NONE())});

// let the GC collect these as they are used only by Inst!
setGlobalRoot(instHashIndex, emptyInstHashTable());
setGlobalRoot(Types.memoryIndex, Types.createEmptyTypeMemory());
setGlobalRoot(Global.instHashIndex, emptyInstHashTable());
setGlobalRoot(Global.typesIndex, Types.createEmptyTypeMemory());
then
(cache,env_2,ih,dae2);

Expand Down Expand Up @@ -379,8 +377,8 @@ algorithm
//print("\nSetSource+DAE: " +& realString(System.getTimerIntervalTime()));

// let the GC collect these as they are used only by Inst!
setGlobalRoot(instHashIndex, emptyInstHashTable());
setGlobalRoot(Types.memoryIndex, Types.createEmptyTypeMemory());
setGlobalRoot(Global.instHashIndex, emptyInstHashTable());
setGlobalRoot(Global.typesIndex, Types.createEmptyTypeMemory());
then
(cache, env_2, ih, dae);

Expand Down Expand Up @@ -443,8 +441,8 @@ algorithm
Error.addMessage(Error.ERROR_FLATTENING, {cname_str});

// let the GC collect these as they are used only by Inst!
setGlobalRoot(instHashIndex, emptyInstHashTable());
setGlobalRoot(Types.memoryIndex, Types.createEmptyTypeMemory());
setGlobalRoot(Global.instHashIndex, emptyInstHashTable());
setGlobalRoot(Global.typesIndex, Types.createEmptyTypeMemory());
then
fail();
end matchcontinue;
Expand Down Expand Up @@ -1827,7 +1825,7 @@ algorithm
_, graph, csets, instSingleCref)
equation
false = RTOpts.debugFlag("noCache");
instHash = getGlobalRoot(instHashIndex);
instHash = getGlobalRoot(Global.instHashIndex);
envPathOpt = Env.getEnvPath(inEnv);
fullEnvPathPlusClass = Absyn.selectPathsOpt(envPathOpt, Absyn.IDENT(className));
{SOME(FUNC_instClassIn(inputs, outputs)),_} = BaseHashTable.get(fullEnvPathPlusClass, instHash);
Expand Down Expand Up @@ -2806,7 +2804,7 @@ algorithm
case (cache,env,ih,mods,pre,ci_state,c as SCode.CLASS(name = className, restriction=r),vis,inst_dims)
equation
false = RTOpts.debugFlag("noCache");
instHash = getGlobalRoot(instHashIndex);
instHash = getGlobalRoot(Global.instHashIndex);
envPathOpt = Env.getEnvPath(inEnv);
className = SCode.className(c);
fullEnvPathPlusClass = Absyn.selectPathsOpt(envPathOpt, Absyn.IDENT(className));
Expand Down Expand Up @@ -2835,7 +2833,7 @@ algorithm
ConnectionGraph.ConnectionGraph> outputs;
equation
false = RTOpts.debugFlag("noCache");
instHash = getGlobalRoot(instHashIndex);
instHash = getGlobalRoot(Global.instHashIndex);
envPathOpt = Env.getEnvPath(inEnv);
fullEnvPathPlusClass = Absyn.selectPathsOpt(envPathOpt, Absyn.IDENT(className));
{SOME(FUNC_instClassIn(inputs, outputs)), _} = get(fullEnvPathPlusClass, instHash);
Expand Down Expand Up @@ -16124,53 +16122,53 @@ algorithm
// we have them both
case (fullEnvPathPlusClass, SOME(fullInst), SOME(partialInst))
equation
instHash = getGlobalRoot(instHashIndex);
instHash = getGlobalRoot(Global.instHashIndex);
instHash = BaseHashTable.add((fullEnvPathPlusClass,{fullInstOpt,partialInstOpt}),instHash);
setGlobalRoot(instHashIndex, instHash);
setGlobalRoot(Global.instHashIndex, instHash);
then
();

// we have a partial inst result and the full in the cache
case (fullEnvPathPlusClass, NONE(), SOME(partialInst))
equation
instHash = getGlobalRoot(instHashIndex);
instHash = getGlobalRoot(Global.instHashIndex);
// see if we have a full inst here
{SOME(fullInst),_} = BaseHashTable.get(fullEnvPathPlusClass, instHash);
instHash = BaseHashTable.add((fullEnvPathPlusClass,{SOME(fullInst),partialInstOpt}),instHash);
setGlobalRoot(instHashIndex, instHash);
setGlobalRoot(Global.instHashIndex, instHash);
then
();

// we have a partial inst result and the full is NOT in the cache
case (fullEnvPathPlusClass, NONE(), SOME(partialInst))
equation
instHash = getGlobalRoot(instHashIndex);
instHash = getGlobalRoot(Global.instHashIndex);
// see if we have a full inst here
// failed above {SOME(fullInst),_} = get(fullEnvPathPlusClass, instHash);
instHash = BaseHashTable.add((fullEnvPathPlusClass,{NONE(),partialInstOpt}),instHash);
setGlobalRoot(instHashIndex, instHash);
setGlobalRoot(Global.instHashIndex, instHash);
then
();

// we have a full inst result and the partial in the cache
case (fullEnvPathPlusClass, SOME(fullInst), NONE())
equation
instHash = getGlobalRoot(instHashIndex);
instHash = getGlobalRoot(Global.instHashIndex);
// see if we have a partial inst here
{_,SOME(partialInst)} = BaseHashTable.get(fullEnvPathPlusClass, instHash);
instHash = BaseHashTable.add((fullEnvPathPlusClass,{fullInstOpt,SOME(partialInst)}),instHash);
setGlobalRoot(instHashIndex, instHash);
setGlobalRoot(Global.instHashIndex, instHash);
then
();

// we have a full inst result and the partial is NOT in the cache
case (fullEnvPathPlusClass, SOME(fullInst), NONE())
equation
instHash = getGlobalRoot(instHashIndex);
instHash = getGlobalRoot(Global.instHashIndex);
// see if we have a partial inst here
// failed above {_,SOME(partialInst)} = get(fullEnvPathPlusClass, instHash);
instHash = BaseHashTable.add((fullEnvPathPlusClass,{fullInstOpt,NONE()}),instHash);
setGlobalRoot(instHashIndex, instHash);
setGlobalRoot(Global.instHashIndex, instHash);
then
();

Expand Down
5 changes: 3 additions & 2 deletions Compiler/FrontEnd/SCodeUtil.mo
Expand Up @@ -52,6 +52,7 @@ protected import Builtin;
protected import Debug;
protected import Dump;
protected import Error;
protected import Global;
protected import Inst;
protected import InstanceHierarchy;
protected import List;
Expand Down Expand Up @@ -83,8 +84,8 @@ algorithm

case (inProgram)
equation
setGlobalRoot(Inst.instHashIndex, Inst.emptyInstHashTable());
setGlobalRoot(Types.memoryIndex, Types.createEmptyTypeMemory());
setGlobalRoot(Global.instHashIndex, Inst.emptyInstHashTable());
setGlobalRoot(Global.typesIndex, Types.createEmptyTypeMemory());
// adrpo: TODO! FIXME! disable function caching for now as some tests fail.
// setGlobalRoot(Ceval.cevalHashIndex, Ceval.emptyCevalHashTable());
Absyn.PROGRAM(classes=inClasses) = MetaUtil.createMetaClassesInProgram(inProgram);
Expand Down
12 changes: 5 additions & 7 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -71,9 +71,6 @@ public
type TypeMemoryEntry = tuple<DAE.Type, DAE.ExpType>;
type TypeMemoryEntryList = list<TypeMemoryEntry>;
type TypeMemoryEntryListArray = array<TypeMemoryEntryList>;
// the index of the type memory in the global table
constant Integer memoryIndex = 1;


protected import ComponentReference;
protected import Dump;
Expand All @@ -82,6 +79,7 @@ protected import Error;
protected import Expression;
protected import ExpressionDump;
protected import ExpressionSimplify;
protected import Global;
protected import List;
protected import Patternm;
protected import Print;
Expand Down Expand Up @@ -3587,7 +3585,7 @@ algorithm
equation
// oh the horror. if you don't understand this, contact adrpo
// get from global roots
tyMem = getGlobalRoot(memoryIndex);
tyMem = getGlobalRoot(Global.typesIndex);
// select a list based on the constructor of TType value
indexBasedOnValueConstructor = valueConstructor(tt);
tyLst = arrayGet(tyMem, indexBasedOnValueConstructor + 1);
Expand All @@ -3599,7 +3597,7 @@ algorithm
List.deleteMemberOnTrue(inType, tyLst, typeMemoryEntryEq);
tyLst = tyEnt :: tyLst;
tyMem = arrayUpdate(tyMem, indexBasedOnValueConstructor + 1, tyLst);
setGlobalRoot(memoryIndex, tyMem);
setGlobalRoot(Global.typesIndex, tyMem);
then
expTy;

Expand All @@ -3610,14 +3608,14 @@ algorithm
expTy = elabType_dispatch(inType);
// oh the horror. if you don't understand this, contact adrpo
// get from global roots
tyMem = getGlobalRoot(memoryIndex);
tyMem = getGlobalRoot(Global.typesIndex);
// select a list based on the constructor of TType value
indexBasedOnValueConstructor = valueConstructor(tt);
tyLst = arrayGet(tyMem, indexBasedOnValueConstructor + 1);
// add the translation to the list and set the array
tyMem = arrayUpdate(tyMem, indexBasedOnValueConstructor + 1, (inType, expTy)::tyLst);
// set the global cache with the new value
setGlobalRoot(memoryIndex, tyMem);
setGlobalRoot(Global.typesIndex, tyMem);
then
expTy;

Expand Down
9 changes: 8 additions & 1 deletion Compiler/Global/Global.mo
Expand Up @@ -45,6 +45,13 @@ import InstInfo;
import Interactive;
import Pool;

constant Integer instHashIndex = 0;
constant Integer typesIndex = 1;
constant Integer crefIndex = 2;
constant Integer builtinIndex = 3;
constant Integer profilerTime1Index = 5;
constant Integer profilerTime2Index = 6;

type Names = Name.Names;
type Scopes = Scope.Scopes;
type InstInfo = InstInfo.Info;
Expand Down Expand Up @@ -226,4 +233,4 @@ algorithm
scope := Scope.get(sc, id);
end getScope;

end Global;
end Global;
2 changes: 1 addition & 1 deletion Compiler/Main/Main.mo
Expand Up @@ -1165,7 +1165,7 @@ algorithm
// search for System.startTimer/System.stopTimer/System.getTimerIntervalTimer
// System.resetTimer();

//setGlobalRoot(ComponentReference.crefMemoryIndex, ComponentReference.createEmptyCrefMemory());
//setGlobalRoot(Global.crefIndex, ComponentReference.createEmptyCrefMemory());
//Env.globalCache = fill(Env.emptyCache,1);
symbolTable = readSettings(args);
ismode = RTOpts.debugFlag("interactive");
Expand Down

0 comments on commit 69c783c

Please sign in to comment.