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

SCM Repository

[diderot] View of /trunk/src/compiler/mid-il/check-mid-il.sml
ViewVC logotype

View of /trunk/src/compiler/mid-il/check-mid-il.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 450 - (download) (annotate)
Thu Oct 21 15:58:26 2010 UTC (8 years, 5 months ago) by jhr
File size: 3120 byte(s)
  Change name of MidIL Transform operator to PosToImgSpace.  Also added GradToWorldSpace operator to MidIL.
(* check-mid-il.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure CheckOps : OPERATOR_TY = struct

    structure Op = MidOps
    structure Ty = MidILTypes

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

    val vec3Ty = Ty.VecTy 3

  (* Return the signature of a MidIL operator. *)
    fun sigOf rator = (case rator
	   of Op.Add ty => (ty, [ty, ty])
	    | Op.Sub ty => (ty, [ty, ty])
	    | Op.Mul ty => (ty, [ty, ty])
	    | Op.Div ty => (ty, [ty, ty])
	    | Op.Neg 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.Sin => (Ty.realTy, [Ty.realTy])
	    | Op.Cos => (Ty.realTy, [Ty.realTy])
	    | Op.Pow => (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.VecTy d, _) => (Ty.realTy, [ty])
	    | Op.Norm d => (Ty.realTy, [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.Subscript(Ty.IVecTy d) => (Ty.intTy, [Ty.IVecTy d, Ty.intTy])
	    | Op.Subscript(Ty.VecTy d) => (Ty.realTy, [Ty.VecTy d, Ty.intTy])
	    | Op.Floor d => (Ty.VecTy d, [Ty.VecTy d])
	    | Op.IntToReal => (Ty.realTy, [Ty.intTy])
	    | Op.TruncToInt d => (Ty.IVecTy d, [Ty.VecTy d])
	    | Op.RoundToInt d => (Ty.IVecTy d, [Ty.VecTy d])
	    | Op.CeilToInt d => (Ty.IVecTy d, [Ty.VecTy d])
	    | Op.FloorToInt d => (Ty.IVecTy d, [Ty.VecTy d])
	    | Op.VoxelAddress(ImageInfo.ImgInfo{dim, ...}) =>
		(Ty.AddrTy, List.tabulate(dim, fn _ => Ty.intTy))
	    | Op.LoadVoxels(_, d) => (Ty.VecTy d, [Ty.AddrTy])
	    | Op.PosToImgSpace(ImageInfo.ImgInfo{dim, ...}) => (Ty.VecTy dim, [Ty.VecTy dim])
	    | Op.GradToWorldSpace(ImageInfo.ImgInfo{dim, ...}) => (Ty.VecTy dim, [Ty.VecTy dim])
	    | Op.EvalKernel(d, _, _) => (Ty.VecTy d, [Ty.VecTy d])
	    | Op.LoadImage _ => (Ty.ImageTy, [])
	    | Op.Inside(ImageInfo.ImgInfo{dim, ...}) => (Ty.BoolTy, [Ty.VecTy dim])
	    | Op.Input(ty, _) => (ty, [])
	    | Op.InputWithDefault(ty, _) => (ty, [ty])
	    | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
	  (* end case *))

    fun typeOfCons [] = NONE
      | typeOfCons tys =
	  if List.all (fn ty => Ty.same(Ty.intTy, ty)) tys
	    then SOME(Ty.IVecTy(List.length tys))
	  else if List.all (fn ty => Ty.same(Ty.realTy, ty)) tys
	    then SOME(Ty.VecTy(List.length tys))
	    else NONE

  end

structure CheckMidIL = CheckILFn (
    structure IL = MidIL
    structure OpTy = CheckOps)

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