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

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/high-ir/check-high.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/high-ir/check-high.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4434 - (view) (download)

1 : jhr 3487 (* check-high.sml
2 :     *
3 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 :     * All rights reserved.
7 :     *)
8 :    
9 :     structure CheckOps : OPERATOR_TY = struct
10 :    
11 :     structure Op = HighOps
12 :     structure Ty = HighTypes
13 :    
14 :     type rator = Op.rator
15 :     type ty = Ty.ty
16 :    
17 : jhr 4051 fun chkIndex (idx, bnd) = ((0 <= idx) andalso (idx < bnd))
18 :    
19 : jhr 3487 (* Return the signature of a HighIL operator. *)
20 :     fun sigOf rator = (case rator
21 :     of Op.IAdd => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
22 :     | Op.ISub => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
23 :     | Op.IMul => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
24 :     | Op.IDiv => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
25 :     | Op.IMod => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
26 :     | Op.INeg => (Ty.IntTy, [Ty.IntTy])
27 :     | Op.LT ty => (Ty.BoolTy, [ty, ty])
28 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
29 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
30 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
31 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
32 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
33 :     | Op.Power => (Ty.realTy, [Ty.realTy, Ty.IntTy])
34 : jhr 4434 | Op.BAnd => (Ty.BoolTy, [Ty.BoolTy, Ty.BoolTy])
35 :     | Op.BOr => (Ty.BoolTy, [Ty.BoolTy, Ty.BoolTy])
36 :     | Op.BNot => (Ty.BoolTy, [Ty.BoolTy])
37 : jhr 3530 | Op.Abs ty => (ty, [ty])
38 : jhr 3506 | Op.Max ty => (ty, [ty, ty])
39 :     | Op.Min ty => (ty, [ty, ty])
40 : jhr 3830 | Op.Clamp ty => (ty, [ty, Ty.realTy, Ty.realTy])
41 :     | Op.MapClamp ty => (ty, [ty, ty, ty])
42 : jhr 3487 | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
43 : jhr 4317 | Op.Zero ty => (ty, [])
44 :     | Op.TensorIndex(ty as Ty.TensorTy shp, idxs) =>
45 :     if ListPair.allEq chkIndex (idxs, shp)
46 :     then (Ty.realTy, [ty])
47 :     else raise Fail("sigOf: invalid index in operator " ^ Op.toString rator)
48 : jhr 3487 | Op.Select(ty as Ty.TupleTy tys, i) =>
49 :     if (1 <= i) andalso (i <= length tys)
50 :     then (List.nth(tys, i-1), [ty])
51 :     else raise Fail("sigOf: invalid operator " ^ Op.toString rator)
52 : jhr 3508 | Op.Subscript(ty as Ty.SeqTy(elemTy, _)) => (elemTy, [ty, Ty.IntTy])
53 : jhr 3487 | Op.MkDynamic(ty, n) => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, SOME n)])
54 :     | Op.Prepend ty => (Ty.SeqTy(ty, NONE), [ty, Ty.SeqTy(ty, NONE)])
55 :     | Op.Append ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), ty])
56 :     | Op.Concat ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), Ty.SeqTy(ty, NONE)])
57 : jhr 4317 | Op.Range => (Ty.SeqTy(Ty.intTy, NONE), [Ty.IntTy, Ty.IntTy])
58 : jhr 3487 | Op.Length ty => (Ty.intTy, [Ty.SeqTy(ty, NONE)])
59 : jhr 4349 | Op.SphereQuery(1, strandTy) =>
60 :     (Ty.SeqTy(strandTy, NONE), [Ty.realTy, Ty.realTy])
61 :     | Op.SphereQuery(dim, strandTy) =>
62 :     (Ty.SeqTy(strandTy, NONE), [Ty.TensorTy[dim], Ty.realTy])
63 : jhr 3487 | Op.IntToReal => (Ty.realTy, [Ty.IntTy])
64 :     | Op.TruncToInt => (Ty.IntTy, [Ty.realTy])
65 :     | Op.RoundToInt => (Ty.IntTy, [Ty.realTy])
66 :     | Op.CeilToInt => (Ty.IntTy, [Ty.realTy])
67 :     | Op.FloorToInt => (Ty.IntTy, [Ty.realTy])
68 : jhr 4394 | Op.NumStrands _ => (Ty.IntTy, [])
69 : jhr 4434 | Op.Strands(strandTy, _) => (Ty.SeqTy(strandTy, NONE), [])
70 : jhr 3487 | Op.Kernel _ => (Ty.KernelTy, [])
71 : jhr 4043 | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
72 : jhr 4317 | Op.ImageDim(info, _) => (Ty.IntTy, [Ty.ImageTy info])
73 :     | Op.BorderCtlDefault info =>
74 :     (Ty.ImageTy info, [Ty.ImageTy info, Ty.TensorTy(ImageInfo.voxelShape info)])
75 :     | Op.BorderCtlClamp info => (Ty.ImageTy info, [Ty.ImageTy info])
76 :     | Op.BorderCtlMirror info => (Ty.ImageTy info, [Ty.ImageTy info])
77 :     | Op.BorderCtlWrap info => (Ty.ImageTy info, [Ty.ImageTy info])
78 : jhr 3487 | Op.LoadSeq(ty, _) => (ty, [])
79 :     | Op.LoadImage(ty, _) => (ty, [])
80 : jhr 4317 | Op.MathFn f => MathFns.sigOf (Ty.realTy, f)
81 : jhr 3487 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
82 :     (* end case *))
83 :    
84 : jhr 4265 (* utility function for synthesizing eigenvector/eigenvalue signature *)
85 :     fun eigenSig dim = let
86 :     val resTy = [
87 :     Ty.SeqTy(Ty.realTy, SOME dim),
88 :     Ty.SeqTy(Ty.vecTy dim, SOME dim)
89 :     ]
90 :     in
91 :     (resTy, [Ty.TensorTy[dim, dim]])
92 :     end
93 :    
94 :     fun msigOf rator = (case rator
95 :     of Op.Eigen2x2 => eigenSig 2
96 :     | Op.Eigen3x3 => eigenSig 3
97 :     | Op.Print tys => ([], tys)
98 :     | _ => raise Fail("msigOf: invalid operator " ^ Op.toString rator)
99 :     (* end case *))
100 :    
101 : jhr 3487 fun typeOfCons (Ty.TensorTy dd', (ty1 as Ty.TensorTy dd)::r) =
102 :     if List.all (fn ty => Ty.same(ty1, ty)) r
103 :     then (dd' = (List.length r + 1)::dd)
104 :     else false
105 :     | typeOfCons _ = false
106 :    
107 :     fun typeOfSeq (Ty.SeqTy(ty, NONE), tys) = List.all (fn ty' => Ty.same(ty, ty')) tys
108 :     | typeOfSeq (Ty.SeqTy(ty, SOME n), tys) =
109 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
110 :     | typeOfSeq _ = false
111 :    
112 : jhr 3937 fun isStrandTy (Ty.StrandTy _) = true
113 :     | isStrandTy _ = false
114 :    
115 :     fun isBoolTy Ty.BoolTy = true
116 :     | isBoolTy _ = false
117 :    
118 : jhr 3487 end
119 :    
120 :     structure CheckHigh = CheckIRFn (
121 :     structure IR = HighIR
122 :     structure OpTy = CheckOps)
123 :    
124 :     structure HighPP = SSAPPFn (HighIR)

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