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 2278 - (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 1956 | Op.ColonMul(ty1 as Ty.TensorTy dd1, ty2 as Ty.TensorTy(d21::d22::dd2)) => let
53 :     fun last2 ([d1, d2], prefix) = (prefix, d1, d2)
54 :     | last2 (d::dd, prefix) = last2(dd, d::prefix)
55 :     | last2 _ = raise Fail("sigOf: invalid operator " ^ Op.toString rator)
56 :     val (prefix, d11, d12) = last2 (dd1, [])
57 :     in
58 :     if (d11 <> d21) orelse (d12 <> d22)
59 :     then raise Fail("sigOf: invalid operator " ^ Op.toString rator)
60 :     else (Ty.TensorTy(List.revAppend(prefix, dd2)), [ty1, ty2])
61 :     end
62 : jhr 420 | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])
63 : jhr 1116 | Op.Norm(ty as Ty.TensorTy _) => (Ty.realTy, [ty])
64 :     | Op.Normalize d => (Ty.vecTy d, [Ty.vecTy d])
65 :     | Op.Scale(ty as Ty.TensorTy(_::_)) => (ty, [Ty.realTy, ty])
66 : jhr 420 | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
67 : jhr 1640 | Op.EigenVecs2x2 => eigenSig 2
68 :     | Op.EigenVecs3x3 => eigenSig 3
69 :     | Op.EigenVals2x2 => (Ty.SeqTy(Ty.realTy, 2), [Ty.TensorTy[2,2]])
70 :     | Op.EigenVals3x3 => (Ty.SeqTy(Ty.realTy, 3), [Ty.TensorTy[3,3]])
71 : jhr 1116 | Op.Identity d => (Ty.TensorTy[d,d], [])
72 :     | Op.Zero ty => (ty, [])
73 :     | Op.Trace d => (Ty.realTy, [Ty.TensorTy[d, d]])
74 : jhr 1640 | Op.Select(ty as Ty.TupleTy tys, i) => (List.nth(tys, i-1), [ty])
75 :     | Op.Index(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
76 :     | Op.Index(ty as Ty.SeqTy(elemTy, _), _) => (elemTy, [ty])
77 : jhr 1116 | Op.Subscript(ty as Ty.TensorTy dd) => (Ty.realTy, ty :: List.map (fn _ => Ty.intTy) dd)
78 : jhr 1640 | Op.Subscript(ty as Ty.SeqTy(elemTy, d)) => (elemTy, [ty, Ty.intTy])
79 : jhr 2278 | Op.Subscript(ty as Ty.DynSeqTy(elemTy)) => (elemTy, [ty, Ty.intTy])
80 : jhr 1689 | Op.MkDynamic(ty, n) => (Ty.DynSeqTy ty, [Ty.SeqTy(ty, n)])
81 :     | Op.Prepend ty => (Ty.DynSeqTy ty, [ty, Ty.DynSeqTy ty])
82 :     | Op.Append ty => (Ty.DynSeqTy ty, [Ty.DynSeqTy ty, ty])
83 :     | Op.Concat ty => (Ty.DynSeqTy ty, [Ty.DynSeqTy ty, Ty.DynSeqTy ty])
84 : jhr 1925 | Op.Length ty => (Ty.intTy, [Ty.DynSeqTy ty])
85 : jhr 1116 | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
86 :     | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
87 :     | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
88 :     | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
89 : jhr 420 | Op.IntToReal => (Ty.realTy, [Ty.intTy])
90 : jhr 1640 | Op.RealToInt 1 => (Ty.IntTy, [Ty.realTy])
91 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.TensorTy[d]])
92 :     (* FIXME: the type of RealToInt should be
93 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.SeqTy(Ty.realTy, d)])
94 :     *)
95 : jhr 1116 | Op.VoxelAddress(info, offset) => let
96 :     val dim = ImageInfo.dim info
97 :     in
98 :     (Ty.AddrTy info, Ty.ImageTy info :: List.tabulate(dim, fn _ => Ty.intTy))
99 :     end
100 :     | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
101 :     | Op.PosToImgSpace info => let
102 :     val dim = ImageInfo.dim info
103 :     in
104 :     (Ty.vecTy dim, [Ty.ImageTy info, Ty.vecTy dim])
105 :     end
106 :     | Op.TensorToWorldSpace(info, ty) => (ty, [Ty.ImageTy info, ty])
107 :     | Op.EvalKernel(d, _, _) => (Ty.vecTy d, [Ty.vecTy d])
108 :     | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
109 : jhr 2027 | Op.LoadSeq(ty, _) => (ty, [])
110 :     | Op.LoadImage(ty, _, _) => (ty, [])
111 : jhr 2011 | Op.Input(Inputs.INP{ty, ...}) => (ty, [])
112 : jhr 1640 | Op.Print tys => (Ty.TupleTy[], tys)
113 : jhr 420 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
114 :     (* end case *))
115 :    
116 : jhr 1116 fun typeOfCons (_, []) = false
117 : jhr 1689 | typeOfCons (Ty.SeqTy(ty, n), tys) =
118 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
119 : jhr 1116 | typeOfCons (expectedTy, tys as ty1::_) =
120 :     if List.all (fn ty => Ty.same(ty1, ty)) tys
121 :     then (case (expectedTy, ty1)
122 : jhr 1640 of (Ty.SeqTy(_, n), Ty.IntTy) => (n = List.length tys)
123 : jhr 1116 | (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')
124 :     | _ => false
125 :     (* end case *))
126 :     else false
127 : jhr 420
128 :     end
129 :    
130 :     structure CheckMidIL = CheckILFn (
131 :     structure IL = MidIL
132 :     structure OpTy = CheckOps)
133 : jhr 1116
134 :     structure MidPP = SSAPPFn (MidIL)
135 :    

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