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

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