40 |
| S.E_Cons args => [(lhs, IL.CONS(List.map (lookup env) args))] |
| S.E_Cons args => [(lhs, IL.CONS(List.map (lookup env) args))] |
41 |
(* end case *)) |
(* end case *)) |
42 |
|
|
43 |
|
fun cvtBlock (env, S.Block stms) = |
44 |
|
|
45 |
(* convert a statement, where env is the mapping from Simple AST variables to |
(* convert a statement, where env is the mapping from Simple AST variables to |
46 |
* their current SSA name, assigned is the set of AST variables assigned to |
* their current SSA name, assigned is the set of AST variables assigned to |
47 |
* in the current context, and stm is the statement to convert. |
* in the current context, and stm is the statement to convert. |
48 |
*) |
*) |
49 |
and cvtStmt (env, assigned, stm, preStms, k) = (case stm |
and cvtStmt (env, assigned, stm, preStms, k) = (case stm |
50 |
of S.S_Block stms => |
of S.S_Assign(x, e) => let |
|
| S.S_Assign(x, e) => let |
|
51 |
val x' = newVar x |
val x' = newVar x |
52 |
val stms = cvtExp(env, x', e) |
val stms = cvtExp(env, x', e) |
53 |
val assigned = VSet.add(assigned, x) |
val assigned = VSet.add(assigned, x) |
55 |
in |
in |
56 |
k (env, assigned, stm::preStms) |
k (env, assigned, stm::preStms) |
57 |
end |
end |
58 |
| S.S_IfThenElse(x, s1, s2) => |
| S.S_IfThenElse(x, b1, b2) => let |
59 |
|
val x' = lookup env x |
60 |
|
val (b1, env1, assigned1) = block(env, b1) |
61 |
|
val (b2, env2, assigned2) = block(env, b2) |
62 |
|
val assigned = VSet.union(assigned1, assigned2) |
63 |
|
val (env, phis) = let |
64 |
|
fun mkPhi (x, (env, phis) = let |
65 |
|
val x1 = lookup(env1, x) |
66 |
|
val x2 = lookup(env2, x) |
67 |
|
val x' = newVar x |
68 |
|
in |
69 |
|
(VMap.insert(env, x, x'), (x', [x1, x2])::phis) |
70 |
|
end |
71 |
|
in |
72 |
|
VSet.foldl mkPhi (env, []) assigned |
73 |
|
end |
74 |
|
in |
75 |
|
end |
76 |
| S.S_New(name, xs) => |
| S.S_New(name, xs) => |
77 |
| S.S_Die => |
| S.S_Die => |
78 |
| S.S_Stabilize => |
| S.S_Stabilize => |
79 |
(* end case *)) |
(* end case *)) |
80 |
|
|
81 |
|
fun newBlock (??, stm) = |
82 |
|
|
83 |
|
and nextStmt (env, assigned, stm, ??) = |
84 |
|
|
85 |
|
and join (env |
86 |
fun translate (S.Program{globals, globaInit, actors}) = ?? |
fun translate (S.Program{globals, globaInit, actors}) = ?? |
87 |
|
|
88 |
end |
end |