27 |
| cvtTy SrcTy.IntTy = DstTy.intTy |
| cvtTy SrcTy.IntTy = DstTy.intTy |
28 |
| cvtTy (SrcTy.TensorTy[]) = DstTy.realTy |
| cvtTy (SrcTy.TensorTy[]) = DstTy.realTy |
29 |
| cvtTy (SrcTy.TensorTy[d]) = DstTy.VecTy d |
| cvtTy (SrcTy.TensorTy[d]) = DstTy.VecTy d |
30 |
| cvtTy _ = raise Fail "unexpected higher-order tensor type" |
| cvtTy SrcTy.ImageTy = DstTy.ImageTy |
31 |
|
| cvtTy ty = raise Fail("unexpected type " ^ SrcTy.toString ty) |
32 |
|
|
33 |
fun rename (env : var_env, x) = (case VTbl.find env x |
fun rename (env : var_env, x) = (case VTbl.find env x |
34 |
of SOME x' => x' |
of SOME x' => x' |
113 |
| SrcOp.Inside => (case args |
| SrcOp.Inside => (case args |
114 |
of [pos, fld] => expandInside(env, y, pos, fld) |
of [pos, fld] => expandInside(env, y, pos, fld) |
115 |
(* end case *)) |
(* end case *)) |
116 |
(* QUESTION: there is no MidIL equivalant, but these might be floating |
| SrcOp.Field fld => raise Fail "impossible" |
|
* around, which could cause invalid MidIL to be generated. |
|
|
*) |
|
|
| SrcOp.Field fld => [] |
|
117 |
| SrcOp.Probe => (case args |
| SrcOp.Probe => (case args |
118 |
of [fld, pos] => expandProbe(env, y, fld, pos) |
of [fld, pos] => expandProbe(env, y, fld, pos) |
119 |
(* end case *)) |
(* end case *)) |
125 |
|
|
126 |
(* expand a SrcIL assignment to a list of DstIL assignments *) |
(* expand a SrcIL assignment to a list of DstIL assignments *) |
127 |
fun expand (env, (y, rhs)) = let |
fun expand (env, (y, rhs)) = let |
128 |
val y' = rename (env, y) |
fun assign rhs = [(rename (env, y), rhs)] |
|
fun assign rhs = [(y', rhs)] |
|
129 |
in |
in |
130 |
case rhs |
case rhs |
131 |
of SrcIL.VAR x => assign (DstIL.VAR(rename(env, x))) |
of SrcIL.VAR x => assign (DstIL.VAR(rename(env, x))) |
132 |
| SrcIL.LIT lit => assign (DstIL.LIT lit) |
| SrcIL.LIT lit => assign (DstIL.LIT lit) |
133 |
| SrcIL.OP(rator, args) => expandOp (env, y', rator, args) |
| SrcIL.OP(SrcOp.Field _, args) => [] |
134 |
|
| SrcIL.OP(rator, args) => expandOp (env, rename (env, y), rator, args) |
135 |
| SrcIL.CONS args => assign (DstIL.CONS(renameList(env, args))) |
| SrcIL.CONS args => assign (DstIL.CONS(renameList(env, args))) |
136 |
(* end case *) |
(* end case *) |
137 |
end |
end |
164 |
stateInit = Trans.translate (env, stateInit), |
stateInit = Trans.translate (env, stateInit), |
165 |
methods = List.map transMethod methods |
methods = List.map transMethod methods |
166 |
} |
} |
167 |
|
(* filter out field variables, since they will be made explicit in |
168 |
|
* the MidIL. |
169 |
|
*) |
170 |
|
val globals = let |
171 |
|
fun filter x = (case SrcIL.Var.ty x |
172 |
|
of SrcTy.FieldTy => NONE |
173 |
|
| _ => SOME x |
174 |
|
(* end case *)) |
175 |
|
in |
176 |
|
List.mapPartial filter globals |
177 |
|
end |
178 |
in |
in |
179 |
DstIL.Program{ |
DstIL.Program{ |
180 |
globals = renameList (env, globals), |
globals = renameList (env, globals), |