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

SCM Repository

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

Annotation of /branches/charisee/src/compiler/mid-to-low/mid-to-low.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2400 - (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 :     structure SrcIL = MidIL
16 :     structure SrcOp = MidOps
17 : jhr 1640 structure SrcSV = SrcIL.StateVar
18 :     structure SrcTy = MidILTypes
19 : jhr 387 structure VTbl = SrcIL.Var.Tbl
20 : lamonts 345 structure DstIL = LowIL
21 : jhr 464 structure DstTy = LowILTypes
22 : lamonts 345 structure DstOp = LowOps
23 :    
24 : jhr 1640 (* instantiate the translation environment *)
25 :     local
26 :     type var_env = DstIL.var VTbl.hash_table
27 :     type state_var_env = DstIL.state_var SrcSV.Tbl.hash_table
28 : jhr 387
29 : jhr 1640 fun rename (env : var_env, x) = (case VTbl.find env x
30 :     of SOME x' => x'
31 :     | NONE => let
32 :     val x' = DstIL.Var.new (SrcIL.Var.name x, SrcIL.Var.ty x)
33 :     in
34 :     VTbl.insert env (x, x');
35 :     x'
36 :     end
37 :     (* end case *))
38 : lamonts 345
39 : jhr 1640 fun renameSV (env : state_var_env, x) = (case SrcSV.Tbl.find env x
40 :     of SOME x' => x'
41 :     | NONE => let
42 :     val x' = DstIL.StateVar.new (SrcSV.isOutput x, SrcSV.name x, SrcSV.ty x)
43 :     in
44 :     SrcSV.Tbl.insert env (x, x');
45 :     x'
46 :     end
47 :     (* end case *))
48 :     in
49 :     structure Env = TranslateEnvFn (
50 :     struct
51 :     structure SrcIL = SrcIL
52 :     structure DstIL = DstIL
53 :     type var_env = var_env
54 :     type state_var_env = state_var_env
55 :     val rename = rename
56 :     val renameSV = renameSV
57 :     end)
58 :     end (* local *)
59 :    
60 : jhr 463 (* convert a rational to a FloatLit.float value. We do this by long division
61 :     * with a cutoff when we get to 12 digits.
62 :     *)
63 : cchiw 2398
64 : jhr 463 fun ratToFloat r = (case Rational.explode r
65 : jhr 464 of {sign=0, ...} => FloatLit.zero false
66 : jhr 2356 | {sign, num, denom=1} => FloatLit.fromInt(IntInf.fromInt sign * num)
67 : jhr 463 | {sign, num, denom} => let
68 :     (* normalize so that num <= denom *)
69 :     val (denom, exp) = let
70 :     fun lp (n, denom) = if (denom < num)
71 :     then lp(n+1, denom*10)
72 : jhr 464 else (denom, n)
73 : jhr 463 in
74 : jhr 464 lp (1, denom)
75 : jhr 463 end
76 :     (* normalize so that num <= denom < 10*num *)
77 : jhr 464 val (num, exp) = let
78 :     fun lp (n, num) = if (10*num < denom)
79 :     then lp(n-1, 10*num)
80 :     else (num, n)
81 :     in
82 :     lp (exp, num)
83 :     end
84 : jhr 463 (* divide num/denom, computing the resulting digits *)
85 :     fun divLp (n, a) = let
86 :     val (q, r) = IntInf.divMod(a, denom)
87 :     in
88 :     if (r = 0) then (q, [])
89 :     else if (n < 12) then let
90 :     val (d, dd) = divLp(n+1, 10*r)
91 :     in
92 : jhr 464 if (d < 10)
93 :     then (q, (IntInf.toInt d)::dd)
94 :     else (q+1, 0::dd)
95 : jhr 463 end
96 :     else if (IntInf.div(10*r, denom) < 5)
97 :     then (q, [])
98 :     else (q+1, []) (* round up *)
99 :     end
100 : jhr 464 val digits = let
101 :     val (d, dd) = divLp (0, num)
102 :     in
103 :     (IntInf.toInt d)::dd
104 :     end
105 : jhr 463 in
106 : jhr 464 FloatLit.fromDigits{isNeg=(sign < 0), digits=digits, exp=exp}
107 : jhr 463 end
108 : jhr 464 (* end case *))
109 : jhr 463
110 : cchiw 2397 (*Note, do we need types?
111 :     fun imul (r : DstIL.var, a, b) = (r, DstIL.OP(DstOp.IMul DstTy.intTy, [a, b]))
112 :     fun iadd (r : DstIL.var, a, b) = (r, DstIL.OP(DstOp.IAdd DstTy.intTy, [a, b]))
113 :     fun ilit (r : DstIL.var, n) = (r, DstIL.LIT(Literal.Int(IntInf.fromInt n)))
114 :     fun radd (r : DstIL.var, a, b) = (r, DstIL.OP(DstOp.IAdd DstTy.realTy, [a, b]))
115 :     *)
116 : cchiw 2398
117 : cchiw 2397 fun imul (r : DstIL.var, a, b) = (r, DstIL.OP(DstOp.IMul, [a, b]))
118 :     fun iadd (r : DstIL.var, a, b) = (r, DstIL.OP(DstOp.IAdd, [a, b]))
119 : jhr 1116 fun ilit (r : DstIL.var, n) = (r, DstIL.LIT(Literal.Int(IntInf.fromInt n)))
120 : cchiw 2397 fun radd (r : DstIL.var, a, b) = (r, DstIL.OP(DstOp.IAdd, [a, b]))
121 : jhr 511
122 : cchiw 2398
123 :    
124 : jhr 465 (* expand the EvalKernel operations into vector operations. The parameters
125 :     * are
126 : jhr 459 * result -- the lhs variable to store the result
127 : jhr 465 * d -- the vector width of the operation, which should be equal
128 :     * to twice the support of the kernel
129 : jhr 459 * h -- the kernel
130 :     * k -- the derivative of the kernel to evaluate
131 : jhr 465 *
132 :     * The generated code is computing
133 :     *
134 :     * result = a_0 + x*(a_1 + x*(a_2 + ... x*a_n) ... )
135 :     *
136 :     * as a d-wide vector operation, where n is the degree of the kth derivative
137 :     * of h and the a_i are coefficient vectors that have an element for each
138 :     * piece of h. The computation is implemented as follows
139 :     *
140 :     * m_n = x * a_n
141 :     * s_{n-1} = a_{n-1} + m_n
142 :     * m_{n-1} = x * s_{n-1}
143 :     * s_{n-2} = a_{n-2} + m_{n-1}
144 :     * m_{n-2} = x * s_{n-2}
145 :     * ...
146 :     * s_1 = a_1 + m_2
147 :     * m_1 = x * s_1
148 :     * result = a_0 + m_1
149 : jhr 1116 *
150 :     * Note that the coeffient vectors are flipped (cf high-to-low/probe.sml).
151 : jhr 459 *)
152 : cchiw 2397
153 :    
154 :     (****************************)
155 :     (*Note, assuming Mult->IMult,
156 :     since otherwise would have created a tensor multiply or a scale.
157 :    
158 :     *)
159 :     fun decideAdd(n, arg)= case n
160 :     of DstTy.vecTy 1 => DstIL.OP(DstOp.IAdd, arg)
161 :     | DstTy.IntTy => DstIL.OP(DstOp.IAdd, arg)
162 :     |_ => let
163 :     val shape = shapeVarToTensor sv
164 :     val operator = EinOp.addTensors
165 : cchiw 2398 in
166 : cchiw 2397 DSTIL.EINAPP(S.transform(operator,[len(shape), shape]), n )
167 : cchiw 2398 end
168 : cchiw 2397
169 :    
170 :     (****************************)
171 :    
172 : cchiw 2400 (*Is coeff val ints? if so don't need decideadd function, can just used addI *)
173 :    
174 :     fun expandEvalKernel (result, d, h, k, [x]) = let
175 : jhr 459 val {isCont, segs} = Kernel.curve (h, k)
176 : jhr 465 (* degree of polynomial *)
177 :     val deg = List.length(hd segs) - 1
178 : jhr 463 (* convert to a vector of vectors to give fast access *)
179 : jhr 1116 val segs = Vector.fromList (List.rev (List.map Vector.fromList segs))
180 : jhr 463 (* get the kernel coefficient value for the d'th term of the i'th
181 :     * segment.
182 :     *)
183 : jhr 465 fun coefficient d i =
184 :     Literal.Float(ratToFloat (Vector.sub (Vector.sub(segs, i), d)))
185 : jhr 1116 val ty = DstTy.vecTy d
186 : jhr 463 val coeffs = List.tabulate (deg+1,
187 : jhr 465 fn i => DstIL.Var.new("a"^Int.toString i, ty))
188 : cchiw 2400
189 : jhr 464 (* code to define the coefficient vectors *)
190 :     val coeffVecs = let
191 :     fun mk (x, (i, code)) = let
192 :     val lits = List.tabulate(d, coefficient i)
193 :     val vars = List.tabulate(d, fn _ => DstIL.Var.new("_f", DstTy.realTy))
194 :     val code =
195 :     ListPair.map (fn (x, lit) => (x, DstIL.LIT lit)) (vars, lits) @
196 : jhr 1116 (x, DstIL.CONS(DstIL.Var.ty x, vars)) :: code
197 : jhr 464 in
198 :     (i-1, code)
199 :     end
200 :     in
201 :     #2 (List.foldr mk (deg, []) coeffs)
202 :     end
203 : jhr 463 (* build the evaluation of the polynomials in reverse order *)
204 : jhr 465 fun pTmp i = DstIL.Var.new("prod" ^ Int.toString i, ty)
205 :     fun sTmp i = DstIL.Var.new("sum" ^ Int.toString i, ty)
206 :     fun eval (i, [coeff]) = let
207 :     val m = pTmp i
208 : cchiw 2397
209 : jhr 465 in
210 : cchiw 2397 (*(m, [(m, DstIL.OP(DstOp.Mul ty, [x, coeff]) )])*)
211 :    
212 :     (m, [(m, DstIL.OP(DstOp.IMul, [x, coeff]) )])
213 : jhr 465 end
214 : jhr 467 | eval (i, coeff::r) = let
215 : jhr 465 val (m, stms) = eval(i+1, r)
216 :     val s = sTmp i
217 : jhr 467 val m' = pTmp i
218 : cchiw 2397
219 :     (*val stms =
220 :     (m', DstIL.OP(DstOp.IMul ty, [x, s])) ::
221 :     (s, DstIL.OP(DstOp.IAdd ty, [coeff, m])) ::
222 :     stms*)
223 :    
224 :     val replaceAdd= decideAdd(ty, [coeff, m])
225 : cchiw 2400 (*I think add here is just used on ints, so don't need decideAdd function*)
226 : jhr 463 val stms =
227 : cchiw 2397 (m', DstIL.OP(DstOp.IMul, [x, s])) ::
228 :     (s, replaceAdd) ::
229 :     stms
230 :    
231 :    
232 : jhr 463 in
233 : jhr 465 (m', stms)
234 : jhr 463 end
235 : jhr 1116 val evalCode = (case coeffs
236 :     of [a0] => (* constant function *)
237 :     [(result, DstIL.VAR a0)]
238 :     | a0::r => let
239 :     val (m, stms) = eval (1, r)
240 : cchiw 2400
241 : cchiw 2398 val replaceAdd=decideAdd(ty, [a0,m])
242 :     in
243 :     List.rev ((result, replaceAdd)::stms)
244 :     (*List.rev ((result, DstIL.OP(DstOp.IAdd ty, [a0, m]))::stms)*)
245 :    
246 :     end
247 : jhr 1116 (* end case *))
248 : jhr 459 in
249 : jhr 464 coeffVecs @ evalCode
250 : jhr 459 end
251 : jhr 387
252 : jhr 1116 (* FIXME: we will get better down-stream CSE if we structure the address computation
253 :     * as
254 :     * (base + stride * (...)) + offset
255 :     * since the lhs argument will be the same for each sample.
256 :     *)
257 :     (* add code to handle the offset and stride when addressing non-scalar image data *)
258 :     fun adjustForStrideAndOffset (1, _, ix, code) = (ix, code)
259 :     | adjustForStrideAndOffset (stride, 0, ix, code) = let
260 :     val offp = DstIL.Var.new ("offp", DstTy.intTy)
261 :     val stride' = DstIL.Var.new ("stride", DstTy.intTy)
262 :     in
263 :     (offp, imul(offp, stride', ix) :: ilit(stride', stride) :: code)
264 :     end
265 :     | adjustForStrideAndOffset (stride, offset, ix, code) = let
266 :     val offp = DstIL.Var.new ("offp", DstTy.intTy)
267 :     val stride' = DstIL.Var.new ("stride", DstTy.intTy)
268 :     val offset' = DstIL.Var.new ("offset", DstTy.intTy)
269 :     val t = DstIL.Var.new ("t", DstTy.intTy)
270 :     val code =
271 :     iadd(offp, offset', t) ::
272 :     ilit (offset', offset) ::
273 :     imul(t, stride', ix) ::
274 :     ilit (stride', stride) ::
275 :     code
276 :     in
277 :     (offp, code)
278 :     end
279 :    
280 : jhr 465 (* compute the load address for a given set of voxels indices. For the
281 :     * operation
282 :     *
283 : jhr 1116 * VoxelAddress<info,offset>(i_1, ..., i_d)
284 : jhr 465 *
285 :     * the address is given by
286 :     *
287 : jhr 1116 * base + offset + stride * (i_1 + N_1 * (i_2 + N_2 * (... + N_{d-1} * i_d) ...))
288 : jhr 465 *
289 :     * where
290 :     * base -- base address of the image data
291 : jhr 1116 * stride -- number of samples per voxel
292 :     * offset -- offset of sample being addressed
293 : jhr 465 * N_i -- size of ith axis in elements
294 : jhr 1116 *
295 :     * Note that we are following the Nrrd convention that the axes are ordered
296 :     * in fastest to slowest order. We are also assuming the C semantics of address
297 :     * arithmetic, where the offset will be automatically scaled by the size of the
298 :     * elements.
299 : jhr 465 *)
300 : cchiw 2398
301 :    
302 : jhr 1116 fun expandVoxelAddress (result, info, offset, [img, ix]) = let
303 :     val dim = ImageInfo.dim info
304 :     val stride = ImageInfo.stride info
305 :     val shape = ImageInfo.voxelShape info
306 :     val (offp, code) = adjustForStrideAndOffset (stride, offset, ix, [])
307 :     val addrTy = DstTy.AddrTy info
308 :     val base = DstIL.Var.new ("imgBaseAddr", addrTy)
309 : cchiw 2398
310 :     (*Add here is of address type, assume it is okay to keep IADD since not tensors*)
311 : cchiw 2397 val code = (result, DstIL.OP(DstOp.IAdd addrTy, [base, offp])) ::
312 : jhr 1116 (base, DstIL.OP(DstOp.ImageAddress info, [img])) ::
313 :     code
314 :     in
315 :     List.rev code
316 :     end
317 :     | expandVoxelAddress (result, info, offset, img::ix1::indices) = let
318 :     val dim = ImageInfo.dim info
319 :     val sizes = ImageInfo.sizes info
320 :     val stride = ImageInfo.stride info
321 :     val shape = ImageInfo.voxelShape info
322 :     (* get N_1 ... N_{d-1} *)
323 : jhr 2356 (* FIXME: sizes is [] when the image does not have a proxy *)
324 : jhr 1116 val sizes = List.take (sizes, List.length sizes - 1)
325 : jhr 511 (* generate the address computation code in reverse order *)
326 :     fun gen (d, [n], [ix]) = let
327 :     val n' = DstIL.Var.new ("n" ^ Int.toString d, DstTy.intTy)
328 :     val t = DstIL.Var.new ("t", DstTy.intTy)
329 :     val code = [
330 :     imul(t, n', ix),
331 : jhr 1116 ilit(n', n)
332 : jhr 511 ]
333 :     in
334 :     (t, code)
335 :     end
336 :     | gen (d, n::ns, ix::ixs) = let
337 :     val n' = DstIL.Var.new ("n" ^ Int.toString d, DstTy.intTy)
338 :     val t1 = DstIL.Var.new ("t1", DstTy.intTy)
339 :     val t2 = DstIL.Var.new ("t2", DstTy.intTy)
340 :     val (t, code) = gen (d+1, ns, ixs)
341 :     val code =
342 :     imul(t2, n', t1) ::
343 : jhr 1116 ilit(n', n) ::
344 : jhr 511 iadd(t1, ix, t) :: code
345 :     in
346 :     (t2, code)
347 :     end
348 : jhr 2356 (* FIXME: sizes is [] when the image does not have a proxy *)
349 : jhr 1116 val (tmp, code) = gen (0, sizes, indices)
350 :     val t = DstIL.Var.new ("index", DstTy.intTy)
351 :     val code = iadd(t, ix1, tmp) :: code
352 :     val (offp, code) = adjustForStrideAndOffset (stride, offset, t, code)
353 :     val addrTy = DstTy.AddrTy info
354 :     val base = DstIL.Var.new ("imgBaseAddr", addrTy)
355 : cchiw 2397 val code = (result, DstIL.OP(DstOp.IAdd addrTy, [base, offp])) ::
356 : jhr 1116 (base, DstIL.OP(DstOp.ImageAddress info, [img])) ::
357 : jhr 511 code
358 :     in
359 :     List.rev code
360 :     end
361 : lamonts 345
362 : jhr 1370
363 : cchiw 2397
364 : jhr 431 fun expandOp (env, y, rator, args) = let
365 : jhr 1640 val args' = Env.renameList (env, args)
366 : jhr 465 fun assign rator' = [(y, DstIL.OP(rator', args'))]
367 : jhr 431 in
368 :     case rator
369 : cchiw 2397 of SrcOp.IAdd ty => assign (DstOp.IAdd ty)
370 :     | SrcOp.ISub ty => assign (DstOp.ISub ty)
371 :     | SrcOp.IMul ty => assign (DstOp.IMul ty)
372 :     | SrcOp.IDiv ty => assign (DstOp.IDiv ty)
373 :     | SrcOp.INeg ty => assign (DstOp.INeg ty)
374 : jhr 1116 | SrcOp.Abs ty => assign (DstOp.Abs ty)
375 : jhr 459 | SrcOp.LT ty => assign (DstOp.LT ty)
376 :     | SrcOp.LTE ty => assign (DstOp.LTE ty)
377 :     | SrcOp.EQ ty => assign (DstOp.EQ ty)
378 :     | SrcOp.NEQ ty => assign (DstOp.NEQ ty)
379 :     | SrcOp.GT ty => assign (DstOp.GT ty)
380 :     | SrcOp.GTE ty => assign (DstOp.GTE ty)
381 :     | SrcOp.Not => assign (DstOp.Not)
382 :     | SrcOp.Max => assign (DstOp.Max)
383 :     | SrcOp.Min => assign (DstOp.Min)
384 : jhr 1295 | SrcOp.Clamp ty => assign (DstOp.Clamp ty)
385 : jhr 1116 | SrcOp.Lerp ty => assign (DstOp.Lerp ty)
386 : cchiw 2397 | SrcOp.Norm ty => assign (DstOp.Norm ty)
387 : jhr 1116 | SrcOp.Normalize d => assign (DstOp.Normalize d)
388 : cchiw 2398
389 : jhr 1116 | SrcOp.Zero ty => assign (DstOp.Zero ty)
390 : jhr 459 | SrcOp.PrincipleEvec ty => assign (DstOp.PrincipleEvec ty)
391 : jhr 1640 | SrcOp.EigenVals2x2 => assign (DstOp.EigenVals2x2)
392 :     | SrcOp.EigenVals3x3 => assign (DstOp.EigenVals3x3)
393 : cchiw 2397
394 : jhr 1640 | SrcOp.Select(ty as SrcTy.TupleTy tys, i) => assign (DstOp.Select(ty, i))
395 :     | SrcOp.Index(ty, i) => assign (DstOp.Index(ty, i))
396 : cchiw 2397 | SrcOp.ISubscript ty => assign (DstOp.ISubscript ty)
397 : jhr 1116 | SrcOp.Ceiling d => assign (DstOp.Ceiling d)
398 : jhr 459 | SrcOp.Floor d => assign (DstOp.Floor d)
399 : jhr 1116 | SrcOp.Round d => assign (DstOp.Round d)
400 :     | SrcOp.Trunc d => assign (DstOp.Trunc d)
401 : jhr 459 | SrcOp.IntToReal => assign (DstOp.IntToReal)
402 : jhr 1116 | SrcOp.RealToInt d => assign (DstOp.RealToInt d)
403 :     | SrcOp.VoxelAddress(info, offset) => expandVoxelAddress (y, info, offset, args')
404 : jhr 459 | SrcOp.LoadVoxels(rty, d) => assign (DstOp.LoadVoxels(rty, d))
405 : jhr 460 | SrcOp.PosToImgSpace info => assign (DstOp.PosToImgSpace info)
406 : jhr 1116 | SrcOp.TensorToWorldSpace(info, ty) => assign (DstOp.TensorToWorldSpace(info, ty))
407 : jhr 465 | SrcOp.EvalKernel(d, h, k) => expandEvalKernel(y, d, h, k, args')
408 : jhr 459 | SrcOp.LoadImage info => assign (DstOp.LoadImage info)
409 :     | SrcOp.Inside info => assign (DstOp.Inside info)
410 : jhr 1301 | SrcOp.Input(ty, s, desc) => assign (DstOp.Input(ty, s, desc))
411 :     | SrcOp.InputWithDefault(ty, s, desc) =>
412 :     assign (DstOp.InputWithDefault(ty, s, desc))
413 : jhr 1640 | rator => raise Fail("bogus operator " ^ SrcOp.toString rator)
414 : jhr 431 (* end case *)
415 :     end
416 :    
417 : cchiw 2398 fun expandEinOp (env, y, Ein.EIN{params, index, body}, args) = let
418 :     fun assign2 rator' =
419 :     [(y, DstIL.EINAPP(rator', Env.renameList(env, args)))]
420 :    
421 :     fun assign params'=
422 :     assign2 Ein.EIN{params=params', index=index, body=body}
423 :     fun cvtToInt rator' = let
424 :     val t = DstIL.Var.new ("t", DstTy.realTy)
425 :     in [
426 :     (t, DstIL.OP(rator', Env.renameList(env, args))),
427 :     (y, DstIL.OP(DstOp.RealToInt 1, [t]))
428 :     ] end
429 :     fun dummy () = [(y, DstIL.LIT(Literal.Int 0))]
430 :    
431 :     in
432 :     case params
433 :     of E.Const _ => assign params
434 :     | E.Tensor _ => assign params
435 :     | E.Field _ => dummy()
436 :     | E.Add _ => assign params
437 :     | E.Sum _ => assign params
438 :     | E.Prod _ => assign params
439 :     | E.Div _ => assign params
440 :     | E.Sub _ => assign params
441 :     | E.Neg _ => assign params
442 :     | E.Delta _ => assign params
443 :     | E.Epsilon _=> assign params
444 :     | E.Conv _ => dummy()
445 :     | E.Partial _ => assign params
446 :     | E.Probe _=> dummy()
447 :     | E.Apply _ => assign params
448 :    
449 :     (* end case *)
450 :     end
451 :     handle ex => (print(concat["error converting ", SrcOp.toString rator, "\n"]); raise ex)
452 :    
453 :    
454 :    
455 : jhr 1116 (* expand a SrcIL assignment to a DstIL CFG *)
456 : jhr 387 fun expand (env, (y, rhs)) = let
457 : jhr 1640 val y' = Env.rename (env, y)
458 :     fun assign rhs = [DstIL.ASSGN(y', rhs)]
459 : jhr 387 in
460 :     case rhs
461 : jhr 1640 of SrcIL.STATE x => assign (DstIL.STATE(Env.renameSV(env, x)))
462 :     | SrcIL.VAR x => assign (DstIL.VAR(Env.rename(env, x)))
463 : jhr 387 | SrcIL.LIT lit => assign (DstIL.LIT lit)
464 : jhr 1640 | SrcIL.OP(rator, args) => List.map DstIL.ASSGN (expandOp (env, y', rator, args))
465 :     | SrcIL.APPLY(f, args) => assign (DstIL.APPLY(f, Env.renameList(env, args)))
466 :     | SrcIL.CONS(ty, args) => assign (DstIL.CONS(ty, Env.renameList(env, args)))
467 : cchiw 2398 | SrcIL.EINAPP(rator, args) =>
468 :     List.map DstIL.EINAPP (expandEinOp (env, Env.rename (env, y), rator, args))
469 :     (* end case *)
470 :     end
471 : lamonts 345
472 : cchiw 2398
473 : jhr 1640 (* expand a SrcIL multi-assignment to a DstIL CFG *)
474 :     fun mexpand (env, (ys, rator, xs)) = let
475 :     val ys' = Env.renameList(env, ys)
476 :     val rator' = (case rator
477 :     of SrcOp.EigenVecs2x2 => DstOp.EigenVecs2x2
478 :     | SrcOp.EigenVecs3x3 => DstOp.EigenVecs3x3
479 :     | SrcOp.Print tys => DstOp.Print tys
480 :     | _ => raise Fail("bogus operator " ^ SrcOp.toString rator)
481 :     (* end case *))
482 :     val xs' = Env.renameList(env, xs)
483 :     val nd = DstIL.Node.mkMASSIGN(ys', rator', xs')
484 :     in
485 :     DstIL.CFG{entry=nd, exit=nd}
486 :     end
487 :    
488 : jhr 387 structure Trans = TranslateFn (
489 :     struct
490 : jhr 1640 open Env
491 :     val expand = DstIL.CFG.mkBlock o expand
492 :     val mexpand = mexpand
493 : jhr 387 end)
494 :    
495 : jhr 1116 fun translate prog = let
496 :     val prog = Trans.translate prog
497 : jhr 387 in
498 : jhr 1116 LowILCensus.init prog;
499 :     prog
500 : jhr 387 end
501 :    
502 : jhr 435 end

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