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 4164, Thu Jul 7 12:56:59 2016 UTC revision 4166, Thu Jul 7 14:33:11 2016 UTC
# Line 39  Line 39 
39      structure VSet = SV.Set      structure VSet = SV.Set
40    
41      datatype context      datatype context
42        = ConstInit | GlobalInit | StateInit        = ConstInit | UserFunc | GlobalInit | StateInit
43        | InitMeth | UpdateMeth | StabilizeMeth        | InitMeth | UpdateMeth | StabilizeMeth
44        | Create | GlobalUpdate        | Create | GlobalUpdate
45    
# Line 121  Line 121 
121              | _ => false              | _ => false
122            (* end case *))            (* end case *))
123    
     fun addVar (x, vs) = if isLocal x then VSet.add(vs, x) else vs  
   
     fun addList (xs, vs) = List.foldl addVar vs xs  
   
124  (* FIXME: need to use context to filter out globals in some situations *)  (* FIXME: need to use context to filter out globals in some situations *)
125      fun analyzeBlock cxt blk = let      fun analyzeBlock cxt blk = let
126            val globals = ref VSet.empty            val globals = ref VSet.empty
127              fun addGlobal x = (globals := VSet.add(!globals, x))
128              fun addVar (x, vs) =
129                    if isLocal x then VSet.add(vs, x)
130                    else (case (SV.kindOf x, cxt)
131                       of (SV.ConstVar, ConstInit) => ()
132                        | (SV.ConstVar, _) => addGlobal x
133                        | (SV.InputVar, ConstInit) => ()
134                        | (SV.InputVar, _) => addGlobal x
135                        | (SV.GlobalVar, ConstInit) => ()
136                        | (SV.GlobalVar, GlobalInit) => ()
137                        | (SV.GlobalVar, _) => addGlobal x
138                        | _ => ()
139                      (* end case *);
140                      vs)
141              fun addList (xs, vs) = List.foldl addVar vs xs
142          (* compute the used local and global variables of a Simple AST expression *)          (* compute the used local and global variables of a Simple AST expression *)
143            fun addUses (e, vs) = let            fun addUses (e, vs) = let
144                  val u = (case e                  val u = (case e
# Line 146  Line 157 
157                          | S.E_InsideImage(pos, img, _) => [pos, img]                          | S.E_InsideImage(pos, img, _) => [pos, img]
158                        (* end case *))                        (* end case *))
159                  in                  in
160                    case List.partition SV.isGlobal u                    addList (u, vs)
                    of ([], []) => vs  
                     | (gvs, []) => (globals := addList (gvs, !globals); vs)  
                     | ([], u) => addList (u, vs)  
                     | (gvs, u) => (globals := addList (gvs, !globals); addList (u, vs))  
                   (* end case *)  
161                  end                  end
162            fun doBlock (blk as S.Block{code, ...}, liveIn) = let            fun doBlock (blk as S.Block{code, ...}, liveIn) = let
163                  val result as (liveOut, assigns) = List.foldr doStm (liveIn, VSet.empty) code                  val result as (liveOut, assigns) = List.foldr doStm (liveIn, VSet.empty) code
# Line 195  Line 201 
201              | doStm (_, acc) = acc              | doStm (_, acc) = acc
202            val (bnd, assigns) = doBlock (blk, VSet.empty)            val (bnd, assigns) = doBlock (blk, VSet.empty)
203            in            in
204    print(concat[
205    "globals = {", String.concatWithMap "," SV.uniqueNameOf (VSet.listItems (!globals)), "}\n"]);
206              setGlobalsOfBlock (blk, !globals)              setGlobalsOfBlock (blk, !globals)
207            end            end
208    
209      fun analyze (S.Program{constInit, globInit, strand, create, init, update, ...}) = let      fun analyze (S.Program{constInit, funcs, globInit, strand, create, init, update, ...}) = let
210            val S.Strand{stateInit, initM, updateM, stabilizeM, ...} = strand            val S.Strand{stateInit, initM, updateM, stabilizeM, ...} = strand
211            in            in
212              analyzeBlock ConstInit constInit;              analyzeBlock ConstInit constInit;
213    print "## functions\n";
214                List.app (fn (S.Func{body, ...}) => analyzeBlock UserFunc body) funcs;
215    print "## global init\n";
216              analyzeBlock GlobalInit globInit;              analyzeBlock GlobalInit globInit;
217    print "## state init\n";
218              analyzeBlock StateInit stateInit;              analyzeBlock StateInit stateInit;
219              Option.app (analyzeBlock InitMeth) initM;              Option.app (analyzeBlock InitMeth) initM;
220              analyzeBlock UpdateMeth updateM;              analyzeBlock UpdateMeth updateM;

Legend:
Removed from v.4164  
changed lines
  Added in v.4166

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