Skip to content

Commit

Permalink
+ propagating parallelism for variables through SCode. Everything jus…
Browse files Browse the repository at this point in the history
…t falls through.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11101 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
mahge committed Feb 13, 2012
1 parent 2bec83b commit 63308b7
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 58 deletions.
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Builtin.mo
Expand Up @@ -128,8 +128,8 @@ public constant SCode.Prefixes commonPrefixes =
SCode.NOT_REPLACEABLE());

protected
constant SCode.Attributes attrConst = SCode.ATTR({},SCode.NOT_FLOW(),SCode.NOT_STREAM(),SCode.CONST(),Absyn.BIDIR());
constant SCode.Attributes attrParam = SCode.ATTR({},SCode.NOT_FLOW(),SCode.NOT_STREAM(),SCode.PARAM(),Absyn.BIDIR());
constant SCode.Attributes attrConst = SCode.ATTR({},SCode.NOT_FLOW(),SCode.NOT_STREAM(),SCode.NON_PARALLEL(),SCode.CONST(),Absyn.BIDIR());
constant SCode.Attributes attrParam = SCode.ATTR({},SCode.NOT_FLOW(),SCode.NOT_STREAM(),SCode.NON_PARALLEL(),SCode.PARAM(),Absyn.BIDIR());

/*
- The primitive types
Expand Down
36 changes: 20 additions & 16 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -4414,7 +4414,7 @@ algorithm
SCode.R_TYPE(),
SCode.DERIVED(
tSpec,SCode.NOMOD(),
SCode.ATTR({}, SCode.NOT_FLOW(), SCode.NOT_STREAM(), SCode.VAR(), Absyn.BIDIR()),
SCode.ATTR({}, SCode.NOT_FLOW(), SCode.NOT_STREAM(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.BIDIR()),
NONE()),
Absyn.dummyInfo);
(cache,cenv,ih,_,_,csets,ty,_,oDA,_)=instClass(cache,env,ih,UnitAbsyn.noStore,DAE.NOMOD(),pre,c,dims,impl,INNER_CALL(), ConnectionGraph.EMPTY, inSets);
Expand Down Expand Up @@ -6710,7 +6710,8 @@ algorithm
Absyn.InnerOuter io;
SCode.Attributes attr;
list<Absyn.Subscript> ad;
SCode.Variability param;
SCode.Parallelism prl;
SCode.Variability var;
Absyn.Direction dir;
Absyn.TypeSpec t;
SCode.Mod m;
Expand All @@ -6736,7 +6737,7 @@ algorithm
// a component
case (cache,env,ih,mods,pre,ci_state,
((comp as SCode.COMPONENT(n,SCode.PREFIXES(vis,redecl,finalPrefix,io,repl),
attr as SCode.ATTR(ad,flowPrefix,streamPrefix,param,dir),
attr as SCode.ATTR(ad,flowPrefix,streamPrefix,prl,var,dir),
t,m,comment,condition,info),cmod) :: xs),
inst_dims,impl)
equation
Expand All @@ -6763,7 +6764,7 @@ algorithm

// Debug.traceln(" extendFrameV comp " +& n +& " m:" +& Mod.printModStr(cmod_1) +& " compm: " +& Mod.printModStr(compmod) +& " cm: " +& Mod.printModStr(cmod));
env_1 = Env.extendFrameV(env,
DAE.TYPES_VAR(n,DAE.ATTR(flowPrefix,streamPrefix,param,dir,io),vis,
DAE.TYPES_VAR(n,DAE.ATTR(flowPrefix,streamPrefix,var,dir,io),vis,
DAE.T_UNKNOWN_DEFAULT,DAE.UNBOUND(),NONE()), SOME((comp,cmod_1)), Env.VAR_UNTYPED(), {});
(cache,env_2,ih) = addComponentsToEnv2(cache, env_1, ih, mods, pre, ci_state, xs, inst_dims, impl);
then
Expand Down Expand Up @@ -7244,7 +7245,7 @@ algorithm

cls = SCode.CLASS(id, SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(),
SCode.NOT_PARTIAL(), SCode.R_TYPE(), SCode.DERIVED(ts, SCode.NOMOD(),
SCode.ATTR(ad, fp, sp, SCode.VAR(), Absyn.BIDIR()),
SCode.ATTR(ad, fp, sp, SCode.NON_PARALLEL(), SCode.VAR(), Absyn.BIDIR()),
NONE()), info);

// The variable declaration and the (optional) equation modification are inspected for array dimensions.
Expand Down Expand Up @@ -9642,7 +9643,8 @@ algorithm
Absyn.InnerOuter io;
SCode.Attributes attr;
list<Absyn.Subscript> ad;
SCode.Variability param;
SCode.Parallelism prl1;
SCode.Variability var1;
Absyn.Direction dir;
Absyn.Path t;
Absyn.TypeSpec tsNew,tsOld;
Expand Down Expand Up @@ -9713,22 +9715,22 @@ algorithm
cmod = DAE.NOMOD();
pf = prefixes;
io = SCode.prefixesInnerOuter(pf);
SCode.ATTR(ad,flowPrefix,streamPrefix,param,dir) = attr;
SCode.ATTR(ad,flowPrefix,streamPrefix,prl1,var1,dir) = attr;

(cache,tyVar,SOME((SCode.COMPONENT(n,_,_,Absyn.TPATH(t, _),_,comment,cond,info),_)),_)
= Lookup.lookupIdent(cache, env, id);
//Debug.traceln("update comp " +& n +& " with mods:" +& Mod.printModStr(mods) +& " m:" +& SCodeDump.printModStr(m) +& " cm:" +& Mod.printModStr(cmod));
(cache,cl,cenv) = Lookup.lookupClass(cache, env, t, false);
//Debug.traceln("got class " +& SCodeDump.printClassStr(cl));
(mods,cmod,m) = noModForUpdatedComponents(param,updatedComps,cref,mods,cmod,m);
(mods,cmod,m) = noModForUpdatedComponents(var1,updatedComps,cref,mods,cmod,m);
crefs = getCrefFromMod(m);
crefs2 = getCrefFromDim(ad);
crefs3 = getCrefFromCond(cond);
crefs_1 = listAppend(listAppend(crefs, crefs2),crefs3);
crefs_2 = removeCrefFromCrefs(crefs_1, cref);
updatedComps = BaseHashTable.add((cref,0),updatedComps);
(cache,env2,ih,updatedComps) = updateComponentsInEnv2(cache, env, ih, pre, DAE.NOMOD(), crefs_2, ci_state, impl, updatedComps, SOME(cref));
(cache,env_1,ih,updatedComps) = updateComponentInEnv2(cache,env2,cenv,ih,pre,t,n,ad,cl,attr,pf,DAE.ATTR(flowPrefix,streamPrefix,param,dir,io),info,m,cmod,mods,cref,ci_state,impl,updatedComps);
(cache,env_1,ih,updatedComps) = updateComponentInEnv2(cache,env2,cenv,ih,pre,t,n,ad,cl,attr,pf,DAE.ATTR(flowPrefix,streamPrefix,var1,dir,io),info,m,cmod,mods,cref,ci_state,impl,updatedComps);

//print("updateComponentInEnv: NEW ENV:\n" +& Env.printEnvStr(env_1) +& "\n");
then
Expand Down Expand Up @@ -9777,12 +9779,12 @@ algorithm
case (cache,env,ih,pre,mods,cref,ci_state,impl,updatedComps,_)
equation
id = Absyn.crefFirstIdent(cref);
(cache,tyVar,SOME((SCode.COMPONENT(n,pf as SCode.PREFIXES(innerOuter = io),(attr as SCode.ATTR(ad,flowPrefix,streamPrefix,param,dir)),Absyn.TPATH(t, _),m,comment,cond,info),cmod)),_)
(cache,tyVar,SOME((SCode.COMPONENT(n,pf as SCode.PREFIXES(innerOuter = io),(attr as SCode.ATTR(ad,flowPrefix,streamPrefix,prl1,var1,dir)),Absyn.TPATH(t, _),m,comment,cond,info),cmod)),_)
= Lookup.lookupIdent(cache, env, id);
//Debug.traceln("update comp " +& n +& " with mods:" +& Mod.printModStr(mods) +& " m:" +& SCodeDump.printModStr(m) +& " cm:" +& Mod.printModStr(cmod));
(cache,cl,cenv) = Lookup.lookupClass(cache, env, t, false);
//Debug.traceln("got class " +& SCodeDump.printClassStr(cl));
(mods,cmod,m) = noModForUpdatedComponents(param,updatedComps,cref,mods,cmod,m);
(mods,cmod,m) = noModForUpdatedComponents(var1,updatedComps,cref,mods,cmod,m);
crefs = getCrefFromMod(m);
crefs2 = getCrefFromDim(ad);
crefs3 = getCrefFromCond(cond);
Expand All @@ -9795,7 +9797,7 @@ algorithm
crefs_2 = removeOptCrefFromCrefs(crefs_2, currentCref);
updatedComps = BaseHashTable.add((cref,0),updatedComps);
(cache,env2,ih,updatedComps) = updateComponentsInEnv2(cache, env, ih, pre, mods, crefs_2, ci_state, impl, updatedComps, SOME(cref));
(cache,env_1,ih,updatedComps) = updateComponentInEnv2(cache,env2,cenv,ih,pre,t,n,ad,cl,attr,pf,DAE.ATTR(flowPrefix,streamPrefix,param,dir,io),info,m,cmod,mods,cref,ci_state,impl,updatedComps);
(cache,env_1,ih,updatedComps) = updateComponentInEnv2(cache,env2,cenv,ih,pre,t,n,ad,cl,attr,pf,DAE.ATTR(flowPrefix,streamPrefix,var1,dir,io),info,m,cmod,mods,cref,ci_state,impl,updatedComps);
then
(cache,env_1,ih,updatedComps);

Expand Down Expand Up @@ -14864,6 +14866,7 @@ algorithm
Boolean impl;
SCode.Attributes attr;
list<Absyn.Subscript> dim;
SCode.Parallelism prl;
SCode.Variability var;
Absyn.Direction dir;
Absyn.Path t;
Expand All @@ -14888,7 +14891,7 @@ algorithm
),
attributes = (attr as
SCode.ATTR(arrayDims = dim,flowPrefix = f,streamPrefix=s,
variability = var,direction = dir)),
parallelism = prl,variability = var,direction = dir)),
typeSpec = Absyn.TPATH(t, _),modifications = mod,
comment = comment,
info = info),
Expand All @@ -14897,7 +14900,7 @@ algorithm
// - Prefixes (constant, parameter, final, discrete, input, output, ...) of the remaining record components are removed.
var = SCode.VAR();
dir = Absyn.INPUT();
attr = SCode.ATTR(dim,f,s,var,dir);
attr = SCode.ATTR(dim,f,s,prl,var,dir);

//Debug.fprint(Flags.REC_CONST, "inst_record_constructor_elt called\n");
(cache,cl,cenv) = Lookup.lookupClass(cache,env, t, true);
Expand Down Expand Up @@ -16417,15 +16420,16 @@ algorithm
SCode.Flow fl;
SCode.Stream st;
Absyn.Direction dir;
SCode.Parallelism prl;
SCode.Variability vt;

// if classprefix is variable, keep component variability
case(attr,Prefix.PREFIX(_,Prefix.CLASSPRE(SCode.VAR()))) then attr;
// if variability is constant, do not override it!
case(attr as SCode.ATTR(variability = SCode.CONST()),_) then attr;
// if classprefix is parameter or constant, override component variability
case(SCode.ATTR(ad,fl,st,_,dir),Prefix.PREFIX(_,Prefix.CLASSPRE(vt)))
then SCode.ATTR(ad,fl,st,vt,dir);
case(SCode.ATTR(ad,fl,st,prl,_,dir),Prefix.PREFIX(_,Prefix.CLASSPRE(vt)))
then SCode.ATTR(ad,fl,st,prl,vt,dir);
// anything else
case(attr,_) then attr;
end matchcontinue;
Expand Down
5 changes: 3 additions & 2 deletions Compiler/FrontEnd/InstExtends.mo
Expand Up @@ -875,20 +875,21 @@ algorithm
SCode.Flow fp;
SCode.Stream sp;
SCode.Variability var;
SCode.Parallelism prl;
Absyn.Direction dir;
Env.Cache cache;
Env.Env env;
HashTableStringToPath.HashTable ht;
SCode.Element elt;

case (cache,env,SCode.COMPONENT(name, prefixes, SCode.ATTR(ad, fp, sp, var, dir), typeSpec, modifications, comment, condition, info),ht)
case (cache,env,SCode.COMPONENT(name, prefixes, SCode.ATTR(ad, fp, sp, prl, var, dir), typeSpec, modifications, comment, condition, info),ht)
equation
//Debug.fprintln(Flags.DEBUG,"fix comp " +& SCodeDump.printElementStr(elt));
(cache,modifications) = fixModifications(cache,env,modifications,ht);
(cache,typeSpec) = fixTypeSpec(cache,env,typeSpec,ht);
(cache,SOME(ad)) = fixArrayDim(cache, env, SOME(ad), ht);
then
(cache,SCode.COMPONENT(name, prefixes, SCode.ATTR(ad, fp, sp, var, dir), typeSpec, modifications, comment, condition, info));
(cache,SCode.COMPONENT(name, prefixes, SCode.ATTR(ad, fp, sp, prl, var, dir), typeSpec, modifications, comment, condition, info));

case (cache,env,SCode.CLASS(name, prefixes, SCode.ENCAPSULATED(), partialPrefix, restriction, classDef, info),ht)
equation
Expand Down
3 changes: 2 additions & 1 deletion Compiler/FrontEnd/InstSection.mo
Expand Up @@ -3157,6 +3157,7 @@ algorithm
Env.Cache cache;
Absyn.InnerOuter io1,io2;
SCode.Variability vt1,vt2;
SCode.Parallelism prl;
ConnectionGraph.ConnectionGraph graph;
InstanceHierarchy ih;
String componentName;
Expand Down Expand Up @@ -3401,7 +3402,7 @@ algorithm
// declare the added component in the DAE!
(cache,c1_2) = PrefixUtil.prefixCref(cache, env, ih, pre, c1_2);
daeExpandable = Inst.daeDeclare(c1_2, state, ty1,
SCode.ATTR({}, flowPrefix1, streamPrefix1, vt1, dir1),
SCode.ATTR({}, flowPrefix1, streamPrefix1, SCode.NON_PARALLEL(), vt1, dir1),
SCode.PUBLIC(), NONE(), {}, NONE(), NONE(),
SOME(SCode.COMMENT(NONE(), SOME("virtual variable in expandable connector"))),
io1, SCode.NOT_FINAL(), source, true);
Expand Down
15 changes: 8 additions & 7 deletions Compiler/FrontEnd/Lookup.mo
Expand Up @@ -2164,6 +2164,7 @@ algorithm
SCode.Redeclare redecl;
Absyn.InnerOuter io;
list<Absyn.Subscript> d;
SCode.Parallelism prl;
SCode.Variability var;
Absyn.Direction dir;
Absyn.TypeSpec tp;
Expand All @@ -2181,7 +2182,7 @@ algorithm
SCode.COMPONENT(
id,
SCode.PREFIXES(vis, redecl, f as SCode.FINAL(), io, repl),
SCode.ATTR(d,fl,st,var,dir),tp,mod,comment,cond,info)),cmod) :: rest),mods,env)
SCode.ATTR(d,fl,st,prl,var,dir),tp,mod,comment,cond,info)),cmod) :: rest),mods,env)
equation
(_,mod_1) = Mod.elabMod(Env.emptyCache(), env, InnerOuter.emptyInstHierarchy, Prefix.NOPRE(), mod, false, info);
mod_1 = Mod.merge(mods,mod_1,env,Prefix.NOPRE());
Expand All @@ -2201,14 +2202,14 @@ algorithm
// dir = Absyn.INPUT();
vis = SCode.PROTECTED();
then
(SCode.COMPONENT(id,SCode.PREFIXES(vis,redecl,f,io,repl),SCode.ATTR(d,fl,st,var,dir),tp,umod,comment,cond,info) :: res);
(SCode.COMPONENT(id,SCode.PREFIXES(vis,redecl,f,io,repl),SCode.ATTR(d,fl,st,prl,var,dir),tp,umod,comment,cond,info) :: res);

// constants become protected, Modelica Spec 3.2, Section 12.6, Record Constructor Functions, page 140
case ((((comp as
SCode.COMPONENT(
id,
SCode.PREFIXES(vis, redecl, f, io, repl),
SCode.ATTR(d,fl,st,var as SCode.CONST(),dir),tp,mod,comment,cond,info)),cmod) :: rest),mods,env)
SCode.ATTR(d,fl,st,prl,var as SCode.CONST(),dir),tp,mod,comment,cond,info)),cmod) :: rest),mods,env)
equation
(_,mod_1) = Mod.elabMod(Env.emptyCache(), env, InnerOuter.emptyInstHierarchy, Prefix.NOPRE(), mod, false, info);
mod_1 = Mod.merge(mods,mod_1,env,Prefix.NOPRE());
Expand All @@ -2228,14 +2229,14 @@ algorithm
//dir = Absyn.INPUT();
vis = SCode.PROTECTED();
then
(SCode.COMPONENT(id,SCode.PREFIXES(vis,redecl,f,io,repl),SCode.ATTR(d,fl,st,var,dir),tp,umod,comment,cond,info) :: res);
(SCode.COMPONENT(id,SCode.PREFIXES(vis,redecl,f,io,repl),SCode.ATTR(d,fl,st,prl,var,dir),tp,umod,comment,cond,info) :: res);

// all others, add input see Modelica Spec 3.2, Section 12.6, Record Constructor Functions, page 140
case ((((comp as
SCode.COMPONENT(
id,
SCode.PREFIXES(vis, redecl, f, io, repl),
SCode.ATTR(d,fl,st,var,dir),tp,mod,comment,cond,info)),cmod) :: rest),mods,env)
SCode.ATTR(d,fl,st,prl,var,dir),tp,mod,comment,cond,info)),cmod) :: rest),mods,env)
equation
(_,mod_1) = Mod.elabMod(Env.emptyCache(), env, InnerOuter.emptyInstHierarchy, Prefix.NOPRE(), mod, false, info);
mod_1 = Mod.merge(mods,mod_1,env,Prefix.NOPRE());
Expand All @@ -2254,7 +2255,7 @@ algorithm
// var = SCode.VAR();
dir = Absyn.INPUT();
then
(SCode.COMPONENT(id,SCode.PREFIXES(vis, redecl, f, io, repl),SCode.ATTR(d,fl,st,var,dir),tp,umod,comment,cond,info) :: res);
(SCode.COMPONENT(id,SCode.PREFIXES(vis, redecl, f, io, repl),SCode.ATTR(d,fl,st,prl,var,dir),tp,umod,comment,cond,info) :: res);

case ((comp,cmod)::_,mods,_)
equation
Expand All @@ -2279,7 +2280,7 @@ algorithm
//print(" creating element of type: " +& id +& "\n");
//print(" with generated mods:" +& SCode.printSubs1Str(submodlst) +& "\n");
outElement := SCode.COMPONENT("result",SCode.defaultPrefixes,
SCode.ATTR({},SCode.NOT_FLOW(),SCode.NOT_STREAM(),SCode.VAR(),Absyn.OUTPUT()),
SCode.ATTR({},SCode.NOT_FLOW(),SCode.NOT_STREAM(),SCode.NON_PARALLEL(),SCode.VAR(),Absyn.OUTPUT()),
Absyn.TPATH(Absyn.IDENT(id),NONE()),
SCode.NOMOD(),NONE(),NONE(),Absyn.dummyInfo);
end buildRecordConstructorResultElt;
Expand Down

0 comments on commit 63308b7

Please sign in to comment.