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

SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/high-to-mid/high-to-mid.sml
ViewVC logotype

Diff of /branches/vis12/src/compiler/high-to-mid/high-to-mid.sml

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

revision 365, Wed Sep 29 20:07:58 2010 UTC revision 391, Thu Oct 14 13:18:24 2010 UTC
# Line 16  Line 16 
16      structure SrcOp = HighOps      structure SrcOp = HighOps
17      structure VTbl = SrcIL.Var.Tbl      structure VTbl = SrcIL.Var.Tbl
18      structure DstIL = MidIL      structure DstIL = MidIL
19        structure DstTy = MidILTypes
20      structure DstOp = MidOps      structure DstOp = MidOps
21    
22      type var_env = DstIL.var SrcIL.Var.Tbl.hash_table      type var_env = DstIL.var VTbl.hash_table
23    
24      fun rename (env : var_env, x) = (case VTbl.find env x      fun rename (env : var_env, x) = (case VTbl.find env x
25             of SOME x' => x'             of SOME x' => x'
# Line 29  Line 30 
30                    x'                    x'
31                  end                  end
32            (* end case *))            (* end case *))
33        fun renameList (env, xs) = List.map (fn x => rename(env, x)) xs
34    
35    (* expand the field Inside operator into a image-space test *)    (* expand the field Inside operator into a image-space test *)
36      fun expandInside (env, result, pos, fld) = let      fun expandInside (env, result, pos, fld) = let
# Line 59  Line 61 
61              Probe.expand (result, fld, pos)              Probe.expand (result, fld, pos)
62            end            end
63    
64      fun cvtTy SrcOp.BoolTy = DstOp.BoolTy      fun cvtTy SrcOp.BoolTy = DstTy.BoolTy
65        | cvtTy SrcOp.StringTy = DstOp.StringTy        | cvtTy SrcOp.StringTy = DstTy.StringTy
66        | cvtTy SrcOp.IntTy = DstOp.IntTy        | cvtTy SrcOp.IntTy = DstTy.intTy
67        | cvtTy (SrcOp.TensorTy[]) = DstOp.realTy        | cvtTy (SrcOp.TensorTy[]) = DstTy.realTy
68        | cvtTy (SrcOp.TensorTy[d]) = DstOp.VecTy d        | cvtTy (SrcOp.TensorTy[d]) = DstTy.VecTy d
69        | cvtTy _ = raise Fail "unexpected higher-order tensor type"        | cvtTy _ = raise Fail "unexpected higher-order tensor type"
70    
71      fun arity (SrcOp.TensorTy[]) = 1      fun arity (SrcOp.TensorTy[]) = 1
# Line 72  Line 74 
74    
75      fun expandOp (env, y, rator, args) = let      fun expandOp (env, y, rator, args) = let
76            fun assign rator' =            fun assign rator' =
77                  [(y, DstIL.OP(rator', List.map (fn x => rename(env, x)) args))]                  [(y, DstIL.OP(rator', renameList(env, args)))]
78            in            in
79              case rator              case rator
80               of SrcOp.Add ty => assign (DstOp.Add(cvtTy ty))               of SrcOp.Add ty => assign (DstOp.Add(cvtTy ty))
# Line 122  Line 124 
124              (* end case *)              (* end case *)
125            end            end
126    
127      (* expand a SrcIL assignment to a list of DstIL assignments *)
128      fun expand (env, (y, rhs)) = let      fun expand (env, (y, rhs)) = let
129            val y' = rename (env, y)            val y' = rename (env, y)
130            fun assign rhs = [(y', rhs)]            fun assign rhs = [(y', rhs)]
# Line 129  Line 132 
132              case rhs              case rhs
133               of SrcIL.VAR x => assign (DstIL.VAR(rename(env, x)))               of SrcIL.VAR x => assign (DstIL.VAR(rename(env, x)))
134                | SrcIL.LIT lit => assign (DstIL.LIT lit)                | SrcIL.LIT lit => assign (DstIL.LIT lit)
135                | SrcIL.OP(rator, args) =>                | SrcIL.OP(rator, args) => expandOp (env, y', rator, args)
136                    expandOp (env, y', rator, args)                | SrcIL.CONS args => assign (DstIL.CONS(renameList(env, args)))
               | SrcIL.CONS args =>  
                   assign (DstIL.CONS(List.map (fn x => rename(env, x)) args))  
137              (* end case *)              (* end case *)
138            end            end
139    
# Line 147  Line 148 
148          val expand = expand          val expand = expand
149        end)        end)
150    
151      fun translate (SrcIL.Program{globals, globalInit, actors}) =      fun translate (SrcIL.Program{globals, globalInit, actors}) = let
152            raise Fail "unimplemented"            val env = VTbl.mkTable (256, Fail "env")
153              fun transMethod (SrcIL.Method{name, stateIn, stateOut, body}) =
154                    DstIL.Method{
155                        name = name,
156                        stateIn = renameList (env, stateIn),
157                        stateOut = renameList (env, stateOut),
158                        body = Trans.translate (env, body)
159                      }
160              fun transActor (SrcIL.Actor{name, params, state, stateInit, methods}) =
161                    DstIL.Actor{
162                        name = name,
163                        params = renameList (env, params),
164                        state = renameList (env, state),
165                        stateInit = Trans.translate (env, stateInit),
166                        methods = List.map transMethod methods
167                      }
168              in
169                DstIL.Program{
170                    globals = renameList (env, globals),
171                    globalInit = Trans.translate (env, globalInit),
172                    actors = List.map transActor actors
173                  }
174              end
175    
176    end    end

Legend:
Removed from v.365  
changed lines
  Added in v.391

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