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

SCM Repository

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

Diff of /trunk/src/compiler/translate/translate.sml

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

revision 168, Wed Jul 21 20:58:37 2010 UTC revision 190, Sat Jul 31 04:39:18 2010 UTC
# Line 3  Line 3 
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *   *
6   * Translate AST code into the IL representation.   * Translate Simple-AST code into the IL representation.
7   *)   *)
8    
9  structure Translate : sig  structure Translate : sig
10    
11      val translate : AST.program -> ??      val translate : Simple.program -> HighIL.program
12    
13    end = struct    end = struct
14    
15        structure S = Simple
16      structure VMap = Var.Map      structure VMap = Var.Map
17        structure VSet = Var.Set
18      structure IL = HighIL      structure IL = HighIL
19    
20    (* expression translation *)      fun lookup env x = (case VMap.find x
21      fun cvtExpr (env, exp, kont) = let             of SOME x' => x'
22            fun cvt e = (case e              | NONE => raise Fail(concat[
23                   of AST.E_Var(x, tyArgs, ty) =>                    "no binding for ", Var.toString x, " in environment"
24                    | AST.E_Lit lit =>                  ])
                   | AST.E_Tuple es =>  
                   | AST.E_Apply(f, tyArgs, args, ty) =>  
                   | AST.E_Cons of expr list  
                   | AST.E_Cond(e1, e2, e3) =>  
25                  (* end case *))                  (* end case *))
26    
27      (* create a new instance of a variable *)
28        fun newVar x = IL.newVar (Var.nameOf x)
29    
30      (* expression translation *)
31        fun cvtExpr (env, lhs, exp) = (case exp
32               of S.E_Var x => [(lhs, IL.VAR(lookup env x))]
33                | S.E_Lit lit => [(lhs, IL.LIT lit)]
34                | S.E_Tuple xs => raise Fail "E_Tuple not implemeted"
35                | S.E_Apply(f, tyArgs, args, ty) => let
36                    val args' = List.map (lookup env) args
37            in            in
38                      TranslateBasis.translate (lhs, f, tyArgs, args')
39            end            end
40                | S.E_Cons args => [(lhs, IL.CONS(List.map (lookup env) args))]
41              (* end case *))
42    
43      and cvtStmt (env, stm) = (case stm      fun cvtBlock (env, S.Block stms) =
44             of AST.S_Block of stmt list  
45              | AST.S_Decl of var_decl    (* convert a statement, where env is the mapping from Simple AST variables to
46              | AST.S_IfThenElse of expr * stmt * stmt     * their current SSA name, assigned is the set of AST variables assigned to
47              | AST.S_Assign of var * expr     * in the current context, and stm is the statement to convert.
48              | AST.S_New of Atom.atom * expr list     *)
49              | AST.S_Die      and cvtStmt (env, assigned, stm, preStms, k) = (case stm
50              | AST.S_Stabilize             of S.S_Assign(x, e) => let
51                    val x' = newVar x
52                    val stms = cvtExp(env, x', e)
53                    val assigned = VSet.add(assigned, x)
54                    val env = VMap.insert(env, x, x')
55                    in
56                      k (env, assigned, stm::preStms)
57                    end
58                | S.S_IfThenElse(x, b1, b2) => let
59                    val x' = lookup env x
60                    val (b1, env1, assigned1) = block(env, b1)
61                    val (b2, env2, assigned2) = block(env, b2)
62                    val assigned = VSet.union(assigned1, assigned2)
63                    val (env, phis) = let
64                          fun mkPhi (x, (env, phis) = let
65                                val x1 = lookup(env1, x)
66                                val x2 = lookup(env2, x)
67                                val x' = newVar x
68                                in
69                                  (VMap.insert(env, x, x'), (x', [x1, x2])::phis)
70                                end
71                          in
72                            VSet.foldl mkPhi (env, []) assigned
73                          end
74                    in
75                    end
76                | S.S_New(name, xs) =>
77                | S.S_Die =>
78                | S.S_Stabilize =>
79            (* end case *))            (* end case *))
80    
81        fun newBlock (??, stm) =
82    
83        and nextStmt (env, assigned, stm, ??) =
84    
85        and join (env
86        fun translate (S.Program{globals, globaInit, actors}) = ??
87    
88    end    end

Legend:
Removed from v.168  
changed lines
  Added in v.190

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