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 3864 - (download) (annotate)
Mon May 16 13:23:38 2016 UTC (4 years ago) by jhr
Original Path: branches/vis15/src/compiler/tree-to-c/gen-strand.sml
File size: 1821 byte(s)
working on merge: 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 : TargetSpec.t * TreeIR.strand -> CLang.decl list

  end = struct

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

  (* 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
	    CL.D_Func(["static"], methTy, methName, params, body)

    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
	    genInitiallyMethod (spec, name, initM) @
	    genUpdateMethod (spec, name, updateM) ::
	    genStabilizeMethod (spec, name, stabilizeM)


ViewVC Help
Powered by ViewVC 1.0.0