Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/compiler/codegen/codegen-fn.sml
ViewVC logotype

Diff of /branches/pure-cfg/src/compiler/codegen/codegen-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/compiler/codegen/codegen-fn.sml revision 455, Wed Oct 27 02:42:13 2010 UTC branches/pure-cfg/src/compiler/codegen/codegen-fn.sml revision 477, Sat Nov 13 16:02:07 2010 UTC
# Line 17  Line 17 
17      structure Src = LowIL      structure Src = LowIL
18      structure SrcV = LowIL.Var      structure SrcV = LowIL.Var
19      structure SrcOp = LowOps      structure SrcOp = LowOps
20        structure SrcNd = LowIL.Node
21    
22      (* a property marking nodes that are directly referenced by statememts. *)
23        local
24          val {getFn, setFn, ...} = SrcNd.newFlag ()
25        in
26        val isFirst = getFn
27        fun markFirst nd = setFn(nd, true)
28        end
29    
30      (* walk the statements, marking the first nodes of the statements *)
31        fun markNodes (stm as SrcIL.STM{kind, next}) = (
32              case kind
33               of SrcIL.S_SIMPLE nd => markFirst (nd, stm)
34                | SrcIL.S_IF{cond, thenBranch, elseBranch} => (
35                    markFirst (cond, stm);
36                    markNodes thenBranch;
37                    markNodes elseBranch)
38                | SrcIL.S_LOOP{hdr, cond, body} => (
39                    markNodes hdr;
40                    markFirst (cond, stm);
41                    markNodes body)
42              (* end case *);
43              case next
44               of NONE => ()
45                | SOME stm => markNodes stm
46              (* end case *))
47    
48    (* a mapping from LowIL variables to target expressions.  Variables get    (* a mapping from LowIL variables to target expressions.  Variables get
49     * removed when the expressions are used as arguments.     * removed when the expressions are used as arguments.
# Line 115  Line 142 
142    
143      fun gen (vtbl, stm) = let      fun gen (vtbl, stm) = let
144            val doAssign = doAssign vtbl            val doAssign = doAssign vtbl
145              fun mkBlock [] = ?
146                | mkBlock [s] = s
147                | mkBlock stms = T.Stmt.block stms
148            fun doStmt (SrcIL.STM{kind, next, ...}) = let            fun doStmt (SrcIL.STM{kind, next, ...}) = let
149                  val stms = (case kind                  val stms = (case kind
150                         of SrcIL.S_SIMPLE nd => doNode nd                         of SrcIL.S_SIMPLE nd => doNode nd
151                          | SrcIL.S_IF{cond, thenBranch, elseBranch} =>                          | SrcIL.S_IF{cond, thenBranch, elseBranch} => let
152                          | SrcIL.S_LOOP{hdr, cond, body} =>                              val SrcIL.ND{kind=SrcIL.COND{cond, ...}, ...} = cond
153                                val s1 = mkBlock(doStmt thenBranch)
154                                val s2 = mkBlock(doStmt elseBranch)
155                                in
156    (* FIXME: check for empty else branch *)
157                                  T.ifthenelse(VDefTbl.useDefOf vtbl cond, s1, s2)
158                                end
159                            | SrcIL.S_LOOP{hdr, cond, body} => raise Fail "LOOP not supported yet"
160                        (* end case *))                        (* end case *))
161                  val rest = (case next                  val rest = (case next
162                         of NONE => VDefTbl.flush vtbl                         of NONE => VDefTbl.flush vtbl
# Line 128  Line 165 
165                  in                  in
166                    stms @ rest                    stms @ rest
167                  end                  end
168              and doNode (SrcIL.ND{kind, ...}) = (case kind
169                     of SrcIL.NULL => ??
170                      | SrcIL.ENTRY{succ} => nextNode succ
171                      | SrcIL.JOIN{succ, ...} =>
172                      | SrcIL.COND{cond, ...} =>
173                      | SrcIL.BLOCK{body, succ, ...} =>
174                          List.app doAssign body @ nextNode succ
175                      | SrcIL.NEW{actor, args, ...} =>
176                      | SrcIL.DIE _ =>
177                      | SrcIL.STABILIZE _ =>
178                      | SrcIL.EXIT _ =>
179                    (* end case *))
180              and nextNode nd = if isFirst nd then [] else doNode nd
181            in            in
182                mkBlock (doStmt stm)
183            end            end
184    
185    end    end

Legend:
Removed from v.455  
changed lines
  Added in v.477

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