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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3762 - (view) (download)

1 : jhr 3750 (* tree-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 TreeIR. For now, these are identical to the LowIR types.
9 :     *)
10 :    
11 : jhr 3754 structure TreeTypes =
12 :     struct
13 :    
14 :     datatype ty
15 :     = BoolTy | StringTy | IntTy | RealTy
16 : jhr 3762 (* FIXME: we could use just CompVecTy[] for RealTy and CompVecTy[d] for VecTy(d). *)
17 : jhr 3754 | VecTy of int (* real vector of given width *)
18 :     | CompVecTy of int list (* composite vector with the given pieces *)
19 :     | TensorTy of int * ty (* type of 2nd-order (or higher) tensor *)
20 :     | TupleTy of ty list (* tuples; used for multiple return values *)
21 :     | SeqTy of ty * int option
22 :     | AddrTy of ImageInfo.info (* voxel address *)
23 :     | ImageTy of ImageInfo.info
24 :    
25 :     val intTy = IntTy
26 :     val realTy = RealTy
27 : jhr 3757 fun vecTy 1 = RealTy
28 :     | vecTy n = VecTy n
29 : jhr 3754 fun iVecTy 1 = IntTy
30 :     | iVecTy n = SeqTy(IntTy, SOME n)
31 :    
32 :     (* smart constructor for tensor type that prunes out dimensions with size 1 *)
33 :     fun tensorTy (1, ty) = ty
34 :     | tensorTy arg = TensorTy arg
35 :    
36 :     (* is a type a composite-vector type? *)
37 :     fun isCompVecTy (CompVecTy _) = true
38 :     | isCompVecTy _ = false
39 :    
40 :     fun same (BoolTy, BoolTy) = true
41 :     | same (StringTy, StringTy) = true
42 :     | same (IntTy, IntTy) = true
43 :     | same (RealTy, RealTy) = true
44 :     | same (VecTy d1, VecTy d2) = (d1 = d2)
45 :     | same (CompVecTy dd1, CompVecTy dd2) = ListPair.allEq (op =) (dd1, dd2)
46 :     | same (TensorTy(d1, ty1), TensorTy(d2, ty2)) = (d1 = d2) andalso same(ty1, ty2)
47 :     | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
48 :     | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
49 :     | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
50 :     | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
51 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
52 :     | same _ = false
53 :    
54 :     fun hash BoolTy = 0w1
55 :     | hash StringTy = 0w2
56 :     | hash IntTy = 0w3
57 :     | hash RealTy = 0w5
58 :     | hash (VecTy d) = 0w7 * Word.fromInt d
59 :     | hash (CompVecTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w5 dd
60 :     | hash (TensorTy(d, ty)) = 0w13 * (Word.fromInt d + hash ty)
61 :     | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w17 tys
62 :     | hash (SeqTy(ty, NONE)) = hash ty + 0w19
63 :     | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23
64 :     | hash (AddrTy info) = 0w37 + ImageInfo.hash info
65 :     | hash (ImageTy info) = 0w41 * ImageInfo.hash info + 0w6
66 :    
67 :     fun toString BoolTy = "bool"
68 :     | toString StringTy = "string"
69 :     | toString IntTy = "int"
70 :     | toString RealTy = "real"
71 :     | toString (VecTy d) = "vec" ^ Int.toString d
72 :     | toString (CompVecTy dd) = String.concat [
73 :     "vecs{", String.concatWithMap ":" Int.toString dd, "}"
74 :     ]
75 :     | toString (TensorTy(d, ty)) = String.concat [
76 :     "tensor(", Int.toString d, ",", toString ty, ")"
77 :     ]
78 :     | toString (TupleTy tys) = String.concat [
79 :     "(", String.concatWithMap " * " toString tys, ")"
80 :     ]
81 :     | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
82 :     | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
83 :     | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
84 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
85 :    
86 :     end

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