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

SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/low-il/check-low-il.sml
ViewVC logotype

Diff of /branches/vis12/src/compiler/low-il/check-low-il.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1115, Thu May 5 04:42:18 2011 UTC revision 1116, Thu May 5 04:49:02 2011 UTC
# Line 12  Line 12 
12      type rator = Op.rator      type rator = Op.rator
13      type ty = Ty.ty      type ty = Ty.ty
14    
15      val vec3Ty = Ty.VecTy 3      val vec3Ty = Ty.vecTy 3
16    
17    (* Return the signature of a LowIL operator. *)    (* Return the signature of a LowIL operator. *)
18      fun sigOf rator = (case rator      fun sigOf rator = (case rator
19             of Op.Add Ty.AddrTy => (Ty.AddrTy, [Ty.AddrTy, Ty.intTy])             of Op.Add(Ty.AddrTy rTy) => (Ty.AddrTy rTy, [Ty.AddrTy rTy, Ty.intTy])
20              | Op.Add ty => (ty, [ty, ty])              | Op.Add ty => (ty, [ty, ty])
21              | Op.Sub Ty.AddrTy => (Ty.AddrTy, [Ty.AddrTy, Ty.intTy])              | Op.Sub(Ty.AddrTy rTy) => (Ty.AddrTy rTy, [Ty.AddrTy rTy, Ty.intTy])
22              | Op.Sub ty => (ty, [ty, ty])              | Op.Sub ty => (ty, [ty, ty])
23              | Op.Mul ty => (ty, [ty, ty])              | Op.Mul ty => (ty, [ty, ty])
24              | Op.Div ty => (ty, [ty, ty])              | Op.Div ty => (ty, [ty, ty])
25              | Op.Neg ty => (ty, [ty])              | Op.Neg ty => (ty, [ty])
26                | Op.Abs ty => (ty, [ty])
27              | Op.LT ty => (Ty.BoolTy, [ty, ty])              | Op.LT ty => (Ty.BoolTy, [ty, ty])
28              | Op.LTE ty => (Ty.BoolTy, [ty, ty])              | Op.LTE ty => (Ty.BoolTy, [ty, ty])
29              | Op.EQ ty => (Ty.BoolTy, [ty, ty])              | Op.EQ ty => (Ty.BoolTy, [ty, ty])
# Line 32  Line 33 
33              | Op.Not => (Ty.BoolTy, [Ty.BoolTy])              | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
34              | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])              | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])
35              | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])              | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])
36              | Op.Sin => (Ty.realTy, [Ty.realTy])              | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
37              | Op.Cos => (Ty.realTy, [Ty.realTy])              | Op.Dot d => (Ty.realTy, [Ty.vecTy d, Ty.vecTy d])
38              | Op.Pow => (Ty.realTy, [Ty.realTy, Ty.realTy])              | Op.MulVecMat(d1, d2) => (Ty.vecTy d2, [Ty.vecTy d1, Ty.TensorTy[d1, d2]])
39              | Op.Dot d => (Ty.realTy, [Ty.VecTy d, Ty.VecTy d])              | Op.MulMatVec(d1, d2) => (Ty.vecTy d1, [Ty.TensorTy[d1, d2], Ty.vecTy d2])
40                | Op.MulMatMat(d1, d2, d3) => (Ty.TensorTy[d1, d3], [Ty.TensorTy[d1, d2], Ty.TensorTy[d2, d3]])
41              | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])              | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])
42                | Op.Select(ty as Ty.IVecTy 1, _) => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
43              | Op.Select(ty as Ty.IVecTy d, _) => (Ty.intTy, [ty])              | Op.Select(ty as Ty.IVecTy d, _) => (Ty.intTy, [ty])
44              | Op.Select(ty as Ty.VecTy d, _) => (Ty.realTy, [ty])              | Op.Select(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
45              | Op.Norm d => (Ty.realTy, [Ty.VecTy d])              | Op.Norm(ty as Ty.TensorTy _) => (Ty.realTy, [ty])
46              | Op.Scale d => (Ty.VecTy d, [Ty.realTy, Ty.VecTy d])              | Op.Normalize d => (Ty.vecTy d, [Ty.vecTy d])
47              | Op.InvScale d => (Ty.VecTy d, [Ty.VecTy d, Ty.realTy])              | Op.Scale(ty as Ty.TensorTy(_::_)) => (ty, [Ty.realTy, ty])
48              | Op.CL => raise Fail "Op.CL unimplemented"              | Op.CL => raise Fail "Op.CL unimplemented"
49              | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"              | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
50                | Op.Identity d => (Ty.TensorTy[d,d], [])
51                | Op.Zero ty => (ty, [])
52                | Op.Trace d => (Ty.realTy, [Ty.TensorTy[d, d]])
53              | Op.Subscript(Ty.IVecTy d) => (Ty.intTy, [Ty.IVecTy d, Ty.intTy])              | Op.Subscript(Ty.IVecTy d) => (Ty.intTy, [Ty.IVecTy d, Ty.intTy])
54              | Op.Subscript(Ty.VecTy d) => (Ty.realTy, [Ty.VecTy d, Ty.intTy])              | Op.Subscript(ty as Ty.TensorTy dd) => (Ty.realTy, ty :: List.map (fn _ => Ty.intTy) dd)
55              | Op.Floor d => (Ty.VecTy d, [Ty.VecTy d])              | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
56                | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
57                | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
58                | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
59              | Op.IntToReal => (Ty.realTy, [Ty.intTy])              | Op.IntToReal => (Ty.realTy, [Ty.intTy])
60              | Op.TruncToInt d => (Ty.IVecTy d, [Ty.VecTy d])              | Op.RealToInt d => (Ty.IVecTy d, [Ty.vecTy d])
61              | Op.RoundToInt d => (Ty.IVecTy d, [Ty.VecTy d])              | Op.ImageAddress info => (Ty.AddrTy info, [Ty.ImageTy info])
62              | Op.CeilToInt d => (Ty.IVecTy d, [Ty.VecTy d])              | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
63              | Op.FloorToInt d => (Ty.IVecTy d, [Ty.VecTy d])              | Op.PosToImgSpace info => let
64              | Op.ImageAddress(ImageInfo.ImgInfo{dim, ...}) => (Ty.AddrTy, [])                  val dim = ImageInfo.dim info
65              | Op.LoadVoxels(_, d) => (Ty.VecTy d, [Ty.AddrTy])                  in
66              | Op.PosToImgSpace(ImageInfo.ImgInfo{dim, ...}) => (Ty.VecTy dim, [Ty.VecTy dim])                    (Ty.vecTy dim, [Ty.ImageTy info, Ty.vecTy dim])
67              | Op.GradToWorldSpace(ImageInfo.ImgInfo{dim, ...}) => (Ty.VecTy dim, [Ty.VecTy dim])                  end
68              | Op.LoadImage _ => (Ty.ImageTy, [])              | Op.TensorToWorldSpace(info, ty) => (ty, [Ty.ImageTy info, ty])
69              | Op.Inside(ImageInfo.ImgInfo{dim, ...}) => (Ty.BoolTy, [Ty.VecTy dim])              | Op.LoadImage info => (Ty.ImageTy info, [Ty.StringTy])
70                | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
71              | Op.Input(ty, _) => (ty, [])              | Op.Input(ty, _) => (ty, [])
72              | Op.InputWithDefault(ty, _) => (ty, [ty])              | Op.InputWithDefault(ty, _) => (ty, [ty])
73              | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)              | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
74            (* end case *))            (* end case *))
75    
76      fun typeOfCons [] = NONE      fun typeOfCons (_, []) = false
77        | typeOfCons tys =        | typeOfCons (expectedTy, tys as ty1::_) =
78            if List.all (fn ty => Ty.same(Ty.intTy, ty)) tys            if List.all (fn ty => Ty.same(ty1, ty)) tys
79              then SOME(Ty.IVecTy(List.length tys))              then (case (expectedTy, ty1)
80            else if List.all (fn ty => Ty.same(Ty.realTy, ty)) tys                 of (Ty.IVecTy n, Ty.IVecTy 1) => (n = List.length tys)
81              then SOME(Ty.VecTy(List.length tys))                  | (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')
82              else NONE                  | _ => false
83                  (* end case *))
84                else false
85    
86    end    end
87    
88  structure CheckLowIL = CheckILFn (  structure CheckLowIL = CheckILFn (
89      structure IL = LowIL      structure IL = LowIL
90      structure OpTy = CheckOps)      structure OpTy = CheckOps)
91    
92    structure LowPP = SSAPPFn (LowIL)

Legend:
Removed from v.1115  
changed lines
  Added in v.1116

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