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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2533 - (download) (annotate)
Thu Jan 30 04:58:56 2014 UTC (5 years, 7 months ago) by cchiw
File size: 3343 byte(s)
type checker
(* 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

(* FIXME: perhaps we should replage TensorTy wity SeqTy at this stage? *)
    datatype ty
      = BoolTy | StringTy | IntTy
      | TensorTy of int list	        (* tensor types, which include reals, sequences of reals, etc. *)
      | TupleTy of ty list              (* tuples; used for multiple return values *)
      | SeqTy of ty * int
      | AddrTy of ImageInfo.info        (* voxel address *)
      | ImageTy of ImageInfo.info
  | KernelTy
  | indexTy of int list (*Specific index *)
  | imgIndex of int list (*Image Index V_0 or V_1, [] for scalars*)

 

    val intTy = IntTy
    fun iVecTy 1 = IntTy
      | iVecTy n = SeqTy(IntTy, n)
    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 (IntTy, IntTy) = true
      | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
      | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
      | same (SeqTy(ty1, n1), SeqTy(ty2, n2)) = (n1 = n2) andalso same(ty1, ty2)
      | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
      | same (ImageTy info1, ImageTy info2) = ImageInfo.same(info1, info2)
      | same (KernelTy, KernelTy) = true
   

(*FIx HERE*)
      | same (TensorTy [],intTy)=true
      | same (intTy,TensorTy [])=true
    
      | same(indexTy dd1, indexTy dd2)=(dd1=dd2)
      | same (imgIndex dd1, imgIndex dd2) = (dd1=dd2)
      | same _ = false

    fun hash BoolTy = 0w1
      | hash StringTy = 0w2
      | hash IntTy = 0w3
      | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w4 dd
      | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys
      | hash (SeqTy(ty, n)) = Word.fromInt n * hash ty + 0w11
      | hash (AddrTy info) = 0w5 + ImageInfo.hash info
      | hash (ImageTy info) = 0w13 * ImageInfo.hash info + 0w6
      | hash KernelTy = 0w17
      | hash (imgIndex _ )=0w19


    fun toString BoolTy = "bool"
      | toString StringTy = "string"
      | toString IntTy = "int"
      | toString (TensorTy[]) = "real"
     (*) | toString (TensorTy[d]) = "real " ^ Int.toString d^"--"*)
      | toString (TensorTy dd) = String.concat[
	    "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
	  ]
      | toString (TupleTy tys) = String.concat[
            "(", String.concatWith " * " (List.map toString tys), ")"
          ]
      | toString (SeqTy(ty, n)) = concat[toString ty, "{", Int.toString n, "}"]
      | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
      | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
      | toString KernelTy = "kernel"
      | toString(indexTy [])="-"
      | toString(indexTy dd)=String.concat["Specific Index:[", String.concatWith "," (List.map Int.toString dd), "]"]
      | toString(imgIndex dd)=String.concat["{", String.concatWith "," (List.map Int.toString dd), "}"]


  end

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