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 2154, Mon Feb 18 16:54:22 2013 UTC revision 2365, Fri Apr 12 12:52:31 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.IfThenElse(_, s1, s2)) = contIsNext s1 orelse contIsNext s2        | 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
80        | contIsNext _ = true        | contIsNext _ = true
81    
82      fun simplifyProgram (AST.Program dcls) = let      fun simplifyProgram (AST.Program{props, decls}) = let
83            val inputs = ref []            val inputs = ref []
84            val globals = ref []            val globals = ref []
85            val globalInit = ref []            val globalInit = ref []
# Line 148  Line 153 
153                        setInitially (simplifyInit(false, creat, iters))                        setInitially (simplifyInit(false, creat, iters))
154                  (* end case *))                  (* end case *))
155            in            in
156              List.app simplifyDecl dcls;              List.app simplifyDecl decls;
157              S.Program{              S.Program{
158                    props = props,
159                  inputs = List.rev(!inputs),                  inputs = List.rev(!inputs),
160                  globals = List.rev(!globals),                  globals = List.rev(!globals),
161                  globalInit = mkBlock (!globalInit),                  globalInit = mkBlock (!globalInit),
# Line 186  Line 192 
192                }                }
193            end            end
194    
195      and simplifyStrand {name, params, state, methods} = let      and simplifyStrand (AST.Strand{name, params, state, methods}) = let
196            fun simplifyState ([], xs, stms) = (List.rev xs, mkBlock stms)            fun simplifyState ([], xs, stms) = (List.rev xs, mkBlock stms)
197              | simplifyState (AST.VD_Decl(x, e) :: r, xs, stms) = let              | simplifyState (AST.VD_Decl(x, e) :: r, xs, stms) = let
198                  val (stms, e') = simplifyExp (e, stms)                  val (stms, e') = simplifyExp (e, stms)
# Line 335  Line 341 
341              | AST.E_Coerce{srcTy, dstTy, e} => let              | AST.E_Coerce{srcTy, dstTy, e} => let
342                  val (stms, x) = simplifyExpToVar (e, stms)                  val (stms, x) = simplifyExpToVar (e, stms)
343                  val result = newTemp dstTy                  val result = newTemp dstTy
344                    val rhs = S.E_Coerce{srcTy = cvtTy srcTy, dstTy = cvtTy dstTy, x = x}
345                  in                  in
346                    (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)
347                  end                  end
348            (* end case *))            (* end case *))
349    

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

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