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/util.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3941 - (download) (annotate)
Wed Jun 8 19:10:45 2016 UTC (3 years, 1 month ago) by jhr
File size: 2587 byte(s)
  working on merge
(* util.sml
 *
 * Various common code for the Low IR to Tree Ir translation.
 *
 * 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 Util : sig

  (* translate a Low IR type to a Tree IR type *)
    val trType : LowTypes.ty -> TreeTypes.t

  (* translate a Low IR type to an APIType *)
    val toAPIType : LowTypes.ty -> APITypes.t

  (* create new tree IL variables *)
    val newParamVar : LowIR.var -> TreeVar.t
    val newLocalVar : LowIR.var -> TreeVar.t
    val newIterVar : LowIR.var -> TreeVar.t
    val newTempVar : string * TreeTypes.t -> TreeVar.t

  (* create a list of variables for the pieces of a vector layout *)
    val newVectorVars : TreeTypes.vec_layout -> TreeVar.t list

  end = struct

    fun trType ty = (case ty
	   of LowTypes.BoolTy => TreeTypes.BoolTy
	    | LowTypes.StringTy => TreeTypes.StringTy
	    | LowTypes.IntTy => TreeTypes.IntTy
	    | LowTypes.TensorTy[] => TreeTypes.realTy
	    | LowTypes.TensorTy dd => TreeTypes.TensorTy dd
	    | LowTypes.TupleTy tys => TreeTypes.TupleTy(List.map trType tys)
	    | LowTypes.SeqTy(ty, dim) => TreeTypes.SeqTy(trType ty, dim)
	    | LowTypes.ImageTy info => TreeTypes.ImageTy info
	    | LowTypes.StrandTy n => TreeTypes.StrandTy n
	  (* end case *))

    fun toAPIType ty = (case ty
	   of LowTypes.BoolTy => APITypes.BoolTy
	    | LowTypes.StringTy => APITypes.StringTy
	    | LowTypes.IntTy => APITypes.IntTy
	    | LowTypes.TensorTy dd => APITypes.TensorTy dd
	    | LowTypes.SeqTy(ty, dim) => APITypes.SeqTy(toAPIType ty, dim)
	    | LowTypes.ImageTy info =>
		APITypes.ImageTy(ImageInfo.dim info, ImageInfo.voxelShape info)
	    | _ => raise Fail("toAPIType: unexpected " ^ LowTypes.toString ty)
	  (* end case *))

    local
      val cnt = ref 0
      fun newVar prefix x = let
            val n = !cnt
            in
              cnt := n+1;
              TreeVar.new (
		String.concat[prefix, LowIR.Var.name x, "_", Int.toString n],
		trType (LowIR.Var.ty x))
            end
    in

    val newParamVar = newVar "p_"
    val newLocalVar = newVar "l_"
    val newIterVar = newVar "i_"

    fun newTempVar (prefix, ty) = let
	  val n = !cnt
	  in
	    cnt := n+1;
            TreeVar.new (String.concat[prefix, "_", Int.toString n], ty)
	  end

    fun newVectorVars layout = let
	  fun newV ty = let
		val n = !cnt
		in
		  cnt := n+1;
		  TreeVar.new ("v_" ^ Int.toString n, ty)
		end
	  in
	    List.map newV (TreeTypes.piecesOf layout)
	  end

    end (* local *)

  end

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