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

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/compiler/c-util/tree-to-c-fn.sml
ViewVC logotype

Diff of /branches/pure-cfg/src/compiler/c-util/tree-to-c-fn.sml

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

branches/pure-cfg/src/compiler/c-util/tree-to-c.sml revision 1283, Mon Jun 6 22:24:53 2011 UTC branches/pure-cfg/src/compiler/c-util/tree-to-c-fn.sml revision 1285, Tue Jun 7 10:33:17 2011 UTC
# Line 6  Line 6 
6   * Translate TreeIL to the C version of CLang.   * Translate TreeIL to the C version of CLang.
7   *)   *)
8    
9  structure TreeToC : sig  signature TREE_VAR_TO_C =
10      sig
11        type env = CLang.typed_var TreeIL.Var.Map.map
12      (* translate a variable that occurs in an l-value context (i.e., as the target of an assignment) *)
13        val lvalueVar : env * TreeIL.var -> CLang.exp
14      (* translate a variable that occurs in a r-value context *)
15        val rvalueVar : env * TreeIL.var -> CLang.exp
16      end
17    
18      datatype var = V of (CLang.ty * CLang.var)  functor TreeToCFn (VarToC : TREE_VAR_TO_C) : sig
19    
20      type env = var TreeIL.Var.Map.map      type env = CLang.typed_var TreeIL.Var.Map.map
21    
22      val trType : TreeIL.Ty.ty -> CLang.ty      val trType : TreeIL.Ty.ty -> CLang.ty
23    
# Line 35  Line 42 
42      structure Ty = IL.Ty      structure Ty = IL.Ty
43      structure V = IL.Var      structure V = IL.Var
44    
45      datatype var = V of (CLang.ty * CLang.var)      datatype var = datatype CLang.typed_var
46        type env = CLang.typed_var TreeIL.Var.Map.map
     type env = var TreeIL.Var.Map.map  
47    
48      fun lookup (env, x) = (case V.Map.find (env, x)      fun lookup (env, x) = (case V.Map.find (env, x)
49             of SOME(V(_, x')) => x'             of SOME(V(_, x')) => x'
# Line 111  Line 117 
117              CL.mkSubscript(e2, intExp ix)              CL.mkSubscript(e2, intExp ix)
118            end            end
119    
   (* translate a variable use *)  
     fun trVar (env, x) = (case V.kind x  
            of IL.VK_Global => CL.mkVar(lookup(env, x))  
             | IL.VK_State strand => CL.mkIndirect(CL.mkVar "selfIn", lookup(env, x))  
             | IL.VK_Local => CL.mkVar(lookup(env, x))  
           (* end case *))  
   
120    (* Translate a TreeIL operator application to a CLang expression *)    (* Translate a TreeIL operator application to a CLang expression *)
121      fun trOp (rator, args) = (case (rator, args)      fun trOp (rator, args) = (case (rator, args)
122             of (Op.Add ty, [a, b]) =>             of (Op.Add ty, [a, b]) =>
# Line 259  Line 258 
258            (* end case *))            (* end case *))
259    
260      fun trExp (env, e) = (case e      fun trExp (env, e) = (case e
261             of IL.E_Var x => trVar (env, x)             of IL.E_Var x => VarToC.rvalueVar (env, x)
262              | IL.E_Lit(Literal.Int n) => CL.mkInt(n, !N.gIntTy)              | IL.E_Lit(Literal.Int n) => CL.mkInt(n, !N.gIntTy)
263              | IL.E_Lit(Literal.Bool b) => CL.mkBool b              | IL.E_Lit(Literal.Bool b) => CL.mkBool b
264              | IL.E_Lit(Literal.Float f) => CL.mkFlt(f, !N.gRealTy)              | IL.E_Lit(Literal.Float f) => CL.mkFlt(f, !N.gRealTy)
# Line 273  Line 272 
272      and trExps (env, exps) = List.map (fn exp => trExp(env, exp)) exps      and trExps (env, exps) = List.map (fn exp => trExp(env, exp)) exps
273    
274      fun trAssign (env, lhs, rhs) = let      fun trAssign (env, lhs, rhs) = let
275            val lhs = (case V.kind lhs            val lhs = VarToC.lvalueVar (env, lhs)
                  of IL.VK_Global => CL.mkVar(lookup(env, lhs))  
                   | IL.VK_State strand => CL.mkIndirect(CL.mkVar "selfOut", lookup(env, lhs))  
                   | IL.VK_Local => CL.mkVar(lookup(env, lhs))  
                 (* end case *))  
276            in            in
277            (* certain rhs forms, such as those that return a matrix,            (* certain rhs forms, such as those that return a matrix,
278             * require a function call instead of an assignment             * require a function call instead of an assignment
# Line 327  Line 322 
322                      doRows (0, trExps(env, args))                      doRows (0, trExps(env, args))
323                    end                    end
324                | IL.E_Var x => (case IL.Var.ty x                | IL.E_Var x => (case IL.Var.ty x
325                     of Ty.TensorTy[n,m] => [CL.mkCall(N.copyMat(n,m), [lhs, trVar(env, x)])]                     of Ty.TensorTy[n,m] => [CL.mkCall(N.copyMat(n,m), [lhs, VarToC.rvalueVar(env, x)])]
326                      | _ => [CL.mkAssign(lhs, trVar(env, x))]                      | _ => [CL.mkAssign(lhs, VarToC.rvalueVar(env, x))]
327                    (* end case *))                    (* end case *))
328                | _ => [CL.mkAssign(lhs, trExp(env, rhs))]                | _ => [CL.mkAssign(lhs, trExp(env, rhs))]
329              (* end case *)              (* end case *)

Legend:
Removed from v.1283  
changed lines
  Added in v.1285

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