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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/translate/analyze-simple.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/translate/analyze-simple.sml

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

revision 3501, Thu Dec 17 20:07:13 2015 UTC revision 3502, Thu Dec 17 23:13:35 2015 UTC
# Line 16  Line 16 
16      val analyze : Simple.block -> unit      val analyze : Simple.block -> unit
17    
18      val assignedVars : Simple.block -> SimpleVar.Set.set      val assignedVars : Simple.block -> SimpleVar.Set.set
19      val liveVars : Simple.block -> SimpleVar.Set.set      val liveIn  : Simple.block -> SimpleVar.Set.set
20        val liveOut : Simple.block -> SimpleVar.Set.set
21    
22    end = struct    end = struct
23    
# Line 35  Line 36 
36      local      local
37        val {getFn, setFn, ...} = S.newProp (fn _ => VSet.empty)        val {getFn, setFn, ...} = S.newProp (fn _ => VSet.empty)
38      in      in
39      val liveVars = getFn      val liveIn = getFn
40      val setLive = setFn      val setLiveIn = setFn
41        end
42    
43        local
44          val {getFn, setFn, ...} = S.newProp (fn _ => VSet.empty)
45        in
46        val liveOut = getFn
47        val setLiveOut = setFn
48      end      end
49    
50    (* does a variable have local scope *)    (* does a variable have local scope *)
# Line 70  Line 78 
78            end            end
79    
80      fun analyze blk = let      fun analyze blk = let
81            fun doBlock (blk as S.Block{code, ...}, acc) = let            fun doBlock (blk as S.Block{code, ...}, liveIn) = let
82                  val result as (liveOut, assigns) = List.foldr doStm acc code                  val result as (liveOut, assigns) = List.foldr doStm (liveIn, VSet.empty) code
83                  in                  in
84                    setAssigned (blk, assigns);                    setAssigned (blk, assigns);
85                    setLive (blk, liveOut);                    setLiveIn (blk, liveIn);
86                      setLiveOut (blk, liveOut);
87                    result                    result
88                  end                  end
89            and doStm (S.S_Var(x, NONE), (live, assigns)) =            and doStm (S.S_Var(x, NONE), (live, assigns)) =
# Line 83  Line 92 
92                  (addUses(e, VSet.subtract(live, x)), VSet.subtract(assigns, x))                  (addUses(e, VSet.subtract(live, x)), VSet.subtract(assigns, x))
93              | doStm (S.S_Assign(x, e), (live, assigns)) =              | doStm (S.S_Assign(x, e), (live, assigns)) =
94                  (addUses(e, VSet.subtract(live, x)), addVar(x, assigns))                  (addUses(e, VSet.subtract(live, x)), addVar(x, assigns))
95              | doStm (S.S_Foreach(x, _, b), acc) = let              | doStm (S.S_Foreach(x, _, b), (liveIn, assignsIn)) = let
96                  val (liveOut, assigns) = doBlock (b, acc)                  val (liveOut, assigns) = doBlock (b, liveIn)
97                  val liveOut = VSet.subtract(liveOut, x)                  val liveOut = VSet.union(VSet.subtract(liveOut, x), liveIn)
98                  val assigns = VSet.subtract(assigns, x)                  val assigns = VSet.union(VSet.subtract(assigns, x), assignsIn)
99                  in                  in
100  (* QUESTION: do we want to modify the properties of b? *)  (* QUESTION: do we want to modify the properties of b? *)
101                    (liveOut, assigns)                    (liveOut, assigns)
102                  end                  end
103              | doStm (S.S_IfThenElse(_, b1, b2), acc) = let              | doStm (S.S_IfThenElse(_, b1, b2), (liveIn, assignsIn)) = let
104                  val (live1, assigns1) = doBlock (b1, acc)                  val (live1, assigns1) = doBlock (b1, liveIn)
105                  val (live2, assigns2) = doBlock (b2, acc)                  val (live2, assigns2) = doBlock (b2, liveIn)
106                    val assigns = VSet.union(assignsIn, VSet.union(assigns1, assigns2))
107                  in                  in
108                    (VSet.union(live1, live2), VSet.union(assigns1, assigns2))                    (VSet.union(live1, live2), assigns)
109                  end                  end
110              | doStm (S.S_Return x, (live, assigns)) = (addVar (x, live), assigns)              | doStm (S.S_Return x, (live, assigns)) = (addVar (x, live), assigns)
111              | doStm (S.S_Print xs, (live, assigns)) = (addList (xs, live), assigns)              | doStm (S.S_Print xs, (live, assigns)) = (addList (xs, live), assigns)
112              | doStm (_, acc) = acc              | doStm (_, acc) = acc
113            val (bnd, assigns) = doBlock (blk, (VSet.empty, VSet.empty))            val (bnd, assigns) = doBlock (blk, VSet.empty)
114            in            in
115              ()              ()
116            end            end

Legend:
Removed from v.3501  
changed lines
  Added in v.3502

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