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

SCM Repository

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

Annotation of /trunk/src/compiler/low-il/check-low-il.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1116 - (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 :     (* 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 1116 | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
37 :     | Op.Dot d => (Ty.realTy, [Ty.vecTy d, Ty.vecTy d])
38 :     | Op.MulVecMat(d1, d2) => (Ty.vecTy d2, [Ty.vecTy d1, Ty.TensorTy[d1, d2]])
39 :     | Op.MulMatVec(d1, d2) => (Ty.vecTy d1, [Ty.TensorTy[d1, d2], Ty.vecTy d2])
40 :     | Op.MulMatMat(d1, d2, d3) => (Ty.TensorTy[d1, d3], [Ty.TensorTy[d1, d2], Ty.TensorTy[d2, d3]])
41 : jhr 458 | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])
42 : jhr 1116 | Op.Select(ty as Ty.IVecTy 1, _) => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
43 : jhr 458 | Op.Select(ty as Ty.IVecTy d, _) => (Ty.intTy, [ty])
44 : jhr 1116 | Op.Select(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
45 :     | Op.Norm(ty as Ty.TensorTy _) => (Ty.realTy, [ty])
46 :     | Op.Normalize d => (Ty.vecTy d, [Ty.vecTy d])
47 :     | Op.Scale(ty as Ty.TensorTy(_::_)) => (ty, [Ty.realTy, ty])
48 : jhr 458 | Op.CL => raise Fail "Op.CL unimplemented"
49 :     | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
50 : jhr 1116 | Op.Identity d => (Ty.TensorTy[d,d], [])
51 :     | Op.Zero ty => (ty, [])
52 :     | Op.Trace d => (Ty.realTy, [Ty.TensorTy[d, d]])
53 : jhr 458 | Op.Subscript(Ty.IVecTy d) => (Ty.intTy, [Ty.IVecTy d, Ty.intTy])
54 : jhr 1116 | Op.Subscript(ty as Ty.TensorTy dd) => (Ty.realTy, ty :: List.map (fn _ => Ty.intTy) dd)
55 :     | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
56 :     | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
57 :     | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
58 :     | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
59 : jhr 458 | Op.IntToReal => (Ty.realTy, [Ty.intTy])
60 : jhr 1116 | Op.RealToInt d => (Ty.IVecTy d, [Ty.vecTy d])
61 :     | Op.ImageAddress info => (Ty.AddrTy info, [Ty.ImageTy info])
62 :     | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
63 :     | Op.PosToImgSpace info => let
64 :     val dim = ImageInfo.dim info
65 :     in
66 :     (Ty.vecTy dim, [Ty.ImageTy info, Ty.vecTy dim])
67 :     end
68 :     | Op.TensorToWorldSpace(info, ty) => (ty, [Ty.ImageTy info, ty])
69 :     | Op.LoadImage info => (Ty.ImageTy info, [Ty.StringTy])
70 :     | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
71 : jhr 458 | Op.Input(ty, _) => (ty, [])
72 :     | Op.InputWithDefault(ty, _) => (ty, [ty])
73 :     | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
74 :     (* end case *))
75 :    
76 : jhr 1116 fun typeOfCons (_, []) = false
77 :     | typeOfCons (expectedTy, tys as ty1::_) =
78 :     if List.all (fn ty => Ty.same(ty1, ty)) tys
79 :     then (case (expectedTy, ty1)
80 :     of (Ty.IVecTy n, Ty.IVecTy 1) => (n = List.length tys)
81 :     | (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')
82 :     | _ => false
83 :     (* end case *))
84 :     else false
85 : jhr 458
86 :     end
87 :    
88 :     structure CheckLowIL = CheckILFn (
89 :     structure IL = LowIL
90 :     structure OpTy = CheckOps)
91 : jhr 1116
92 :     structure LowPP = SSAPPFn (LowIL)

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