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

trunk/src/compiler/mid-il/check-mid-il.sml revision 450, Thu Oct 21 15:58:26 2010 UTC branches/vis12/src/compiler/mid-il/check-mid-il.sml revision 1925, Sat Jun 23 14:16:09 2012 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      (* utility function for synthesizing eigenvector/eigenvalue signature *)
18        fun eigenSig dim = let
19              val tplTy = Ty.TupleTy[
20                      Ty.SeqTy(Ty.realTy, dim),
21                      Ty.SeqTy(Ty.vecTy dim, dim)
22                    ]
23              in
24                (tplTy, [Ty.TensorTy[dim, dim]])
25              end
26    
27    (* Return the signature of a MidIL operator. *)    (* Return the signature of a MidIL operator. *)
28      fun sigOf rator = (case rator      fun sigOf rator = (case rator
# Line 21  Line 31 
31              | Op.Mul ty => (ty, [ty, ty])              | Op.Mul ty => (ty, [ty, ty])
32              | Op.Div ty => (ty, [ty, ty])              | Op.Div ty => (ty, [ty, ty])
33              | Op.Neg ty => (ty, [ty])              | Op.Neg ty => (ty, [ty])
34                | Op.Abs ty => (ty, [ty])
35              | Op.LT ty => (Ty.BoolTy, [ty, ty])              | Op.LT ty => (Ty.BoolTy, [ty, ty])
36              | Op.LTE ty => (Ty.BoolTy, [ty, ty])              | Op.LTE ty => (Ty.BoolTy, [ty, ty])
37              | Op.EQ ty => (Ty.BoolTy, [ty, ty])              | Op.EQ ty => (Ty.BoolTy, [ty, ty])
# Line 30  Line 41 
41              | Op.Not => (Ty.BoolTy, [Ty.BoolTy])              | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
42              | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])              | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])
43              | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])              | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])
44              | Op.Sin => (Ty.realTy, [Ty.realTy])              | Op.Clamp ty => (ty, [ty, ty, ty])
45              | Op.Cos => (Ty.realTy, [Ty.realTy])              | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
46              | Op.Pow => (Ty.realTy, [Ty.realTy, Ty.realTy])              | Op.Dot d => (Ty.realTy, [Ty.vecTy d, Ty.vecTy d])
47              | Op.Dot d => (Ty.realTy, [Ty.VecTy d, Ty.VecTy d])              | Op.MulVecMat(d1, d2) => (Ty.vecTy d2, [Ty.vecTy d1, Ty.TensorTy[d1, d2]])
48                | Op.MulMatVec(d1, d2) => (Ty.vecTy d1, [Ty.TensorTy[d1, d2], Ty.vecTy d2])
49                | Op.MulMatMat(d1, d2, d3) => (Ty.TensorTy[d1, d3], [Ty.TensorTy[d1, d2], Ty.TensorTy[d2, d3]])
50              | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])              | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])
51              | Op.Select(ty as Ty.IVecTy d, _) => (Ty.intTy, [ty])              | Op.Norm(ty as Ty.TensorTy _) => (Ty.realTy, [ty])
52              | Op.Select(ty as Ty.VecTy d, _) => (Ty.realTy, [ty])              | Op.Normalize d => (Ty.vecTy d, [Ty.vecTy d])
53              | Op.Norm d => (Ty.realTy, [Ty.VecTy d])              | Op.Scale(ty as Ty.TensorTy(_::_)) => (ty, [Ty.realTy, ty])
             | Op.Scale d => (Ty.VecTy d, [Ty.realTy, Ty.VecTy d])  
             | Op.InvScale d => (Ty.VecTy d, [Ty.VecTy d, Ty.realTy])  
             | Op.CL => raise Fail "Op.CL unimplemented"  
