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 4043 - (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 :     (* utility function for synthesizing eigenvector/eigenvalue signature *)
18 :     fun eigenSig dim = let
19 :     val tplTy = Ty.TupleTy[
20 :     Ty.SeqTy(Ty.realTy, SOME dim),
21 :     Ty.SeqTy(Ty.vecTy dim, SOME dim)
22 :     ]
23 :     in
24 :     (tplTy, [Ty.TensorTy[dim, dim]])
25 :     end
26 :    
27 :     (* Return the signature of a HighIL operator. *)
28 :     fun sigOf rator = (case rator
29 :     of Op.IAdd => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
30 :     | Op.ISub => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
31 :     | Op.IMul => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
32 :     | Op.IDiv => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
33 :     | Op.IMod => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
34 :     | Op.INeg => (Ty.IntTy, [Ty.IntTy])
35 :     | Op.LT ty => (Ty.BoolTy, [ty, ty])
36 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
37 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
38 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
39 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
40 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
41 :     | Op.Power => (Ty.realTy, [Ty.realTy, Ty.IntTy])
42 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
43 : jhr 3530 | Op.Abs ty => (ty, [ty])
44 : jhr 3506 | Op.Max ty => (ty, [ty, ty])
45 :     | Op.Min ty => (ty, [ty, ty])
46 : jhr 3830 | Op.Clamp ty => (ty, [ty, Ty.realTy, Ty.realTy])
47 :     | Op.MapClamp ty => (ty, [ty, ty, ty])
48 : jhr 3487 | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
49 :     | Op.Eigen2x2 => eigenSig 2
50 :     | Op.Eigen3x3 => eigenSig 3
51 : jhr 3508 | Op.Zero ty => (ty, [])
52 : jhr 3797 | Op.TensorIndex(ty, _) => (Ty.realTy, [ty])
53 : jhr 3487 | Op.Select(ty as Ty.TupleTy tys, i) =>
54 :     if (1 <= i) andalso (i <= length tys)
55 :     then (List.nth(tys, i-1), [ty])
56 :     else raise Fail("sigOf: invalid operator " ^ Op.toString rator)
57 : jhr 3508 | Op.Subscript(ty as Ty.SeqTy(elemTy, _)) => (elemTy, [ty, Ty.IntTy])
58 : jhr 3487 | Op.MkDynamic(ty, n) => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, SOME n)])
59 :     | Op.Prepend ty => (Ty.SeqTy(ty, NONE), [ty, Ty.SeqTy(ty, NONE)])
60 :     | Op.Append ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), ty])
61 :     | Op.Concat ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), Ty.SeqTy(ty, NONE)])
62 : jhr 3508 | Op.Range => (Ty.SeqTy(Ty.intTy, NONE), [Ty.IntTy, Ty.IntTy])
63 : jhr 3487 | Op.Length ty => (Ty.intTy, [Ty.SeqTy(ty, NONE)])
64 : jhr 3508 | Op.SphereQuery(ptTy, strandTy) => (Ty.SeqTy(strandTy, NONE), [ptTy, Ty.realTy])
65 : jhr 3487 | Op.IntToReal => (Ty.realTy, [Ty.IntTy])
66 :     | Op.TruncToInt => (Ty.IntTy, [Ty.realTy])
67 :     | Op.RoundToInt => (Ty.IntTy, [Ty.realTy])
68 :     | Op.CeilToInt => (Ty.IntTy, [Ty.realTy])
69 :     | Op.FloorToInt => (Ty.IntTy, [Ty.realTy])
70 : jhr 3508 (* not sure if we will need these
71 :     | R_All of ty
72 :     | R_Exists of ty
73 :     | R_Max of ty
74 :     | R_Min of ty
75 :     | R_Sum of ty
76 :     | R_Product of ty
77 :     | R_Mean of ty
78 :     | R_Variance of ty
79 :     *)
80 : jhr 3487 | Op.Kernel _ => (Ty.KernelTy, [])
81 : jhr 4043 | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
82 : jhr 3487 | Op.ImageDim(info, _) => (Ty.IntTy, [Ty.ImageTy info])
83 :     | Op.BorderCtlDefault info =>
84 :     (Ty.ImageTy info, [Ty.ImageTy info, Ty.TensorTy(ImageInfo.voxelShape info)])
85 :     | Op.BorderCtlClamp info => (Ty.ImageTy info, [Ty.ImageTy info])
86 :     | Op.BorderCtlMirror info => (Ty.ImageTy info, [Ty.ImageTy info])
87 :     | Op.BorderCtlWrap info => (Ty.ImageTy info, [Ty.ImageTy info])
88 :     | Op.LoadSeq(ty, _) => (ty, [])
89 :     | Op.LoadImage(ty, _) => (ty, [])
90 :     | Op.Print tys => (Ty.TupleTy[], tys)
91 : jhr 3757 | Op.MathFn f => MathFns.sigOf (Ty.realTy, f)
92 : jhr 3487 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
93 :     (* end case *))
94 :    
95 :     fun typeOfCons (Ty.TensorTy dd', (ty1 as Ty.TensorTy dd)::r) =
96 :     if List.all (fn ty => Ty.same(ty1, ty)) r
97 :     then (dd' = (List.length r + 1)::dd)
98 :     else false
99 :     | typeOfCons _ = false
100 :    
101 :     fun typeOfSeq (Ty.SeqTy(ty, NONE), tys) = List.all (fn ty' => Ty.same(ty, ty')) tys
102 :     | typeOfSeq (Ty.SeqTy(ty, SOME n), tys) =
103 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
104 :     | typeOfSeq _ = false
105 :    
106 : jhr 3937 fun isStrandTy (Ty.StrandTy _) = true
107 :     | isStrandTy _ = false
108 :    
109 :     fun isBoolTy Ty.BoolTy = true
110 :     | isBoolTy _ = false
111 :    
112 : jhr 3487 end
113 :    
114 :     structure CheckHigh = CheckIRFn (
115 :     structure IR = HighIR
116 :     structure OpTy = CheckOps)
117 :    
118 :     structure HighPP = SSAPPFn (HighIR)

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