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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2603 - (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 : cchiw 2525
28 :    
29 : jhr 458 (* Return the signature of a LowIL operator. *)
30 :     fun sigOf rator = (case rator
31 : cchiw 2522 of Op.IAdd => (Ty.intTy, [Ty.intTy,Ty.intTy])
32 :     | Op.ISub => (Ty.intTy, [Ty.intTy,Ty.intTy])
33 :     | Op.IMul => (Ty.intTy, [Ty.intTy,Ty.intTy])
34 :     | Op.IDiv => (Ty.intTy, [Ty.intTy,Ty.intTy])
35 :     | Op.INeg =>(Ty.intTy, [Ty.intTy])
36 : jhr 2356 | Op.Abs ty => (ty, [ty])
37 :     | 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 :     | Op.Clamp ty => (ty, [ty, ty, ty])
47 :     | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
48 :     | Op.Norm(ty as Ty.TensorTy _) => (Ty.realTy, [ty])
49 :     | Op.Normalize d => (Ty.vecTy d, [Ty.vecTy d])
50 :     | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
51 : jhr 1640 | Op.EigenVecs2x2 => eigenSig 2
52 :     | Op.EigenVecs3x3 => eigenSig 3
53 :     | Op.EigenVals2x2 => (Ty.SeqTy(Ty.realTy, 2), [Ty.TensorTy[2,2]])
54 :     | Op.EigenVals3x3 => (Ty.SeqTy(Ty.realTy, 3), [Ty.TensorTy[3,3]])
55 : jhr 2356 | Op.Zero ty => (ty, [])
56 : jhr 1640 | Op.Select(ty as Ty.TupleTy tys, i) => (List.nth(tys, i-1), [ty])
57 : jhr 2356 | Op.Index(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
58 :     | Op.Index(ty as Ty.SeqTy(elemTy, _), _) => (elemTy, [ty])
59 :     | Op.Subscript(ty as Ty.TensorTy dd) => (Ty.realTy, ty :: List.map (fn _ => Ty.intTy) dd)
60 :     | Op.Subscript(ty as Ty.SeqTy(elemTy, d)) => (elemTy, [ty, Ty.intTy])
61 :     | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
62 :     | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
63 :     | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
64 :     | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
65 :     | Op.IntToReal => (Ty.realTy, [Ty.intTy])
66 :     | Op.RealToInt 1 => (Ty.IntTy, [Ty.realTy])
67 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.TensorTy[d]])
68 : jhr 1640 (* FIXME: the type of RealToInt should be
69 : jhr 2356 | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.SeqTy(Ty.realTy, d)])
70 : jhr 1640 *)
71 : jhr 2356 | Op.ImageAddress info => (Ty.AddrTy info, [Ty.ImageTy info])
72 :     | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
73 : cchiw 2525 | Op.LoadImage info => (Ty.ImageTy info, [])
74 : jhr 2356 | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
75 : cchiw 2522 (* | Op.Input(ty, _, _) => (ty, [])
76 :     | Op.InputWithDefault(ty, _, _) => (ty, [ty])*)
77 : jhr 1640 | Op.Print tys => (Ty.TupleTy[], tys)
78 : cchiw 2525 | Op.Transform info => let
79 :     val dim = ImageInfo.dim info
80 :     in
81 :     (Ty.TensorTy[dim,dim], [])
82 :     end
83 :     | Op.Translate info => let
84 :     val dim = ImageInfo.dim info
85 :     in
86 :     (Ty.TensorTy[dim,dim], [])
87 :     end
88 :     (*real or int argument?*)
89 : cchiw 2555 | Op.S ( _ , Ty.indexTy i, Ty.TensorTy j) =>
90 :     if (length(i)>length(j)) then raise Fail"Not right Size"
91 :     else (Ty.TensorTy[] ,[Ty.TensorTy j])
92 :     | Op.S ( _ ,Ty.indexTy i, ty) => (Ty.TensorTy[] ,[ty])
93 :     | Op.V ( _ ,d,_, Ty.TensorTy([])) => raise Fail "Real, where there should be a higher order tensor"
94 : cchiw 2525 | Op.V ( _ ,d,_, Ty.TensorTy(ty)) => (Ty.TensorTy([d]),[Ty.TensorTy(ty)])
95 :     | Op.C _ => (Ty.TensorTy[] ,[])
96 :     (*Should be reals*)
97 :     | Op.addSca => (Ty.TensorTy([]), [Ty.TensorTy([]),Ty.TensorTy([])])
98 :     | Op.subSca => (Ty.TensorTy([]), [Ty.TensorTy([]),Ty.TensorTy([])])
99 :     | Op.prodSca => (Ty.TensorTy([]), [Ty.TensorTy([]),Ty.TensorTy([])])
100 :     | Op.divSca =>(Ty.TensorTy([]), [Ty.TensorTy([]),Ty.TensorTy([])])
101 :    
102 :     | Op.addVec(d)=>(Ty.TensorTy([d]),[Ty.TensorTy([d]),Ty.TensorTy([d])])
103 :     | Op.subVec(d)=>(Ty.TensorTy([d]),[Ty.TensorTy([d]),Ty.TensorTy([d])])
104 :     | Op.prodVec(d)=>(Ty.TensorTy([d]),[Ty.TensorTy([d]),Ty.TensorTy([d])])
105 :     | Op.prodScaV(d)=>(Ty.TensorTy([d]),[Ty.TensorTy([]),Ty.TensorTy([d])])
106 : cchiw 2555 | Op.sumVec(d)=>(Ty.TensorTy([]),[Ty.TensorTy([d])])
107 : cchiw 2525
108 : cchiw 2533
109 :     | Op.cons(Ty.TensorTy(ty),_)=>let
110 : cchiw 2525 val h=hd(ty)
111 : cchiw 2603 val list=tl(ty) (*List.take(ty, length(ty)-1)*)
112 : cchiw 2525 val arg=List.tabulate(h,fn _=>Ty.TensorTy(list))
113 :     in (Ty.TensorTy(ty),arg)
114 :     end
115 :    
116 : cchiw 2533 | Op.cons(Ty.IntTy,n)=>let
117 :     val arg=List.tabulate(n,fn _=>Ty.TensorTy([]))
118 :     in
119 :     (Ty.TensorTy([n]), arg)
120 :     end
121 : cchiw 2525
122 : cchiw 2533 (*imgAddr: shape of IMG, dim, Args: dim number of ints*)
123 :     | Op.imgAddr(info , ty,dim)=> let
124 :     val arg=List.tabulate(dim,fn _=>Ty.intTy)
125 :     in (Ty.intTy, arg)
126 :     end
127 :    
128 :     (*imgLoad, dim, int-2*support:Args:addrVar*)
129 :     | Op.imgLoad (info ,i,j)=>(Ty.TensorTy([j]), [Ty.intTy])
130 :    
131 :    
132 : cchiw 2525 | Op.Kernel _ => (Ty.KernelTy, [])
133 :     | _ => raise Fail("sigOf: In low-IL Does not have: invalid operator " ^ Op.toString rator)
134 : jhr 2356 (* end case *))
135 : jhr 458
136 : jhr 1116 fun typeOfCons (_, []) = false
137 :     | typeOfCons (expectedTy, tys as ty1::_) =
138 : jhr 2356 if List.all (fn ty => Ty.same(ty1, ty)) tys
139 :     then (case (expectedTy, ty1)
140 :     of (Ty.SeqTy(_, n), Ty.IntTy) => (n = List.length tys)
141 :     | (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')
142 : cchiw 2525
143 : jhr 2356 | _ => false
144 :     (* end case *))
145 :     else false
146 : jhr 458
147 :     end
148 :    
149 :     structure CheckLowIL = CheckILFn (
150 :     structure IL = LowIL
151 :     structure OpTy = CheckOps)
152 : jhr 1116
153 :     structure LowPP = SSAPPFn (LowIL)

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