25 |
structure VSet = Var.Set |
structure VSet = Var.Set |
26 |
structure VMap = Var.Map |
structure VMap = Var.Map |
27 |
|
|
28 |
(* the kinds of things a variable in Simple AST can be bound to *) |
(* identify the image load operations and their antecedents; in terms of BTA, |
|
datatype var_binding |
|
|
= RHS of S.exp |
|
|
| Param |
|
|
|
|
|
(* identify the image load operations and lift them and their antecedents; in terms of BTA, |
|
29 |
* this phase is essentially determining what must be static in order to get the image |
* this phase is essentially determining what must be static in order to get the image |
30 |
* info needed for the rest of the compile. |
* info needed for the rest of the compile. |
31 |
*) |
*) |
32 |
fun liftLoads block = let |
fun findStatics block = let |
33 |
(* analysis to compute the set of static variables *) |
(* analysis to compute the set of static variables *) |
34 |
fun mkStatic (env, statics, x) = if VSet.member(statics, x) |
fun mkStatic (env, statics, x) = if VSet.member(statics, x) |
35 |
then statics |
then statics |
82 |
| _ => (env, statics) |
| _ => (env, statics) |
83 |
(* end case *)) |
(* end case *)) |
84 |
val statics = doBlock (VMap.empty, VSet.empty, block) |
val statics = doBlock (VMap.empty, VSet.empty, block) |
|
(* lift out the static code *) |
|
|
fun doBlock (S.Block stms) = let |
|
|
fun doStmts ([], staticStms) = S.Block(List.rev staticStms) |
|
|
| doStmts (stm::stms, staticStms) = (case doStmt stm |
|
|
of SOME stm => doStmts (stms, stm::staticStms) |
|
|
| NONE => doStmts (stms, staticStms) |
|
|
(* end case *)) |
|
|
in |
|
|
doStmts (stms, []) |
|
|
end |
|
|
and doStmt stm = (case stm |
|
|
of S.S_Assign(x, e) => if VSet.member(statics, x) |
|
|
then SOME stm |
|
|
else NONE |
|
|
| S.S_IfThenElse(x, b1, b2) => if VSet.member(statics, x) |
|
|
then SOME(S.S_IfThenElse(x, doBlock b1, doBlock b2)) |
|
|
else NONE |
|
|
| _ => NONE |
|
|
(* end case *)) |
|
|
val staticBlock = doBlock block |
|
85 |
in |
in |
86 |
Log.msg "**** static variables: "; |
Log.msg "**** static variables: "; |
87 |
VSet.app (fn x => Log.msg(" "^Var.uniqueNameOf x)) statics; |
VSet.app (fn x => Log.msg(" "^Var.uniqueNameOf x)) statics; |
88 |
Log.msg "\n"; |
Log.msg "\n"; |
89 |
staticBlock |
statics |
90 |
end |
end |
91 |
|
|
92 |
(* given values for the static variables; reduce the static initialization code *) |
(* given values for the static variables; reduce the static initialization code *) |
121 |
end |
end |
122 |
|
|
123 |
fun transform (prog as S.Program{globals, globalInit, actors}) = let |
fun transform (prog as S.Program{globals, globalInit, actors}) = let |
124 |
val staticInit = liftLoads globalInit |
val statics = findStatics globalInit |
125 |
val staticEnv = Eval.evalStatics staticInit |
val staticEnv = Eval.evalStatics (statics, globalInit) |
126 |
val globalInit = reduce (staticEnv, globalInit) |
val globalInit = reduce (staticEnv, globalInit) |
127 |
in |
in |
128 |
S.Program{ |
S.Program{ |