Home My Page Projects Code Snippets Project Openings diderot

SCM Repository

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

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

revision 221, Tue Aug 3 20:13:55 2010 UTC revision 435, Tue Oct 19 13:14:20 2010 UTC
# Line 1  Line 1
1  (* simplify.sml  (* simplify.sml
2   *   *
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
5   *   *
6   * Simplify the AST representation.   * Simplify the AST representation.
# Line 24  Line 24
24    (* make a block out of a list of statements that are in reverse order *)    (* make a block out of a list of statements that are in reverse order *)
25      fun mkBlock stms = S.Block(List.rev stms)      fun mkBlock stms = S.Block(List.rev stms)
26
27      fun transform (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 actors = ref []            val actors = ref []
31            fun simplifyDecl dcl = (case dcl            fun simplifyDecl dcl = (case dcl
32                   of AST.D_Input(x, NONE) => let                   of AST.D_Input(x, NONE) => let
33                        val e' = S.E_Input(Var.nameOf x, NONE)                        val e' = S.E_Input(Var.monoTypeOf x, Var.nameOf x, NONE)
34                        in                        in
35                          globals := x :: !globals;                          globals := x :: !globals;
36                          globalInit := S.S_Assign(x, e') :: !globalInit                          globalInit := S.S_Assign(x, e') :: !globalInit
37                        end                        end
38                    | AST.D_Input(x, SOME e) => let                    | AST.D_Input(x, SOME e) => let
39                        val (stms, x') = simplifyExpToVar (e, [])                        val (stms, x') = simplifyExpToVar (e, [])
40                        val e' = S.E_Input(Var.nameOf x, SOME x')                        val e' = S.E_Input(Var.monoTypeOf x, Var.nameOf x, SOME x')
41                        in                        in
42                          globals := x :: !globals;                          globals := x :: !globals;
43                          globalInit := S.S_Assign(x, e') :: (stms @ !globalInit)                          globalInit := S.S_Assign(x, e') :: (stms @ !globalInit)
# Line 143  Line 143
143                  in                  in
144                    (stms, S.E_Cons xs)                    (stms, S.E_Cons xs)
145                  end                  end
146              | AST.E_Cond(e1, e2, e3) => let              | AST.E_Slice(e, indices, ty) => let (* tensor slicing *)
147                    val (stms, x) = simplifyExpToVar (e, stms)
148                    fun f ([], ys, stms) = (stms, List.rev ys)
149                      | f (NONE::es, ys, stms) = f (es, NONE::ys, stms)
150                      | f (SOME e::es, ys, stms) = let
151                          val (stms, y) = simplifyExpToVar (e, stms)
152                          in
153                            f (es, SOME y::ys, stms)
154                          end
155                    val (stms, indices) = f (indices, [], stms)
156                    in
157                      (stms, S.E_Slice(x, indices, ty))
158                    end
159                | AST.E_Cond(e1, e2, e3, ty) => let
160                (* a conditional expression gets turned into an if-then-else statememt *)                (* a conditional expression gets turned into an if-then-else statememt *)
161                  val result = newTemp Ty.T_Bool                  val result = newTemp ty
162                  val (stms, x) = simplifyExpToVar (e1, stms)                  val (stms, x) = simplifyExpToVar (e1, stms)
163                  fun simplifyBranch e = let                  fun simplifyBranch e = let
164                        val (stms, e) = simplifyExp (e, [])                        val (stms, e) = simplifyExp (e, [])
165                        in                        in
166                          mkBlock (S.S_Assign(result, e)::stms)                          mkBlock (S.S_Assign(result, e)::stms)
167                        end                        end
168                  val s1 = simplifyBranch e1                  val s1 = simplifyBranch e2
169                  val s2 = simplifyBranch e2                  val s2 = simplifyBranch e3
170                  in                  in
171                    (S.S_IfThenElse(x, s1, s2) :: stms, S.E_Var result)                    (S.S_IfThenElse(x, s1, s2) :: stms, S.E_Var result)
172                  end                  end
# Line 183  Line 196
196              f (exps, [], stms)              f (exps, [], stms)
197            end            end
198
199        fun transform ast = let
200              val simple = simplifyProgram ast
201              val _ = SimplePP.output (Log.logFile(), simple)       (* DEBUG *)
202              val simple = Lift.transform simple
203              in
204                simple
205              end
206
207    end    end

Legend:
 Removed from v.221 changed lines Added in v.435