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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/low-to-tree/low-to-tree.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/low-to-tree/low-to-tree.sml

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

revision 4173, Fri Jul 8 11:49:31 2016 UTC revision 4175, Fri Jul 8 15:26:30 2016 UTC
# Line 67  Line 67 
67    
68    (* associate Tree IL function variables with Low IL variables using properties *)    (* associate Tree IL function variables with Low IL variables using properties *)
69      local      local
70        fun mkFuncVar f = let        val {setFn, getFn : IR.func -> TreeFunc.t, ...} =
71              val (resTy, paramTys) = IR.Func.ty f              IR.Func.newProp (fn f => raise Fail("no binding for function " ^ IR.Func.toString f))
72              in              in
73        val getFuncVar = getFn
74        fun mkFuncVar (f, needsWrld, hasGlobs) = let
75              val (resTy, paramTys) = IR.Func.ty f
76  (* QUESTION: what about vector result/arguments? *)  (* QUESTION: what about vector result/arguments? *)
77                TreeFunc.new (IR.Func.name f, U.trType resTy, List.map U.trType paramTys)            val f' = TreeFunc.new (
78              end                  IR.Func.name f, U.trType resTy, List.map U.trType paramTys,
79                    needsWrld, hasGlobs)
80      in      in
81      val {getFn = getFuncVar, ...} = IR.Func.newProp mkFuncVar              setFn (f, f'); f'
82              end
83      end      end
84    
85    (* for variables that are in an equivalence class (see UnifyVars), we use a single    (* for variables that are in an equivalence class (see UnifyVars), we use a single
# Line 887  Line 892 
892    
893      fun trCFG info cfg = ScopeVars.assignScopes ([], trCFGWithEnv (Env.new info, cfg))      fun trCFG info cfg = ScopeVars.assignScopes ([], trCFGWithEnv (Env.new info, cfg))
894    
895      (* Convert a user-defined function.  We need to check for language features
896       * that require the world pointer (e.g., printing) and for references to global variables.
897       *)
898      fun trFunc info (IR.Func{name, params, body}) = let      fun trFunc info (IR.Func{name, params, body}) = let
           val name' = getFuncVar name  
899            val params' = List.map U.newParamVar params            val params' = List.map U.newParamVar params
900            val env = Env.new info            val env = Env.new info
901            val _ = ListPair.appEq            val _ = ListPair.appEq
902                      (fn (x, x') => Env.bindSimple (env, x, T.E_Var x'))                      (fn (x, x') => Env.bindSimple (env, x, T.E_Var x'))
903                        (params, params')                        (params, params')
904            val body' = ScopeVars.assignScopes (params', trCFGWithEnv (env, body))            val body' = ScopeVars.assignScopes (params', trCFGWithEnv (env, body))
905              val {needsWorld, usesGlobals} = Util.analyzeBlock body'
906              val name' = mkFuncVar (name, needsWorld, usesGlobals)
907            in            in
908              T.Func{name = name', params = params', body = body'}              T.Func{name = name', params = params', body = body'}
909            end            end
# Line 903  Line 912 
912     * that require the world pointer (e.g., printing) and for references to global variables.     * that require the world pointer (e.g., printing) and for references to global variables.
913     *)     *)
914      fun mkMethod body = let      fun mkMethod body = let
915            fun chkBlock (T.Block{body, ...}, uG, nW) =            val {needsWorld, usesGlobals} = Util.analyzeBlock body
                 chkStms (body, uG, nW)  
           and chkStms ([], uG, nW) = (uG, nW)  
             | chkStms (stm::stms, uG, nW) = let  
                 fun next (true, true) = (true, true)  
                   | next (uG, nW) = chkStms (stms, uG, nW)  
                 in  
                   case stm  
                    of T.S_Assign(_, _, e) => next (chkExp (e, uG, nW))  
                     | T.S_MAssign(_, e) => next (chkExp (e, uG, nW))  
                     | T.S_GAssign(_, e) => next (chkExp (e, true, nW))  
                     | T.S_IfThen(e, blk) => let  
                         val (uG, nW) = chkExp (e, uG, nW)  
                         in  
                           next (chkBlock (blk, uG, nW))  
                         end  
                     | T.S_IfThenElse(e, blk1, blk2) => let  
                         val (uG, nW) = chkExp (e, uG, nW)  
                         val (uG, nW) = chkBlock (blk1, uG, nW)  
                         in  
                           next (chkBlock (blk2, uG, nW))  
                         end  
                     | T.S_For(_, e1, e2, blk) => let  
                         val (uG, nW) = chkExp (e1, uG, nW)  
                         val (uG, nW) = chkExp (e2, uG, nW)  
                         in  
                           next (chkBlock (blk, uG, nW))  
                         end  
                     | T.S_Foreach(_, e, blk) => let  
                         val (uG, nW) = chkExp (e, uG, nW)  
                         in  
                           next (chkBlock (blk, uG, nW))  
                         end  
                     | T.S_LoadNrrd _ => raise Fail "unexpected LoadNrrd"  
                     | T.S_Input _ => raise Fail "unexpected Input"  
                     | T.S_InputNrrd _ => raise Fail "unexpected InputNrrd"  
                     | T.S_New(_, es) => next (chkExps (es, uG, true))  
                     | T.S_Save(_, e) => next (chkExp (e, uG, nW))  
                     | T.S_Print(_, es) => next (chkExps (es, uG, true))  
                     | _ => next (uG, nW)  
                   (* end case *)  
                 end  
           and chkExps ([], uG, nW) = (uG, nW)  
             | chkExps (_, true, true) = (true, true)  
             | chkExps (e::es, uG, nW) = let  
                 val (uG, nW) = chkExp (e, uG, nW)  
                 in  
                   chkExps (es, uG, nW)  
                 end  
           and chkExp (T.E_Global gv, _, nW) = (true, nW)  
             | chkExp (T.E_State(SOME e, _), uG, nW) = chkExp (e, uG, nW)  
             | chkExp (T.E_Op(TOp.SphereQuery _, es), uG, nW) = chkExps (es, uG, true)  
             | chkExp (T.E_Op(_, es), uG, nW) = chkExps (es, uG, nW)  
             | chkExp (T.E_Vec(_, _, es), uG, nW) = chkExps (es, uG, nW)  
             | chkExp (T.E_Cons(es, _), uG, nW) = chkExps (es, uG, nW)  
             | chkExp (T.E_Seq(es, _), uG, nW) = chkExps (es, uG, nW)  
             | chkExp (T.E_Pack(_, es), uG, nW) = chkExps (es, uG, nW)  
             | chkExp (T.E_VLoad(_, e, _), uG, nW) = chkExp (e, uG, nW)  
             | chkExp (_, uG, nW) = (uG, nW)  
           val (usesGlobals, needsWorld) = chkBlock (body, false, false)  
916            in            in
917              T.Method{usesGlobals = usesGlobals, needsWorld = needsWorld, body = body}              T.Method{needsW = needsWorld, hasG = usesGlobals, body = body}
918            end            end
919    
920      fun trStrand info strand = let      fun trStrand info strand = let

Legend:
Removed from v.4173  
changed lines
  Added in v.4175

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