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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 565 - (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 :     val vec3Ty = Ty.VecTy 3
16 :    
17 :     (* Return the signature of a LowIL operator. *)
18 :     fun sigOf rator = (case rator
19 : jhr 548 of Op.Add(Ty.AddrTy rTy) => (Ty.AddrTy rTy, [Ty.AddrTy rTy, Ty.intTy])
20 : jhr 510 | Op.Add ty => (ty, [ty, ty])
21 : jhr 548 | 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 :     | Op.LT ty => (Ty.BoolTy, [ty, ty])
27 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
28 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
29 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
30 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
31 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
32 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
33 :     | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])
34 :     | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])
35 :     | Op.Sin => (Ty.realTy, [Ty.realTy])
36 :     | Op.Cos => (Ty.realTy, [Ty.realTy])
37 :     | Op.Pow => (Ty.realTy, [Ty.realTy, Ty.realTy])
38 :     | Op.Dot d => (Ty.realTy, [Ty.VecTy d, Ty.VecTy d])
39 :     | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])
40 :     | Op.Select(ty as Ty.IVecTy d, _) => (Ty.intTy, [ty])
41 :     | Op.Select(ty as Ty.VecTy d, _) => (Ty.realTy, [ty])
42 :     | Op.Norm d => (Ty.realTy, [Ty.VecTy d])
43 :     | Op.Scale d => (Ty.VecTy d, [Ty.realTy, Ty.VecTy d])
44 :     | Op.InvScale d => (Ty.VecTy d, [Ty.VecTy d, Ty.realTy])
45 :     | Op.CL => raise Fail "Op.CL unimplemented"
46 :     | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
47 :     | Op.Subscript(Ty.IVecTy d) => (Ty.intTy, [Ty.IVecTy d, Ty.intTy])
48 :     | Op.Subscript(Ty.VecTy d) => (Ty.realTy, [Ty.VecTy d, Ty.intTy])
49 : jhr 565 | Op.Ceiling d => (Ty.VecTy d, [Ty.VecTy d])
50 : jhr 458 | Op.Floor d => (Ty.VecTy d, [Ty.VecTy d])
51 : jhr 565 | Op.Round d => (Ty.VecTy d, [Ty.VecTy d])
52 :     | Op.Trunc d => (Ty.VecTy d, [Ty.VecTy d])
53 : jhr 458 | Op.IntToReal => (Ty.realTy, [Ty.intTy])
54 : jhr 565 | Op.RealToInt d => (Ty.IVecTy d, [Ty.VecTy d])
55 : jhr 548 | Op.ImageAddress info => (Ty.AddrTy info, [Ty.ImageTy info])
56 :     | Op.LoadVoxels(info, n) => (Ty.VecTy n, [Ty.AddrTy info])
57 :     | Op.PosToImgSpace info => let
58 :     val dim = ImageInfo.dim info
59 :     in
60 :     (Ty.VecTy dim, [Ty.ImageTy info, Ty.VecTy dim])
61 :     end
62 :     | Op.GradToWorldSpace info => let
63 :     val dim = ImageInfo.dim info
64 :     in
65 :     (Ty.VecTy dim, [Ty.ImageTy info, Ty.VecTy dim])
66 :     end
67 :     | Op.LoadImage info => (Ty.ImageTy info, [Ty.StringTy])
68 :     | Op.Inside(info, _) => (Ty.BoolTy, [Ty.VecTy(ImageInfo.dim info), Ty.ImageTy info])
69 : jhr 458 | Op.Input(ty, _) => (ty, [])
70 :     | Op.InputWithDefault(ty, _) => (ty, [ty])
71 :     | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
72 :     (* end case *))
73 :    
74 :     fun typeOfCons [] = NONE
75 :     | typeOfCons tys =
76 :     if List.all (fn ty => Ty.same(Ty.intTy, ty)) tys
77 :     then SOME(Ty.IVecTy(List.length tys))
78 :     else if List.all (fn ty => Ty.same(Ty.realTy, ty)) tys
79 :     then SOME(Ty.VecTy(List.length tys))
80 :     else NONE
81 :    
82 :     end
83 :    
84 :     structure CheckLowIL = CheckILFn (
85 :     structure IL = LowIL
86 :     structure OpTy = CheckOps)

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