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

SCM Repository

[diderot] Diff of /trunk/src/compiler/translate/translate.sml
ViewVC logotype

Diff of /trunk/src/compiler/translate/translate.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2483, Mon Oct 14 16:27:24 2013 UTC revision 2636, Tue May 27 16:18:36 2014 UTC
# Line 194  Line 194 
194                    TranslateBasis.translate (lhs, f, tyArgs, args')                    TranslateBasis.translate (lhs, f, tyArgs, args')
195                  end                  end
196              | S.E_Cons args => [IL.ASSGN(lhs, IL.CONS(IL.Var.ty lhs, List.map (lookup env) args))]              | S.E_Cons args => [IL.ASSGN(lhs, IL.CONS(IL.Var.ty lhs, List.map (lookup env) args))]
197                | S.E_Seq args => [IL.ASSGN(lhs, IL.CONS(IL.Var.ty lhs, List.map (lookup env) args))]
198              | S.E_Slice(x, indices, ty) => let              | S.E_Slice(x, indices, ty) => let
199                  val x = lookup env x                  val x = lookup env x
200                  val mask = List.map isSome indices                  val mask = List.map isSome indices
# Line 216  Line 217 
217                          " ==> ", Ty.toString dstTy                          " ==> ", Ty.toString dstTy
218                        ])                        ])
219                  (* end case *))                  (* end case *))
220              | S.E_Input(_, name, NONE, NONE) =>              | S.E_LoadImage(ty, nrrd, info) => [IL.ASSGN(lhs, IL.OP(Op.LoadImage(cvtTy ty, nrrd, info), []))]
                 [IL.ASSGN(lhs, IL.OP(HighOps.Input(IL.Var.ty lhs, name, ""), []))]  
             | S.E_Input(_, name, SOME desc, NONE) =>  
                 [IL.ASSGN(lhs, IL.OP(HighOps.Input(IL.Var.ty lhs, name, desc), []))]  
             | S.E_Input(_, name, NONE, SOME dflt) =>  
                 [IL.ASSGN(lhs, IL.OP(HighOps.InputWithDefault(IL.Var.ty lhs, name, ""), [lookup env dflt]))]  
             | S.E_Input(_, name, SOME desc, SOME dflt) =>  
                 [IL.ASSGN(lhs, IL.OP(HighOps.InputWithDefault(IL.Var.ty lhs, name, desc), [lookup env dflt]))]  
             | S.E_LoadImage(info, name) => [IL.ASSGN(lhs, IL.OP(HighOps.LoadImage info, [lookup env name]))]  
221            (* end case *))            (* end case *))
222    
223    (* add nodes to save the strand state, followed by an exit node *)    (* add nodes to save the strand state, followed by an exit node *)
# Line 434  Line 427 
427              condCons (hasNew, StrandUtil.NewStrands, []))              condCons (hasNew, StrandUtil.NewStrands, []))
428            end            end
429    
430      fun translate (S.Program{globals, globalInit, init, strands, ...}) = let      fun cvtInputs inputs = let
431            val (globalInit, env) = let            fun cvt ((x, inp), (env, stms)) = let
432                  fun mkExit env = let                  val x' = newVar x
433                        val nd = IL.Node.mkRETURN(VMap.listItems env)                  val stm = IL.ASSGN(x', IL.OP(Op.Input(Inputs.map cvtTy inp), []))
434                        in                        in
435                          IL.CFG{entry = nd, exit = nd}                    (VMap.insert(env, x, x'), stm::stms)
436                        end                        end
437              val (env, stms) = List.foldr cvt (VMap.empty, []) inputs
438                  in                  in
439                    cvtTopLevelBlock (VMap.empty, globalInit, mkExit)              (IL.CFG.mkBlock stms, env)
440              end
441    
442      (* gather the top-level definitions in a block.  This is a hack that is used to make all
443       * of the globally defined variables visible to the rest of the program (including intermediate
444       * results) so that later transforms (e.g., field normalization) will work.  Eventually the
445       * variable analysis phase ought to clean things up.
446       *)
447        fun definedVars (IL.CFG{entry, ...}) = let
448              fun gather (nd, vars) = (case IL.Node.kind nd
449                     of IL.NULL => vars
450                      | IL.ENTRY{succ, ...} => gather(!succ, vars)
451                      | IL.COND{trueBranch, ...} => let
452                          val (phis, succ) = findJoin (!trueBranch)
453                          val vars = List.foldl (fn ((x, _), vars) => x::vars) vars (!phis)
454                          in
455                            gather (succ, vars)
456                          end
457                      | IL.COM{succ, ...} => gather (!succ, vars)
458                      | IL.ASSIGN{stm=(x, _), succ, ...} => gather(!succ, x::vars)
459                      | IL.MASSIGN{stm=(xs, _, _), succ, ...} => gather(!succ, xs@vars)
460                      | _ => raise Fail("gather: unexpected " ^ IL.Node.toString nd)
461                    (* end case *))
462              and findJoin nd = (case IL.Node.kind nd
463                     of IL.JOIN{phis, succ, ...} => (phis, !succ)
464                      | IL.COND{trueBranch, ...} => findJoin (#2 (findJoin (!trueBranch)))
465                      | IL.COM{succ, ...} => findJoin (!succ)
466                      | IL.ASSIGN{succ, ...} => findJoin (!succ)
467                      | IL.MASSIGN{succ, ...} => findJoin (!succ)
468                      | _ => raise Fail("findJoin: unexpected " ^ IL.Node.toString nd)
469                    (* end case *))
470              in
471                List.rev (gather (entry, []))
472              end
473    
474        fun translate (S.Program{props, inputs, globals, globalInit, init, strands, ...}) = let
475              val (globalInit, env) = let
476                    val (inputBlk, inputEnv) = cvtInputs inputs
477                    val (globBlk, env) = cvtBlock (([], []), inputEnv, [], globalInit)
478                    val cfg = IL.CFG.prependNode (IL.Node.mkENTRY(), inputBlk)
479                    val cfg = IL.CFG.concat(cfg, globBlk)
480                    val exit = IL.Node.mkRETURN(VMap.listItems inputEnv @ definedVars globBlk)
481                    val cfg = IL.CFG.concat (cfg, IL.CFG{entry = exit, exit = exit})
482                    in
483                      (cfg, env)
484                  end                  end
485          (* construct a reduced environment that just defines the globals. *)          (* construct a reduced environment that just defines the globals (including inputs). *)
486            val env = let            val env = let
487                  val lookup = lookup env                  val lookup = lookup env
488                  fun cvtVar (x, env) = VMap.insert(env, x, lookup x)                  fun cvtVar (x, env) = VMap.insert(env, x, lookup x)
489                  val env = List.foldl cvtVar VMap.empty globals                  val env = List.foldl (fn ((x, _), env) => cvtVar(x, env)) VMap.empty inputs
490                    val env = List.foldl cvtVar env globals
491                  in                  in
492                    env                    env
493                  end                  end
# Line 490  Line 529 
529                      }                      }
530                  end                  end
531            val prog = IL.Program{            val prog = IL.Program{
532    (* FIXME: we should just use the properties from the Simple program *)
533                    props = checkProps strands,                    props = checkProps strands,
534                    globalInit = globalInit,                    globalInit = globalInit,
535                    initially = init,                    initially = init,

Legend:
Removed from v.2483  
changed lines
  Added in v.2636

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