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 511 - (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 511 of Op.Add Ty.AddrTy => (Ty.AddrTy, [Ty.AddrTy, Ty.intTy])
20 :     | Op.Add ty => (ty, [ty, ty])
21 :     | Op.Sub Ty.AddrTy => (Ty.AddrTy, [Ty.AddrTy, 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 :     | Op.Floor d => (Ty.VecTy d, [Ty.VecTy d])
50 :     | Op.IntToReal => (Ty.realTy, [Ty.intTy])
51 :     | Op.TruncToInt d => (Ty.IVecTy d, [Ty.VecTy d])
52 :     | Op.RoundToInt d => (Ty.IVecTy d, [Ty.VecTy d])
53 :     | Op.CeilToInt d => (Ty.IVecTy d, [Ty.VecTy d])
54 :     | Op.FloorToInt d => (Ty.IVecTy d, [Ty.VecTy d])
55 : jhr 511 | Op.ImageAddress(ImageInfo.ImgInfo{dim, ...}) => (Ty.AddrTy, [])
56 : jhr 458 | Op.LoadVoxels(_, d) => (Ty.VecTy d, [Ty.AddrTy])
57 :     | Op.PosToImgSpace(ImageInfo.ImgInfo{dim, ...}) => (Ty.VecTy dim, [Ty.VecTy dim])
58 :     | Op.GradToWorldSpace(ImageInfo.ImgInfo{dim, ...}) => (Ty.VecTy dim, [Ty.VecTy dim])
59 :     | Op.LoadImage _ => (Ty.ImageTy, [])
60 :     | Op.Inside(ImageInfo.ImgInfo{dim, ...}) => (Ty.BoolTy, [Ty.VecTy dim])
61 :     | Op.Input(ty, _) => (ty, [])
62 :     | Op.InputWithDefault(ty, _) => (ty, [ty])
63 :     | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
64 :     (* end case *))
65 :    
66 :     fun typeOfCons [] = NONE
67 :     | typeOfCons tys =
68 :     if List.all (fn ty => Ty.same(Ty.intTy, ty)) tys
69 :     then SOME(Ty.IVecTy(List.length tys))
70 :     else if List.all (fn ty => Ty.same(Ty.realTy, ty)) tys
71 :     then SOME(Ty.VecTy(List.length tys))
72 :     else NONE
73 :    
74 :     end
75 :    
76 :     structure CheckLowIL = CheckILFn (
77 :     structure IL = LowIL
78 :     structure OpTy = CheckOps)

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