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

SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/simplify/simplify.sml
ViewVC logotype

Diff of /branches/vis12/src/compiler/simplify/simplify.sml

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

revision 1115, Thu May 5 04:42:18 2011 UTC revision 1116, Thu May 5 04:49:02 2011 UTC
# Line 27  Line 27 
27      fun simplifyProgram (AST.Program dcls) = let      fun simplifyProgram (AST.Program dcls) = let
28            val globals = ref []            val globals = ref []
29            val globalInit = ref []            val globalInit = ref []
30              val initially = ref NONE
31            val strands = ref []            val strands = ref []
32              fun setInitially init = (case !initially
33                     of NONE => initially := SOME init
34    (* FIXME: the check for multiple initially decls should happen in type checking *)
35                      | SOME _ => raise Fail "multiple initially declarations"
36                    (* end case *))
37            fun simplifyDecl dcl = (case dcl            fun simplifyDecl dcl = (case dcl
38                   of AST.D_Input(x, NONE) => let                   of AST.D_Input(x, NONE) => let
39                        val e' = S.E_Input(Var.monoTypeOf x, Var.nameOf x, NONE)                        val e' = S.E_Input(Var.monoTypeOf x, Var.nameOf x, NONE)
# Line 49  Line 55 
55                          globalInit := S.S_Assign(x, e') :: (stms @ !globalInit)                          globalInit := S.S_Assign(x, e') :: (stms @ !globalInit)
56                        end                        end
57                    | AST.D_Strand info => strands := simplifyStrand info :: !strands                    | AST.D_Strand info => strands := simplifyStrand info :: !strands
58                    | AST.D_InitialArray(e, iters) => () (* FIXME *)                    | AST.D_InitialArray(creat, iters) =>
59                    | AST.D_InitialCollection(e, iters) => () (* FIXME *)                        setInitially (simplifyInit(true, creat, iters))
60                      | AST.D_InitialCollection(creat, iters) =>
61                          setInitially (simplifyInit(false, creat, iters))
62                  (* end case *))                  (* end case *))
63            in            in
64              List.app simplifyDecl dcls;              List.app simplifyDecl dcls;
65              S.Program{              S.Program{
66                  globals = List.rev(!globals),                  globals = List.rev(!globals),
67                  globalInit = mkBlock (!globalInit),                  globalInit = mkBlock (!globalInit),
68                    init = (case !initially
69    (* FIXME: the check for the initially block should really happen in typechecking *)
70                       of NONE => raise Fail "missing initially declaration"
71                        | SOME blk => blk
72                      (* end case *)),
73                  strands = List.rev(!strands)                  strands = List.rev(!strands)
74                }                }
75            end            end
76    
77        and simplifyInit (isArray, AST.C_Create(strand, exps), iters) = let
78              val (stms, xs) = simplifyExpsToVars (exps, [])
79              val creat = S.C_Create{
80                      argInit = mkBlock stms,
81                      name = strand,
82                      args = xs
83                    }
84              fun simplifyIter (AST.I_Range(x, e1, e2), (iters, stms)) = let
85                    val (stms, lo) = simplifyExpToVar (e1, stms)
86                    val (stms, hi) = simplifyExpToVar (e2, stms)
87                    in
88                      ({param=x, lo=lo, hi=hi}::iters, stms)
89                    end
90              val (iters, stms) = List.foldl simplifyIter ([], []) iters
91              in
92                S.Initially{
93                    isArray = isArray,
94                    rangeInit = mkBlock stms,
95                    iters = List.rev iters,
96                    create = creat
97                  }
98              end
99    
100      and simplifyStrand {name, params, state, methods} = let      and simplifyStrand {name, params, state, methods} = let
101            fun simplifyState ([], xs, stms) = (List.rev xs, mkBlock stms)            fun simplifyState ([], xs, stms) = (List.rev xs, mkBlock stms)
102              | simplifyState (AST.VD_Decl(x, e) :: r, xs, stms) = let              | simplifyState (AST.VD_Decl(x, e) :: r, xs, stms) = let
# Line 81  Line 117 
117      and simplifyMethod (AST.M_Method(name, body)) =      and simplifyMethod (AST.M_Method(name, body)) =
118            S.Method(name, simplifyBlock body)            S.Method(name, simplifyBlock body)
119    
120    (* simplify a statement into a single statement (i.e., a block if it expands into more    (* simplify a statement into a single statement (i.e., a block if it expands
121     * than one new statement.     * into more than one new statement).
122     *)     *)
123      and simplifyBlock stm = mkBlock (simplifyStmt (stm, []))      and simplifyBlock stm = mkBlock (simplifyStmt (stm, []))
124    
# Line 159  Line 195 
195              | AST.E_Cond(e1, e2, e3, ty) => let              | AST.E_Cond(e1, e2, e3, ty) => let
196                (* a conditional expression gets turned into an if-then-else statememt *)                (* a conditional expression gets turned into an if-then-else statememt *)
197                  val result = newTemp ty                  val result = newTemp ty
198                  val (stms, x) = simplifyExpToVar (e1, stms)                  val (stms, x) = simplifyExpToVar (e1, S.S_Var result :: stms)
199                  fun simplifyBranch e = let                  fun simplifyBranch e = let
200                        val (stms, e) = simplifyExp (e, [])                        val (stms, e) = simplifyExp (e, [])
201                        in                        in

Legend:
Removed from v.1115  
changed lines
  Added in v.1116

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