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

SCM Repository

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

View of /branches/pure-cfg/src/compiler/low-il/check-low-il.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: 3377 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
(* check-low-il.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure CheckOps : OPERATOR_TY = struct

    structure Op = LowOps
    structure Ty = LowILTypes

    type rator = Op.rator
    type ty = Ty.ty

    val vec3Ty = Ty.vecTy 3

  (* Return the signature of a LowIL operator. *)
    fun sigOf rator = (case rator
	   of Op.Add(Ty.AddrTy rTy) => (Ty.AddrTy rTy, [Ty.AddrTy rTy, Ty.intTy])
	    | Op.Add ty => (ty, [ty, ty])
	    | Op.Sub(Ty.AddrTy rTy) => (Ty.AddrTy rTy, [Ty.AddrTy rTy, Ty.intTy])
	    | Op.Sub ty => (ty, [ty, ty])
	    | Op.Mul ty => (ty, [ty, ty])
	    | Op.Div ty => (ty, [ty, ty])
	    | Op.Neg ty => (ty, [ty])
	    | Op.Abs ty => (ty, [ty])
	    | Op.LT ty => (Ty.BoolTy, [ty, ty])
	    | Op.LTE ty => (Ty.BoolTy, [ty, ty])
	    | Op.EQ ty => (Ty.BoolTy, [ty, ty])
	    | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
	    | Op.GT ty => (Ty.BoolTy, [ty, ty])
	    | Op.GTE ty => (Ty.BoolTy, [ty, ty])
	    | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
	    | Op.Max => (Ty.realTy, [Ty.realTy, Ty.realTy])
	    | Op.Min => (Ty.realTy, [Ty.realTy, Ty.realTy])
	    | Op.Dot d => (Ty.realTy, [Ty.vecTy d, Ty.vecTy d])
	    | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])
	    | Op.Select(ty as Ty.IVecTy d, _) => (Ty.intTy, [ty])
	    | Op.Select(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
	    | Op.Norm d => (Ty.realTy, [Ty.vecTy d])
	    | Op.Normalize d => (Ty.vecTy d, [Ty.vecTy d])
	    | Op.Scale d => (Ty.vecTy d, [Ty.realTy, Ty.vecTy d])
	    | Op.InvScale d => (Ty.vecTy d, [Ty.vecTy d, Ty.realTy])
	    | Op.CL => raise Fail "Op.CL unimplemented"
	    | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
	    | Op.Trace d => (Ty.realTy, [Ty.TensorTy[d, d]])
	    | Op.Subscript(Ty.IVecTy d) => (Ty.intTy, [Ty.IVecTy d, Ty.intTy])
	    | Op.Subscript(Ty.TensorTy[d]) => (Ty.realTy, [Ty.vecTy d, Ty.intTy])
	    | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
	    | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
	    | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
	    | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
	    | Op.IntToReal => (Ty.realTy, [Ty.intTy])
	    | Op.RealToInt d => (Ty.IVecTy d, [Ty.vecTy d])
	    | Op.ImageAddress info => (Ty.AddrTy info, [Ty.ImageTy info])
	    | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
	    | Op.PosToImgSpace info => let
		val dim = ImageInfo.dim info
		in
		  (Ty.vecTy dim, [Ty.ImageTy info, Ty.vecTy dim])
		end
	    | Op.GradToWorldSpace info => let
		val dim = ImageInfo.dim info
		in
		  (Ty.vecTy dim, [Ty.ImageTy info, Ty.vecTy dim])
		end
	    | Op.LoadImage info => (Ty.ImageTy info, [Ty.StringTy])
	    | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
	    | Op.Input(ty, _) => (ty, [])
	    | Op.InputWithDefault(ty, _) => (ty, [ty])
	    | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
	  (* end case *))

    fun typeOfCons (_, []) = false
      | typeOfCons (expectedTy, tys as ty1::_) =
	  if List.all (fn ty => Ty.same(ty1, ty)) tys
	    then (case (expectedTy, ty1)
	       of (Ty.IVecTy n, Ty.IVecTy 1) => (n = List.length tys)
		| (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')
		| _ => false
	      (* end case *))
	    else false

  end

structure CheckLowIL = CheckILFn (
    structure IL = LowIL
    structure OpTy = CheckOps)

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