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/target-cpu.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3864 - (download) (annotate)
Mon May 16 13:23:38 2016 UTC (3 years, 6 months ago) by jhr
Original Path: branches/vis15/src/compiler/tree-to-c/tree-to-c.sml
File size: 2415 byte(s)
working on merge: code generation
(* tree-to-c.sml
 *
 * Code generation for the sequential and parallel targets.
 *
 * 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 TreeToC : sig

    val target : TargetOptions.t -> {
	    info : TreeIR.target_info,
	    generate : TreeIR.program -> unit
	  }

  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
	  val methFn = CL.D_Func(["static"], resTy, fName, params, 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 generate (tgt : TargetOptions.t) prog = let
	  val IR.Program{
		  props, target, consts, inputs, constInit,
		  globals, globalInit, strand, create, update
		} = prog
	  val spec = TargetSpec.mk (tgt, props)
	  in
	    if (* standalone exec *)
	      then
	      else
	  end

    fun info (tgt : TargetOptions.t) = {
	    layout = if (#scalar tgt)
		then DefaultLayout.scalar
		else DefaultLayout.layout (DefaultLayout.gccVectorSizes (#double tgt)),
	    isInline =
	       fn LowOps.EigenVecs2x2 => false
		| LowOps.EigenVecs3x3 => false
		| LowOps.EigenVals2x2 => false
		| LowOps.EigenVals3x3 => false
		| LowOps.Zero => false
		| _ => true
	  }

    fun target tgt = {
	    info = info tgt,
	    generate = generate tgt
	  }

  end

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