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 2154, Mon Feb 18 16:54:22 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.IfThenElse(_, s1, s2)) = contIsNext s1 orelse contIsNext s2
72          | contIsNext AST.S_Die = false
73          | contIsNext AST.S_Stabilize = false
74          | contIsNext (AST.S_Return _) = false
75          | contIsNext _ = true
76    
77      fun simplifyProgram (AST.Program dcls) = let      fun simplifyProgram (AST.Program dcls) = let
78            val inputs = ref []            val inputs = ref []
79            val globals = ref []            val globals = ref []
80            val globalInit = ref []            val globalInit = ref []
81              val funcs = ref []
82            val initially = ref NONE            val initially = ref NONE
83            val strands = ref []            val strands = ref []
84            fun setInitially init = (case !initially            fun setInitially init = (case !initially
# Line 130  Line 139 
139                          globals := x :: !globals;                          globals := x :: !globals;
140                          globalInit := S.S_Assign(x, e') :: (stms @ !globalInit)                          globalInit := S.S_Assign(x, e') :: (stms @ !globalInit)
141                        end                        end
142                      | AST.D_Func(f, params, body) =>
143                          funcs := S.Func{f=f, params=params, body=simplifyBlock body} :: !funcs
144                    | AST.D_Strand info => strands := simplifyStrand info :: !strands                    | AST.D_Strand info => strands := simplifyStrand info :: !strands
145                    | AST.D_InitialArray(creat, iters) =>                    | AST.D_InitialArray(creat, iters) =>
146                        setInitially (simplifyInit(true, creat, iters))                        setInitially (simplifyInit(true, creat, iters))
# Line 142  Line 153 
153                  inputs = List.rev(!inputs),                  inputs = List.rev(!inputs),
154                  globals = List.rev(!globals),                  globals = List.rev(!globals),
155                  globalInit = mkBlock (!globalInit),                  globalInit = mkBlock (!globalInit),
156                    funcs = List.rev(!funcs),
157                  init = (case !initially                  init = (case !initially
158  (* FIXME: the check for the initially block should really happen in typechecking *)  (* FIXME: the check for the initially block should really happen in typechecking *)
159                     of NONE => raise Fail "missing initially declaration"                     of NONE => raise Fail "missing initially declaration"
# Line 199  Line 211 
211     *)     *)
212      and simplifyBlock stm = mkBlock (simplifyStmt (stm, []))      and simplifyBlock stm = mkBlock (simplifyStmt (stm, []))
213    
214      (* simplify the statement stm where stms is a reverse-order list of preceeding simplified
215       * statements.  This function returns a reverse-order list of simplified statements.
216       * Note that error reporting is done in the typechecker, but it does not prune unreachable
217       * code.
218       *)
219      and simplifyStmt (stm, stms) = (case stm      and simplifyStmt (stm, stms) = (case stm
220             of AST.S_Block body => let             of AST.S_Block body => let
221                  fun simplify ([], stms) = stms                  fun simplify ([], stms) = stms
222                    | simplify (stm::r, stms) = simplify (r, simplifyStmt (stm, stms))                    | simplify (stm::r, stms) = if contIsNext stm
223                          then simplify (r, simplifyStmt (stm, stms))
224                          else simplifyStmt (stm, stms)  (* prune unreachable statements *)
225                  in                  in
226                    simplify (body, stms)                    simplify (body, stms)
227                  end                  end
# Line 230  Line 249 
249                  end                  end
250              | AST.S_Die => S.S_Die :: stms              | AST.S_Die => S.S_Die :: stms
251              | AST.S_Stabilize => S.S_Stabilize :: stms              | AST.S_Stabilize => S.S_Stabilize :: stms
252                | AST.S_Return e => let
253                    val (stms, x) = simplifyExpToVar (e, stms)
254                    in
255                      S.S_Return x :: stms
256                    end
257              | AST.S_Print args => let              | AST.S_Print args => let
258                  val (stms, xs) = simplifyExpsToVars (args, stms)                  val (stms, xs) = simplifyExpsToVars (args, stms)
259                  in                  in
# Line 342  Line 366 
366    
367      fun transform (errStrm, ast) = let      fun transform (errStrm, ast) = let
368            val simple = simplifyProgram ast            val simple = simplifyProgram ast
369            val _ = SimplePP.output (Log.logFile(), simple)       (* DEBUG *)            val _ = SimplePP.output (Log.logFile(), "simplify", simple)   (* DEBUG *)
370              val simple = Inliner.transform simple
371              val _ = SimplePP.output (Log.logFile(), "inlining", simple)   (* DEBUG *)
372  (*  (*
373            val simple = Lift.transform simple            val simple = Lift.transform simple
374                  handle Eval.Error msg => (Error.error(errStrm, msg); simple)                  handle Eval.Error msg => (Error.error(errStrm, msg); simple)

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

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