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

SCM Repository

[diderot] Diff of /trunk/src/compiler/mid-to-low/mid-to-low.sml
ViewVC logotype

Diff of /trunk/src/compiler/mid-to-low/mid-to-low.sml

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

revision 345, Mon Sep 20 19:22:51 2010 UTC revision 459, Wed Oct 27 12:54:03 2010 UTC
# Line 1  Line 1 
1  (* mid-to-low.sml  (* mid-to-low.sml
2   *   *
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *   *
6   * Translation from MidIL to LowIL representations.   * Translation from MidIL to LowIL representations.
# Line 8  Line 8 
8    
9  structure MidToLow : sig  structure MidToLow : sig
10    
11      val translate : HighIL.program -> MidIL.program      val translate : MidIL.program -> LowIL.program
12    
13          end = struct          end = struct
14    
15    
16      structure SrcIL = MidIL      structure SrcIL = MidIL
17      structure SrcOp = MidOps      structure SrcOp = MidOps
18        structure VTbl = SrcIL.Var.Tbl
19      structure DstIL = LowIL      structure DstIL = LowIL
20      structure DstOp = LowOps      structure DstOp = LowOps
     structure VMap = SrcIL.Var.Map  
21    
22      fun lookupVar (env, x) = (case VMap.find(env, x)      type var_env = DstIL.var VTbl.hash_table
23    
24        fun rename (env : var_env, x) = (case VTbl.find env x
25             of SOME x' => x'             of SOME x' => x'
26              | NONE => raise Fail("unknown variable "^SrcIL.Var.toString x)              | NONE => let
27                    val x' = DstIL.Var.new (SrcIL.Var.name x)
28                    in
29                      VTbl.insert env (x, x');
30                      x'
31                    end
32            (* end case *))            (* end case *))
33        fun renameList (env, xs) = List.map (fn x => rename(env, x)) xs
34    
35      (* expand the EvalKernel operations into vector operations.  The parameters are
36          fun lookup     *    result  -- the lhs variable to store the result
37       *    d       -- the vector width of the operation, which should be equal to twice the
38    (* expand the EvalKernel operations into vector operations *)     *               support of the kernel
39      fun expandKernel (dimSize,kern,k,vec) =     *    h       -- the kernel
40       *    k       -- the derivative of the kernel to evaluate
41       *)
42        fun expandKernel (result, d, h, k) = let
43              val {isCont, segs} = Kernel.curve (h, k)
44              in
45              end
46    
47    (* compute the load address for a given set of voxels indices *)    (* compute the load address for a given set of voxels indices *)
48      fun computeVoxelAddress (info,vec) =      fun expandVoxelAddress (result, info) = ??
49    
50        fun expandOp (env, y, rator, args) = let
51              fun assign rator' =
52                    [(y, DstIL.OP(rator', renameList(env, args)))]
53              in
54                case rator
55                 of SrcOp.Add ty => assign (DstOp.Add ty)
56                  | SrcOp.Sub ty => assign (DstOp.Sub ty)
57                  | SrcOp.Mul ty => assign (DstOp.Mul ty)
58                  | SrcOp.Div ty => assign (DstOp.Div ty)
59                  | SrcOp.Neg ty => assign (DstOp.Neg ty)
60                  | SrcOp.LT ty => assign (DstOp.LT ty)
61                  | SrcOp.LTE ty => assign (DstOp.LTE ty)
62                  | SrcOp.EQ ty => assign (DstOp.EQ ty)
63                  | SrcOp.NEQ ty => assign (DstOp.NEQ ty)
64                  | SrcOp.GT ty => assign (DstOp.GT ty)
65                  | SrcOp.GTE ty => assign (DstOp.GTE ty)
66                  | SrcOp.Not => assign (DstOp.Not)
67                  | SrcOp.Max => assign (DstOp.Max)
68                  | SrcOp.Min => assign (DstOp.Min)
69                  | SrcOp.Sin => assign (DstOp.Sin)
70                  | SrcOp.Cos => assign (DstOp.Cos)
71                  | SrcOp.Pow => assign (DstOp.Pow)
72                  | SrcOp.Dot d => assign (DstOp.Dot d)
73                  | SrcOp.Cross => assign (DstOp.Cross)
74                  | SrcOp.Select ty => assign (DstOp.Select ty) * int
75                  | SrcOp.Norm d => assign (DstOp.Norm d)
76                  | SrcOp.Scale d => assign (DstOp.Scale d)
77                  | SrcOp.InvScale d => assign (DstOp.InvScale d)
78                  | SrcOp.CL => assign (DstOp.CL)
79                  | SrcOp.PrincipleEvec ty => assign (DstOp.PrincipleEvec ty)
80                  | SrcOp.Subscript ty => assign (DstOp.Subscript ty)
81                  | SrcOp.Floor d => assign (DstOp.Floor d)
82                  | SrcOp.IntToReal => assign (DstOp.IntToReal)
83                  | SrcOp.TruncToInt d => assign (DstOp.TruncToInt d)
84                  | SrcOp.RoundToInt d => assign (DstOp.RoundToInt d)
85                  | SrcOp.CeilToInt d => assign (DstOp.CeilToInt d)
86                  | SrcOp.FloorToInt d => assign (DstOp.FloorToInt d)
87                  | SrcOp.VoxelAddress info => expandVoxelAddress (y, info)
88                  | SrcOp.LoadVoxels(rty, d) => assign (DstOp.LoadVoxels(rty, d))
89                  | SrcOp.Transform info => assign (DstOp.Transform info)
90                  | SrcOp.EvalKernel(d, h, k) => expandEvalKernel(y, d, h, k)
91                  | SrcOp.LoadImage info => assign (DstOp.LoadImage info)
92                  | SrcOp.Inside info => assign (DstOp.Inside info)
93                  | SrcOp.Input(ty, name) => assign (DstOp.Input(ty, name))
94                  | SrcOp.InputWithDefault(ty, name) => assign (DstOp.InputWithDefault(ty, name))
95                  | _ => raise Fail("unexpected " ^ SrcOp.toString rator)
96                (* end case *)
97              end
98    
99      (* expand a SrcIL assignment to a list of DstIL assignments *)
100        fun expand (env, (y, rhs)) = let
101              val y' = rename (env, y)
102              fun assign rhs = [(y', rhs)]
103              in
104                case rhs
105                 of SrcIL.VAR x => assign (DstIL.VAR(rename(env, x)))
106                  | SrcIL.LIT lit => assign (DstIL.LIT lit)
107                  | SrcIL.OP(rator, args) => expandOp (env, y', rator, args)
108                  | SrcIL.CONS args => assign (DstIL.CONS(renameList(env, args)))
109                (* end case *)
110              end
111    
112      fun translate prog = raise Fail "FIXME"      structure Trans =  TranslateFn (
113          struct
114            structure SrcIL = SrcIL
115            structure DstIL = DstIL
116    
117            type var_env = var_env
118    
119            val rename = rename
120            val expand = expand
121          end)
122    
123        fun translate (SrcIL.Program{globals, globalInit, actors}) = let
124              val env = VTbl.mkTable (256, Fail "env")
125              fun transMethod (SrcIL.Method{name, stateIn, stateOut, body}) =
126                    DstIL.Method{
127                        name = name,
128                        stateIn = renameList (env, stateIn),
129                        stateOut = renameList (env, stateOut),
130                        body = Trans.translate (env, body)
131                      }
132              fun transActor (SrcIL.Actor{name, params, state, stateInit, methods}) =
133                    DstIL.Actor{
134                        name = name,
135                        params = renameList (env, params),
136                        state = renameList (env, state),
137                        stateInit = Trans.translate (env, stateInit),
138                        methods = List.map transMethod methods
139                      }
140              in
141                DstIL.Program{
142                    globals = renameList (env, globals),
143                    globalInit = Trans.translate (env, globalInit),
144                    actors = List.map transActor actors
145                  }
146              end
147    
148    end    end

Legend:
Removed from v.345  
changed lines
  Added in v.459

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