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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/target-cpu/gen-strand.sml
ViewVC logotype

View of /branches/vis15/src/compiler/target-cpu/gen-strand.sml

Parent Directory Parent Directory | Revision Log Revision Log

Revision 3908 - (download) (annotate)
Tue May 24 14:33:23 2016 UTC (3 years, 1 month ago) by jhr
File size: 2697 byte(s)
working on merge: runtime and code generation
(* gen-strand.sml
 * Code generation for strands
 * 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 GenStrand : sig

    val gen : CodeGenEnv.t * TreeIR.strand -> CLang.decl list

  end = struct

    structure IR = TreeIR
    structure CL = CLang
    structure RN = CxxNames
    structure Env = CodeGenEnv

  (* generate the strand-state initialization code.  The variables are the strand
   * parameters.
    fun genStateInit (env, strandName, strandTy, params, body) = let
	  val fName = strandName ^ "_init"
	  val selfParam = if TargetSpec.dualState(Env.target env)
		then RN.selfOutVar
		else RN.selfVar
	  val params =
		CL.PARAM([], strandTy, selfParam) ::
		  List.map (fn (CL.V(ty, x)) => CL.PARAM([], ty, x)) params
	  val params = if #hasGlobals(Env.target env)
		then RN.globalsParam :: params
		else params
	  val body = TreeToCxx.trBlock (env, body)
	    CL.D_Func(["static"], CL.voidTy, fName, params, body)

  (* generate a function definition for a strand method *)
    fun genMethod (env, strandName, strandTy, methTy, methName, body) = let
	  val fName = concat[strandName, "_", methName]
	  val stateParams = if TargetSpec.dualState(Env.target env)
		then [
		    CL.PARAM(["const"], strandTy, RN.selfVar),
		    CL.PARAM([], strandTy, RN.selfOutVar)
		else [CL.PARAM([], strandTy, RN.selfVar)]
	  val params = if #hasGlobals(Env.target env)
		then RN.globalsParam :: stateParams
		else stateParams
	  val body = TreeToCxx.trBlock (env, body)
	    CL.D_Func(["static"], methTy, methName, params, body)

    fun genInitiallyMethod (_, _, _, NONE) = []
      | genInitiallyMethod (spec, strandName, strandTy, SOME body) =
	  [genMethod (spec, strandName, strandTy, CL.T_Named "StrandStatus_t", "initially", body)]

    fun genUpdateMethod (spec, strandName, strandTy, body) =
	  genMethod (spec, strandName, strandTy, CL.T_Named "StrandStatus_t", "update", body)

    fun genStabilizeMethod (_, _, _, NONE) = []
      | genStabilizeMethod (spec, strandName, strandTy, SOME body) =
	  [genMethod (spec, strandName, strandTy, CL.voidTy, "stabilize", body)]

    fun gen (env, strand) = let
	  val IR.Strand{name, params, state, stateInit, initM, updateM, stabilizeM} = strand
	  val name = Atom.toString name
	  val strandTy = CL.T_Ptr(CL.T_Named(name ^ "_strand"))
	    genStateInit (env, name, strandTy, ??, stateInit) ::
	    genInitiallyMethod (env, name, strandTy, initM) @
	    genUpdateMethod (env, name, strandTy, updateM) ::
	    genStabilizeMethod (env, name, strandTy, stabilizeM)


ViewVC Help
Powered by ViewVC 1.0.0