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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3750, Wed Apr 13 07:35:23 2016 UTC revision 3754, Thu Apr 14 22:45:39 2016 UTC
# Line 8  Line 8 
8   * Types for the TreeIR.  For now, these are identical to the LowIR types.   * Types for the TreeIR.  For now, these are identical to the LowIR types.
9   *)   *)
10    
11  structure TreeTypes = LowTypes  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

Legend:
Removed from v.3750  
changed lines
  Added in v.3754

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