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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 736 - (download) (annotate)
Sat Apr 2 18:50:43 2011 UTC (8 years, 5 months ago) by jhr
File size: 1999 byte(s)
  Overhaul in the way that the MidIL and LowIL represent tensor types (especially
  for orders > 1).  We still need to deal with the flattening of tensor-value
  construction
(* mid-il-types.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * Types for the MidIL.
 *)

structure MidILTypes =
  struct

    datatype ty
      = BoolTy | StringTy
      | IVecTy of int		(* integers; both scalars and sequences *)
      | TensorTy of int list	(* tensor types, which include reals, sequences of reals, etc. *)
      | AddrTy of ImageInfo.info (* voxel address *)
      | ImageTy of ImageInfo.info

    val intTy = IVecTy 1
    val realTy = TensorTy[]
    fun vecTy 1 = realTy
      | vecTy n = TensorTy[n]

    fun tensorTy dd = (case (List.mapPartial (fn 1 => NONE | d => SOME d) dd)
	   of [] => realTy (* 0-order tensors are represented as reals *)
	    | dd => TensorTy dd
	  (* end case *))

    fun same (BoolTy, BoolTy) = true
      | same (StringTy, StringTy) = true
      | same (IVecTy n1, IVecTy n2) = (n1 = n2)
      | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
      | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
      | same (ImageTy info1, ImageTy info2) = ImageInfo.same(info1, info2)
      | same _ = false

    fun hash BoolTy = 0w1
      | hash StringTy = 0w2
      | hash (IVecTy d) = 0w7 * Word.fromInt d + 0w3
      | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w4 dd
      | hash (AddrTy info) = 0w5 + ImageInfo.hash info
      | hash (ImageTy info) = 0w13 * ImageInfo.hash info + 0w6

    fun toString BoolTy = "bool"
      | toString StringTy = "string"
      | toString (IVecTy 1) = "int"
      | toString (IVecTy d) = "int" ^ Int.toString d
      | toString (TensorTy[]) = "real"
      | toString (TensorTy[d]) = "real" ^ Int.toString d
      | toString (TensorTy dd) = String.concat[
	    "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
	  ]
      | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
      | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]

  end

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