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

SCM Repository

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

View of /trunk/src/compiler/translate/translate.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 190 - (download) (annotate)
Sat Jul 31 04:39:18 2010 UTC (9 years, 1 month ago) by jhr
File size: 2420 byte(s)
  Minor work on translation
(* translate.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *
 * Translate Simple-AST code into the IL representation.
 *)

structure Translate : sig

    val translate : Simple.program -> HighIL.program

  end = struct

    structure S = Simple
    structure VMap = Var.Map
    structure VSet = Var.Set
    structure IL = HighIL

    fun lookup env x = (case VMap.find x
	   of SOME x' => x'
	    | NONE => raise Fail(concat[
		  "no binding for ", Var.toString x, " in environment"
		])
	  (* end case *))

  (* create a new instance of a variable *)
    fun newVar x = IL.newVar (Var.nameOf x)

  (* expression translation *)
    fun cvtExpr (env, lhs, exp) = (case exp
	   of S.E_Var x => [(lhs, IL.VAR(lookup env x))]
	    | S.E_Lit lit => [(lhs, IL.LIT lit)]
	    | S.E_Tuple xs => raise Fail "E_Tuple not implemeted"
	    | S.E_Apply(f, tyArgs, args, ty) => let
		val args' = List.map (lookup env) args
		in
		  TranslateBasis.translate (lhs, f, tyArgs, args')
		end
	    | S.E_Cons args => [(lhs, IL.CONS(List.map (lookup env) args))]
	  (* end case *))

    fun cvtBlock (env, S.Block stms) =

  (* convert a statement, where env is the mapping from Simple AST variables to
   * their current SSA name, assigned is the set of AST variables assigned to
   * in the current context, and stm is the statement to convert.
   *)
    and cvtStmt (env, assigned, stm, preStms, k) = (case stm
	   of S.S_Assign(x, e) => let
		val x' = newVar x
		val stms = cvtExp(env, x', e)
		val assigned = VSet.add(assigned, x)
		val env = VMap.insert(env, x, x')
		in
		  k (env, assigned, stm::preStms)
		end
	    | S.S_IfThenElse(x, b1, b2) => let
		val x' = lookup env x
		val (b1, env1, assigned1) = block(env, b1)
		val (b2, env2, assigned2) = block(env, b2)
		val assigned = VSet.union(assigned1, assigned2)
		val (env, phis) = let
		      fun mkPhi (x, (env, phis) = let
			    val x1 = lookup(env1, x)
			    val x2 = lookup(env2, x)
			    val x' = newVar x
			    in
			      (VMap.insert(env, x, x'), (x', [x1, x2])::phis)
			    end
		      in
			VSet.foldl mkPhi (env, []) assigned
		      end
		in
		end
	    | S.S_New(name, xs) =>
	    | S.S_Die =>
	    | S.S_Stabilize =>
	  (* end case *))

    fun newBlock (??, stm) =

    and nextStmt (env, assigned, stm, ??) =

    and join (env
    fun translate (S.Program{globals, globaInit, actors}) = ??

  end

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