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 387 - (view) (download)

1 : lamonts 345 (* mid-to-low.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * Translation from MidIL to LowIL representations.
7 :     *)
8 :    
9 :     structure MidToLow : sig
10 :    
11 :     val translate : HighIL.program -> MidIL.program
12 :    
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 :     (* expand the EvalKernel operations into vector operations *)
36 : jhr 387 fun expandKernel (dimSize, kern, k, vec) = ??
37 :    
38 : lamonts 345 (* compute the load address for a given set of voxels indices *)
39 : jhr 387 fun computeVoxelAddress (info, vec) = ??
40 : lamonts 345
41 : jhr 387 (* expand a SrcIL assignment to a list of DstIL assignments *)
42 :     fun expand (env, (y, rhs)) = let
43 :     val y' = rename (env, y)
44 :     fun assign rhs = [(y', rhs)]
45 :     in
46 :     case rhs
47 :     of SrcIL.VAR x => assign (DstIL.VAR(rename(env, x)))
48 :     | SrcIL.LIT lit => assign (DstIL.LIT lit)
49 :     | SrcIL.OP(rator, args) => expandOp (env, y', rator, args)
50 :     | SrcIL.CONS args => assign (DstIL.CONS(renameList(env, args)))
51 :     (* end case *)
52 :     end
53 : lamonts 345
54 : jhr 387 structure Trans = TranslateFn (
55 :     struct
56 :     structure SrcIL = SrcIL
57 :     structure DstIL = DstIL
58 :    
59 :     type var_env = var_env
60 :    
61 :     val rename = rename
62 :     val expand = expand
63 :     end)
64 :    
65 :     fun translate (SrcIL.Program{globals, globalInit, actors}) = let
66 :     val env = VTbl.mkTable (256, Fail "env")
67 :     fun transMethod (SrcIL.Method{name, stateIn, stateOut, body}) =
68 :     DstIL.Method{
69 :     name = name,
70 :     stateIn = renameList (env, stateIn),
71 :     stateOut = renameList (env, stateOut),
72 :     body = Trans.translate (env, body)
73 :     }
74 :     fun transActor (SrcIL.Actor{name, params, state, stateInit, methods}) =
75 :     DstIL.Actor{
76 :     name = name,
77 :     params = renameList (env, params),
78 :     state = renameList (env, state),
79 :     stateInit = Trans.translate (env, stateInit),
80 :     methods = List.map transMethod methods
81 :     }
82 :     in
83 :     DstIL.Program{
84 :     globals = renameList (env, globals),
85 :     globalInit = Trans.translate (env, globalInit),
86 :     actors = List.map transActor actors
87 :     }
88 :     end
89 :    
90 : lamonts 345 end

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