102 |
*) |
*) |
103 |
fun translateStmts (env, stm) = let |
fun translateStmts (env, stm) = let |
104 |
val renameNd = renameNd env |
val renameNd = renameNd env |
105 |
|
(* set the CFG edges of the node corresponding to the source node *) |
106 |
|
fun setEdges (srcNd as SrcIL.ND{kind, ...}) = let |
107 |
|
val dstNd as DstIL.ND{kind=dstKind, ...} = renameNd srcNd |
108 |
|
in |
109 |
|
case kind |
110 |
|
of SrcIL.NULL => raise Fail "unexpected NULL node" |
111 |
|
| SrcIL.ENTRY{succ} => DstNd.setSucc(dstNd, renameNd(!succ)) |
112 |
|
| SrcIL.JOIN{preds, succ, ...} => let |
113 |
|
val DstIL.JOIN{preds=dstPreds, ...} = dstKind |
114 |
|
in |
115 |
|
dstPreds := List.map renameNd (!preds); |
116 |
|
DstNd.setSucc (dstNd, renameNd(!succ)) |
117 |
|
end |
118 |
|
| SrcIL.COND{pred, trueBranch, falseBranch, ...} => ( |
119 |
|
DstNd.setPred (dstNd, renameNd(!pred)); |
120 |
|
DstNd.setTrueBranch (dstNd, renameNd(!trueBranch)); |
121 |
|
DstNd.setFalseBranch (dstNd, renameNd(!falseBranch))) |
122 |
|
| SrcIL.BLOCK{pred, succ, ...} => ( |
123 |
|
DstNd.setPred (dstNd, renameNd(!pred)); |
124 |
|
DstNd.setSucc (dstNd, renameNd(!succ))) |
125 |
|
| SrcIL.NEW{pred, succ, ...} => ( |
126 |
|
DstNd.setPred (dstNd, renameNd(!pred)); |
127 |
|
DstNd.setSucc (dstNd, renameNd(!succ))) |
128 |
|
| SrcIL.DIE{pred} => DstNd.setPred (dstNd, renameNd(!pred)) |
129 |
|
| SrcIL.STABILIZE{pred} => DstNd.setPred (dstNd, renameNd(!pred)) |
130 |
|
| SrcIL.EXIT{pred} => DstNd.setPred (dstNd, renameNd(!pred)) |
131 |
|
(* end case *) |
132 |
|
end |
133 |
|
(* translate statements *) |
134 |
fun trans (SrcIL.STM{kind, next, ...}) = let |
fun trans (SrcIL.STM{kind, next, ...}) = let |
135 |
fun new kind' = DstStm.new(kind', Option.map trans next) |
fun new kind' = DstStm.new(kind', Option.map trans next) |
136 |
in |
in |
149 |
(* end case *) |
(* end case *) |
150 |
end |
end |
151 |
in |
in |
152 |
|
SrcIL.applyToNodes setEdges stm; |
153 |
trans stm |
trans stm |
154 |
end |
end |
155 |
|
|