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

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