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

SCM Repository

[diderot] View of /trunk/src/compiler/high-il/high-il-types.sml
ViewVC logotype

View of /trunk/src/compiler/high-il/high-il-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 426 - (download) (annotate)
Mon Oct 18 18:49:55 2010 UTC (8 years, 8 months ago) by jhr
File size: 1185 byte(s)
  Filter out dimensions of size one in tensor types
(* high-il-types.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *)

structure HighILTypes =
  struct

    datatype ty
      = BoolTy | StringTy | IntTy
      | TensorTy of int list
      | KernelTy | ImageTy | FieldTy

    val intTy = IntTy
    val realTy = TensorTy[]
    val vec3Ty = TensorTy[3]

  (* smart constructor for tensor type that prunes out dimensions with size 1 *)
    fun tensorTy dd = TensorTy(List.mapPartial (fn 1 => NONE | d => SOME d) dd)

    fun same (ty1 : ty, ty2) = (ty1 = ty2)

    fun hash BoolTy = 0w1
      | hash StringTy = 0w2
      | hash IntTy = 0w3
      | hash (TensorTy dd) = List.foldl (fn (d, s) => Word.fromInt d + s) 0w4 dd
      | hash KernelTy = 0w5
      | hash ImageTy = 0w6
      | hash FieldTy = 0w7

    fun toString BoolTy = "bool"
      | toString StringTy = "string"
      | toString IntTy = "int"
      | toString (TensorTy[]) = "real"
      | toString (TensorTy dd) = String.concat[
	    "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
	  ]
      | toString KernelTy = "kernel"
      | toString ImageTy = "image"
      | toString FieldTy = "field"

  end

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