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

SCM Repository

[diderot] View of /branches/vis12-cl/src/compiler/IL/translate-env-fn.sml
ViewVC logotype

View of /branches/vis12-cl/src/compiler/IL/translate-env-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2804 - (download) (annotate)
Sat Nov 8 17:33:59 2014 UTC (4 years, 9 months ago) by jhr
File size: 2869 byte(s)
  merge in new globals code from vis12 branch
(* translate-env-fn.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

signature TRANSLATE_ENV_PARAMS =
  sig

    structure SrcIL : SSA
    structure DstIL : SSA

    val cvtTy : SrcIL.Ty.ty -> DstIL.Ty.ty

  end

functor TranslateEnvFn (Params : TRANSLATE_ENV_PARAMS) : sig

    structure SrcIL : SSA
    structure DstIL : SSA

    type env

    val mkEnv : unit -> env

    val rename : (env * SrcIL.var) -> DstIL.var
    val renameList : (env * SrcIL.var list) -> DstIL.var list
    val renameGV : (env * SrcIL.global_var) -> DstIL.global_var
    val renameSV : (env * SrcIL.state_var) -> DstIL.state_var

    val insertNd : (env * Stamp.stamp * DstIL.node) -> unit
    val findNd : env -> Stamp.stamp -> DstIL.node option

  end = struct

    structure SrcIL = Params.SrcIL
    structure SrcGV = SrcIL.GlobalVar
    structure SrcSV = SrcIL.StateVar
    structure DstIL = Params.DstIL

    type var_env = DstIL.var SrcIL.Var.Tbl.hash_table
    type global_var_env = DstIL.global_var SrcGV.Tbl.hash_table
    type state_var_env = DstIL.state_var SrcSV.Tbl.hash_table

    datatype env = E of {
        ndMap : DstIL.node Stamp.Tbl.hash_table,
        vMap : var_env,
        gvMap : global_var_env,
        svMap : state_var_env
      }

    fun mkEnv () = E{
            ndMap = Stamp.Tbl.mkTable (256, Fail "ndMap"),
            vMap = SrcIL.Var.Tbl.mkTable (256, Fail "vMap"),
            gvMap = SrcIL.GlobalVar.Tbl.mkTable (64, Fail "gvMap"),
            svMap = SrcIL.StateVar.Tbl.mkTable (64, Fail "svMap")
          }

    fun rename (E{vMap, ...}, x) = (case SrcIL.Var.Tbl.find vMap x
          of SOME x' => x'
           | NONE => let
               val x' = DstIL.Var.new (SrcIL.Var.name x, Params.cvtTy(SrcIL.Var.ty x))
               in
                 SrcIL.Var.Tbl.insert vMap (x, x');
                 x'
               end
         (* end case *))

    fun renameGV (E{gvMap, ...}, x) = (case SrcGV.Tbl.find gvMap x
           of SOME x' => x'
            | NONE => let
                val x' = DstIL.GlobalVar.new (SrcGV.isInput x, SrcGV.name x, Params.cvtTy(SrcGV.ty x))
                in
                  SrcGV.Tbl.insert gvMap (x, x');
                  x'
                end
          (* end case *))

    fun renameSV (E{svMap, ...}, x) = (case SrcSV.Tbl.find svMap x
           of SOME x' => x'
            | NONE => let
                val x' = DstIL.StateVar.new (SrcSV.isOutput x, SrcSV.name x, Params.cvtTy(SrcSV.ty x))
                in
                  SrcSV.Tbl.insert svMap (x, x');
                  x'
                end
          (* end case *))

    fun renameList (env, xs) = List.map (fn x => rename (env, x)) xs

    fun insertNd (E{ndMap, ...}, id, nd) = Stamp.Tbl.insert ndMap (id, nd)

    fun findNd (E{ndMap, ...}) = Stamp.Tbl.find ndMap

  end

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