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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1689 - (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 458 | 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 458 | 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 : jhr 1640 | Op.Select(ty as Ty.TupleTy tys, i) => (List.nth(tys, i-1), [ty])
64 :     | Op.Index(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
65 :     | Op.Index(ty as Ty.SeqTy(elemTy, _), _) => (elemTy, [ty])
66 : jhr 1116 | Op.Subscript(ty as Ty.TensorTy dd) => (Ty.realTy, ty :: List.map (fn _ => Ty.intTy) dd)
67 : jhr 1640 | Op.Subscript(ty as Ty.SeqTy(elemTy, d)) => (elemTy, [ty, Ty.intTy])
68 : jhr 1689 | Op.MkDynamic(ty, n) => (Ty.DynSeqTy ty, [Ty.SeqTy(ty, n)])
69 :     | Op.Prepend ty => (Ty.DynSeqTy ty, [ty, Ty.DynSeqTy ty])
70 :     | Op.Append ty => (Ty.DynSeqTy ty, [Ty.DynSeqTy ty, ty])
71 :     | Op.Concat ty => (Ty.DynSeqTy ty, [Ty.DynSeqTy ty, Ty.DynSeqTy ty])
72 : jhr 1116 | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
73 :     | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
74 :     | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
75 :     | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
76 : jhr 458 | Op.IntToReal => (Ty.realTy, [Ty.intTy])
77 : jhr 1640 | Op.RealToInt 1 => (Ty.IntTy, [Ty.realTy])
78 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.TensorTy[d]])
79 :     (* FIXME: the type of RealToInt should be
80 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.SeqTy(Ty.realTy, d)])
81 :     *)
82 : jhr 1116 | Op.ImageAddress info => (Ty.AddrTy info, [Ty.ImageTy info])
83 :     | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
84 :     | Op.PosToImgSpace info => let
85 :     val dim = ImageInfo.dim info
86 :     in
87 :     (Ty.vecTy dim, [Ty.ImageTy info, Ty.vecTy dim])
88 :     end
89 :     | Op.TensorToWorldSpace(info, ty) => (ty, [Ty.ImageTy info, ty])
90 :     | Op.LoadImage info => (Ty.ImageTy info, [Ty.StringTy])
91 :     | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
92 : jhr 1301 | Op.Input(ty, _, _) => (ty, [])
93 :     | Op.InputWithDefault(ty, _, _) => (ty, [ty])
94 : jhr 1640 | Op.Print tys => (Ty.TupleTy[], tys)
95 : jhr 458 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
96 :     (* end case *))
97 :    
98 : jhr 1116 fun typeOfCons (_, []) = false
99 : jhr 1689 | typeOfCons (Ty.SeqTy(ty, n), tys) =
100 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
101 : jhr 1116 | typeOfCons (expectedTy, tys as ty1::_) =
102 :     if List.all (fn ty => Ty.same(ty1, ty)) tys
103 :     then (case (expectedTy, ty1)
104 : jhr 1640 of (Ty.SeqTy(_, n), Ty.IntTy) => (n = List.length tys)
105 : jhr 1116 | (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')
106 :     | _ => false
107 :     (* end case *))
108 :     else false
109 : jhr 458
110 :     end
111 :    
112 :     structure CheckLowIL = CheckILFn (
113 :     structure IL = LowIL
114 :     structure OpTy = CheckOps)
115 : jhr 1116
116 :     structure LowPP = SSAPPFn (LowIL)

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