SCM Repository
View of /trunk/src/compiler/common/inputs.sml
Parent Directory
|
Revision Log
Revision 340 -
(download)
(annotate)
Mon Sep 13 15:34:36 2010 UTC (10 years, 7 months ago) by jhr
File size: 2576 byte(s)
Mon Sep 13 15:34:36 2010 UTC (10 years, 7 months ago) by jhr
File size: 2576 byte(s)
Working on debugging HighIL optimization
(* inputs.sml * * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) * All rights reserved. * * Support for processing static inputs to a program *) structure Inputs : sig (* returns true if the argument has the form of a command-line input specification *) val isCmdLineInput : string -> bool (* initialize the table from the command-line arguments; returns false if there was * an error processing an argument. *) val initFromArgs : string list -> bool (* getInput(name, fromString, optDefault) gets the value of the named input. * if the value is not defined in the table and there is a default, then the * default is returned. Otherwise it reads it from standard input *) val getInput : string * (string -> 'a option) * 'a option -> 'a option end = struct structure Tbl = AtomTable val inputs : string AtomTable.hash_table = AtomTable.mkTable(32, Fail "input table") fun notEq #"=" = false | notEq _ = true fun isCmdLineInput s = String.isPrefix "-D" s fun initFromArgs args = let fun doArg arg = let val arg = Substring.full arg in if Substring.isPrefix "-D" arg then let val arg = Substring.triml 2 arg val (name, rest) = Substring.splitl notEq arg in if (Substring.size name > 0) andalso (Substring.size rest > 1) then ( AtomTable.insert inputs (Atom.atom' name, Substring.string(Substring.triml 1 rest)); true) else false end else true end in AtomTable.clear inputs; List.all doArg args end fun getInput (name, fromString : string -> 'a option, optDefault : 'a option) = let fun cvt s = (case fromString s of NONE => ( TextIO.output(TextIO.stdErr, concat[ "ERROR: value \"", String.toString s, "\" for input ", name, " is invalid\n" ]); NONE) | someVal => someVal (* end case *)) val name' = Atom.atom name in case AtomTable.find inputs name' of NONE => (case optDefault of NONE => ( TextIO.output(TextIO.stdOut, concat[ "input value for ", name, ": " ]); TextIO.flushOut TextIO.stdOut; case TextIO.inputLine TextIO.stdIn of SOME ln => let val ln = String.substring(ln, 0, size ln - 1) in AtomTable.insert inputs (name', ln); (* cache value *) cvt ln end | NONE => OS.Process.exit OS.Process.failure (* end case *)) | someVal => someVal (* end case *)) | SOME v => fromString v (* end case *) end end
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |