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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3757 - (download) (annotate)
Fri Apr 15 14:30:25 2016 UTC (3 years, 6 months ago) by jhr
File size: 3459 byte(s)
working on merge
(* tree-types.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *
 * Types for the TreeIR.  For now, these are identical to the LowIR types.
 *)

structure TreeTypes =
  struct

    datatype ty
      = BoolTy | StringTy | IntTy | RealTy
      | VecTy of int			(* real vector of given width *)
      | CompVecTy of int list		(* composite vector with the given pieces *)
      | TensorTy of int * ty		(* type of 2nd-order (or higher) tensor *)
      | TupleTy of ty list              (* tuples; used for multiple return values *)
      | SeqTy of ty * int option
      | AddrTy of ImageInfo.info        (* voxel address *)
      | ImageTy of ImageInfo.info

    val intTy = IntTy
    val realTy = RealTy
    fun vecTy 1 = RealTy
      | vecTy n = VecTy n
    fun iVecTy 1 = IntTy
      | iVecTy n = SeqTy(IntTy, SOME n)

  (* smart constructor for tensor type that prunes out dimensions with size 1 *)
    fun tensorTy (1, ty) = ty
      | tensorTy arg = TensorTy arg

  (* is a type a composite-vector type? *)
    fun isCompVecTy (CompVecTy _) = true
      | isCompVecTy _ = false

    fun same (BoolTy, BoolTy) = true
      | same (StringTy, StringTy) = true
      | same (IntTy, IntTy) = true
      | same (RealTy, RealTy) = true
      | same (VecTy d1, VecTy d2) = (d1 = d2)
      | same (CompVecTy dd1, CompVecTy dd2) = ListPair.allEq (op =) (dd1, dd2)
      | same (TensorTy(d1, ty1), TensorTy(d2, ty2)) = (d1 = d2) andalso same(ty1, ty2)
      | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
      | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
      | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
      | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
      | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
      | same _ = false

    fun hash BoolTy = 0w1
      | hash StringTy = 0w2
      | hash IntTy = 0w3
      | hash RealTy = 0w5
      | hash (VecTy d) = 0w7 * Word.fromInt d
      | hash (CompVecTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w5 dd
      | hash (TensorTy(d, ty)) = 0w13 * (Word.fromInt d + hash ty)
      | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w17 tys
      | hash (SeqTy(ty, NONE)) = hash ty + 0w19
      | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23
      | hash (AddrTy info) = 0w37 + ImageInfo.hash info
      | hash (ImageTy info) = 0w41 * ImageInfo.hash info + 0w6

    fun toString BoolTy = "bool"
      | toString StringTy = "string"
      | toString IntTy = "int"
      | toString RealTy = "real"
      | toString (VecTy d) = "vec" ^ Int.toString d
      | toString (CompVecTy dd) = String.concat [
            "vecs{", String.concatWithMap ":" Int.toString dd, "}"
	  ]
      | toString (TensorTy(d, ty)) = String.concat [
            "tensor(", Int.toString d, ",", toString ty, ")"
          ]
      | toString (TupleTy tys) = String.concat [
            "(", String.concatWithMap " * " toString tys, ")"
          ]
      | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
      | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
      | 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