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

SCM Repository

[diderot] View of /branches/vis12/src/compiler/driver/options.sml
ViewVC logotype

View of /branches/vis12/src/compiler/driver/options.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1693 - (download) (annotate)
Mon Feb 20 12:55:09 2012 UTC (7 years, 8 months ago) by jhr
File size: 4703 byte(s)
  In preperation of making library generation the default, I'm adding
  a flag for specifying that the target is a standalone executable
(* options.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * Support for processing runtime options.
 *)

structure Options : sig

    exception Usage of string

    val parseCmdLine : string list -> {
	    help : bool,			(* "-help" specified? *)
	    log : bool,				(* logging enabled? *)
	    defs : string list,			(* input-variable definitions *)
	    target : TargetUtil.target_desc,
            output : string option,             (* "-o" specified file *)
            standalone : bool,                  (* true if target is standalone executable *)
	    file : string
	  }

    val usage : string -> string

  end = struct

    structure G = GetOpt

    exception Usage of string

  (* some option flags *)
    val helpFlg = ref false
    val debugFlg = ref false
    val doubleFlg = ref false
    val outputOpt : string option ref = ref NONE
    val standaloneFlg = ref false
    val logFlg = ref false
    val statsFlg = Stats.reportStats
    val target = ref TargetUtil.TARGET_C
    val parallel = ref false

    fun setFlag (flg, value) = G.NoArg(fn () => (flg := value))

    fun mkFlagOption (tag, flag, desc) = let
	  val default = !flag
	  val tag = if default
		then "disable-"^tag
		else "enable-"^tag
	  in {
	    short = "", long = [tag],
	    desc = setFlag (flag, not default),
	    help = desc
	  } end

  (* create the target option descriptor. *)
    local
      val desc = if Paths.cudaEnabled then ["  cuda    -- generate CUDA code"] else []
      val desc = if Paths.clEnabled then  "  cl      -- generate OpenCL code" :: desc else desc
      val desc = "  pthread -- generate parallel C code" :: desc
      val desc = "  c       -- generate C code (default)" :: desc
      val desc = "specify the target platform:" :: desc
      fun parseTargetOpt "c" = (target := TargetUtil.TARGET_C)
	| parseTargetOpt "cl" = if Paths.clEnabled
	    then (target := TargetUtil.TARGET_CL)
	    else raise Usage "cl target not supported by this version"
	| parseTargetOpt "cuda" = if Paths.cudaEnabled
	    then (target := TargetUtil.TARGET_CUDA)
	    else raise Usage "cuda target not supported by this version"
	| parseTargetOpt "pthread" = (target := TargetUtil.TARGET_C; parallel := true)
	| parseTargetOpt opt = raise Usage(concat["unrecognized target \"", opt, "\""])
    in
    val targetOptDesc = {
	    short = "",
	    long = ["target"],
	    desc = G.ReqArg(parseTargetOpt, "target"),
	    help = String.concatWith "\n" desc
	  }
    end

    val optionList = [
	    { short = "h", long = ["help"],
	      desc = setFlag (helpFlg, true),
	      help = "print command-line options"
	    },
            { short = "", long = ["exec"],
              desc = setFlag (standaloneFlg, true),
              help = "generate a standalone executable"
            },
            { short = "o", long = ["output"],
              desc = G.ReqArg(fn s => outputOpt := SOME s, "file"),
              help = "specify the executable file name"
            },
	    { short = "g", long = ["debug"],
	      desc = setFlag (debugFlg, true),
	      help = "enable debugging information in executable"
	    },
            { short = "", long = ["double"],
              desc = setFlag (doubleFlg, true),
              help = "use double-precision floats for reals"
            },
	    { short = "", long = ["log"],
	      desc = setFlag (logFlg, true),
	      help = "generate compiler debugging log"
	    },
	    { short = "", long = ["stats"],
	      desc = setFlag (statsFlg, true),
	      help = "report optimization statistics"
	    },
	    targetOptDesc
(* TODO: -double *)
	  ]
	  @ List.map mkFlagOption HighOptimizer.controls
	  @ List.map mkFlagOption MidOptimizer.controls
	  @ List.map mkFlagOption LowOptimizer.controls

    fun parseCmdLine args = let
	(* first we filter out any variable definitions *)
	  val (defs, rest) = List.partition Inputs.isCmdLineInput args
	  val (opts, files) = G.getOpt {
		  argOrder = G.RequireOrder,
		  options = optionList,
		  errFn = fn s => raise Usage s
		} args
	(* figure out target details *)
	  val targetDesc = {
		  target = !target,
		  parallel = !parallel,
		  double = !doubleFlg,
		  debug = !debugFlg
		}
	  in {
	    help = !helpFlg,
	    log = !logFlg,
	    defs = defs,
	    target = targetDesc,
            output = !outputOpt,
            standalone = !standaloneFlg,
	    file = (case files
	       of [] => if !helpFlg then "" else raise Usage "missing file argument"
		| f::_ => f
	      (* end case *))
	  } end

    fun usage cmd = G.usageInfo {
	    header = concat["usage: ", cmd, " [options] file.diderot\n  Options:"],
	    options = optionList
	  }

  end

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