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

SCM Repository

[diderot] Annotation of /branches/vis12/src/compiler/mid-il/check-mid-il.sml
ViewVC logotype

Annotation of /branches/vis12/src/compiler/mid-il/check-mid-il.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 423 - (view) (download)
Original Path: trunk/src/compiler/mid-il/check-mid-il.sml

1 : jhr 420 (* check-mid-il.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure CheckOps : OPERATOR_TY = struct
8 :    
9 :     structure Op = MidOps
10 :     structure Ty = MidILTypes
11 :    
12 :     type rator = Op.rator
13 :     type ty = Ty.ty
14 :    
15 :     val vec3Ty = Ty.VecTy 3
16 :    
17 :     (* Return the signature of a MidIL operator. *)
18 :     fun sigOf rator = (case rator
19 :     of Op.Add ty => (ty, [ty, ty])
20 :     | Op.Sub ty => (ty, [ty, ty])
21 :     | Op.Mul ty => (ty, [ty, ty])
22 :     | Op.Div ty => (ty, [ty, ty])
23 :     | Op.Neg ty => (ty, [ty])
24 :     | Op.LT ty => (Ty.BoolTy, [ty, ty])
25 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
26 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
27 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
28 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
29 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
30 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
31 :     | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])
32 :     | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])
33 :     | Op.Sin => (Ty.realTy, [Ty.realTy])
34 :     | Op.Cos => (Ty.realTy, [Ty.realTy])
35 :     | Op.Pow => (Ty.realTy, [Ty.realTy, Ty.realTy])
36 :     | Op.Dot d => (Ty.realTy, [Ty.VecTy d, Ty.VecTy d])
37 :     | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])
38 :     | Op.Select(ty as Ty.IVecTy d, _) => (Ty.intTy, [ty])
39 :     | Op.Select(ty as Ty.VecTy d, _) => (Ty.realTy, [ty])
40 :     | Op.Norm d => (Ty.realTy, [Ty.VecTy d])
41 :     | Op.Scale d => (Ty.VecTy d, [Ty.realTy, Ty.VecTy d])
42 :     | Op.InvScale d => (Ty.VecTy d, [Ty.VecTy d, Ty.realTy])
43 :     | Op.CL => raise Fail "Op.CL unimplemented"
44 :     | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
45 :     | Op.Subscript(Ty.IVecTy d) => (Ty.intTy, [Ty.IVecTy d, Ty.intTy])
46 :     | Op.Subscript(Ty.VecTy d) => (Ty.realTy, [Ty.VecTy d, Ty.intTy])
47 :     | Op.Floor d => (Ty.VecTy d, [Ty.VecTy d])
48 :     | Op.IntToReal => (Ty.realTy, [Ty.intTy])
49 :     | Op.TruncToInt d => (Ty.IVecTy d, [Ty.VecTy d])
50 :     | Op.RoundToInt d => (Ty.IVecTy d, [Ty.VecTy d])
51 :     | Op.CeilToInt d => (Ty.IVecTy d, [Ty.VecTy d])
52 :     | Op.FloorToInt d => (Ty.IVecTy d, [Ty.VecTy d])
53 :     | Op.VoxelAddress(ImageInfo.ImgInfo{dim, ...}) =>
54 :     (Ty.AddrTy, List.tabulate(dim, fn _ => Ty.intTy))
55 :     | Op.LoadVoxels(_, d) => (Ty.VecTy d, [Ty.AddrTy])
56 :     | Op.Transform(ImageInfo.ImgInfo{dim, ...}) => (Ty.VecTy dim, [Ty.VecTy dim])
57 : jhr 422 | Op.EvalKernel(d, _, _) => (Ty.VecTy d, [Ty.VecTy d])
58 : jhr 420 | Op.LoadImage _ => (Ty.ImageTy, [])
59 : jhr 423 | Op.Inside(ImageInfo.ImgInfo{dim, ...}) => (Ty.BoolTy, [Ty.VecTy dim])
60 : jhr 420 | Op.Input(ty, _) => (ty, [])
61 :     | Op.InputWithDefault(ty, _) => (ty, [ty])
62 :     | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
63 :     (* end case *))
64 :    
65 :     fun typeOfCons [] = NONE
66 :     | typeOfCons tys =
67 :     if List.all (fn ty => Ty.same(Ty.IVecTy 0, ty)) tys
68 :     then SOME(Ty.IVecTy(List.length tys))
69 :     else if List.all (fn ty => Ty.same(Ty.VecTy 0, ty)) tys
70 :     then SOME(Ty.VecTy(List.length tys))
71 :     else NONE
72 :    
73 :     end
74 :    
75 :     structure CheckMidIL = CheckILFn (
76 :     structure IL = MidIL
77 :     structure OpTy = CheckOps)

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