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

SCM Repository

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

Annotation of /branches/vis15/src/compiler/mid-ir/mid-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3480 - (view) (download)

1 : jhr 3480 (* mid-types.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 :     * Types for the MidIR.
9 :     *)
10 :    
11 :     structure MidTypes =
12 :     struct
13 :    
14 :     datatype ty
15 :     = BoolTy | StringTy | IntTy
16 :     | TensorTy of int list (* tensor types, which include reals, sequences of reals, etc. *)
17 :     | TupleTy of ty list (* tuples; used for multiple return values *)
18 :     | SeqTy of ty * int
19 :     | AddrTy of ImageInfo.info (* voxel address *)
20 :     | ImageTy of ImageInfo.info
21 :     | KernelTy
22 :     (* FIXME: ask Charisee about the following *)
23 :     | indexTy of int list (* Specific index *)
24 :     | imgIndex of int list (* Image Index V_0 or V_1, [] for scalars *)
25 :     | vectorLength of int list
26 :     | unionTy of int (*union5_t *)
27 :     | R of RationalEin.rat
28 :    
29 :     val intTy = IntTy
30 :     fun iVecTy 1 = IntTy
31 :     | iVecTy n = SeqTy(IntTy, n)
32 :     val realTy = TensorTy[]
33 :     fun vecTy 1 = realTy
34 :     | vecTy n = TensorTy[n]
35 :    
36 :     fun tensorTy dd = (case (List.mapPartial (fn 1 => NONE | d => SOME d) dd)
37 :     of [] => realTy (* 0-order tensors are represented as reals *)
38 :     | dd => TensorTy dd
39 :     (* end case *))
40 :    
41 :     fun same (BoolTy, BoolTy) = true
42 :     | same (StringTy, StringTy) = true
43 :     | same (IntTy, IntTy) = true
44 :     | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
45 :     | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
46 :     | same (SeqTy(ty1, n1), SeqTy(ty2, n2)) = (n1 = n2) andalso same(ty1, ty2)
47 :     | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
48 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.same(info1, info2)
49 :     | same (KernelTy, KernelTy) = true
50 :     (* ??? the following don't seem correct ??? *)
51 :     | same (TensorTy[], intTy) = true
52 :     | same (intTy, TensorTy[]) = true
53 :     | same (indexTy dd1, indexTy dd2)=(dd1=dd2)
54 :     | same (imgIndex dd1, imgIndex dd2) = (dd1=dd2)
55 :     | same (vectorLength dd1, vectorLength dd2) = (dd1=dd2)
56 :     | same (unionTy n1, unionTy n2)= (n1=n2)
57 :     | same _ = false
58 :    
59 :     fun hash BoolTy = 0w1
60 :     | hash StringTy = 0w2
61 :     | hash IntTy = 0w3
62 :     | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w4 dd
63 :     | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys
64 :     | hash (SeqTy(ty, n)) = Word.fromInt n * hash ty + 0w11
65 :     | hash (AddrTy info) = 0w5 + ImageInfo.hash info
66 :     | hash (ImageTy info) = 0w13 * ImageInfo.hash info + 0w6
67 :     | hash KernelTy = 0w17
68 :     | hash (imgIndex _ )=0w19
69 :     | hash (indexTy dd)= List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w23 dd
70 :     | hash (vectorLength _)=0w29
71 :     | hash (unionTy n1)= 0w31
72 :    
73 :     fun toString BoolTy = "bool"
74 :     | toString StringTy = "string"
75 :     | toString IntTy = "int"
76 :     | toString (TensorTy[]) = "real"
77 :     | toString (TensorTy[n1])=String.concat["VecTy<", Int.toString n1, ">"]
78 :     | toString (TensorTy dd) = String.concat["tensor[", String.concatWith "," (List.map Int.toString dd), "]" ]
79 :     | toString (TupleTy tys) = String.concat[ "(", String.concatWith " * " (List.map toString tys), ")"]
80 :     | toString (SeqTy(ty, n)) = concat[toString ty, "SeqTy{", Int.toString n, "}"]
81 :     | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
82 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
83 :     | toString KernelTy = "kernel"
84 :     | toString (indexTy []) = "-"
85 :     | toString (indexTy dd) = String.concat["Specific Index:[", String.concatWithMap "," Int.toString dd, "]"]
86 :     | toString (imgIndex dd) = String.concat["ImgSpecificIndex:[", String.concatWithMap "," Int.toString dd, "]"]
87 :     | toString (vectorLength dd) = String.concat["[", String.concatWithMap "," Int.toString dd, "]"]
88 :     | toString (unionTy n1) = String.concat["Unionty", Int.toString n1]
89 :    
90 :     (*Quick fix*)
91 :     fun cmp (e1, e2) = String.compare(toString(e1), toString(e2))
92 :    
93 :     end

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