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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 420 - (view) (download)

1 : jhr 411 (* check-high-il.sml
2 : jhr 404 *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 : jhr 405 structure CheckOps : OPERATOR_TY = struct
8 : jhr 404
9 :     structure Op = HighOps
10 :     structure Ty = HighILTypes
11 :    
12 : jhr 405 type rator = Op.rator
13 :     type ty = Ty.ty
14 :    
15 : jhr 420 (* Return the signature of a HighIL operator. *)
16 : jhr 412 fun sigOf rator = (case rator
17 : jhr 404 of Op.Add ty => (ty, [ty, ty])
18 :     | Op.Sub ty => (ty, [ty, ty])
19 :     | Op.Mul ty => (ty, [ty, ty])
20 :     | Op.Div ty => (ty, [ty, ty])
21 :     | Op.Neg ty => (ty, [ty])
22 :     | Op.LT ty => (Ty.BoolTy, [ty, ty])
23 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
24 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
25 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
26 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
27 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
28 :     | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])
29 :     | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])
30 :     | Op.Sin => (Ty.realTy, [Ty.realTy])
31 :     | Op.Cos => (Ty.realTy, [Ty.realTy])
32 :     | Op.Pow => (Ty.realTy, [Ty.realTy, Ty.realTy])
33 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
34 :     | Op.Dot ty => (Ty.realTy, [ty, ty])
35 :     | Op.Cross => (Ty.vec3Ty, [Ty.vec3Ty, Ty.vec3Ty])
36 : jhr 412 | Op.Norm ty => (Ty.realTy, [ty])
37 : jhr 404 | Op.Scale ty => (ty, [Ty.realTy, ty])
38 :     | Op.InvScale ty => (ty, [ty, Ty.realTy])
39 : jhr 407 | Op.CL => (Ty.realTy, [Ty.TensorTy[3, 3]])
40 :     | Op.PrincipleEvec(resTy as Ty.TensorTy[d]) => (resTy, [Ty.TensorTy[d,d]])
41 :     | Op.Slice(ty as Ty.TensorTy dd, m) => let
42 : jhr 404 val (resDims, idxDims) = let
43 :     fun f (d, false, (rds, ids)) = (d::rds, ids)
44 :     | f (_, true, (rds, ids)) = (rds, Ty.IntTy::ids)
45 :     in
46 : jhr 412 ListPair.foldr f ([], []) (dd, m)
47 : jhr 404 end
48 :     in
49 : jhr 412 (Ty.TensorTy resDims, ty::idxDims)
50 : jhr 404 end
51 : jhr 407 | Op.Subscript(ty as Ty.TensorTy dd) =>
52 : jhr 404 (Ty.realTy, ty :: List.map (fn _ => Ty.IntTy) dd)
53 :     | Op.IntToReal => (Ty.realTy, [Ty.IntTy])
54 :     | Op.TruncToInt => (Ty.IntTy, [Ty.realTy])
55 :     | Op.RoundToInt => (Ty.IntTy, [Ty.realTy])
56 :     | Op.CeilToInt => (Ty.IntTy, [Ty.realTy])
57 :     | Op.FloorToInt => (Ty.IntTy, [Ty.realTy])
58 :     | Op.Kernel _ => (Ty.KernelTy, [])
59 :     | Op.LoadImage _ => (Ty.ImageTy, [])
60 : jhr 407 | Op.Convolve => (Ty.FieldTy, [Ty.ImageTy, Ty.KernelTy])
61 : jhr 408 | Op.Inside domTy => (Ty.BoolTy, [domTy, Ty.FieldTy])
62 : jhr 404 | Op.Field _ => (Ty.FieldTy, [])
63 :     | Op.AddField => (Ty.FieldTy, [Ty.FieldTy, Ty.FieldTy])
64 :     | Op.ScaleField => (Ty.FieldTy, [Ty.realTy, Ty.FieldTy])
65 :     | Op.NegField => (Ty.FieldTy, [Ty.FieldTy])
66 :     | Op.DiffField => (Ty.FieldTy, [Ty.FieldTy])
67 : jhr 408 | Op.Probe(rngTy, domTy) => (rngTy, [Ty.FieldTy, domTy])
68 :     | Op.Input(ty, _) => (ty, [])
69 :     | Op.InputWithDefault(ty, _) => (ty, [ty])
70 : jhr 412 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
71 : jhr 404 (* end case *))
72 :    
73 : jhr 412 fun typeOfCons ((ty1 as Ty.TensorTy dd)::r) =
74 :     if List.all (fn ty => Ty.same(ty1, ty)) r
75 :     then SOME(Ty.TensorTy((List.length r + 1) :: dd))
76 :     else NONE
77 :     | typeOfCons _ = NONE
78 :    
79 : jhr 404 end
80 : jhr 405
81 :     structure CheckHighIL = CheckILFn (
82 :     structure IL = HighIL
83 :     structure OpTy = CheckOps)

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