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 2140, Thu Feb 14 23:58:15 2013 UTC revision 2328, Fri Mar 22 18:21:07 2013 UTC
# Line 16  Line 16 
16      structure S = Simple      structure S = Simple
17      structure InP = Inputs      structure InP = Inputs
18    
19      (* the SimpleAST and AST currently use the same type representation, but
20       * we prune out meta variables.
21       *)
22        val cvtTy = TypeUtil.prune
23    
24      local      local
25        val tempName = Atom.atom "_t"        val tempName = Atom.atom "_t"
26      in      in
27      fun newTemp ty = Var.new (tempName, AST.LocalVar, ty)      fun newTemp ty = Var.new (tempName, AST.LocalVar, cvtTy ty)
28      end      end
29    
30    (* 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 *)
# Line 68  Line 73 
73    
74    (* is the given statement's continuation the syntactically following statement? *)    (* is the given statement's continuation the syntactically following statement? *)
75      fun contIsNext (AST.S_Block stms) = List.all contIsNext stms      fun contIsNext (AST.S_Block stms) = List.all contIsNext stms
76          | contIsNext (AST.S_IfThenElse(_, s1, s2)) = contIsNext s1 orelse contIsNext s2
77        | contIsNext AST.S_Die = false        | contIsNext AST.S_Die = false
78        | contIsNext AST.S_Stabilize = false        | contIsNext AST.S_Stabilize = false
79        | contIsNext (AST.S_Return _) = false        | contIsNext (AST.S_Return _) = false
# Line 185  Line 191 
191                }                }
192            end            end
193    
194      and simplifyStrand {name, params, state, methods} = let      and simplifyStrand (AST.Strand{name, params, state, methods}) = let
195            fun simplifyState ([], xs, stms) = (List.rev xs, mkBlock stms)            fun simplifyState ([], xs, stms) = (List.rev xs, mkBlock stms)
196              | simplifyState (AST.VD_Decl(x, e) :: r, xs, stms) = let              | simplifyState (AST.VD_Decl(x, e) :: r, xs, stms) = let
197                  val (stms, e') = simplifyExp (e, stms)                  val (stms, e') = simplifyExp (e, stms)
# Line 210  Line 216 
216     *)     *)
217      and simplifyBlock stm = mkBlock (simplifyStmt (stm, []))      and simplifyBlock stm = mkBlock (simplifyStmt (stm, []))
218    
219      (* simplify the statement stm where stms is a reverse-order list of preceeding simplified
220       * statements.  This function returns a reverse-order list of simplified statements.
221       * Note that error reporting is done in the typechecker, but it does not prune unreachable
222       * code.
223       *)
224      and simplifyStmt (stm, stms) = (case stm      and simplifyStmt (stm, stms) = (case stm
225             of AST.S_Block body => let             of AST.S_Block body => let
 (* FIXME: we should probably prune unreachable code in the typechecker and issue a warning! *)  
226                  fun simplify ([], stms) = stms                  fun simplify ([], stms) = stms
227                    | simplify (stm::r, stms) = if contIsNext stm                    | simplify (stm::r, stms) = if contIsNext stm
228                        then simplify (r, simplifyStmt (stm, stms))                        then simplify (r, simplifyStmt (stm, stms))
229                        else simplify (r, [])  (* prune unreachable statements *)                        else simplifyStmt (stm, stms)  (* prune unreachable statements *)
230                  in                  in
231                    simplify (body, stms)                    simplify (body, stms)
232                  end                  end
# Line 330  Line 340 
340              | AST.E_Coerce{srcTy, dstTy, e} => let              | AST.E_Coerce{srcTy, dstTy, e} => let
341                  val (stms, x) = simplifyExpToVar (e, stms)                  val (stms, x) = simplifyExpToVar (e, stms)
342                  val result = newTemp dstTy                  val result = newTemp dstTy
343                    val rhs = S.E_Coerce{srcTy = cvtTy srcTy, dstTy = cvtTy dstTy, x = x}
344                  in                  in
345                    (S.S_Assign(result, S.E_Coerce{srcTy=srcTy, dstTy=dstTy, x=x})::stms, S.E_Var result)                    (S.S_Assign(result, rhs)::stms, S.E_Var result)
346                  end                  end
347            (* end case *))            (* end case *))
348    
# Line 361  Line 372 
372    
373      fun transform (errStrm, ast) = let      fun transform (errStrm, ast) = let
374            val simple = simplifyProgram ast            val simple = simplifyProgram ast
375            val _ = SimplePP.output (Log.logFile(), simple)       (* DEBUG *)            val _ = SimplePP.output (Log.logFile(), "simplify", simple)   (* DEBUG *)
376              val simple = Inliner.transform simple
377              val _ = SimplePP.output (Log.logFile(), "inlining", simple)   (* DEBUG *)
378  (*  (*
379            val simple = Lift.transform simple            val simple = Lift.transform simple
380                  handle Eval.Error msg => (Error.error(errStrm, msg); simple)                  handle Eval.Error msg => (Error.error(errStrm, msg); simple)

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

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