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

SCM Repository

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

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

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

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

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

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