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

SCM Repository

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

Diff of /branches/vis12/src/compiler/translate/translate.sml

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

revision 2193, Sun Feb 24 11:50:36 2013 UTC revision 2194, Sun Feb 24 12:33:40 2013 UTC
# Line 307  Line 307 
307                    | S.S_Stabilize => (                    | S.S_Stabilize => (
308                        killPath joinStk;                        killPath joinStk;
309                        (IL.CFG.concat (cfg, saveStrandState (env, state, IL.Node.mkSTABILIZE())), env))                        (IL.CFG.concat (cfg, saveStrandState (env, state, IL.Node.mkSTABILIZE())), env))
310                      | S.S_Return _ => raise Fail "unexpected return"
311                    | S.S_Print args => let                    | S.S_Print args => let
312                        val args = List.map (lookup env) args                        val args = List.map (lookup env) args
313                        val nd = IL.Node.mkMASSIGN([], Op.Print(List.map IL.Var.ty args), args)                        val nd = IL.Node.mkMASSIGN([], Op.Print(List.map IL.Var.ty args), args)
# Line 437  Line 438 
438              (IL.CFG.mkBlock stms, env)              (IL.CFG.mkBlock stms, env)
439            end            end
440    
441      fun translate (S.Program{inputs, globals, globalInit, funcs, init, strands}) = let    (* gather the top-level definitions in a block.  This is a hack that is used to make all
442            val (globalInit, env) = let     * of the globally defined variables visible to the rest of the program (including intermediate
443                  fun mkExit env = let     * results) so that later transforms (e.g., field normalization) will work.  Eventually the
444                        val nd = IL.Node.mkRETURN(VMap.listItems env)     * variable analysis phase ought to clean things up.
445       *)
446        fun definedVars (IL.CFG{entry, ...}) = let
447              fun gather (nd, vars) = (case IL.Node.kind nd
448                     of IL.NULL => vars
449                      | IL.ENTRY{succ, ...} => gather(!succ, vars)
450                      | IL.COND{trueBranch, ...} => let
451                          val (phis, succ) = findJoin (!trueBranch)
452                          val vars = List.foldl (fn ((x, _), vars) => x::vars) vars (!phis)
453                          in
454                            gather (succ, vars)
455                          end
456                      | IL.COM{succ, ...} => gather (!succ, vars)
457                      | IL.ASSIGN{stm=(x, _), succ, ...} => gather(!succ, x::vars)
458                      | IL.MASSIGN{stm=(xs, _, _), succ, ...} => gather(!succ, xs@vars)
459                      | _ => raise Fail("gather: unexpected " ^ IL.Node.toString nd)
460                    (* end case *))
461              and findJoin nd = (case IL.Node.kind nd
462                     of IL.JOIN{phis, succ, ...} => (phis, !succ)
463                      | IL.COND{trueBranch, ...} => findJoin (#2 (findJoin (!trueBranch)))
464                      | IL.COM{succ, ...} => findJoin (!succ)
465                      | IL.ASSIGN{succ, ...} => findJoin (!succ)
466                      | IL.MASSIGN{succ, ...} => findJoin (!succ)
467                      | _ => raise Fail("findJoin: unexpected " ^ IL.Node.toString nd)
468                    (* end case *))
469                        in                        in
470                          IL.CFG{entry = nd, exit = nd}              List.rev (gather (entry, []))
471                        end                        end
472                  val (inputBlk, env) = cvtInputs inputs  
473                  val (globBlk, env) = cvtBlock (([], []), env, [], globalInit)      fun translate (S.Program{inputs, globals, globalInit, funcs, init, strands}) = let
474              val (globalInit, env) = let
475                    val (inputBlk, inputEnv) = cvtInputs inputs
476                    val (globBlk, env) = cvtBlock (([], []), inputEnv, [], globalInit)
477                  val cfg = IL.CFG.prependNode (IL.Node.mkENTRY(), inputBlk)                  val cfg = IL.CFG.prependNode (IL.Node.mkENTRY(), inputBlk)
478                  val cfg = IL.CFG.concat(cfg, globBlk)                  val cfg = IL.CFG.concat(cfg, globBlk)
479                  val cfg = IL.CFG.concat (cfg, mkExit env)                  val exit = IL.Node.mkRETURN(VMap.listItems inputEnv @ definedVars globBlk)
480                    val cfg = IL.CFG.concat (cfg, IL.CFG{entry = exit, exit = exit})
481                  in                  in
482                    (cfg, env)                    (cfg, env)
483                  end                  end

Legend:
Removed from v.2193  
changed lines
  Added in v.2194

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