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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1116 - (view) (download)

1 : jhr 420 (* check-mid-il.sml
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 420 * All rights reserved.
5 :     *)
6 :    
7 :     structure CheckOps : OPERATOR_TY = struct
8 :    
9 :     structure Op = MidOps
10 :     structure Ty = MidILTypes
11 :    
12 :     type rator = Op.rator
13 :     type ty = Ty.ty
14 :    
15 : jhr 1116 val vec3Ty = Ty.vecTy 3
16 : jhr 420
17 :     (* Return the signature of a MidIL operator. *)
18 :     fun sigOf rator = (case rator
19 :     of Op.Add ty => (ty, [ty, ty])
20 :     | Op.Sub ty => (ty, [ty, ty])
21 :     | Op.Mul ty => (ty, [ty, ty])
22 :     | Op.Div ty => (ty, [ty, ty])
23 :     | Op.Neg ty => (ty, [ty])
24 : jhr 1116 | Op.Abs ty => (ty, [ty])
25 : jhr 420 | Op.LT ty => (Ty.BoolTy, [ty, ty])
26 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
27 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
28 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
29 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
30 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
31 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
32 :     | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])
33 :     | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])
34 : jhr 1116 | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
35 :     | Op.Dot d => (Ty.realTy, [Ty.vecTy d, Ty.vecTy d])
36 :     | Op.MulVecMat(d1, d2) => (Ty.vecTy d2, [Ty.vecTy d1, Ty.TensorTy[d1, d2]])
37 :     | Op.MulMatVec(d1, d2) => (Ty.vecTy d1, [Ty.TensorTy[d1, d2], Ty.vecTy d2])
38 :     | Op.MulMatMat(d1, d2, d3) => (Ty.TensorTy[d1, d3], [Ty.TensorTy[d1, d2], Ty.TensorTy[d2, d3]])
39 : jhr 420 | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])
40 : jhr 1116 | Op.Select(ty as Ty.IVecTy 1, _) => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
41 : jhr 420 | Op.Select(ty as Ty.IVecTy d, _) => (Ty.intTy, [ty])
42 : jhr 1116 | Op.Select(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
43 :     | Op.Norm(ty as Ty.TensorTy _) => (Ty.realTy, [ty])
44 :     | Op.Normalize d => (Ty.vecTy d, [Ty.vecTy d])
45 :     | Op.Scale(ty as Ty.TensorTy(_::_)) => (ty, [Ty.realTy, ty])
46 : jhr 420 | Op.CL => raise Fail "Op.CL unimplemented"
47 :     | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
48 : jhr 1116 | Op.Identity d => (Ty.TensorTy[d,d], [])
49 :     | Op.Zero ty => (ty, [])
50 :     | Op.Trace d => (Ty.realTy, [Ty.TensorTy[d, d]])
51 : jhr 420 | Op.Subscript(Ty.IVecTy d) => (Ty.intTy, [Ty.IVecTy d, Ty.intTy])
52 : jhr 1116 | Op.Subscript(ty as Ty.TensorTy dd) => (Ty.realTy, ty :: List.map (fn _ => Ty.intTy) dd)
53 :     | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
54 :     | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
55 :     | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
56 :     | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
57 : jhr 420 | Op.IntToReal => (Ty.realTy, [Ty.intTy])
58 : jhr 1116 | Op.RealToInt d => (Ty.IVecTy d, [Ty.vecTy d])
59 :     | Op.VoxelAddress(info, offset) => let
60 :     val dim = ImageInfo.dim info
61 :     in
62 :     (Ty.AddrTy info, Ty.ImageTy info :: List.tabulate(dim, fn _ => Ty.intTy))
63 :     end
64 :     | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
65 :     | Op.PosToImgSpace info => let
66 :     val dim = ImageInfo.dim info
67 :     in
68 :     (Ty.vecTy dim, [Ty.ImageTy info, Ty.vecTy dim])
69 :     end
70 :     | Op.TensorToWorldSpace(info, ty) => (ty, [Ty.ImageTy info, ty])
71 :     | Op.EvalKernel(d, _, _) => (Ty.vecTy d, [Ty.vecTy d])
72 :     | Op.LoadImage info => (Ty.ImageTy info, [Ty.StringTy])
73 :     | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
74 : jhr 420 | Op.Input(ty, _) => (ty, [])
75 :     | Op.InputWithDefault(ty, _) => (ty, [ty])
76 :     | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
77 :     (* end case *))
78 :    
79 : jhr 1116 fun typeOfCons (_, []) = false
80 :     | typeOfCons (expectedTy, tys as ty1::_) =
81 :     if List.all (fn ty => Ty.same(ty1, ty)) tys
82 :     then (case (expectedTy, ty1)
83 :     of (Ty.IVecTy n, Ty.IVecTy 1) => (n = List.length tys)
84 :     | (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')
85 :     | _ => false
86 :     (* end case *))
87 :     else false
88 : jhr 420
89 :     end
90 :    
91 :     structure CheckMidIL = CheckILFn (
92 :     structure IL = MidIL
93 :     structure OpTy = CheckOps)
94 : jhr 1116
95 :     structure MidPP = SSAPPFn (MidIL)
96 :    

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