Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /trunk/src/compiler/mid-to-low/mid-to-low.sml
ViewVC logotype

Annotation of /trunk/src/compiler/mid-to-low/mid-to-low.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 459 - (view) (download)

1 : lamonts 345 (* mid-to-low.sml
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : lamonts 345 * All rights reserved.
5 :     *
6 :     * Translation from MidIL to LowIL representations.
7 :     *)
8 :    
9 :     structure MidToLow : sig
10 :    
11 : jhr 459 val translate : MidIL.program -> LowIL.program
12 : lamonts 345
13 : jhr 387 end = struct
14 : lamonts 345
15 : jhr 387
16 : lamonts 345 structure SrcIL = MidIL
17 :     structure SrcOp = MidOps
18 : jhr 387 structure VTbl = SrcIL.Var.Tbl
19 : lamonts 345 structure DstIL = LowIL
20 :     structure DstOp = LowOps
21 :    
22 : jhr 387 type var_env = DstIL.var VTbl.hash_table
23 :    
24 :     fun rename (env : var_env, x) = (case VTbl.find env x
25 : lamonts 345 of SOME x' => x'
26 : jhr 387 | NONE => let
27 :     val x' = DstIL.Var.new (SrcIL.Var.name x)
28 :     in
29 :     VTbl.insert env (x, x');
30 :     x'
31 :     end
32 : lamonts 345 (* end case *))
33 : jhr 387 fun renameList (env, xs) = List.map (fn x => rename(env, x)) xs
34 : lamonts 345
35 : jhr 459 (* expand the EvalKernel operations into vector operations. The parameters are
36 :     * result -- the lhs variable to store the result
37 :     * d -- the vector width of the operation, which should be equal to twice the
38 :     * support of the kernel
39 :     * h -- the kernel
40 :     * k -- the derivative of the kernel to evaluate
41 :     *)
42 :     fun expandKernel (result, d, h, k) = let
43 :     val {isCont, segs} = Kernel.curve (h, k)
44 :     in
45 :     end
46 : jhr 387
47 : lamonts 345 (* compute the load address for a given set of voxels indices *)
48 : jhr 459 fun expandVoxelAddress (result, info) = ??
49 : lamonts 345
50 : jhr 431 fun expandOp (env, y, rator, args) = let
51 :     fun assign rator' =
52 :     [(y, DstIL.OP(rator', renameList(env, args)))]
53 :     in
54 :     case rator
55 : jhr 459 of SrcOp.Add ty => assign (DstOp.Add ty)
56 :     | SrcOp.Sub ty => assign (DstOp.Sub ty)
57 :     | SrcOp.Mul ty => assign (DstOp.Mul ty)
58 :     | SrcOp.Div ty => assign (DstOp.Div ty)
59 :     | SrcOp.Neg ty => assign (DstOp.Neg ty)
60 :     | SrcOp.LT ty => assign (DstOp.LT ty)
61 :     | SrcOp.LTE ty => assign (DstOp.LTE ty)
62 :     | SrcOp.EQ ty => assign (DstOp.EQ ty)
63 :     | SrcOp.NEQ ty => assign (DstOp.NEQ ty)
64 :     | SrcOp.GT ty => assign (DstOp.GT ty)
65 :     | SrcOp.GTE ty => assign (DstOp.GTE ty)
66 :     | SrcOp.Not => assign (DstOp.Not)
67 :     | SrcOp.Max => assign (DstOp.Max)
68 :     | SrcOp.Min => assign (DstOp.Min)
69 :     | SrcOp.Sin => assign (DstOp.Sin)
70 :     | SrcOp.Cos => assign (DstOp.Cos)
71 :     | SrcOp.Pow => assign (DstOp.Pow)
72 :     | SrcOp.Dot d => assign (DstOp.Dot d)
73 :     | SrcOp.Cross => assign (DstOp.Cross)
74 :     | SrcOp.Select ty => assign (DstOp.Select ty) * int
75 :     | SrcOp.Norm d => assign (DstOp.Norm d)
76 :     | SrcOp.Scale d => assign (DstOp.Scale d)
77 :     | SrcOp.InvScale d => assign (DstOp.InvScale d)
78 :     | SrcOp.CL => assign (DstOp.CL)
79 :     | SrcOp.PrincipleEvec ty => assign (DstOp.PrincipleEvec ty)
80 :     | SrcOp.Subscript ty => assign (DstOp.Subscript ty)
81 :     | SrcOp.Floor d => assign (DstOp.Floor d)
82 :     | SrcOp.IntToReal => assign (DstOp.IntToReal)
83 :     | SrcOp.TruncToInt d => assign (DstOp.TruncToInt d)
84 :     | SrcOp.RoundToInt d => assign (DstOp.RoundToInt d)
85 :     | SrcOp.CeilToInt d => assign (DstOp.CeilToInt d)
86 :     | SrcOp.FloorToInt d => assign (DstOp.FloorToInt d)
87 :     | SrcOp.VoxelAddress info => expandVoxelAddress (y, info)
88 :     | SrcOp.LoadVoxels(rty, d) => assign (DstOp.LoadVoxels(rty, d))
89 :     | SrcOp.Transform info => assign (DstOp.Transform info)
90 :     | SrcOp.EvalKernel(d, h, k) => expandEvalKernel(y, d, h, k)
91 :     | SrcOp.LoadImage info => assign (DstOp.LoadImage info)
92 :     | SrcOp.Inside info => assign (DstOp.Inside info)
93 :     | SrcOp.Input(ty, name) => assign (DstOp.Input(ty, name))
94 :     | SrcOp.InputWithDefault(ty, name) => assign (DstOp.InputWithDefault(ty, name))
95 : jhr 431 | _ => raise Fail("unexpected " ^ SrcOp.toString rator)
96 :     (* end case *)
97 :     end
98 :    
99 : jhr 387 (* expand a SrcIL assignment to a list of DstIL assignments *)
100 :     fun expand (env, (y, rhs)) = let
101 :     val y' = rename (env, y)
102 :     fun assign rhs = [(y', rhs)]
103 :     in
104 :     case rhs
105 :     of SrcIL.VAR x => assign (DstIL.VAR(rename(env, x)))
106 :     | SrcIL.LIT lit => assign (DstIL.LIT lit)
107 :     | SrcIL.OP(rator, args) => expandOp (env, y', rator, args)
108 :     | SrcIL.CONS args => assign (DstIL.CONS(renameList(env, args)))
109 :     (* end case *)
110 :     end
111 : lamonts 345
112 : jhr 387 structure Trans = TranslateFn (
113 :     struct
114 :     structure SrcIL = SrcIL
115 :     structure DstIL = DstIL
116 :    
117 :     type var_env = var_env
118 :    
119 :     val rename = rename
120 :     val expand = expand
121 :     end)
122 :    
123 :     fun translate (SrcIL.Program{globals, globalInit, actors}) = let
124 :     val env = VTbl.mkTable (256, Fail "env")
125 :     fun transMethod (SrcIL.Method{name, stateIn, stateOut, body}) =
126 :     DstIL.Method{
127 :     name = name,
128 :     stateIn = renameList (env, stateIn),
129 :     stateOut = renameList (env, stateOut),
130 :     body = Trans.translate (env, body)
131 :     }
132 :     fun transActor (SrcIL.Actor{name, params, state, stateInit, methods}) =
133 :     DstIL.Actor{
134 :     name = name,
135 :     params = renameList (env, params),
136 :     state = renameList (env, state),
137 :     stateInit = Trans.translate (env, stateInit),
138 :     methods = List.map transMethod methods
139 :     }
140 :     in
141 :     DstIL.Program{
142 :     globals = renameList (env, globals),
143 :     globalInit = Trans.translate (env, globalInit),
144 :     actors = List.map transActor actors
145 :     }
146 :     end
147 :    
148 : jhr 435 end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0