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 2059, Tue Oct 30 17:46:04 2012 UTC revision 2140, Thu Feb 14 23:58:15 2013 UTC
# Line 66  Line 66 
66              (* end case *)              (* end case *)
67            end            end
68    
69      (* is the given statement's continuation the syntactically following statement? *)
70        fun contIsNext (AST.S_Block stms) = List.all contIsNext stms
71          | contIsNext AST.S_Die = false
72          | contIsNext AST.S_Stabilize = false
73          | contIsNext (AST.S_Return _) = false
74          | contIsNext _ = true
75    
76      fun simplifyProgram (AST.Program dcls) = let      fun simplifyProgram (AST.Program dcls) = let
77            val inputs = ref []            val inputs = ref []
78            val globals = ref []            val globals = ref []
79            val globalInit = ref []            val globalInit = ref []
80              val funcs = ref []
81            val initially = ref NONE            val initially = ref NONE
82            val strands = ref []            val strands = ref []
83            fun setInitially init = (case !initially            fun setInitially init = (case !initially
# Line 130  Line 138 
138                          globals := x :: !globals;                          globals := x :: !globals;
139                          globalInit := S.S_Assign(x, e') :: (stms @ !globalInit)                          globalInit := S.S_Assign(x, e') :: (stms @ !globalInit)
140                        end                        end
141                      | AST.D_Func(f, params, body) =>
142                          funcs := S.Func{f=f, params=params, body=simplifyBlock body} :: !funcs
143                    | AST.D_Strand info => strands := simplifyStrand info :: !strands                    | AST.D_Strand info => strands := simplifyStrand info :: !strands
144                    | AST.D_InitialArray(creat, iters) =>                    | AST.D_InitialArray(creat, iters) =>
145                        setInitially (simplifyInit(true, creat, iters))                        setInitially (simplifyInit(true, creat, iters))
# Line 142  Line 152 
152                  inputs = List.rev(!inputs),                  inputs = List.rev(!inputs),
153                  globals = List.rev(!globals),                  globals = List.rev(!globals),
154                  globalInit = mkBlock (!globalInit),                  globalInit = mkBlock (!globalInit),
155                    funcs = List.rev(!funcs),
156                  init = (case !initially                  init = (case !initially
157  (* FIXME: the check for the initially block should really happen in typechecking *)  (* FIXME: the check for the initially block should really happen in typechecking *)
158                     of NONE => raise Fail "missing initially declaration"                     of NONE => raise Fail "missing initially declaration"
# Line 201  Line 212 
212    
213      and simplifyStmt (stm, stms) = (case stm      and simplifyStmt (stm, stms) = (case stm
214             of AST.S_Block body => let             of AST.S_Block body => let
215    (* FIXME: we should probably prune unreachable code in the typechecker and issue a warning! *)
216                  fun simplify ([], stms) = stms                  fun simplify ([], stms) = stms
217                    | simplify (stm::r, stms) = simplify (r, simplifyStmt (stm, stms))                    | simplify (stm::r, stms) = if contIsNext stm
218                          then simplify (r, simplifyStmt (stm, stms))
219                          else simplify (r, [])  (* prune unreachable statements *)
220                  in                  in
221                    simplify (body, stms)                    simplify (body, stms)
222                  end                  end
# Line 230  Line 244 
244                  end                  end
245              | AST.S_Die => S.S_Die :: stms              | AST.S_Die => S.S_Die :: stms
246              | AST.S_Stabilize => S.S_Stabilize :: stms              | AST.S_Stabilize => S.S_Stabilize :: stms
247                | AST.S_Return e => let
248                    val (stms, x) = simplifyExpToVar (e, stms)
249                    in
250                      S.S_Return x :: stms
251                    end
252              | AST.S_Print args => let              | AST.S_Print args => let
253                  val (stms, xs) = simplifyExpsToVars (args, stms)                  val (stms, xs) = simplifyExpsToVars (args, stms)
254                  in                  in

Legend:
Removed from v.2059  
changed lines
  Added in v.2140

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