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

SCM Repository

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

Annotation of /branches/lamont/src/compiler/high-il/check-high-il.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2298 - (view) (download)

1 : jhr 411 (* check-high-il.sml
2 : jhr 404 *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 404 * All rights reserved.
5 :     *)
6 :    
7 : jhr 405 structure CheckOps : OPERATOR_TY = struct
8 : jhr 404
9 :     structure Op = HighOps
10 :     structure Ty = HighILTypes
11 :    
12 : jhr 405 type rator = Op.rator
13 :     type ty = Ty.ty
14 :    
15 : jhr 1640 (* utility function for synthesizing eigenvector/eigenvalue signature *)
16 :     fun eigenSig dim = let
17 :     val tplTy = Ty.TupleTy[
18 :     Ty.SeqTy(Ty.realTy, dim),
19 :     Ty.SeqTy(Ty.vecTy dim, dim)
20 :     ]
21 :     in
22 :     (tplTy, [Ty.TensorTy[dim, dim]])
23 :     end
24 :    
25 : jhr 420 (* Return the signature of a HighIL operator. *)
26 : jhr 412 fun sigOf rator = (case rator
27 : jhr 2298 of Op.Add ty => (ty, [ty, ty])
28 :     | Op.Sub ty => (ty, [ty, ty])
29 :     | Op.Mul ty => (ty, [ty, ty])
30 :     | Op.Div ty => (ty, [ty, ty])
31 :     | Op.Neg ty => (ty, [ty])
32 :     | Op.Abs ty => (ty, [ty])
33 :     | Op.LT ty => (Ty.BoolTy, [ty, ty])
34 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
35 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
36 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
37 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
38 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
39 :     | Op.Power => (Ty.realTy, [Ty.realTy, Ty.IntTy])
40 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
41 :     | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])
42 :     | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])
43 :     | Op.Clamp ty => (ty, [ty, ty, ty])
44 :     | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
45 :     | Op.Dot ty => (Ty.realTy, [ty, ty])
46 :     | Op.MulVecMat(ty as Ty.TensorTy[d1, d2]) => (Ty.TensorTy[d2], [Ty.TensorTy[d1], ty])
47 :     | Op.MulMatVec(ty as Ty.TensorTy[d1, d2]) => (Ty.TensorTy[d1], [ty, Ty.TensorTy[d2]])
48 :     | Op.MulMatMat(ty1 as Ty.TensorTy[d1, d2], ty2 as Ty.TensorTy[d2', d3]) =>
49 :     (Ty.TensorTy[d1, d3], [ty1, ty2])
50 :     | Op.MulVecTen3(ty as Ty.TensorTy[d1, d2, d3]) =>
51 :     (Ty.TensorTy[d2, d3], [Ty.TensorTy[d1], ty])
52 :     | Op.MulTen3Vec(ty as Ty.TensorTy[d1, d2, d3]) =>
53 :     (Ty.TensorTy[d1, d2], [ty, Ty.TensorTy[d3]])
54 :     | Op.ColonMul(ty1 as Ty.TensorTy dd1, ty2 as Ty.TensorTy(d21::d22::dd2)) => let
55 :     fun last2 ([d1, d2], prefix) = (prefix, d1, d2)
56 :     | last2 (d::dd, prefix) = last2(dd, d::prefix)
57 :     | last2 _ = raise Fail("sigOf: invalid operator " ^ Op.toString rator)
58 :     val (prefix, d11, d12) = last2 (dd1, [])
59 :     in
60 :     if (d11 <> d21) orelse (d12 <> d22)
61 :     then raise Fail("sigOf: invalid operator " ^ Op.toString rator)
62 :     else (Ty.TensorTy(List.revAppend(prefix, dd2)), [ty1, ty2])
63 :     end
64 :     | Op.Cross => (Ty.vec3Ty, [Ty.vec3Ty, Ty.vec3Ty])
65 :     | Op.Outer(ty as Ty.TensorTy[d1, d2]) => (ty, [Ty.TensorTy[d1], Ty.TensorTy[d2]])
66 :     | Op.Norm ty => (Ty.realTy, [ty])
67 :     | Op.Normalize ty => (ty, [ty])
68 :     | Op.Dist ty => (Ty.realTy,[ty,ty])
69 :     | Op.SphereQuery ty => ((Ty.DynSeqTy ty),[Ty.realTy])
70 :     | Op.R_All ty => (Ty.BoolTy, [Ty.BoolTy,Ty.BoolTy,ty])
71 :     | Op.R_Exists ty => (Ty.BoolTy, [Ty.BoolTy,Ty.BoolTy,ty])
72 :     | Op.R_Max ty => (Ty.TensorTy[],[Ty.TensorTy[],Ty.TensorTy[],ty])
73 :     | Op.R_Min ty => (Ty.TensorTy[],[Ty.TensorTy[],Ty.TensorTy[],ty])
74 :     | Op.R_Sum ty => (Ty.TensorTy[],[Ty.TensorTy[],Ty.TensorTy[],ty])
75 :     | Op.R_Product ty => (Ty.TensorTy[],[Ty.TensorTy[],Ty.TensorTy[],ty])
76 :     | Op.R_Mean ty => (Ty.TensorTy[],[Ty.TensorTy[],Ty.TensorTy[],ty])
77 :     | Op.R_Variance ty => (Ty.TensorTy[],[Ty.TensorTy[],Ty.TensorTy[],ty,Ty.TensorTy[]])
78 :     | Op.Scale ty => (ty, [Ty.realTy, ty])
79 :     | Op.PrincipleEvec(resTy as Ty.TensorTy[d]) => (resTy, [Ty.TensorTy[d,d]])
80 : jhr 1640 | Op.Eigen2x2 => eigenSig 2
81 :     | Op.Eigen3x3 => eigenSig 3
82 : jhr 2298 | Op.Identity d => (Ty.TensorTy[d,d], [])
83 :     | Op.Zero ty => (ty, [])
84 :     | Op.Trace ty => (Ty.realTy, [ty])
85 :     | Op.Slice(ty as Ty.TensorTy dd, m) => let
86 :     val (resDims, idxDims) = let
87 :     fun f (d, false, (rds, ids)) = (d::rds, ids)
88 :     | f (_, true, (rds, ids)) = (rds, Ty.IntTy::ids)
89 :     in
90 :     ListPair.foldr f ([], []) (dd, m)
91 :     end
92 :     in
93 :     (Ty.TensorTy resDims, ty::idxDims)
94 :     end
95 :     | Op.TensorSub(ty as Ty.TensorTy dd) =>
96 :     (Ty.realTy, ty :: List.map (fn _ => Ty.IntTy) dd)
97 :     | Op.Select(ty as Ty.TupleTy tys, i) =>
98 : jhr 1640 if (1 <= i) andalso (i <= length tys)
99 :     then (List.nth(tys, i-1), [ty])
100 :     else raise Fail("sigOf: invalid operator " ^ Op.toString rator)
101 : jhr 2298 | Op.SeqSub(ty as Ty.SeqTy(elemTy, _)) => (elemTy, [ty, Ty.IntTy])
102 :     | Op.SeqSub(ty as Ty.DynSeqTy elemTy) => (elemTy, [ty, Ty.IntTy])
103 : jhr 1688 | Op.MkDynamic(ty, n) => (Ty.DynSeqTy ty, [Ty.SeqTy(ty, n)])
104 : jhr 1687 | Op.Prepend ty => (Ty.DynSeqTy ty, [ty, Ty.DynSeqTy ty])
105 :     | Op.Append ty => (Ty.DynSeqTy ty, [Ty.DynSeqTy ty, ty])
106 :     | Op.Concat ty => (Ty.DynSeqTy ty, [Ty.DynSeqTy ty, Ty.DynSeqTy ty])
107 : jhr 1925 | Op.Length ty => (Ty.intTy, [Ty.DynSeqTy ty])
108 : jhr 2298 | Op.IntToReal => (Ty.realTy, [Ty.IntTy])
109 :     | Op.TruncToInt => (Ty.IntTy, [Ty.realTy])
110 :     | Op.RoundToInt => (Ty.IntTy, [Ty.realTy])
111 :     | Op.CeilToInt => (Ty.IntTy, [Ty.realTy])
112 :     | Op.FloorToInt => (Ty.IntTy, [Ty.realTy])
113 :     | Op.Kernel _ => (Ty.KernelTy, [])
114 :     | Op.Field dim => (Ty.FieldTy, [Ty.ImageTy dim, Ty.KernelTy])
115 :     | Op.Inside dim => (Ty.BoolTy, [Ty.TensorTy[dim], Ty.FieldTy])
116 :     | Op.AddField => (Ty.FieldTy, [Ty.FieldTy, Ty.FieldTy])
117 :     | Op.SubField => (Ty.FieldTy, [Ty.FieldTy, Ty.FieldTy])
118 :     | Op.ScaleField => (Ty.FieldTy, [Ty.realTy, Ty.FieldTy])
119 :     | Op.OffsetField => (Ty.FieldTy, [Ty.FieldTy, Ty.realTy])
120 :     | Op.NegField => (Ty.FieldTy, [Ty.FieldTy])
121 :     | Op.DiffField => (Ty.FieldTy, [Ty.FieldTy])
122 :     | Op.CurlField 2 => (Ty.FieldTy, [Ty.FieldTy])
123 :     | Op.CurlField 3 => (Ty.FieldTy, [Ty.FieldTy])
124 :     | Op.Probe(domTy, rngTy) => (rngTy, [Ty.FieldTy, domTy])
125 :     | Op.LoadSeq(ty, _) => (ty, [])
126 :     | Op.LoadImage(ty, _, _) => (ty, [])
127 :     | Op.Input(Inputs.INP{ty, ...}) => (ty, [])
128 : jhr 1640 | Op.Print tys => (Ty.TupleTy[], tys)
129 : jhr 2298 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
130 :     (* end case *))
131 : jhr 404
132 : jhr 1116 fun typeOfCons (Ty.TensorTy dd', (ty1 as Ty.TensorTy dd)::r) =
133 : jhr 2298 if List.all (fn ty => Ty.same(ty1, ty)) r
134 :     then (dd' = (List.length r + 1)::dd)
135 :     else false
136 : jhr 1688 | typeOfCons (Ty.SeqTy(ty, n), tys) =
137 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
138 : jhr 1116 | typeOfCons _ = false
139 : jhr 412
140 : jhr 404 end
141 : jhr 405
142 :     structure CheckHighIL = CheckILFn (
143 :     structure IL = HighIL
144 :     structure OpTy = CheckOps)
145 : jhr 1116
146 :     structure HighPP = SSAPPFn (HighIL)
147 :    

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