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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/codegen/codegen-env.sml
ViewVC logotype

View of /branches/vis15/src/compiler/codegen/codegen-env.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3876 - (download) (annotate)
Wed May 18 17:25:47 2016 UTC (3 years ago) by jhr
File size: 2039 byte(s)
  working on merge
(* codegen-env.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2016 The University of Chicago
 * All rights reserved.
 *)

structure CodeGenEnv : sig

    type t

    val new : {
	    spec : TargetSpec.t,	(* target spec *)
	    global : CLang.var,		(* variable for accessing globals *)
	    selfIn : CLang.var,		(* variable for accessing input strand state *)
	    selfOut : CLang.var		(* variable for accessing output strand state *)
	  } -> t

  (* get the target spec record from the environment *)
    val target : t -> TargetSpec.t

    val lookup : t * TreeVar.t -> CLang.var

    val insert : t * TreeVar.t * CLang.var -> t

  (* lookup the bindings for accessing the globals and strand state *)
    val global : t -> CLang.var
    val selfIn : t -> CLang.var
    val selfOut : t -> CLang.var

  (* get CLang versions of standard Diderot types *)
    val realTy : t -> CLang.ty
    val intTy  : t -> CLang.ty

  end = struct

    structure V = TreeVar
    structure VMap = TreeVar.Map
    structure CL = CLang

    datatype t = Env of {
	vmap : CL.var VMap.map,
	spec : TargetSpec.t
      }

    fun new {spec, global, selfIn, selfOut} = Env{
	    vmap = List.foldl VMap.insert' VMap.empty [
		(PseudoVars.global, global),
		(PseudoVars.selfIn, selfIn),
		(PseudoVars.selfOut, selfOut)
	      ],
	    spec = spec
	  }

    fun target (Env{spec, ...}) = spec

    fun lookup (Env{vmap, ...}, x) = (case VMap.find (vmap, x)
           of SOME x' => x'
            | NONE => raise Fail(concat["lookup(_, ", V.name x, ")"])
          (* end case *))

    fun insert (Env{vmap, spec}, x, x') = Env{vmap = VMap.insert(vmap, x, x'), spec = spec}

    fun global env = lookup(env, PseudoVars.global)
    fun selfIn env = lookup(env, PseudoVars.selfIn)
    fun selfOut env = lookup(env, PseudoVars.selfOut)

    fun realTy (Env{spec, ...}) = if (#double spec) then CL.double else CL.float
    fun intTy (Env{spec, ...}) = if (#longint spec) then CL.int64 else CL.int32

  end

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