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

SCM Repository

[diderot] Annotation of /branches/charisee/src/compiler/mid-il/mid-il-types.sml
ViewVC logotype

Annotation of /branches/charisee/src/compiler/mid-il/mid-il-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2615 - (view) (download)

1 : jhr 391 (* mid-il-types.sml
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 391 * All rights reserved.
5 :     *
6 :     * Types for the MidIL.
7 :     *)
8 :    
9 :     structure MidILTypes =
10 :     struct
11 :    
12 : jhr 1640 (* FIXME: perhaps we should replage TensorTy wity SeqTy at this stage? *)
13 : jhr 391 datatype ty
14 : jhr 1640 = BoolTy | StringTy | IntTy
15 :     | TensorTy of int list (* tensor types, which include reals, sequences of reals, etc. *)
16 :     | TupleTy of ty list (* tuples; used for multiple return values *)
17 :     | SeqTy of ty * int
18 :     | AddrTy of ImageInfo.info (* voxel address *)
19 : jhr 1116 | ImageTy of ImageInfo.info
20 : cchiw 2615 | KernelTy
21 :     | indexTy of int list (*Specific index *)
22 :     | imgIndex of int list (*Image Index V_0 or V_1, [] for scalars*)
23 :     | vectorLength of int list
24 : jhr 391
25 : cchiw 2525
26 :    
27 : jhr 1640 val intTy = IntTy
28 :     fun iVecTy 1 = IntTy
29 :     | iVecTy n = SeqTy(IntTy, n)
30 : jhr 1116 val realTy = TensorTy[]
31 :     fun vecTy 1 = realTy
32 :     | vecTy n = TensorTy[n]
33 : jhr 391
34 : jhr 1116 fun tensorTy dd = (case (List.mapPartial (fn 1 => NONE | d => SOME d) dd)
35 :     of [] => realTy (* 0-order tensors are represented as reals *)
36 :     | dd => TensorTy dd
37 :     (* end case *))
38 : jhr 391
39 : jhr 1116 fun same (BoolTy, BoolTy) = true
40 :     | same (StringTy, StringTy) = true
41 : jhr 1640 | same (IntTy, IntTy) = true
42 : jhr 1116 | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
43 : jhr 1640 | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
44 :     | same (SeqTy(ty1, n1), SeqTy(ty2, n2)) = (n1 = n2) andalso same(ty1, ty2)
45 : jhr 1116 | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
46 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.same(info1, info2)
47 : cchiw 2522 | same (KernelTy, KernelTy) = true
48 : cchiw 2525 | same (TensorTy [],intTy)=true
49 :     | same (intTy,TensorTy [])=true
50 :     | same(indexTy dd1, indexTy dd2)=(dd1=dd2)
51 : cchiw 2530 | same (imgIndex dd1, imgIndex dd2) = (dd1=dd2)
52 : cchiw 2615 | same (vectorLength dd1, vectorLength dd2) = (dd1=dd2)
53 : jhr 1116 | same _ = false
54 :    
55 : jhr 391 fun hash BoolTy = 0w1
56 :     | hash StringTy = 0w2
57 : jhr 1640 | hash IntTy = 0w3
58 : jhr 1116 | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w4 dd
59 : jhr 1640 | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys
60 :     | hash (SeqTy(ty, n)) = Word.fromInt n * hash ty + 0w11
61 : jhr 1116 | hash (AddrTy info) = 0w5 + ImageInfo.hash info
62 :     | hash (ImageTy info) = 0w13 * ImageInfo.hash info + 0w6
63 : cchiw 2522 | hash KernelTy = 0w17
64 : cchiw 2530 | hash (imgIndex _ )=0w19
65 : cchiw 2553 | hash (indexTy _)= 0w23
66 : cchiw 2615 | hash (vectorLength _)=0w29
67 : jhr 391
68 : cchiw 2522
69 : jhr 391 fun toString BoolTy = "bool"
70 :     | toString StringTy = "string"
71 : jhr 1640 | toString IntTy = "int"
72 : jhr 1116 | toString (TensorTy[]) = "real"
73 : cchiw 2615 | toString (TensorTy dd) = String.concat["tensor[", String.concatWith "," (List.map Int.toString dd), "]" ]
74 :     | toString (TupleTy tys) = String.concat[ "(", String.concatWith " * " (List.map toString tys), ")"]
75 : jhr 1640 | toString (SeqTy(ty, n)) = concat[toString ty, "{", Int.toString n, "}"]
76 : jhr 1116 | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
77 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
78 : cchiw 2525 | toString KernelTy = "kernel"
79 :     | toString(indexTy [])="-"
80 :     | toString(indexTy dd)=String.concat["Specific Index:[", String.concatWith "," (List.map Int.toString dd), "]"]
81 : cchiw 2615 | toString(imgIndex dd)=String.concat["ImgSpecificIndex:[", String.concatWith "," (List.map Int.toString dd), "]"]
82 :     | toString(vectorLength dd)=String.concat["ImgSpecificIndex:[", String.concatWith "," (List.map Int.toString dd), "]"]
83 : jhr 391
84 : cchiw 2525
85 : jhr 391 end

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