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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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