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

SCM Repository

[diderot] View of /trunk/src/compiler/IL/translate-fn.sml
ViewVC logotype

View of /trunk/src/compiler/IL/translate-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 359 - (download) (annotate)
Tue Sep 28 22:03:40 2010 UTC (9 years, 6 months ago) by jhr
File size: 2472 byte(s)
  Adding new file for translation support
(* translate-fn.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *
 * This functor supports the common parts of translating between different
 * instances of the SSA-based ILs (e.g., from HighIL to MidIL).
 *)

signature TRANSLATE_PARAMS =
  sig

    structure SrcIL : SSA
    structure DstIL : SSA

    type env = DstIL.var SrcIL.Var.Tbl.hash_table

    val fresh : (env * SrcIL.var) -> DstIL.var
    val rename : (env * SrcIL.var) -> DstIL.var
    val expand : (env * SrcIL.assign) -> DstIL.assign list

  end

functor Translate (Params : TRANSLATE_PARAMS) : sig

    structure SrcIL : SSA
    structure DstIL : SSA

    val translate : env * SrcIL.stmt -> DstIL.stmt

  end = struct

    structure SrcIL : SSA = Params.SrcIL
    structure SrcNd = SrcIL.Node
    structure DstIL : SSA = Params.DstIL

    datatype env = E of {
	ndMap : DstIL.node Stamp.Tbl.hash_table,
	vMap : Params.env
      }

    fun fresh (E{vMap, ...}, x) = let
	  val x' = Params.fresh(vMap, x)
	  in
	    x'
	  end

    fun rename (E{vMap, ...}, x) = Params.rename(vMap, x)

    fun expand (E{vMap, ...}, assign) = Params.expand (vMap, assign)

  (* the first pass creates the nodes of the DstIL CFG and defines
   * the environment that maps from SrcIL nodes and variables to
   * DstIL nodes and variables.
   *)
    fun translateNodes (env, stm) = let
	  fun trans (SrcIL.ND{kind, ...}) = let
		val newNd = (case kind
		    of NULL => raise Fail "unexpected NULL node"
		     | ENTRY _ => SrcNd.mkEntry()
		     | JOIN{preds, phis, succ} =>
		     | COND{pred, cond, trueBranch, falseBranch} =>
		     | BLOCK{pred, body, succ} =>
		     | NEW{pred, actor, args, succ} =>
		     | DIE{pred, ...} =>
		     | STABILIZE{pred} =>
		     | EXIT{pred} =>
		   (* end case *))
	  in
	  end

    fun translate (env, SrcIL.STM{kind, next, ...}) = (case kind
	   of SrcIL.S_SIMPLE(SrcIL.ND{kind, ...}) => (case kind
		 of NULL =>
		  | ENTRY{succ} =>
		  | JOIN{preds, phis, succ} =>
		  | COND{pred, cond, trueBranch, falseBranch} =>
		      raise Fail "impossible"
		  | BLOCK{pred, body, succ} =>
		  | NEW{pred, actor, args, succ} =>
		  | DIE{pred, ...} =>
		  | STABILIZE{pred} =>
		  | EXIT{pred} =>
		(* end case *))
	    | SrcIL.S_IF{cond, thenBranch, elseBranch} =>
	    | SrcIL.S_LOOP{hdr, cond, body} =>
	  (* end case *))

    and translateOpt (env, NONE) = NONE
      | translateOpt (env, SOME stm) = translate (env, stm)

  end

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