aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Commandline.mli
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@college-de-france.fr>2020-05-04 11:11:27 +0200
committerXavier Leroy <xavierleroy@users.noreply.github.com>2020-05-05 14:03:52 +0200
commit4a676623badb718da4055b7f26ee05f5097f4e7b (patch)
tree63ae1519f97355b928ded3eb1092d5bee83a6f42 /lib/Commandline.mli
parentb46c0c01379da17dd96fc0cb8f0458100b7b1e5e (diff)
downloadcompcert-kvx-4a676623badb718da4055b7f26ee05f5097f4e7b.tar.gz
compcert-kvx-4a676623badb718da4055b7f26ee05f5097f4e7b.zip
Move Commandline to the lib/ directory
The Commandline module is reusable in other projects, and its license (GPL) allows such reuse, so its natural place is in lib/ rather than in driver/
Diffstat (limited to 'lib/Commandline.mli')
-rw-r--r--lib/Commandline.mli55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/Commandline.mli b/lib/Commandline.mli
new file mode 100644
index 00000000..8bb6f18f
--- /dev/null
+++ b/lib/Commandline.mli
@@ -0,0 +1,55 @@
+(* *********************************************************************)
+(* *)
+(* The Compcert verified compiler *)
+(* *)
+(* Xavier Leroy, INRIA Paris-Rocquencourt *)
+(* *)
+(* Copyright Institut National de Recherche en Informatique et en *)
+(* Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the GNU General Public License as published by *)
+(* the Free Software Foundation, either version 2 of the License, or *)
+(* (at your option) any later version. This file is also distributed *)
+(* under the terms of the INRIA Non-Commercial License Agreement. *)
+(* *)
+(* *********************************************************************)
+
+(* Parsing of command-line flags and arguments *)
+
+(* A command-line specification is a list of pairs (pattern, action).
+ Command-line words are matched against the patterns, and the
+ corresponding actions are invoked. *)
+
+type pattern =
+ | Exact of string (** exactly this string *)
+ | Prefix of string (** any string starting with this prefix *)
+ | Suffix of string (** any string ending with this suffix *)
+ | Regexp of Str.regexp (** any string matching this anchored regexp *)
+
+val _Regexp: string -> pattern (** text of an [Str] regexp *)
+
+type action =
+ | Set of bool ref (** set the given ref to true *)
+ | Unset of bool ref (** set the given ref to false *)
+ | Self of (string -> unit) (** call the function with the matched string *)
+ | String of (string -> unit) (** read next arg as a string, call function *)
+ | Integer of (int -> unit) (** read next arg as an int, call function *)
+ | Ignore (** ignore the next arg *)
+ | Unit of (unit -> unit) (** call the function with unit as argument *)
+(* Note on precedence: [Exact] patterns are tried first, then the other
+ patterns are tried in the order in which they appear in the list. *)
+
+exception CmdError of string
+(** Raise by [parse_cmdline] when an error occurred *)
+
+val parse_cmdline: (pattern * action) list -> unit
+(** [parse_cmdline actions] parses the command line (after @-file expansion)
+ and performs all [actions]. Raises [CmdError] if an error occurred.
+*)
+
+val longopt_int: string -> (int -> unit) -> pattern * action
+(** [longopt_int key fn] generates a pattern and an action for
+ options of the form [key=<n>] and calls [fn] with the integer argument
+*)
+
+val argv: string array
+(** [argv] contains the complete command line after @-file expandsion *)