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

SCM Repository

[diderot] View of /branches/vis12-cl/src/compiler/c-util/runtime-names.sml
ViewVC logotype

View of /branches/vis12-cl/src/compiler/c-util/runtime-names.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3088 - (download) (annotate)
Tue Mar 17 18:27:27 2015 UTC (6 years, 4 months ago) by jhr
File size: 9022 byte(s)
  working on vis12-cl reorg
(* runtime-names.sml
 *
 * COPYRIGHT (c) 2015 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * These are C-code names, types, and variables that are common to all of the targets.
 *)

structure RuntimeNames : sig

  (* qualify a name by the target's namespace *)
    val qualifyName : string -> Properties.props -> string
  (* qualify a composite name by the target's namespace *)
    val qualifyName' : string -> (Properties.props * string) -> string

  (* the name/type of the world type *)
    val worldTyName : Properties.props -> string
    val worldPtrTy : Properties.props -> CLang.ty

  (* the name/type of the program's global variables struct *)
    val globalsTyName : Properties.props -> string
    val globalsPtrTy : Properties.props -> CLang.ty

  (* the name/type of the program's input variables struct *)
    val inputsTyName : Properties.props -> string
    val inputsPtrTy : Properties.props -> CLang.ty

  (* the name/type of the program's defined-inputs struct *)
    val definedInpTyName : Properties.props -> string
    val definedInpPtrTy : Properties.props -> CLang.ty

  (* the holder for command-line options *)
    val optionsTyName : string
    val optionsPtrTy : CLang.ty

  (* names for input and output variable operations *)
    val inputDesc      : (Properties.props * string) -> string
    val inputGet       : (Properties.props * string) -> string
    val inputSet       : (Properties.props * string) -> string
    val inputSetByName : (Properties.props * string) -> string
    val outputGet      : (Properties.props * string) -> string
    val snapshotGet    : (Properties.props * string) -> string

  (* names of generated functions *)
    val initGlobals : string			   (* function for initializing program globals *)
    val freeGlobals : string		           (* function for freeing program globals *)
    val initDefaults : string                      (* function for initializing input defaults *)
    val registerOpts : string	                   (* function for registering command-line options *)
    val registerOutputOpts : string                (* function for registering output redirection options *)
    val initInputs : string		           (* function for initializing global inputs *)
    val initDefined : Properties.props -> string   (* function for initializing input-defined flags *)
    val checkDefined : Properties.props -> string  (* function for checking input-defined flags *)
    val shutdown : Properties.props -> string      (* function that gets called at the end *)
    val initially : Properties.props -> string	   (* function for creating initial strands *)
    val allocInitially : string                    (* function for allocating initial strands *)

  (* Math utility functions *)
    val evecs2x2 : string
    val evecs3x3 : string
    val evals2x2 : string
    val evals3x3 : string

  (* strand initialization function *)
    val strandInit : string -> string

  (* the name/type of a strand object *)
    val strandTyName : string -> string
    val strandPtrTy : string -> CLang.ty

    val strandDescTy : CLang.ty
    val strandDesc : string -> string
    val strands : string

  (* Run-time system functions for images *)
    val setImage : int -> string
    val loadImage : int -> string
    val freeImage : int -> string

  (* Run-time system functions for dynamic sequences *)
    val loadDynSeq : TreeIL.Ty.ty -> string
    val loadDynSeqFromFile : TreeIL.Ty.ty -> string

  (* functions for defining program-input command-line options *)
    val inputOpt : TreeIL.Ty.ty -> string

  (* Status_t symbols *)
    val kActive = "DIDEROT_ACTIVE"
    val kDie = "DIDEROT_DIE"
    val kStabilize = "DIDEROT_STABILIZE"

  end = struct

    structure Ty = TreeIL.Ty
    structure CL = CLang

    fun qualifyName name (tgt : Properties.props) = #namespace tgt ^ name
    fun qualifyName' fixed (tgt : Properties.props, name) =
	  concat[#namespace tgt, fixed, "_", name]

  (* the name/type of the world type *)
    val worldTyName = qualifyName "World_t"
    fun worldPtrTy tgt = CL.T_Ptr(CL.T_Named(worldTyName tgt))

  (* the name/type of the program's global variables struct *)
    val globalsTyName = qualifyName "Globals_t"
    fun globalsPtrTy tgt = CL.T_Ptr(CL.T_Named(globalsTyName tgt))

  (* the name/type of the program's input variables struct *)
    val inputsTyName = qualifyName "Inputs_t"
    fun inputsPtrTy tgt = CL.T_Ptr(CL.T_Named(inputsTyName tgt))

  (* the name/type of the program's defined-inputs struct *)
    val definedInpTyName = qualifyName "DefinedInputs_t"
    fun definedInpPtrTy tgt = CL.T_Ptr(CL.T_Named(definedInpTyName tgt))

  (* the holder for command-line options *)
    val optionsTyName = "Diderot_Options_t"
    val optionsPtrTy = CL.T_Ptr(CL.T_Named optionsTyName)

  (* generate names for input and output variables *)
    val inputDesc = qualifyName' "InVarDesc"
    val inputGet = qualifyName' "InVarGet"
    val inputSet = qualifyName' "InVarSet"
    val inputSetByName = qualifyName' "InVarSetByName"
    val outputGet = qualifyName' "OutputGet"
    val snapshotGet = qualifyName' "Snapshot"

  (* names of generated types, functions, and globals *)
    val initGlobals = "InitGlobals"		(* function for initializing program globals *)
    val freeGlobals = "FreeGlobals"		(* function for freeing program globals *)
    val initDefaults = "InitDefaults"		(* function for initializing input defaults *)
    val registerOpts = "RegisterGlobalOpts"	(* function for registering command-line options *)
    val registerOutputOpts = "RegisterOutputOpts" (* function for registering output redirection options *)
    val initInputs = "InitInputs"		(* function for initializing global inputs *)
    val initDefined = qualifyName "InitDefined"	(* function for initializing input-defined flags *)
    val checkDefined = qualifyName "ChkDefined"	(* function for checking input-defined flags *)
    val shutdown = qualifyName "Shutdown"	(* function that gets called at the end *)
    val initially = qualifyName "Initially"	(* function for creating initial strands *)
    val allocInitially = "AllocInitially"

  (* Math utility functions *)
    val evecs2x2 = "Diderot_evecs2x2"
    val evecs3x3 = "Diderot_evecs3x3"
    val evals2x2 = "Diderot_evals2x2"
    val evals3x3 = "Diderot_evals3x3"

  (* strand initialization function *)
    fun strandInit strand = strand ^ "_InitState"

  (* the name/type of a strand object *)
    fun strandTyName strand = concat["Strand_", strand, "_t"]
    fun strandPtrTy strand = CL.T_Ptr(CL.T_Named(strandTyName strand))

    val strandDescTy = CL.T_Named "Strand_t"
    fun strandDesc strand = concat["Strand_", strand]
    val strands = "Diderot_Strands"

  (* Run-time system functions for images *)
    fun setImage dim = concat["Diderot_SetImage", Int.toString dim, "D"]
    fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]
    fun freeImage dim = concat["Diderot_FreeImage", Int.toString dim, "D"]

  (* Run-time system functions for dynamic sequences *)
    fun loadDynSeq ty = (case ty
	   of Ty.BoolTy => "Diderot_DynSeqLoadBool"
	    | Ty.IntTy => "Diderot_DynSeqLoadInt"
	    | Ty.TensorTy _ => "Diderot_DynSeqLoadReal"
	    | ty => raise Fail("unsupported sequence type " ^ Ty.toString ty)
          (* end case *))
    fun loadDynSeqFromFile ty = (case ty
	   of Ty.BoolTy => "Diderot_DynSeqLoadBoolFromFile"
	    | Ty.IntTy => "Diderot_DynSeqLoadIntFromFile"
	    | Ty.TensorTy _ => "Diderot_DynSeqLoadRealFromFile"
	    | ty => raise Fail("unsupported sequence type " ^ Ty.toString ty)
          (* end case *))

  (* functions for defining program-input command-line options; note that sequences
   * and images come from nrrd files, which are specified by their filenames.
   *)
    fun inputOpt ty = (case ty
	   of Ty.StringTy => "Diderot_OptAddString"
	    | Ty.BoolTy => "Diderot_OptAddBool"
	    | Ty.IntTy => "Diderot_OptAddInt"
	    | Ty.TensorTy[] => "Diderot_OptAddReal"
	    | Ty.TensorTy[2] => "Diderot_OptAddReal2"
	    | Ty.TensorTy[3] => "Diderot_OptAddReal3"
	    | Ty.TensorTy[4] => "Diderot_OptAddReal4"
	    | Ty.DynSeqTy _ => "Diderot_OptAddString"
            | Ty.ImageTy _ => "Diderot_OptAddString"
            | ty => raise Fail("unsupported input type " ^ Ty.toString ty)
	  (* end case *))

  (* Status_t symbols *)
    val kActive = "DIDEROT_ACTIVE"
    val kDie = "DIDEROT_DIE"
    val kStabilize = "DIDEROT_STABILIZE"

    val toImageSpace = addVecSuffix "ToImageSpace"
    fun toWorldSpace ty = let
	  val suffix = (case ty
		 of Ty.TensorTy[d] => [Int.toString d]
		  | Ty.TensorTy[m,n] => [Int.toString n, "x", Int.toString n]
		  | Ty.TensorTy[m,n,p] => [Int.toString n, "x", Int.toString n, "x", Int.toString p]
		(* end case *))
	  in
	    concat("ToWorldSpace" :: suffix)
	  end
    val inside = addVecSuffix "Inside"

  (* image index control operations *)
    fun indexControl (dim, ctl) = concat["Index", IndexCtl.toString ctl, Int.toString dim]

  end

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