1 : |
jhr |
280 |
(* high-to-mid.sml
|
2 : |
|
|
*
|
3 : |
|
|
* COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
|
4 : |
|
|
* All rights reserved.
|
5 : |
|
|
*
|
6 : |
|
|
* Translation from HighIL to MidIL representations.
|
7 : |
|
|
*)
|
8 : |
|
|
|
9 : |
|
|
structure HighToMid : sig
|
10 : |
|
|
|
11 : |
|
|
val translate : HighIL.program -> MidIL.program
|
12 : |
|
|
|
13 : |
|
|
end = struct
|
14 : |
|
|
|
15 : |
|
|
structure SrcIL = HighIL
|
16 : |
jhr |
334 |
structure SrcOp = HighOps
|
17 : |
jhr |
280 |
structure DstIL = MidIL
|
18 : |
jhr |
334 |
structure DstOp = MidOps
|
19 : |
jhr |
280 |
structure VMap = SrcIL.Var.Map
|
20 : |
|
|
|
21 : |
jhr |
334 |
fun lookupVar (env, x) = (case VMap.find(env, x)
|
22 : |
|
|
of SOME x' => x'
|
23 : |
|
|
| NONE => raise Fail("unknown variable "^SrcIL.Var.toString x)
|
24 : |
|
|
(* end case *))
|
25 : |
|
|
|
26 : |
jhr |
280 |
(* expand the field Inside operator into a image-space test *)
|
27 : |
|
|
fun expandInside (env, result, pos, fld) = let
|
28 : |
|
|
val pos' = lookupVar (env, pos)
|
29 : |
|
|
val fld = (case valueOf fld
|
30 : |
|
|
of SrcIL.OP(SrcOp.Field fld, []) => fld
|
31 : |
|
|
| _ => raise Fail "bogus field binding"
|
32 : |
|
|
(* end case *))
|
33 : |
jhr |
328 |
fun expand (FieldDef.CONV(_, img, _)) = let
|
34 : |
jhr |
334 |
val imgPos = DstIL.Var.new "x"
|
35 : |
jhr |
280 |
in [
|
36 : |
|
|
(imgPos, DstIL.OP(DstOp.Transform img, [pos'])),
|
37 : |
|
|
(result, DstIL.OP(DstOp.Inside img, [imgPos]))
|
38 : |
|
|
] end
|
39 : |
jhr |
328 |
| expand (FieldDef.NEG fld) = expand fld
|
40 : |
|
|
| expand (FieldDef.SUM(fld1, dlf2)) = raise Fail "expandInside: SUM"
|
41 : |
jhr |
280 |
in
|
42 : |
|
|
expand fld
|
43 : |
|
|
end
|
44 : |
|
|
|
45 : |
jhr |
334 |
val expandProbe = Probe.expand
|
46 : |
|
|
|
47 : |
jhr |
328 |
fun translate prog = raise Fail "FIXME"
|
48 : |
jhr |
314 |
|
49 : |
jhr |
280 |
end
|