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

SCM Repository

[diderot] View of /branches/vis12-cl/src/compiler/codegen/properties.sml
ViewVC logotype

View of /branches/vis12-cl/src/compiler/codegen/properties.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3222 - (download) (annotate)
Mon Jul 20 22:20:40 2015 UTC (3 years, 11 months ago) by jhr
File size: 5978 byte(s)
add information about compiler to generated code
(* properties.sml
 *
 * COPYRIGHT (c) 2014 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * Properties, including the target description, that affect code generation.
 *)

structure Properties =
  struct

    type props = {
      (* properties from the command line *)
        diderotc : string,              (* the diderotc command used to invoke this compiler *)
        argv : string list,             (* command-line arguments used to invoke this compiler *)
        version : string,               (* version message string for this compiler *)
      (* properties from the target description *)
        srcFile : string,               (* source filename *)
        outDir : string,                (* directory to put output *)
        outBase : string,               (* basename for output or name of executable *)
        exec : bool,                    (* generate standalone executable? *)
        snapshot : bool,                (* generate functions to get snapshots? *)
        target : TargetUtil.target,     (* target platform *)
        namespace : string,             (* optional namespace prefix *)
        parallel : bool,                (* parallel components? *)
        double : bool,                  (* true for double-precision candidates *)
        longint : bool,                 (* true for 64-bit integers (not currently used) *)
        debug : bool,                   (* true if debugging of the target is enabled *)
        bsp : bool,                     (* true if BSP style execution should always be used *)
      (* properties from analysing the program *)
        hasGlobals : bool,              (* true if the program has global variables *)
        hasInputs : bool,               (* true if the program has input variables *)
        isArray : bool,                 (* true for programs that use a fixed array of strands *)
        hasDynSeq : bool,               (* true for programs that have create dynamic sequences;
                                         * this does not include programs that just load sequences
                                         * from nrrd files. *)
        hasStabilize : bool,            (* true for programs with user-defined stabilize methods *)
        hasDie : bool,                  (* true for programs that have "die" *)
        hasNew : bool,                  (* true for programs that have "new" *)
        hasCom : bool,                  (* true for programs that have strand communication *)
        hasReduce : bool                (* true for programs that have global reduce *)
      }

  (* create the property record from the target description and program properties *)
    fun mkProps (tgt : TargetUtil.target_desc, props : StrandUtil.program_prop list) : props =
          {
            diderotc = CommandLine.name(),
            argv = CommandLine.arguments(),
            version = #version tgt,
            srcFile = #srcFile tgt,
            outDir = #outDir tgt,
            outBase = #outBase tgt,
            exec = #exec tgt,
            snapshot = #snapshot tgt,
            target = #target tgt,
            namespace = #namespace tgt,
            parallel = #parallel tgt,
            double = #double tgt,
            longint = #longint tgt,
            debug = #debug tgt,
            bsp = #bsp tgt,
            hasGlobals = StrandUtil.hasProp StrandUtil.HasGlobals props,
            hasInputs = StrandUtil.hasProp StrandUtil.HasInputs props,
            isArray = StrandUtil.hasProp StrandUtil.StrandArray props,
            hasDynSeq = StrandUtil.hasProp StrandUtil.DynamicSeq props,
            hasStabilize = StrandUtil.hasProp StrandUtil.HasStabilizeMethod props,
            hasDie = StrandUtil.hasProp StrandUtil.StrandsMayDie props,
            hasNew = StrandUtil.hasProp StrandUtil.NewStrands props,
            hasCom = StrandUtil.hasProp StrandUtil.StrandCommunication props,
            hasReduce = StrandUtil.hasProp StrandUtil.GlobalReduce props
          }

  (* returns false if BSP style execution should always be used;
   * this property can be set on the command line, but
   * also holds when program has communication, etc.
   *)
    fun noBSP (p : props) = not(#bsp p orelse #hasCom p orelse #hasReduce p)

  (* returns true if the program does not use inter-strand communication *)
    fun noComm (p : props) = not(#hasCom p)

  (* return true if we need to keep two copies of the state: in and out. *)
    fun dualState (p : props) = (#hasCom p)

  (* convert a target specification to the name of the runtime library *)
    fun runtimeName (props : props) = let
          val l = if #debug props then ["-debug.o"] else [".o"]
          val l = if #parallel props then "-par"::l else l
          val p = if #double props then "-d" else "-f"
          val t = (case #target props
                 of TargetUtil.TARGET_C => "-c"
                  | TargetUtil.TARGET_CL => "-cl"
                  | TargetUtil.TARGET_CUDA => "-cuda"
                (* end case *))
          in
            OS.Path.concat(
              Paths.diderotLib(),
              String.concat("diderot-rt" :: t :: p :: l))
          end

  (* return the CPP floating-point precision definition for the target *)
    fun floatPrecisionDef (p : props) = if #double p
          then "DIDEROT_DOUBLE_PRECISION"
          else "DIDEROT_SINGLE_PRECISION"

  (* return the CPP integer precision definition for the target *)
    fun intPrecisionDef (p : props) = if #longint p
          then "DIDEROT_LONGINT"
          else "DIDEROT_INT"

  (* return the CPP target definition for the target *)
    fun targetDef (p : props) = (case #target p
           of TargetUtil.TARGET_C => if #parallel p
                then "DIDEROT_TARGET_PARALLEL"
                else "DIDEROT_TARGET_C"
            | TargetUtil.TARGET_CL => "DIDEROT_TARGET_CL"
            | TargetUtil.TARGET_CUDA => "DIDEROT_TARGET_CUDA"
          (* end case *))

  end

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