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 3532 - (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 :    
28 : jhr 3532 (* smart constructor for tensor type that prunes out dimensions with size 1 *)
29 :     fun tensorTy dd = TensorTy(List.mapPartial (fn 1 => NONE | d => SOME d) dd)
30 : jhr 3480
31 :     fun same (BoolTy, BoolTy) = true
32 :     | same (StringTy, StringTy) = true
33 :     | same (IntTy, IntTy) = true
34 :     | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
35 :     | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
36 : jhr 3532 | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
37 :     | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
38 : jhr 3480 | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
39 : jhr 3532 | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
40 : jhr 3480 | same (KernelTy, KernelTy) = true
41 : jhr 3532 (* ??? the following two don't seem correct ??? *)
42 : jhr 3480 | same (TensorTy[], intTy) = true
43 :     | same (intTy, TensorTy[]) = true
44 :     | same _ = false
45 :    
46 :     fun hash BoolTy = 0w1
47 :     | hash StringTy = 0w2
48 :     | hash IntTy = 0w3
49 : jhr 3532 | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w5 dd
50 : jhr 3480 | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys
51 : jhr 3532 | hash (SeqTy(ty, NONE)) = hash ty + 0w11
52 :     | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w13
53 : jhr 3480 | hash (AddrTy info) = 0w5 + ImageInfo.hash info
54 :     | hash (ImageTy info) = 0w13 * ImageInfo.hash info + 0w6
55 :     | hash KernelTy = 0w17
56 :    
57 :     fun toString BoolTy = "bool"
58 :     | toString StringTy = "string"
59 :     | toString IntTy = "int"
60 :     | toString (TensorTy[]) = "real"
61 : jhr 3532 | toString (TensorTy dd) = String.concat[
62 :     "tensor[", String.concatWithMap "," Int.toString dd, "]"
63 :     ]
64 :     | toString (TupleTy tys) = String.concat[
65 :     "(", String.concatWithMap " * " toString tys, ")"
66 :     ]
67 :     | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
68 :     | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
69 : jhr 3480 | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
70 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
71 :     | toString KernelTy = "kernel"
72 :    
73 :     end

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