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

SCM Repository

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

View of /branches/vis15/src/compiler/low-to-tree/low-to-tree.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3829 - (download) (annotate)
Thu May 5 21:05:37 2016 UTC (3 years, 1 month ago) by jhr
File size: 4551 byte(s)
  working on merge
(* low-to-tree.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2016 The University of Chicago
 * All rights reserved.
 *)

structure LowToTree : sig

    type vector_layout = int -> TreeTypes.t

    val translate : LowIR.program * vector_layout -> TreeIR.program

  end = struct

    structure SrcIR = LowIR
    structure DstIR = TreeIR

    fun cvtScalarTy SrcTy.BoolTy = DstTy.BoolTy
      | cvtScalarTy SrcTy.IntTy = DstTy.IntTy
      | cvtScalarTy (SrcTy.TensorTy[]) = DstTy.RealTy
      | cvtScalarTy ty = raise Fail(concat["cvtScalarTy(", SrcTy.toString ty, ")"])

    fun trOp (lhs, rator, args) = let
	  fun bindOp rator = bind (lhs, DstIR.E_Op(rator, List.map ?? args))
	  fun binVOp rator = let
	      (* convert a list of LowIR variables, each of which are mapped
	       * to lists of of vector expressions, to a list of list of expressions
	       *)
		val argLists = ??
		val exps = ListPair.map
		      (fn (w, args) => DstIR.E_Op(rator w, args))
			(argLists, pieces)
		in
		  ??
		end
	  in
	    case rator
	     of SrcOp.IAdd => bindOp DstOp.IAdd
	      | SrcOp.ISub => bindOp DstOp.ISub
	      | SrcOp.IMul => bindOp DstOp.IMul
	      | SrcOp.IDiv => bindOp DstOp.IDiv
	      | SrcOp.IMod => bindOp DstOp.IMod
	      | SrcOp.INeg => bindOp DstOp.INeg
	      | SrcOp.RAdd => bindOp DstOp.RAdd
	      | SrcOp.RSub => bindOp DstOp.RSub
	      | SrcOp.RMul => bindOp DstOp.RMul
	      | SrcOp.RDiv => bindOp DstOp.RDiv
	      | SrcOp.RNeg => bindOp DstOp.RNeg
	      | SrcOp.LT ty => bindOp (DstOp.LT (cvtScalarTy ty))
	      | SrcOp.LTE ty => bindOp (DstOp.LTE (cvtScalarTy ty))
	      | SrcOp.EQ ty => bindOp (DstOp.EQ (cvtScalarTy ty))
	      | SrcOp.NEQ ty => bindOp (DstOp.NEQ (cvtScalarTy ty))
	      | SrcOp.GT ty => bindOp (DstOp.GT (cvtScalarTy ty))
	      | SrcOp.GTE ty => bindOp (DstOp.GTE (cvtScalarTy ty))
	      | SrcOp.Not => bindOp DstOp.Not
	      | SrcOp.Abs ty => bindOp (DstOp.Abs (cvtScalarTy ty))
	      | SrcOp.Max ty => bindOp (DstOp.Max (cvtScalarTy ty))
	      | SrcOp.Min ty => bindOp (DstOp.Min (cvtScalarTy ty))
	      | SrcOp.Clamp(SrcTy.TensorTy[n]) =>
	      | SrcOp.Clamp ty => bindOp (DstOp.Clamp (cvtScalarTy ty))
	      | SrcOp.Lerp(SrcTy.TensorTy[n]) =>
	      | SrcOp.Lerp ty => bindOp (DstOp.Lerp (cvtScalarTy ty))
	      | SrcOp.VAdd _ => bindVOp DstOp.VAdd
	      | SrcOp.VSub _ => bindVOp DstOp.VSub
	      | SrcOp.VScale _ => bindVOp DstOp.VScale
	      | SrcOp.VMul _ => bindVOp DstOp.VMul
	      | SrcOp.VNeg _ => bindVOp DstOp.VNeg
	      | SrcOp.VSum _ => bindVOp DstOp.VSum
	      | SrcOp.VProj of int * int
	      | SrcOp.TensorIndex of ty * shape
	      | SrcOp.ProjectLast of ty * shape
	      | SrcOp.EigenVecs2x2
	      | SrcOp.EigenVecs3x3
	      | SrcOp.EigenVals2x2
	      | SrcOp.EigenVals3x3
	      | SrcOp.Zero ty =>
	      | SrcOp.Select of ty * int
	      | SrcOp.Subscript ty =>
	      | SrcOp.MkDynamic of ty * int
	      | SrcOp.Append ty =>
	      | SrcOp.Prepend ty =>
	      | SrcOp.Concat ty =>
	      | SrcOp.Range
	      | SrcOp.Length ty =>
	      | SrcOp.SphereQuery of ty * ty
	      | SrcOp.Sqrt => bindOp DstOp.Sqrt
	      | SrcOp.Cos => bindOp DstOp.Cos
	      | SrcOp.ArcCos => bindOp DstOp.ArcCos
	      | SrcOp.Sin => bindOp DstOp.Sin
	      | SrcOp.ArcSin => bindOp DstOp.ArcSin
	      | SrcOp.Tan => bindOp DstOp.Tan
	      | SrcOp.ArcTan => bindOp DstOp.ArcTan
	      | SrcOp.Ceiling 1 => bindOp (DstOp.Ceiling 1)
	      | SrcOp.Ceiling of int
	      | SrcOp.Floor 1 => bindOp (DstOp.Floor 1)
	      | SrcOp.Floor of int
	      | SrcOp.Round 1 => bindOp (DstOp.Floor 1)
	      | SrcOp.Round of int
	      | SrcOp.Trunc 1 => bindOp (DstOp.Trunc 1)
	      | SrcOp.Trunc of int
	      | SrcOp.IntToReal => bindOp SrcOp.IntToReal
	      | SrcOp.RealToInt of int
	      | SrcOp.R_All ty =>
	      | SrcOp.R_Exists ty =>
	      | SrcOp.R_Max ty =>
	      | SrcOp.R_Min ty =>
	      | SrcOp.R_Sum ty =>
	      | SrcOp.R_Product ty =>
	      | SrcOp.R_Mean ty =>
	      | SrcOp.R_Variance ty =>
	      | SrcOp.Transform of ImageInfo.info
	      | SrcOp.Translate of ImageInfo.info
	      | SrcOp.ControlIndex of ImageInfo.info * idxctl * int
	      | SrcOp.LoadVoxel of ImageInfo.info
	      | SrcOp.Inside of ImageInfo.info * int
	      | SrcOp.ImageDim of ImageInfo.info * int
	      | SrcOp.LoadSeq of ty * string
	      | SrcOp.LoadImage of ty * string
	      | SrcOp.Print of tys
	      | SrcOp.MathFn f => bindOp (DstOp.MathFn f)
	      | _ => (* error *)
	    (* end case *)
	  end

  end

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