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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 736 - (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 :     datatype ty
13 :     = BoolTy | StringTy
14 : jhr 736 | IVecTy of int (* integers; both scalars and sequences *)
15 :     | TensorTy of int list (* tensor types, which include reals, sequences of reals, etc. *)
16 : jhr 548 | AddrTy of ImageInfo.info (* voxel address *)
17 :     | ImageTy of ImageInfo.info
18 : jhr 391
19 : jhr 427 val intTy = IVecTy 1
20 : jhr 736 val realTy = TensorTy[]
21 :     fun vecTy 1 = realTy
22 :     | vecTy n = TensorTy[n]
23 : jhr 391
24 : jhr 736 fun tensorTy dd = (case (List.mapPartial (fn 1 => NONE | d => SOME d) dd)
25 :     of [] => realTy (* 0-order tensors are represented as reals *)
26 :     | dd => TensorTy dd
27 :     (* end case *))
28 :    
29 : jhr 548 fun same (BoolTy, BoolTy) = true
30 :     | same (StringTy, StringTy) = true
31 :     | same (IVecTy n1, IVecTy n2) = (n1 = n2)
32 : jhr 736 | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
33 : jhr 548 | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
34 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.same(info1, info2)
35 :     | same _ = false
36 : jhr 391
37 :     fun hash BoolTy = 0w1
38 :     | hash StringTy = 0w2
39 :     | hash (IVecTy d) = 0w7 * Word.fromInt d + 0w3
40 : jhr 736 | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w4 dd
41 : jhr 548 | hash (AddrTy info) = 0w5 + ImageInfo.hash info
42 :     | hash (ImageTy info) = 0w13 * ImageInfo.hash info + 0w6
43 : jhr 391
44 :     fun toString BoolTy = "bool"
45 :     | toString StringTy = "string"
46 : jhr 427 | toString (IVecTy 1) = "int"
47 : jhr 391 | toString (IVecTy d) = "int" ^ Int.toString d
48 : jhr 736 | toString (TensorTy[]) = "real"
49 :     | toString (TensorTy[d]) = "real" ^ Int.toString d
50 :     | toString (TensorTy dd) = String.concat[
51 :     "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
52 :     ]
53 : jhr 548 | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
54 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
55 : jhr 391
56 :     end

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