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 3578 - (view) (download)

1 : jhr 3480 (* mid-types.sml
2 :     *
3 : jhr 3532 * Types for the MidIR.
4 :     *
5 : jhr 3480 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
6 :     *
7 :     * COPYRIGHT (c) 2015 The University of Chicago
8 :     * All rights reserved.
9 :     *)
10 :    
11 :     structure MidTypes =
12 :     struct
13 :    
14 :     datatype ty
15 :     = BoolTy | StringTy | IntTy
16 : jhr 3532 | TensorTy of int list (* tensor types, which include reals, vectors, etc. *)
17 : jhr 3480 | TupleTy of ty list (* tuples; used for multiple return values *)
18 : jhr 3532 | SeqTy of ty * int option
19 : jhr 3480 | AddrTy of ImageInfo.info (* voxel address *)
20 :     | ImageTy of ImageInfo.info
21 :     | KernelTy
22 :    
23 :     val intTy = IntTy
24 :     val realTy = TensorTy[]
25 :     fun vecTy 1 = realTy
26 :     | vecTy n = TensorTy[n]
27 : jhr 3578 fun iVecTy 1 = IntTy
28 :     | iVecTy n = SeqTy(IntTy, SOME n)
29 : jhr 3480
30 : jhr 3532 (* smart constructor for tensor type that prunes out dimensions with size 1 *)
31 :     fun tensorTy dd = TensorTy(List.mapPartial (fn 1 => NONE | d => SOME d) dd)
32 : jhr 3480
33 :     fun same (BoolTy, BoolTy) = true
34 :     | same (StringTy, StringTy) = true
35 :     | same (IntTy, IntTy) = true
36 :     | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
37 :     | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
38 : jhr 3532 | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
39 :     | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
40 : jhr 3480 | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
41 : jhr 3532 | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
42 : jhr 3480 | same (KernelTy, KernelTy) = true
43 :     | same _ = false
44 :    
45 :     fun hash BoolTy = 0w1
46 :     | hash StringTy = 0w2
47 :     | hash IntTy = 0w3
48 : jhr 3532 | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w5 dd
49 : jhr 3480 | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys
50 : jhr 3532 | hash (SeqTy(ty, NONE)) = hash ty + 0w11
51 :     | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w13
52 : jhr 3480 | hash (AddrTy info) = 0w5 + ImageInfo.hash info
53 :     | hash (ImageTy info) = 0w13 * ImageInfo.hash info + 0w6
54 :     | hash KernelTy = 0w17
55 :    
56 :     fun toString BoolTy = "bool"
57 :     | toString StringTy = "string"
58 :     | toString IntTy = "int"
59 :     | toString (TensorTy[]) = "real"
60 : jhr 3532 | toString (TensorTy dd) = String.concat[
61 :     "tensor[", String.concatWithMap "," Int.toString dd, "]"
62 :     ]
63 :     | toString (TupleTy tys) = String.concat[
64 :     "(", String.concatWithMap " * " toString tys, ")"
65 :     ]
66 :     | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
67 :     | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
68 : jhr 3480 | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
69 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
70 :     | toString KernelTy = "kernel"
71 :    
72 :     end

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