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 435 - (view) (download)
Original Path: trunk/src/compiler/mid-to-low/mid-to-low.sml

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 :     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 431 fun expandOp (env, y, rator, args) = let
42 :     fun assign rator' =
43 :     [(y, DstIL.OP(rator', renameList(env, args)))]
44 :     in
45 :     case rator
46 :     of SrcOp.Add ty =>
47 :     | SrcOp.Sub ty =>
48 :     | SrcOp.Mul ty =>
49 :     | SrcOp.Div ty =>
50 :     | SrcOp.Neg ty =>
51 :     | SrcOp.LT ty =>
52 :     | SrcOp.LTE ty =>
53 :     | SrcOp.EQ ty =>
54 :     | SrcOp.NEQ ty =>
55 :     | SrcOp.GT ty =>
56 :     | SrcOp.GTE ty =>
57 :     | SrcOp.Not =>
58 :     | SrcOp.Max =>
59 :     | SrcOp.Min =>
60 :     | SrcOp.Sin =>
61 :     | SrcOp.Cos =>
62 :     | SrcOp.Pow =>
63 :     | SrcOp.Dot d =>
64 :     | SrcOp.Cross =>
65 :     | SrcOp.Select ty => * int
66 :     | SrcOp.Norm d =>
67 :     | SrcOp.Scale d =>
68 :     | SrcOp.InvScale d =>
69 :     | SrcOp.CL =>
70 :     | SrcOp.PrincipleEvec ty =>
71 :     | SrcOp.Subscript ty =>
72 :     | SrcOp.Floor d =>
73 :     | SrcOp.IntToReal =>
74 :     | SrcOp.TruncToInt d =>
75 :     | SrcOp.RoundToInt d =>
76 :     | SrcOp.CeilToInt d =>
77 :     | SrcOp.FloorToInt d =>
78 :     | SrcOp.VoxelAddress info =>
79 :     | SrcOp.LoadVoxels(rty, d) =>
80 :     | SrcOp.Transform info =>
81 :     | SrcOp.EvalKernel(d, h, k) =>
82 :     | SrcOp.LoadImage info =>
83 :     | SrcOp.Inside info =>
84 :     | SrcOp.Input(ty, name) =>
85 :     | SrcOp.InputWithDefault(ty, name) =>
86 :     | _ => raise Fail("unexpected " ^ SrcOp.toString rator)
87 :     (* end case *)
88 :     end
89 :    
90 : jhr 387 (* expand a SrcIL assignment to a list of DstIL assignments *)
91 :     fun expand (env, (y, rhs)) = let
92 :     val y' = rename (env, y)
93 :     fun assign rhs = [(y', rhs)]
94 :     in
95 :     case rhs
96 :     of SrcIL.VAR x => assign (DstIL.VAR(rename(env, x)))
97 :     | SrcIL.LIT lit => assign (DstIL.LIT lit)
98 :     | SrcIL.OP(rator, args) => expandOp (env, y', rator, args)
99 :     | SrcIL.CONS args => assign (DstIL.CONS(renameList(env, args)))
100 :     (* end case *)
101 :     end
102 : lamonts 345
103 : jhr 387 structure Trans = TranslateFn (
104 :     struct
105 :     structure SrcIL = SrcIL
106 :     structure DstIL = DstIL
107 :    
108 :     type var_env = var_env
109 :    
110 :     val rename = rename
111 :     val expand = expand
112 :     end)
113 :    
114 :     fun translate (SrcIL.Program{globals, globalInit, actors}) = let
115 :     val env = VTbl.mkTable (256, Fail "env")
116 :     fun transMethod (SrcIL.Method{name, stateIn, stateOut, body}) =
117 :     DstIL.Method{
118 :     name = name,
119 :     stateIn = renameList (env, stateIn),
120 :     stateOut = renameList (env, stateOut),
121 :     body = Trans.translate (env, body)
122 :     }
123 :     fun transActor (SrcIL.Actor{name, params, state, stateInit, methods}) =
124 :     DstIL.Actor{
125 :     name = name,
126 :     params = renameList (env, params),
127 :     state = renameList (env, state),
128 :     stateInit = Trans.translate (env, stateInit),
129 :     methods = List.map transMethod methods
130 :     }
131 :     in
132 :     DstIL.Program{
133 :     globals = renameList (env, globals),
134 :     globalInit = Trans.translate (env, globalInit),
135 :     actors = List.map transActor actors
136 :     }
137 :     end
138 :    
139 : jhr 435 end

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