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

SCM Repository

[diderot] View of /trunk/src/compiler/mid-to-low/mid-to-low.sml
ViewVC logotype

View of /trunk/src/compiler/mid-to-low/mid-to-low.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 387 - (download) (annotate)
Fri Oct 8 15:29:24 2010 UTC (9 years, 1 month ago) by jhr
File size: 2430 byte(s)
  Copy some of the translation boilerplate from the high-to-mid translation
  into the mid-to-low translation
(* mid-to-low.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *
 * Translation from MidIL to LowIL representations.
 *)

structure MidToLow : sig

    val translate : HighIL.program -> MidIL.program

  end = struct


    structure SrcIL = MidIL
    structure SrcOp = MidOps
    structure VTbl = SrcIL.Var.Tbl
    structure DstIL = LowIL
    structure DstOp = LowOps

    type var_env = DstIL.var VTbl.hash_table

    fun rename (env : var_env, x) = (case VTbl.find env x
	   of SOME x' => x'
	    | NONE => let
		val x' = DstIL.Var.new (SrcIL.Var.name x)
		in
		  VTbl.insert env (x, x');
		  x'
		end
	  (* end case *))
    fun renameList (env, xs) = List.map (fn x => rename(env, x)) xs

  (* expand the EvalKernel operations into vector operations *)
    fun expandKernel (dimSize, kern, k, vec) = ??

  (* compute the load address for a given set of voxels indices *) 
    fun computeVoxelAddress (info, vec) = ??

  (* expand a SrcIL assignment to a list of DstIL assignments *)
    fun expand (env, (y, rhs)) = let
	  val y' = rename (env, y)
	  fun assign rhs = [(y', rhs)]
	  in
	    case rhs
	     of SrcIL.VAR x => assign (DstIL.VAR(rename(env, x)))
	      | SrcIL.LIT lit => assign (DstIL.LIT lit)
	      | SrcIL.OP(rator, args) => expandOp (env, y', rator, args)
	      | SrcIL.CONS args => assign (DstIL.CONS(renameList(env, args)))
	    (* end case *)
	  end

    structure Trans =  TranslateFn (
      struct
	structure SrcIL = SrcIL
	structure DstIL = DstIL

	type var_env = var_env

	val rename = rename
	val expand = expand
      end)

    fun translate (SrcIL.Program{globals, globalInit, actors}) = let
	  val env = VTbl.mkTable (256, Fail "env")
	  fun transMethod (SrcIL.Method{name, stateIn, stateOut, body}) =
		DstIL.Method{
		    name = name,
		    stateIn = renameList (env, stateIn),
		    stateOut = renameList (env, stateOut),
		    body = Trans.translate (env, body)
		  }
	  fun transActor (SrcIL.Actor{name, params, state, stateInit, methods}) =
		DstIL.Actor{
		    name = name,
		    params = renameList (env, params),
		    state = renameList (env, state),
		    stateInit = Trans.translate (env, stateInit),
		    methods = List.map transMethod methods
		  }
	  in
	    DstIL.Program{
		globals = renameList (env, globals),
		globalInit = Trans.translate (env, globalInit),
		actors = List.map transActor actors
	      }
	  end

  end

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