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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/cfg-ir/translate-env-fn.sml
ViewVC logotype

View of /branches/vis15/src/compiler/cfg-ir/translate-env-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3840 - (download) (annotate)
Mon May 9 20:42:08 2016 UTC (2 years, 10 months ago) by jhr
File size: 3009 byte(s)
working on merge: track state variable properties
(* translate-env-fn.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *)

signature TRANSLATE_ENV_PARAMS =
  sig

    structure SrcIR : SSA
    structure DstIR : SSA

    val cvtTy : SrcIR.Ty.ty -> DstIR.Ty.ty

  end

functor TranslateEnvFn (Params : TRANSLATE_ENV_PARAMS) : sig

    structure SrcIR : SSA
    structure DstIR : SSA

    type env

    val mkEnv : unit -> env

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

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

  end = struct

    structure SrcIR = Params.SrcIR
    structure SrcGV = SrcIR.GlobalVar
    structure SrcSV = SrcIR.StateVar
    structure DstIR = Params.DstIR

    type var_env = DstIR.var SrcIR.Var.Tbl.hash_table
    type global_var_env = DstIR.global_var SrcGV.Tbl.hash_table
    type state_var_env = DstIR.state_var SrcSV.Tbl.hash_table

    datatype env = E of {
        ndMap : DstIR.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 = SrcIR.Var.Tbl.mkTable (256, Fail "vMap"),
            gvMap = SrcIR.GlobalVar.Tbl.mkTable (64, Fail "gvMap"),
            svMap = SrcIR.StateVar.Tbl.mkTable (64, Fail "svMap")
          }

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

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

    fun renameGV (E{gvMap, ...}, x) = (case SrcGV.Tbl.find gvMap x
           of SOME x' => x'
            | NONE => let
                val x' = DstIR.GlobalVar.new (
		      SrcGV.kind x, SrcGV.isUpdated 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' = DstIR.StateVar.new (
		      SrcSV.isOutput x, SrcSV.name x, Params.cvtTy(SrcSV.ty x),
		      SrcSV.isVarying x, SrcSV.isShared x)
                in
                  SrcSV.Tbl.insert svMap (x, x');
                  x'
                end
          (* end case *))

    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