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

SCM Repository

[diderot] Annotation of /branches/vis12/src/compiler/simplify/simplify.sml
ViewVC logotype

Annotation of /branches/vis12/src/compiler/simplify/simplify.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3322 - (view) (download)

1 : jhr 171 (* simplify.sml
2 :     *
3 : jhr 3291 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : jhr 171 * All rights reserved.
7 :     *
8 :     * Simplify the AST representation.
9 :     *)
10 :    
11 :     structure Simplify : sig
12 :    
13 : jhr 1140 val transform : Error.err_stream * AST.program -> Simple.program
14 : jhr 171
15 :     end = struct
16 :    
17 : jhr 2481 structure TU = TypeUtil
18 : jhr 171 structure S = Simple
19 : jhr 2481 structure VMap = Var.Map
20 : jhr 2013 structure InP = Inputs
21 : jhr 171
22 : jhr 2481 val cvtTy = SimpleTypes.simplify
23 : jhr 2328
24 : jhr 2481 fun newTemp ty = SimpleVar.new ("_t", SimpleVar.LocalVar, ty)
25 : jhr 171
26 : jhr 2481 (* convert an AST variable to a Simple variable *)
27 :     fun cvtVar (env, x as Var.V{name, kind, ty=([], ty), ...}) = let
28 :     val x' = SimpleVar.new (name, kind, cvtTy ty)
29 :     in
30 :     (x', VMap.insert(env, x, x'))
31 :     end
32 :    
33 :     fun cvtVars (env, xs) = List.foldr
34 :     (fn (x, (xs, env)) => let
35 :     val (x', env) = cvtVar(env, x)
36 :     in
37 :     (x'::xs, env)
38 :     end) ([], env) xs
39 :    
40 :     fun lookupVar (env, x) = (case VMap.find (env, x)
41 :     of SOME x' => x'
42 :     | NONE => raise Fail(concat["lookupVar(", Var.uniqueNameOf x, ")"])
43 :     (* end case *))
44 :    
45 : jhr 171 (* make a block out of a list of statements that are in reverse order *)
46 : jhr 197 fun mkBlock stms = S.Block(List.rev stms)
47 : jhr 171
48 : jhr 2481 fun inputImage (nrrd, dim, shape) = (
49 : jhr 2633 case ImageInfo.fromNrrd(NrrdInfo.getInfo nrrd, dim, shape)
50 :     of NONE => raise Fail(concat["nrrd file \"", nrrd, "\" does not have expected type"])
51 :     | SOME info => InP.Proxy(nrrd, info)
52 :     (* end case *))
53 : jhr 2013
54 : jhr 2823 datatype 'a ctl_flow_info
55 : jhr 2826 = EXIT (* stm sequence always exits; no pruning so far *)
56 :     | PRUNE of 'a (* stm sequence always exits at last stm in argument, which
57 :     * is either a block of stm list *)
58 :     | CONT (* stm sequence falls through *)
59 :     | EDIT of 'a (* pruned code that has non-exiting paths *)
60 : jhr 2140
61 : jhr 2823 fun pruneUnreachableCode (blk as S.Block stms) = let
62 : jhr 2826 fun isExit S.S_Die = true
63 :     | isExit S.S_Stabilize = true
64 :     | isExit (S.S_Return _) = true
65 :     | isExit _ = false
66 :     fun pruneStms [] = CONT
67 :     | pruneStms [S.S_IfThenElse(x, blk1, blk2)] = (
68 :     case pruneIf(x, blk1, blk2)
69 :     of EXIT => EXIT
70 :     | PRUNE stm => PRUNE[stm]
71 :     | CONT => CONT
72 :     | EDIT stm => EDIT[stm]
73 :     (* end case *))
74 :     | pruneStms [stm] = if isExit stm then EXIT else CONT
75 :     | pruneStms ((stm as S.S_IfThenElse(x, blk1, blk2))::stms) = (
76 :     case pruneIf(x, blk1, blk2)
77 :     of EXIT => PRUNE[stm]
78 :     | PRUNE stm => PRUNE[stm]
79 :     | CONT => (case pruneStms stms
80 :     of PRUNE stms => PRUNE(stm::stms)
81 :     | EDIT stms => EDIT(stm::stms)
82 :     | EXIT => EXIT (* different instances of ctl_flow_info *)
83 :     | CONT => CONT
84 :     (* end case *))
85 :     | EDIT stm => (case pruneStms stms
86 :     of PRUNE stms => PRUNE(stm::stms)
87 :     | EDIT stms => EDIT(stm::stms)
88 :     | _ => EDIT(stm::stms)
89 :     (* end case *))
90 :     (* end case *))
91 :     | pruneStms (stm::stms) = if isExit stm
92 :     then PRUNE[stm]
93 :     else (case pruneStms stms
94 :     of PRUNE stms => PRUNE(stm::stms)
95 :     | EDIT stms => EDIT(stm::stms)
96 :     | info => info
97 :     (* end case *))
98 :     and pruneIf (x, blk1, blk2) = (case (pruneBlk blk1, pruneBlk blk2)
99 :     of (EXIT, EXIT ) => EXIT
100 :     | (CONT, CONT ) => CONT
101 :     | (CONT, EXIT ) => CONT
102 :     | (EXIT, CONT ) => CONT
103 :     | (CONT, EDIT blk2 ) => EDIT(S.S_IfThenElse(x, blk1, blk2))
104 :     | (EDIT blk1, CONT ) => EDIT(S.S_IfThenElse(x, blk1, blk2))
105 :     | (CONT, PRUNE blk2) => EDIT(S.S_IfThenElse(x, blk1, blk2))
106 :     | (PRUNE blk1, CONT ) => EDIT(S.S_IfThenElse(x, blk1, blk2))
107 :     | (EXIT, EDIT blk2 ) => EDIT(S.S_IfThenElse(x, blk1, blk2))
108 :     | (EDIT blk1, EXIT ) => EDIT(S.S_IfThenElse(x, blk1, blk2))
109 :     | (EDIT blk1, EDIT blk2 ) => EDIT(S.S_IfThenElse(x, blk1, blk2))
110 :     | (EDIT blk1, PRUNE blk2) => EDIT(S.S_IfThenElse(x, blk1, blk2))
111 :     | (PRUNE blk1, EDIT blk2 ) => EDIT(S.S_IfThenElse(x, blk1, blk2))
112 :     | (EXIT, PRUNE blk2) => PRUNE(S.S_IfThenElse(x, blk1, blk2))
113 :     | (PRUNE blk1, EXIT ) => PRUNE(S.S_IfThenElse(x, blk1, blk2))
114 :     | (PRUNE blk1, PRUNE blk2) => PRUNE(S.S_IfThenElse(x, blk1, blk2))
115 :     (* end case *))
116 :     and pruneBlk (S.Block stms) = (case pruneStms stms
117 :     of PRUNE stms => PRUNE(S.Block stms)
118 :     | EDIT stms => EDIT(S.Block stms)
119 :     | EXIT => EXIT (* different instances of ctl_flow_info *)
120 :     | CONT => CONT
121 :     (* end case *))
122 :     in
123 :     case pruneBlk blk
124 :     of PRUNE blk => blk
125 :     | EDIT blk => blk
126 :     | _=> blk
127 :     (* end case *)
128 :     end
129 : jhr 2823
130 : jhr 2365 fun simplifyProgram (AST.Program{props, decls}) = let
131 : jhr 2272 val inputs = ref []
132 : jhr 2814 val inputInit = ref []
133 : jhr 2272 val globals = ref []
134 :     val globalInit = ref []
135 :     val funcs = ref []
136 :     val initially = ref NONE
137 :     val strands = ref []
138 :     fun setInitially init = (case !initially
139 :     of NONE => initially := SOME init
140 : jhr 1116 (* FIXME: the check for multiple initially decls should happen in type checking *)
141 : jhr 2272 | SOME _ => raise Fail "multiple initially declarations"
142 :     (* end case *))
143 : jhr 2481 fun simplifyDecl (dcl, env) = (case dcl
144 : jhr 2272 of AST.D_Input(x, desc, NONE) => let
145 : jhr 2782 val (x', env) = cvtVar(env, x)
146 : jhr 2481 val (ty, init) = (case SimpleVar.typeOf x'
147 :     of ty as SimpleTypes.T_Image{dim, shape} => let
148 :     val info = ImageInfo.mkInfo(dim, shape)
149 : jhr 2272 in
150 :     (ty, SOME(InP.Image info))
151 :     end
152 : jhr 2011 | ty => (ty, NONE)
153 : jhr 1996 (* end case *))
154 : jhr 2272 val inp = InP.INP{
155 :     ty = ty,
156 : jhr 2481 name = SimpleVar.nameOf x',
157 : jhr 2272 desc = desc,
158 :     init = init
159 :     }
160 :     in
161 : jhr 2481 inputs := (x', inp) :: !inputs;
162 : jhr 2633 env
163 : jhr 2272 end
164 : jhr 1992 | AST.D_Input(x, desc, SOME(AST.E_LoadNrrd(tvs, nrrd, ty))) => let
165 : jhr 2782 val (x', env) = cvtVar(env, x)
166 : jhr 1996 (* load the nrrd proxy here *)
167 : jhr 1993 val info = NrrdInfo.getInfo nrrd
168 : jhr 2481 val (ty, init) = (case SimpleVar.typeOf x'
169 : jhr 2512 of ty as SimpleTypes.T_DynSequence _ => (ty, InP.DynSeq nrrd)
170 :     | ty as SimpleTypes.T_Image{dim, shape} => (ty, inputImage(nrrd, dim, shape))
171 : jhr 1992 | _ => raise Fail "impossible"
172 :     (* end case *))
173 : jhr 2272 val inp = InP.INP{
174 :     ty = ty,
175 : jhr 2481 name = SimpleVar.nameOf x',
176 : jhr 2272 desc = desc,
177 :     init = SOME init
178 :     }
179 : jhr 1992 in
180 : jhr 2481 inputs := (x', inp) :: !inputs;
181 : jhr 2633 env
182 : jhr 1992 end
183 : jhr 2272 | AST.D_Input(x, desc, SOME e) => let
184 : jhr 2782 val (x', env) = cvtVar(env, x)
185 : jhr 2813 val (stms, e') = simplifyExp (env, e, [])
186 : jhr 2272 val inp = InP.INP{
187 : jhr 2481 ty = SimpleVar.typeOf x',
188 :     name = SimpleVar.nameOf x',
189 : jhr 2272 desc = desc,
190 : jhr 2813 init = NONE
191 : jhr 2272 }
192 :     in
193 : jhr 2481 inputs := (x', inp) :: !inputs;
194 : jhr 2813 inputInit := S.S_Assign(x', e') :: (stms @ !inputInit);
195 : jhr 2633 env
196 : jhr 2272 end
197 :     | AST.D_Var(AST.VD_Decl(x, e)) => let
198 : jhr 2782 val (x', env) = cvtVar(env, x)
199 : jhr 2481 val (stms, e') = simplifyExp (env, e, [])
200 : jhr 2272 in
201 : jhr 2481 globals := x' :: !globals;
202 :     globalInit := S.S_Assign(x', e') :: (stms @ !globalInit);
203 :     env
204 : jhr 2272 end
205 : jhr 2481 | AST.D_Func(f, params, body) => let
206 :     val (f', env) = cvtVar(env, f)
207 :     val (params', env) = cvtVars (env, params)
208 : jhr 2823 val body' = pruneUnreachableCode (simplifyBlock(env, body))
209 : jhr 2481 in
210 :     funcs := S.Func{f=f', params=params', body=body'} :: !funcs;
211 :     env
212 :     end
213 :     | AST.D_Strand info => (
214 :     strands := simplifyStrand(env, info) :: !strands;
215 :     env)
216 :     | AST.D_InitialArray(creat, iters) => (
217 :     setInitially (simplifyInit(env, true, creat, iters));
218 :     env)
219 :     | AST.D_InitialCollection(creat, iters) => (
220 :     setInitially (simplifyInit(env, false, creat, iters));
221 :     env)
222 : jhr 2272 (* end case *))
223 : jhr 2481 val env = List.foldl simplifyDecl VMap.empty decls
224 : jhr 2272 in
225 :     S.Program{
226 : jhr 2633 props = props,
227 : jhr 2814 inputDefaults = mkBlock (!inputInit),
228 : jhr 2272 inputs = List.rev(!inputs),
229 :     globals = List.rev(!globals),
230 :     globalInit = mkBlock (!globalInit),
231 :     funcs = List.rev(!funcs),
232 :     init = (case !initially
233 : jhr 1116 (* FIXME: the check for the initially block should really happen in typechecking *)
234 : jhr 2272 of NONE => raise Fail "missing initially declaration"
235 :     | SOME blk => blk
236 :     (* end case *)),
237 :     strands = List.rev(!strands)
238 :     }
239 :     end
240 : jhr 171
241 : jhr 2481 and simplifyInit (env, isArray, AST.C_Create(strand, exps), iters) = let
242 :     fun simplifyIter (AST.I_Range(x, e1, e2), (env, iters, stms)) = let
243 :     val (stms, lo) = simplifyExpToVar (env, e1, stms)
244 :     val (stms, hi) = simplifyExpToVar (env, e2, stms)
245 :     val (x', env) = cvtVar (env, x)
246 :     in
247 :     (env, {param=x', lo=lo, hi=hi}::iters, stms)
248 :     end
249 :     val (env, iters, iterStms) = List.foldl simplifyIter (env, [], []) iters
250 :     val (stms, xs) = simplifyExpsToVars (env, exps, [])
251 : jhr 2272 val creat = S.C_Create{
252 :     argInit = mkBlock stms,
253 :     name = strand,
254 :     args = xs
255 :     }
256 :     in
257 :     S.Initially{
258 :     isArray = isArray,
259 : jhr 2481 rangeInit = mkBlock iterStms,
260 : jhr 2272 iters = List.rev iters,
261 :     create = creat
262 :     }
263 :     end
264 : jhr 1116
265 : jhr 2481 and simplifyStrand (env, AST.Strand{name, params, state, methods}) = let
266 :     val (params', env) = cvtVars (env, params)
267 :     fun simplifyState (env, [], xs, stms) = (List.rev xs, mkBlock stms, env)
268 :     | simplifyState (env, AST.VD_Decl(x, e) :: r, xs, stms) = let
269 :     val (stms, e') = simplifyExp (env, e, stms)
270 : jhr 2782 val (x', env) = cvtVar(env, x)
271 : jhr 2272 in
272 : jhr 2481 simplifyState (env, r, x'::xs, S.S_Assign(x', e') :: stms)
273 : jhr 2272 end
274 : jhr 2481 val (xs, stm, env) = simplifyState (env, state, [], [])
275 : jhr 2272 in
276 :     S.Strand{
277 :     name = name,
278 : jhr 2481 params = params',
279 : jhr 2272 state = xs, stateInit = stm,
280 : jhr 2481 methods = List.map (simplifyMethod env) methods
281 : jhr 2272 }
282 :     end
283 : jhr 171
284 : jhr 2481 and simplifyMethod env (AST.M_Method(name, body)) =
285 : jhr 2823 S.Method(name, pruneUnreachableCode (simplifyBlock(env, body)))
286 : jhr 171
287 : jhr 1116 (* simplify a statement into a single statement (i.e., a block if it expands
288 :     * into more than one new statement).
289 : jhr 171 *)
290 : jhr 2481 and simplifyBlock (env, stm) = mkBlock (#1 (simplifyStmt (env, stm, [])))
291 : jhr 171
292 : jhr 2147 (* simplify the statement stm where stms is a reverse-order list of preceeding simplified
293 :     * statements. This function returns a reverse-order list of simplified statements.
294 : jhr 2154 * Note that error reporting is done in the typechecker, but it does not prune unreachable
295 :     * code.
296 : jhr 2147 *)
297 : jhr 2481 and simplifyStmt (env, stm, stms) = (case stm
298 : jhr 2272 of AST.S_Block body => let
299 : jhr 2481 fun simplify (_, [], stms) = stms
300 :     | simplify (env', stm::r, stms) = let
301 :     val (stms, env') = simplifyStmt (env', stm, stms)
302 :     in
303 : jhr 2823 simplify (env', r, stms)
304 : jhr 2481 end
305 : jhr 2272 in
306 : jhr 2481 (simplify (env, body, stms), env)
307 : jhr 2272 end
308 :     | AST.S_Decl(AST.VD_Decl(x, e)) => let
309 : jhr 2481 val (stms, e') = simplifyExp (env, e, stms)
310 :     val (x', env) = cvtVar(env, x)
311 : jhr 2272 in
312 : jhr 2481 (S.S_Assign(x', e') :: stms, env)
313 : jhr 2272 end
314 :     | AST.S_IfThenElse(e, s1, s2) => let
315 : jhr 2481 val (stms, x) = simplifyExpToVar (env, e, stms)
316 :     val s1 = simplifyBlock (env, s1)
317 :     val s2 = simplifyBlock (env, s2)
318 : jhr 2272 in
319 : jhr 2481 (S.S_IfThenElse(x, s1, s2) :: stms, env)
320 : jhr 2272 end
321 :     | AST.S_Assign(x, e) => let
322 : jhr 2481 val (stms, e') = simplifyExp (env, e, stms)
323 : jhr 2272 in
324 : jhr 2481 (S.S_Assign(lookupVar(env, x), e') :: stms, env)
325 : jhr 2272 end
326 :     | AST.S_New(name, args) => let
327 : jhr 2481 val (stms, xs) = simplifyExpsToVars (env, args, stms)
328 : jhr 2272 in
329 : jhr 2481 (S.S_New(name, xs) :: stms, env)
330 : jhr 2272 end
331 : jhr 3191 | AST.S_Continue => (S.S_Continue :: stms, env)
332 : jhr 2481 | AST.S_Die => (S.S_Die :: stms, env)
333 :     | AST.S_Stabilize => (S.S_Stabilize :: stms, env)
334 : jhr 2272 | AST.S_Return e => let
335 : jhr 2481 val (stms, x) = simplifyExpToVar (env, e, stms)
336 : jhr 2272 in
337 : jhr 2481 (S.S_Return x :: stms, env)
338 : jhr 2272 end
339 : jhr 1640 | AST.S_Print args => let
340 : jhr 2481 val (stms, xs) = simplifyExpsToVars (env, args, stms)
341 : jhr 1640 in
342 : jhr 2481 (S.S_Print xs :: stms, env)
343 : jhr 1640 end
344 : jhr 2272 (* end case *))
345 : jhr 171
346 : jhr 3322 and simplifyExp (env, exp, stms) = let
347 :     fun doApply (f, tyArgs, args, ty) = let
348 :     val (stms, xs) = simplifyExpsToVars (env, args, stms)
349 :     in
350 :     case Var.kindOf f
351 :     of S.FunVar => (stms, S.E_Apply(lookupVar(env, f), xs, cvtTy ty))
352 :     | S.BasisVar => let
353 :     fun cvtTyArg (Types.TYPE tv) = S.TY(cvtTy(TU.resolve tv))
354 :     | cvtTyArg (Types.DIFF dv) = S.DIFF(TU.monoDiff(TU.resolveDiff dv))
355 :     | cvtTyArg (Types.SHAPE sv) = S.SHAPE(TU.monoShape(TU.resolveShape sv))
356 :     | cvtTyArg (Types.DIM dv) = S.DIM(TU.monoDim(TU.resolveDim dv))
357 :     val tyArgs = List.map cvtTyArg tyArgs
358 :     in
359 :     (stms, S.E_Prim(f, tyArgs, xs, cvtTy ty))
360 :     end
361 :     | _ => raise Fail "bogus application"
362 :     (* end case *)
363 :     end
364 :     in
365 :     case exp
366 :     of AST.E_Var x => (case Var.kindOf x
367 :     of Var.BasisVar => let
368 :     val ty = cvtTy(Var.monoTypeOf x)
369 :     val x' = newTemp ty
370 :     val stm = S.S_Assign(x', S.E_Prim(x, [], [], ty))
371 :     in
372 :     (stm::stms, S.E_Var x')
373 :     end
374 :     | _ => (stms, S.E_Var(lookupVar(env, x)))
375 :     (* end case *))
376 :     | AST.E_Lit lit => (stms, S.E_Lit lit)
377 :     | AST.E_Tuple es => raise Fail "E_Tuple not yet implemented"
378 :     | AST.E_Apply(rator, tyArgs, args as [AST.E_Lit(Literal.Int n)], ty) =>
379 :     (* constant-fold negation of integer literals *)
380 :     if Var.same(BasisVars.neg_i, rator)
381 :     then (stms, S.E_Lit(Literal.Int(~n)))
382 :     else doApply (rator, tyArgs, args, ty)
383 :     | AST.E_Apply(rator, tyArgs, args as [AST.E_Lit(Literal.Float f)], ty as Types.T_Tensor sh) =>
384 :     (* constant-fold negation of real literals *)
385 :     if Var.same(BasisVars.neg_i, rator) andalso List.null(TU.monoShape sh)
386 :     then (stms, S.E_Lit(Literal.Float(FloatLit.negate f)))
387 :     else doApply (rator, tyArgs, args, ty)
388 :     | AST.E_Apply(f, tyArgs, args, ty) => doApply (f, tyArgs, args, ty)
389 :     | AST.E_Cons es => let
390 :     val (stms, xs) = simplifyExpsToVars (env, es, stms)
391 :     in
392 :     (stms, S.E_Cons xs)
393 :     end
394 :     | AST.E_Seq(es, ty) => let
395 :     val (stms, xs) = simplifyExpsToVars (env, es, stms)
396 :     in
397 :     (stms, S.E_Seq(xs, cvtTy ty))
398 :     end
399 :     | AST.E_Slice(e, indices, ty) => let (* tensor slicing *)
400 :     val (stms, x) = simplifyExpToVar (env, e, stms)
401 :     fun f ([], ys, stms) = (stms, List.rev ys)
402 :     | f (NONE::es, ys, stms) = f (es, NONE::ys, stms)
403 :     | f (SOME e::es, ys, stms) = let
404 :     val (stms, y) = simplifyExpToVar (env, e, stms)
405 :     in
406 :     f (es, SOME y::ys, stms)
407 :     end
408 :     val (stms, indices) = f (indices, [], stms)
409 :     in
410 :     (stms, S.E_Slice(x, indices, cvtTy ty))
411 :     end
412 :     | AST.E_Cond(e1, e2, e3, ty) => let
413 :     (* a conditional expression gets turned into an if-then-else statememt *)
414 :     val result = newTemp(cvtTy ty)
415 :     val (stms, x) = simplifyExpToVar (env, e1, S.S_Var result :: stms)
416 :     fun simplifyBranch e = let
417 :     val (stms, e) = simplifyExp (env, e, [])
418 :     in
419 :     mkBlock (S.S_Assign(result, e)::stms)
420 :     end
421 :     val s1 = simplifyBranch e2
422 :     val s2 = simplifyBranch e3
423 :     in
424 :     (S.S_IfThenElse(x, s1, s2) :: stms, S.E_Var result)
425 :     end
426 :     | AST.E_LoadNrrd(_, nrrd, ty) => (case cvtTy ty
427 :     of ty as SimpleTypes.T_DynSequence _ => (stms, S.E_LoadSeq(ty, nrrd))
428 :     | ty as SimpleTypes.T_Image{dim, shape} => (
429 :     case ImageInfo.fromNrrd(NrrdInfo.getInfo nrrd, dim, shape)
430 :     of NONE => raise Fail(concat[
431 :     "nrrd file \"", nrrd, "\" does not have expected type"
432 :     ])
433 :     | SOME info => (stms, S.E_LoadImage(ty, nrrd, info))
434 :     (* end case *))
435 :     | _ => raise Fail "bogus type for E_LoadNrrd"
436 :     (* end case *))
437 :     | AST.E_Coerce{srcTy, dstTy, e} => let
438 :     val (stms, x) = simplifyExpToVar (env, e, stms)
439 :     val dstTy = cvtTy dstTy
440 :     val result = newTemp dstTy
441 :     val rhs = S.E_Coerce{srcTy = cvtTy srcTy, dstTy = dstTy, x = x}
442 :     in
443 :     (S.S_Assign(result, rhs)::stms, S.E_Var result)
444 :     end
445 :     (* end case *)
446 :     end
447 : jhr 171
448 : jhr 2481 and simplifyExpToVar (env, exp, stms) = let
449 :     val (stms, e) = simplifyExp (env, exp, stms)
450 : jhr 2272 in
451 :     case e
452 :     of S.E_Var x => (stms, x)
453 :     | _ => let
454 :     val x = newTemp (S.typeOf e)
455 :     in
456 :     (S.S_Assign(x, e)::stms, x)
457 :     end
458 :     (* end case *)
459 :     end
460 : jhr 171
461 : jhr 2481 and simplifyExpsToVars (env, exps, stms) = let
462 : jhr 2272 fun f ([], xs, stms) = (stms, List.rev xs)
463 :     | f (e::es, xs, stms) = let
464 : jhr 2481 val (stms, x) = simplifyExpToVar (env, e, stms)
465 : jhr 2272 in
466 :     f (es, x::xs, stms)
467 :     end
468 :     in
469 :     f (exps, [], stms)
470 :     end
471 : jhr 171
472 : jhr 1140 fun transform (errStrm, ast) = let
473 : jhr 2272 val simple = simplifyProgram ast
474 :     val _ = SimplePP.output (Log.logFile(), "simplify", simple) (* DEBUG *)
475 :     val simple = Inliner.transform simple
476 :     val _ = SimplePP.output (Log.logFile(), "inlining", simple) (* DEBUG *)
477 :     in
478 :     simple
479 :     end
480 : jhr 227
481 : jhr 171 end

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