54              | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"              | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
55              | Op.Subscript(Ty.IVecTy d) => (Ty.intTy, [Ty.IVecTy d, Ty.intTy])              | Op.EigenVecs2x2 => eigenSig 2
56              | Op.Subscript(Ty.VecTy d) => (Ty.realTy, [Ty.VecTy d, Ty.intTy])              | Op.EigenVecs3x3 => eigenSig 3
57              | Op.Floor d => (Ty.VecTy d, [Ty.VecTy d])              | Op.EigenVals2x2 => (Ty.SeqTy(Ty.realTy, 2), [Ty.TensorTy[2,2]])
58                | Op.EigenVals3x3 => (Ty.SeqTy(Ty.realTy, 3), [Ty.TensorTy[3,3]])
59                | Op.Identity d => (Ty.TensorTy[d,d], [])
60                | Op.Zero ty => (ty, [])
61                | Op.Trace d => (Ty.realTy, [Ty.TensorTy[d, d]])
62                | Op.Select(ty as Ty.TupleTy tys, i) => (List.nth(tys, i-1), [ty])
63                | Op.Index(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
64                | Op.Index(ty as Ty.SeqTy(elemTy, _), _) => (elemTy, [ty])
65                | Op.Subscript(ty as Ty.TensorTy dd) => (Ty.realTy, ty :: List.map (fn _ => Ty.intTy) dd)
66                | Op.Subscript(ty as Ty.SeqTy(elemTy, d)) => (elemTy, [ty, Ty.intTy])
67                | Op.MkDynamic(ty, n) => (Ty.DynSeqTy ty, [Ty.SeqTy(ty, n)])
68                | Op.Prepend ty => (Ty.DynSeqTy ty, [ty, Ty.DynSeqTy ty])
69                | Op.Append ty => (Ty.DynSeqTy ty, [Ty.DynSeqTy ty, ty])
70                | Op.Concat ty => (Ty.DynSeqTy ty, [Ty.DynSeqTy ty, Ty.DynSeqTy ty])
71                | Op.Length ty => (Ty.intTy, [Ty.DynSeqTy ty])
72                | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
73                | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
74                | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
75                | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
76              | Op.IntToReal => (Ty.realTy, [Ty.intTy])              | Op.IntToReal => (Ty.realTy, [Ty.intTy])
77              | Op.TruncToInt d => (Ty.IVecTy d, [Ty.VecTy d])              | Op.RealToInt 1 => (Ty.IntTy, [Ty.realTy])
78              | Op.RoundToInt d => (Ty.IVecTy d, [Ty.VecTy d])              | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.TensorTy[d]])
79              | Op.CeilToInt d => (Ty.IVecTy d, [Ty.VecTy d])  (* FIXME: the type of RealToInt should be
80              | Op.FloorToInt d => (Ty.IVecTy d, [Ty.VecTy d])              | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.SeqTy(Ty.realTy, d)])
81              | Op.VoxelAddress(ImageInfo.ImgInfo{dim, ...}) =>  *)
82                  (Ty.AddrTy, List.tabulate(dim, fn _ => Ty.intTy))              | Op.VoxelAddress(info, offset) => let
83              | Op.LoadVoxels(_, d) => (Ty.VecTy d, [Ty.AddrTy])                  val dim = ImageInfo.dim info
84              | Op.PosToImgSpace(ImageInfo.ImgInfo{dim, ...}) => (Ty.VecTy dim, [Ty.VecTy dim])                  in
85              | Op.GradToWorldSpace(ImageInfo.ImgInfo{dim, ...}) => (Ty.VecTy dim, [Ty.VecTy dim])                    (Ty.AddrTy info, Ty.ImageTy info :: List.tabulate(dim, fn _ => Ty.intTy))
86              | Op.EvalKernel(d, _, _) => (Ty.VecTy d, [Ty.VecTy d])                  end
87              | Op.LoadImage _ => (Ty.ImageTy, [])              | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
88              | Op.Inside(ImageInfo.ImgInfo{dim, ...}) => (Ty.BoolTy, [Ty.VecTy dim])              | Op.PosToImgSpace info => let
89              | Op.Input(ty, _) => (ty, [])                  val dim = ImageInfo.dim info
90              | Op.InputWithDefault(ty, _) => (ty, [ty])                  in
91                      (Ty.vecTy dim, [Ty.ImageTy info, Ty.vecTy dim])
92                    end
93                | Op.TensorToWorldSpace(info, ty) => (ty, [Ty.ImageTy info, ty])
94                | Op.EvalKernel(d, _, _) => (Ty.vecTy d, [Ty.vecTy d])
95                | Op.LoadImage info => (Ty.ImageTy info, [Ty.StringTy])
96                | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
97                | Op.Input(ty, _, _) => (ty, [])
98                | Op.InputWithDefault(ty, _, _) => (ty, [ty])
99                | Op.Print tys => (Ty.TupleTy[], tys)
100              | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)              | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
101            (* end case *))            (* end case *))
102    
103      fun typeOfCons [] = NONE      fun typeOfCons (_, []) = false
104        | typeOfCons tys =        | typeOfCons (Ty.SeqTy(ty, n), tys) =
105            if List.all (fn ty => Ty.same(Ty.intTy, ty)) tys            List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
106              then SOME(Ty.IVecTy(List.length tys))        | typeOfCons (expectedTy, tys as ty1::_) =
107            else if List.all (fn ty => Ty.same(Ty.realTy, ty)) tys            if List.all (fn ty => Ty.same(ty1, ty)) tys
108              then SOME(Ty.VecTy(List.length tys))              then (case (expectedTy, ty1)
109              else NONE                 of (Ty.SeqTy(_, n), Ty.IntTy) => (n = List.length tys)
110                    | (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')
111                    | _ => false
112                  (* end case *))
113                else false
114    
115    end    end
116    
117  structure CheckMidIL = CheckILFn (  structure CheckMidIL = CheckILFn (
118      structure IL = MidIL      structure IL = MidIL
119      structure OpTy = CheckOps)      structure OpTy = CheckOps)
120    
121    structure MidPP = SSAPPFn (MidIL)
122    

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

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