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 1444 - (view) (download)
Original Path: trunk/src/compiler/low-il/check-low-il.sml

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 :     (* Return the signature of a LowIL operator. *)
18 :     fun sigOf rator = (case rator
19 : jhr 1116 of Op.Add(Ty.AddrTy rTy) => (Ty.AddrTy rTy, [Ty.AddrTy rTy, Ty.intTy])
20 : jhr 511 | Op.Add ty => (ty, [ty, ty])
21 : jhr 1116 | Op.Sub(Ty.AddrTy rTy) => (Ty.AddrTy rTy, [Ty.AddrTy rTy, Ty.intTy])
22 : jhr 458 | Op.Sub ty => (ty, [ty, ty])
23 :     | Op.Mul ty => (ty, [ty, ty])
24 :     | Op.Div ty => (ty, [ty, ty])
25 :     | Op.Neg ty => (ty, [ty])
26 : jhr 1116 | Op.Abs ty => (ty, [ty])
27 : jhr 458 | Op.LT ty => (Ty.BoolTy, [ty, ty])
28 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
29 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
30 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
31 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
32 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
33 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
34 :     | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])
35 :     | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])
36 : jhr 1295 | Op.Clamp ty => (ty, [ty, ty, ty])
37 : jhr 1116 | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
38 :     | Op.Dot d => (Ty.realTy, [Ty.vecTy d, Ty.vecTy d])
39 :     | Op.MulVecMat(d1, d2) => (Ty.vecTy d2, [Ty.vecTy d1, Ty.TensorTy[d1, d2]])
40 :     | Op.MulMatVec(d1, d2) => (Ty.vecTy d1, [Ty.TensorTy[d1, d2], Ty.vecTy d2])
41 :     | Op.MulMatMat(d1, d2, d3) => (Ty.TensorTy[d1, d3], [Ty.TensorTy[d1, d2], Ty.TensorTy[d2, d3]])
42 : jhr 458 | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])
43 : jhr 1116 | Op.Select(ty as Ty.IVecTy 1, _) => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
44 : jhr 458 | Op.Select(ty as Ty.IVecTy d, _) => (Ty.intTy, [ty])
45 : jhr 1116 | Op.Select(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
46 :     | Op.Norm(ty as Ty.TensorTy _) => (Ty.realTy, [ty])
47 :     | Op.Normalize d => (Ty.vecTy d, [Ty.vecTy d])
48 :     | Op.Scale(ty as Ty.TensorTy(_::_)) => (ty, [Ty.realTy, ty])
49 : jhr 458 | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
50 : jhr 1116 | Op.Identity d => (Ty.TensorTy[d,d], [])
51 :     | Op.Zero ty => (ty, [])
52 : jhr 458 | Op.Subscript(Ty.IVecTy d) => (Ty.intTy, [Ty.IVecTy d, Ty.intTy])
53 : jhr 1116 | Op.Subscript(ty as Ty.TensorTy dd) => (Ty.realTy, ty :: List.map (fn _ => Ty.intTy) dd)
54 :     | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
55 :     | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
56 :     | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
57 :     | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
58 : jhr 458 | Op.IntToReal => (Ty.realTy, [Ty.intTy])
59 : jhr 1116 | Op.RealToInt d => (Ty.IVecTy d, [Ty.vecTy d])
60 :     | Op.ImageAddress info => (Ty.AddrTy info, [Ty.ImageTy info])
61 :     | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
62 :     | Op.PosToImgSpace info => let
63 :     val dim = ImageInfo.dim info
64 :     in
65 :     (Ty.vecTy dim, [Ty.ImageTy info, Ty.vecTy dim])
66 :     end
67 :     | Op.TensorToWorldSpace(info, ty) => (ty, [Ty.ImageTy info, ty])
68 :     | Op.LoadImage info => (Ty.ImageTy info, [Ty.StringTy])
69 :     | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
70 : jhr 1301 | Op.Input(ty, _, _) => (ty, [])
71 :     | Op.InputWithDefault(ty, _, _) => (ty, [ty])
72 : jhr 458 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
73 :     (* end case *))
74 :    
75 : jhr 1116 fun typeOfCons (_, []) = false
76 :     | typeOfCons (expectedTy, tys as ty1::_) =
77 :     if List.all (fn ty => Ty.same(ty1, ty)) tys
78 :     then (case (expectedTy, ty1)
79 :     of (Ty.IVecTy n, Ty.IVecTy 1) => (n = List.length tys)
80 :     | (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')
81 :     | _ => false
82 :     (* end case *))
83 :     else false
84 : jhr 458
85 :     end
86 :    
87 :     structure CheckLowIL = CheckILFn (
88 :     structure IL = LowIL
89 :     structure OpTy = CheckOps)
90 : jhr 1116
91 :     structure LowPP = SSAPPFn (LowIL)

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