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 1939 - (view) (download)

1 : jhr 420 (* check-mid-il.sml
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 420 * 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 : jhr 1116 val vec3Ty = Ty.vecTy 3
16 : jhr 420
17 : jhr 1640 (* utility function for synthesizing eigenvector/eigenvalue signature *)
18 :     fun eigenSig dim = let
19 :     val tplTy = Ty.TupleTy[
20 :     Ty.SeqTy(Ty.realTy, dim),
21 :     Ty.SeqTy(Ty.vecTy dim, dim)
22 :     ]
23 :     in
24 :     (tplTy, [Ty.TensorTy[dim, dim]])
25 :     end
26 :    
27 : jhr 420 (* Return the signature of a MidIL operator. *)
28 :     fun sigOf rator = (case rator
29 :     of Op.Add ty => (ty, [ty, ty])
30 :     | Op.Sub ty => (ty, [ty, ty])
31 :     | Op.Mul ty => (ty, [ty, ty])
32 :     | Op.Div ty => (ty, [ty, ty])
33 :     | Op.Neg ty => (ty, [ty])
34 : jhr 1116 | Op.Abs ty => (ty, [ty])
35 : jhr 420 | Op.LT ty => (Ty.BoolTy, [ty, ty])
36 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
37 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
38 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
39 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
40 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
41 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
42 :     | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])
43 :     | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])
44 : jhr 1295 | Op.Clamp ty => (ty, [ty, ty, ty])
45 : jhr 1116 | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
46 :     | Op.Dot d => (Ty.realTy, [Ty.vecTy d, Ty.vecTy d])
47 :     | Op.MulVecMat(d1, d2) => (Ty.vecTy d2, [Ty.vecTy d1, Ty.TensorTy[d1, d2]])
48 :     | Op.MulMatVec(d1, d2) => (Ty.vecTy d1, [Ty.TensorTy[d1, d2], Ty.vecTy d2])
49 :     | Op.MulMatMat(d1, d2, d3) => (Ty.TensorTy[d1, d3], [Ty.TensorTy[d1, d2], Ty.TensorTy[d2, d3]])
50 : jhr 1939 | Op.MulVecTen3(d1, d2, d3) => (Ty.TensorTy[d2, d3], [Ty.vecTy d1, Ty.TensorTy[d1, d2, d3]])
51 :     | Op.MulTen3Vec(d1, d2, d3) => (Ty.TensorTy[d1, d2], [Ty.TensorTy[d1, d2, d3], Ty.vecTy d3])
52 : jhr 420 | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])
53 : jhr 1116 | Op.Norm(ty as Ty.TensorTy _) => (Ty.realTy, [ty])
54 :     | Op.Normalize d => (Ty.vecTy d, [Ty.vecTy d])
55 :     | Op.Scale(ty as Ty.TensorTy(_::_)) => (ty, [Ty.realTy, ty])
56 : jhr 420 | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
57 : jhr 1640 | Op.EigenVecs2x2 => eigenSig 2
58 :     | Op.EigenVecs3x3 => eigenSig 3
59 :     | Op.EigenVals2x2 => (Ty.SeqTy(Ty.realTy, 2), [Ty.TensorTy[2,2]])
60 :     | Op.EigenVals3x3 => (Ty.SeqTy(Ty.realTy, 3), [Ty.TensorTy[3,3]])
61 : jhr 1116 | Op.Identity d => (Ty.TensorTy[d,d], [])
62 :     | Op.Zero ty => (ty, [])
63 :     | Op.Trace d => (Ty.realTy, [Ty.TensorTy[d, d]])
64 : jhr 1640 | Op.Select(ty as Ty.TupleTy tys, i) => (List.nth(tys, i-1), [ty])
65 :     | Op.Index(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
66 :     | Op.Index(ty as Ty.SeqTy(elemTy, _), _) => (elemTy, [ty])
67 : jhr 1116 | Op.Subscript(ty as Ty.TensorTy dd) => (Ty.realTy, ty :: List.map (fn _ => Ty.intTy) dd)
68 : jhr 1640 | Op.Subscript(ty as Ty.SeqTy(elemTy, d)) => (elemTy, [ty, Ty.intTy])
69 : jhr 1689 | Op.MkDynamic(ty, n) => (Ty.DynSeqTy ty, [Ty.SeqTy(ty, n)])
70 :     | Op.Prepend ty => (Ty.DynSeqTy ty, [ty, Ty.DynSeqTy ty])
71 :     | Op.Append ty => (Ty.DynSeqTy ty, [Ty.DynSeqTy ty, ty])
72 :     | Op.Concat ty => (Ty.DynSeqTy ty, [Ty.DynSeqTy ty, Ty.DynSeqTy ty])
73 : jhr 1925 | Op.Length ty => (Ty.intTy, [Ty.DynSeqTy ty])
74 : jhr 1116 | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
75 :     | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
76 :     | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
77 :     | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
78 : jhr 420 | Op.IntToReal => (Ty.realTy, [Ty.intTy])
79 : jhr 1640 | Op.RealToInt 1 => (Ty.IntTy, [Ty.realTy])
80 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.TensorTy[d]])
81 :     (* FIXME: the type of RealToInt should be
82 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.SeqTy(Ty.realTy, d)])
83 :     *)
84 : jhr 1116 | Op.VoxelAddress(info, offset) => let
85 :     val dim = ImageInfo.dim info
86 :     in
87 :     (Ty.AddrTy info, Ty.ImageTy info :: List.tabulate(dim, fn _ => Ty.intTy))
88 :     end
89 :     | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
90 :     | Op.PosToImgSpace info => let
91 :     val dim = ImageInfo.dim info
92 :     in
93 :     (Ty.vecTy dim, [Ty.ImageTy info, Ty.vecTy dim])
94 :     end
95 :     | Op.TensorToWorldSpace(info, ty) => (ty, [Ty.ImageTy info, ty])
96 :     | Op.EvalKernel(d, _, _) => (Ty.vecTy d, [Ty.vecTy d])
97 :     | Op.LoadImage info => (Ty.ImageTy info, [Ty.StringTy])
98 :     | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
99 : jhr 1301 | Op.Input(ty, _, _) => (ty, [])
100 :     | Op.InputWithDefault(ty, _, _) => (ty, [ty])
101 : jhr 1640 | Op.Print tys => (Ty.TupleTy[], tys)
102 : jhr 420 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
103 :     (* end case *))
104 :    
105 : jhr 1116 fun typeOfCons (_, []) = false
106 : jhr 1689 | typeOfCons (Ty.SeqTy(ty, n), tys) =
107 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
108 : jhr 1116 | typeOfCons (expectedTy, tys as ty1::_) =
109 :     if List.all (fn ty => Ty.same(ty1, ty)) tys
110 :     then (case (expectedTy, ty1)
111 : jhr 1640 of (Ty.SeqTy(_, n), Ty.IntTy) => (n = List.length tys)
112 : jhr 1116 | (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')
113 :     | _ => false
114 :     (* end case *))
115 :     else false
116 : jhr 420
117 :     end
118 :    
119 :     structure CheckMidIL = CheckILFn (
120 :     structure IL = MidIL
121 :     structure OpTy = CheckOps)
122 : jhr 1116
123 :     structure MidPP = SSAPPFn (MidIL)
124 :    

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