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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3291 - (download) (annotate)
Wed Oct 14 21:25:00 2015 UTC (4 years, 8 months ago) by jhr
File size: 10277 byte(s)
code is copyright University of Chicago
(* runtime-names.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *
 * These are C-code names, types, and variables that are common to all of the targets.
 * Additional names are defined in CTypeNames (scalar and tensor types), and MathNames
 * (math functions).
 *)

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

  (* pointer to scheduler data structure *)
    val schedTyName : Properties.props -> string
    val schedPtrTy : 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 *)

  (* 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    : string
    val kNew       : string
    val kDie       : string
    val kStabilize : string
    val kStable    : string

  (* image types *)
    val imageTyName : int -> string
    val imagePtrTy : int -> CLang.ty

  (* function mapping world to image space *)
    val toImageSpace : int -> string

  (* function mapping image space to world space *)
    val toWorldSpace : TreeIL.Ty.ty -> string

  (* inside test for images *)
    val inside : int -> string

  (* image index control operations *)
    val indexControl : int * IndexCtl.ctl -> string

  (* pointer to a dynamic sequence *)
    val dynSeqTy : CLang.ty

  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]
    fun ptrTy name = CL.T_Ptr(CL.T_Named name)

  (* the name/type of the world type *)
    val worldTyName = qualifyName "World_t"
    fun worldPtrTy tgt = ptrTy(worldTyName tgt)

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

  (* pointer to scheduler data structure *)
    val schedTyName = qualifyName "Sched_t"
    fun schedPtrTy tgt = CL.T_Ptr(CL.T_Named(schedTyName tgt))

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

  (* the name/type of the program's defined-inputs struct *)
    val definedInpTyName = qualifyName "DefinedInputs_t"
    fun definedInpPtrTy tgt = ptrTy(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"

  (* 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 = ptrTy(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 kNew = "DIDEROT_NEW"
    val kDie = "DIDEROT_DIE"
    val kStabilize = "DIDEROT_STABILIZE"
    val kStable = "DIDEROT_STABLE"

  (* image operations *)

    fun imageTyName n = concat["Diderot_image", Int.toString n, "D_t"]
    fun imagePtrTy n = ptrTy(imageTyName n)

    fun toImageSpace d = "ToImageSpace" ^ Int.toString d

    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

    fun inside d = "Inside" ^ Int.toString d

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

  (* pointer to a dynamic sequence *)
    val dynSeqTy = ptrTy "Diderot_DynSeq_t"

  end

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