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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3456 - (view) (download)

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

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