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/low-to-tree.sml
ViewVC logotype

Diff of /branches/pure-cfg/src/compiler/codegen/low-to-tree.sml

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

revision 603, Fri Mar 11 18:47:41 2011 UTC revision 604, Fri Mar 11 18:48:58 2011 UTC
# Line 73  Line 73 
73    
74      fun newScope (E{tbl, ...}) = E{tbl=tbl, locals=[]}      fun newScope (E{tbl, ...}) = E{tbl=tbl, locals=[]}
75    
76    (* use a variable.  If it is a pending expression, we decrement its use count *)    (* use a variable.  If it is a pending expression, we remove it from the table *)
77      fun useVar (E{tbl, ...}) x = (case VT.find tbl x      fun useVar (E{tbl, ...}) x = (case VT.find tbl x
78             of SOME(GLOB x') => T.E_Var x'             of SOME(GLOB x') => T.E_Var x'
79              | SOME(TREE e) => (              | SOME(TREE e) => (
80                    ignore(VT.remove tbl x);
81                    e)
82                | SOME(DEF e) => (
83                  (* if this is the last use of x, then remove it from the table *)
84                  if (decCount x) then ignore(VT.remove tbl x) else ();                  if (decCount x) then ignore(VT.remove tbl x) else ();
85                  e)                  e)
             | SOME(DEF e) => e  
86              | NONE => raise Fail(concat ["useVar(", V.toString x, ")"])              | NONE => raise Fail(concat ["useVar(", V.toString x, ")"])
87            (* end case *))            (* end case *))
88    
# Line 88  Line 91 
91    
92      fun global (E{tbl, ...}, x, x') = VT.insert tbl (x, GLOB x')      fun global (E{tbl, ...}, x, x') = VT.insert tbl (x, GLOB x')
93    
94      (* insert a pending expression into the table.  Note that x should only be used once! *)
95      fun insert (env as E{tbl, ...}, x, exp) = (      fun insert (env as E{tbl, ...}, x, exp) = (
96            VT.insert tbl (x, TREE exp);            VT.insert tbl (x, TREE exp);
97            env)            env)
# Line 114  Line 118 
118              | NONE => bindLocal (env, lhs, rhs)              | NONE => bindLocal (env, lhs, rhs)
119            (* end case *))            (* end case *))
120    
121      fun setDef (env, lhs, rhs) = (case peekGlobal (env, lhs)    (* set the definition of a variable, where the RHS is either a literal constant or a variable *)
122        fun setDef (env as E{tbl, ...}, lhs, rhs) = (case peekGlobal (env, lhs)
123             of SOME x => (rename(env, lhs, x), [T.S_Assign(x, rhs)])             of SOME x => (rename(env, lhs, x), [T.S_Assign(x, rhs)])
124              | NONE => (insert(env, lhs, rhs), [])              | NONE => (VT.insert tbl (lhs, DEF rhs); (env, []))
125            (* end case *))            (* end case *))
126    
127    (* at the end of a block, we need to assign any pending expressions to locals.  The    (* at the end of a block, we need to assign any pending expressions to locals.  The
# Line 136  Line 141 
141            end            end
142    
143      fun doPhi ((lhs, rhs), (env, predBlks : T.stm list list)) = let      fun doPhi ((lhs, rhs), (env, predBlks : T.stm list list)) = let
144            (* t will be the variable in the continuation of the JOIN *)
145            val t = newLocal lhs            val t = newLocal lhs
146            val predBlks = ListPair.map            val predBlks = ListPair.map
147                  (fn (x, stms) => T.S_Assign(t, useVar env x)::stms)                  (fn (x, stms) => T.S_Assign(t, useVar env x)::stms)
# Line 200  Line 206 
206              (* end case *)              (* end case *)
207            end            end
208    
209      (* In order to reconstruct the block-structure from the CFG, we keep a stack of open ifs.
210       * the items on this stack distinguish between when we are processing the then and else
211       * branches of the if.
212       *)
213      datatype open_if      datatype open_if
214      (* working on the "then" branch.  The fields are statments that preceed the if, the condition,      (* working on the "then" branch.  The fields are statments that preceed the if, the condition,
215       * and the else-branch node.       * and the else-branch node.

Legend:
Removed from v.603  
changed lines
  Added in v.604

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