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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 548 - (view) (download)

1 : jhr 411 (* check-high-il.sml
2 : jhr 404 *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 404 * 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 : jhr 517 | Op.LoadImage info => (Ty.ImageTy(ImageInfo.dim info), [Ty.StringTy])
60 : jhr 548 | Op.Field dim => (Ty.FieldTy, [Ty.ImageTy dim, Ty.KernelTy])
61 :     | Op.Inside dim => (Ty.BoolTy, [Ty.TensorTy[dim], Ty.FieldTy])
62 : jhr 404 | Op.AddField => (Ty.FieldTy, [Ty.FieldTy, Ty.FieldTy])
63 :     | Op.ScaleField => (Ty.FieldTy, [Ty.realTy, Ty.FieldTy])
64 :     | Op.NegField => (Ty.FieldTy, [Ty.FieldTy])
65 :     | Op.DiffField => (Ty.FieldTy, [Ty.FieldTy])
66 : jhr 408 | Op.Probe(rngTy, domTy) => (rngTy, [Ty.FieldTy, domTy])
67 :     | Op.Input(ty, _) => (ty, [])
68 :     | Op.InputWithDefault(ty, _) => (ty, [ty])
69 : jhr 412 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
70 : jhr 404 (* end case *))
71 :    
72 : jhr 412 fun typeOfCons ((ty1 as Ty.TensorTy dd)::r) =
73 :     if List.all (fn ty => Ty.same(ty1, ty)) r
74 :     then SOME(Ty.TensorTy((List.length r + 1) :: dd))
75 :     else NONE
76 :     | typeOfCons _ = NONE
77 :    
78 : jhr 404 end
79 : jhr 405
80 :     structure CheckHighIL = CheckILFn (
81 :     structure IL = HighIL
82 :     structure OpTy = CheckOps)

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