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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/tree-to-c/gen-strand.sml
ViewVC logotype

View of /branches/vis15/src/compiler/tree-to-c/gen-strand.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3866 - (download) (annotate)
Mon May 16 16:48:13 2016 UTC (3 years, 2 months ago) by jhr
File size: 2528 byte(s)
working on merge
(* 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 : TargetSpec.t * TreeIR.strand -> CLang.decl list

  end = struct

    structure IR = TreeIR
    structure CL = CLang
    structure Spec = TargetSpec

  (* generate the strand-state initialization code.  The variables are the strand
   * parameters.
   *)
    fun genStateInit (spec, strandName, params, body) = let
	  val globTy = N.globalsPtrTy props
	  val fName = strandName ^ "_init"
	  val selfParam = if Properties.dualState props
		then "selfOut"
		else "self"
	  val params =
		CL.PARAM([], CL.T_Ptr(CL.T_Named tyName), selfParam) ::
		  List.map (fn (CL.V(ty, x)) => CL.PARAM([], ty, x)) params
	  val params = if #hasGlobals props
		then CL.PARAM([], globTy, "glob") :: params
		else params
	  val body = ??
	  in
	    CL.D_Func(["static"], CL.voidTy, fName, params, body)
	  end

  (* generate a function definition for a strand method *)
    fun genMethod (spec, strandName, methTy, methName, body) = let
	  val globTy = N.globalsPtrTy props
	  val fName = concat[strandName, "_", methName]
	  val stateParams = if Spec.dualState spec
		then [
		    CL.PARAM(["const"], CL.T_Ptr(CL.T_Named tyName), "selfIn"),
		    CL.PARAM([], CL.T_Ptr(CL.T_Named tyName), "selfOut")
		  ]
		else [CL.PARAM([], CL.T_Ptr(CL.T_Named tyName), "self")]
	  val params = if #hasGlobals spec
		then CL.PARAM([], globTy, "glob") :: stateParams
		else stateParams
	  val body = ??
	  in
	    CL.D_Func(["static"], methTy, methName, params, body)
	  end

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

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

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

    fun gen (spec : TargetSpec.t, strand) = let
	  val IR.Strand{name, params, state, stateInit, initM, updateM, stabilizeM} = strand
	  in
	    genStateInit (spec, name, ??, stateInit) ::
	    genInitiallyMethod (spec, name, initM) @
	    genUpdateMethod (spec, name, updateM) ::
	    genStabilizeMethod (spec, name, stabilizeM)
	  end

  end

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