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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2084 - (view) (download)

1 : jhr 458 (* check-low-il.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure CheckOps : OPERATOR_TY = struct
8 :    
9 :     structure Op = LowOps
10 :     structure Ty = LowILTypes
11 :    
12 :     type rator = Op.rator
13 :     type ty = Ty.ty
14 :    
15 : jhr 1116 val vec3Ty = Ty.vecTy 3
16 : jhr 458
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 458 (* Return the signature of a LowIL operator. *)
28 :     fun sigOf rator = (case rator
29 : jhr 1116 of Op.Add(Ty.AddrTy rTy) => (Ty.AddrTy rTy, [Ty.AddrTy rTy, Ty.intTy])
30 : jhr 511 | Op.Add ty => (ty, [ty, ty])
31 : jhr 1116 | Op.Sub(Ty.AddrTy rTy) => (Ty.AddrTy rTy, [Ty.AddrTy rTy, Ty.intTy])
32 : jhr 458 | Op.Sub ty => (ty, [ty, ty])
33 :     | Op.Mul ty => (ty, [ty, ty])
34 :     | Op.Div ty => (ty, [ty, ty])
35 :     | Op.Neg ty => (ty, [ty])
36 : jhr 1116 | Op.Abs ty => (ty, [ty])
37 : jhr 458 | Op.LT ty => (Ty.BoolTy, [ty, ty])
38 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
39 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
40 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
41 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
42 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
43 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
44 :     | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])
45 :     | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])
46 : jhr 1295 | Op.Clamp ty => (ty, [ty, ty, ty])
47 : jhr 1116 | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
48 :     | Op.Dot d => (Ty.realTy, [Ty.vecTy d, Ty.vecTy d])
49 :     | Op.MulVecMat(d1, d2) => (Ty.vecTy d2, [Ty.vecTy d1, Ty.TensorTy[d1, d2]])
50 :     | Op.MulMatVec(d1, d2) => (Ty.vecTy d1, [Ty.TensorTy[d1, d2], Ty.vecTy d2])
51 :     | Op.MulMatMat(d1, d2, d3) => (Ty.TensorTy[d1, d3], [Ty.TensorTy[d1, d2], Ty.TensorTy[d2, d3]])
52 : jhr 1939 | Op.MulVecTen3(d1, d2, d3) => (Ty.TensorTy[d2, d3], [Ty.vecTy d1, Ty.TensorTy[d1, d2, d3]])
53 :     | Op.MulTen3Vec(d1, d2, d3) => (Ty.TensorTy[d1, d2], [Ty.TensorTy[d1, d2, d3], Ty.vecTy d3])
54 : jhr 1956 | 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 : jhr 458 | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])
65 : jhr 1116 | Op.Norm(ty as Ty.TensorTy _) => (Ty.realTy, [ty])
66 :     | Op.Normalize d => (Ty.vecTy d, [Ty.vecTy d])
67 :     | Op.Scale(ty as Ty.TensorTy(_::_)) => (ty, [Ty.realTy, ty])
68 : jhr 458 | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
69 : jhr 1640 | Op.EigenVecs2x2 => eigenSig 2
70 :     | Op.EigenVecs3x3 => eigenSig 3
71 :     | Op.EigenVals2x2 => (Ty.SeqTy(Ty.realTy, 2), [Ty.TensorTy[2,2]])
72 :     | Op.EigenVals3x3 => (Ty.SeqTy(Ty.realTy, 3), [Ty.TensorTy[3,3]])
73 : jhr 1116 | Op.Identity d => (Ty.TensorTy[d,d], [])
74 :     | Op.Zero ty => (ty, [])
75 : jhr 1640 | Op.Select(ty as Ty.TupleTy tys, i) => (List.nth(tys, i-1), [ty])
76 :     | Op.Index(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
77 :     | Op.Index(ty as Ty.SeqTy(elemTy, _), _) => (elemTy, [ty])
78 : jhr 1116 | Op.Subscript(ty as Ty.TensorTy dd) => (Ty.realTy, ty :: List.map (fn _ => Ty.intTy) dd)
79 : jhr 1640 | Op.Subscript(ty as Ty.SeqTy(elemTy, d)) => (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 : lamonts 2084 | Op.SphereQuery ty => (ty,[Ty.IntTy])
88 : jhr 1116 | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
89 :     | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
90 : jhr 458 | Op.IntToReal => (Ty.realTy, [Ty.intTy])
91 : jhr 1640 | Op.RealToInt 1 => (Ty.IntTy, [Ty.realTy])
92 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.TensorTy[d]])
93 :     (* FIXME: the type of RealToInt should be
94 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.SeqTy(Ty.realTy, d)])
95 :     *)
96 : jhr 1116 | Op.ImageAddress info => (Ty.AddrTy info, [Ty.ImageTy info])
97 :     | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
98 :     | Op.PosToImgSpace info => let
99 :     val dim = ImageInfo.dim info
100 :     in
101 :     (Ty.vecTy dim, [Ty.ImageTy info, Ty.vecTy dim])
102 :     end
103 :     | Op.TensorToWorldSpace(info, ty) => (ty, [Ty.ImageTy info, ty])
104 : jhr 2009 (* DEPRECATED
105 : jhr 1116 | Op.LoadImage info => (Ty.ImageTy info, [Ty.StringTy])
106 : jhr 2009 *)
107 : jhr 1116 | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
108 : jhr 2011 | Op.Input(Inputs.INP{ty, ...}) => (ty, [])
109 : jhr 2027 | Op.LoadSeq(ty, _) => (ty, [])
110 :     | Op.LoadImage(ty, _, _) => (ty, [])
111 : jhr 1640 | Op.Print tys => (Ty.TupleTy[], tys)
112 : jhr 458 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
113 :     (* end case *))
114 :    
115 : jhr 1116 fun typeOfCons (_, []) = false
116 : jhr 1689 | typeOfCons (Ty.SeqTy(ty, n), tys) =
117 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
118 : jhr 1116 | typeOfCons (expectedTy, tys as ty1::_) =
119 :     if List.all (fn ty => Ty.same(ty1, ty)) tys
120 :     then (case (expectedTy, ty1)
121 : jhr 1640 of (Ty.SeqTy(_, n), Ty.IntTy) => (n = List.length tys)
122 : jhr 1116 | (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')
123 :     | _ => false
124 :     (* end case *))
125 :     else false
126 : jhr 458
127 :     end
128 :    
129 :     structure CheckLowIL = CheckILFn (
130 :     structure IL = LowIL
131 :     structure OpTy = CheckOps)
132 : jhr 1116
133 :     structure LowPP = SSAPPFn (LowIL)

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