file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Options.fst | Options.get_file_name | val get_file_name (mname:string) : ML string | val get_file_name (mname:string) : ML string | let get_file_name mname = mname ^ ".3d" | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 39,
"end_line": 421,
"start_col": 0,
"start_line": 421
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | mname: Prims.string -> FStar.All.ML Prims.string | FStar.All.ML | [
"ml"
] | [] | [
"Prims.string",
"Prims.op_Hat"
] | [] | false | true | false | false | false | let get_file_name mname =
| mname ^ ".3d" | false |
Options.fst | Options.split_3d_file_name | val split_3d_file_name : fn: Prims.string -> FStar.Pervasives.Native.option Prims.string | let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 11,
"end_line": 419,
"start_col": 0,
"start_line": 415
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2 | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | fn: Prims.string -> FStar.Pervasives.Native.option Prims.string | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Prims.op_Equality",
"OS.extension",
"FStar.Pervasives.Native.Some",
"OS.remove_extension",
"Prims.bool",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"OS.basename"
] | [] | false | false | false | true | false | let split_3d_file_name fn =
| let fn = OS.basename fn in
if OS.extension fn = ".3d" then Some (OS.remove_extension fn) else None | false |
|
StructUpdate.fst | StructUpdate.combine | val combine (#a #b: _) (x: t a b) (y: t a b {comp x y}) : t a b | val combine (#a #b: _) (x: t a b) (y: t a b {comp x y}) : t a b | let combine #a #b (x: t a b) (y:t a b{comp x y}) : t a b =
match x, y with
| First a, Second b
| Second b, First a -> Both a b
| Neither, z
| z, Neither -> z | {
"file_name": "share/steel/examples/steel/StructUpdate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 19,
"end_line": 25,
"start_col": 0,
"start_line": 20
} | module StructUpdate
module P = FStar.PCM
module M = Steel.Memory
open FStar.PCM
type t (a:Type) (b:Type) =
| Both : a -> b -> t a b
| First : a -> t a b
| Second : b -> t a b
| Neither : t a b
let comp #a #b (x y:t a b) : prop =
match x, y with
| Neither, _
| _, Neither
| First _, Second _
| Second _, First _ -> True
| _ -> False | {
"checked_file": "/",
"dependencies": [
"Steel.PCMReference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "StructUpdate.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.PCM",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: StructUpdate.t a b -> y: StructUpdate.t a b {StructUpdate.comp x y} -> StructUpdate.t a b | Prims.Tot | [
"total"
] | [] | [
"StructUpdate.t",
"StructUpdate.comp",
"FStar.Pervasives.Native.Mktuple2",
"StructUpdate.Both"
] | [] | false | false | false | false | false | let combine #a #b (x: t a b) (y: t a b {comp x y}) : t a b =
| match x, y with
| First a, Second b | Second b, First a -> Both a b
| Neither, z | z, Neither -> z | false |
Options.fst | Options.display_usage_1 | val display_usage_1 (options: ref (list cmd_option)) : ML unit | val display_usage_1 (options: ref (list cmd_option)) : ML unit | let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options [])) | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 106,
"end_line": 352,
"start_col": 0,
"start_line": 334
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | options: FStar.ST.ref (Prims.list Options.cmd_option) -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"FStar.ST.ref",
"Prims.list",
"Options.cmd_option",
"FStar.IO.print_string",
"Prims.unit",
"Prims.string",
"FStar.Printf.sprintf",
"Options.compute_current_options",
"Prims.Nil",
"FStar.List.iter",
"Prims.bool",
"Prims.op_Negation",
"Options.string_starts_with",
"Options.uu___is_CmdOption",
"Options.negate_name",
"Prims.op_Equality",
"Options.cmd_option_arg_desc",
"Options.cmd_option_description",
"Options.cmd_option_name",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.get_arg0"
] | [] | false | true | false | false | false | let display_usage_1 (options: ref (list cmd_option)) : ML unit =
| FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n"
(get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter (fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate =
if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else ""
in
let visible = not (m `string_starts_with` "__") in
if visible
then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc))
!options;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n"
(compute_current_options options [])) | false |
Options.fst | Options.get_skip_c_makefiles | val get_skip_c_makefiles : unit -> ML bool | val get_skip_c_makefiles : unit -> ML bool | let get_skip_c_makefiles () =
!skip_c_makefiles | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 19,
"end_line": 456,
"start_col": 0,
"start_line": 455
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"Prims.bool",
"FStar.Heap.trivial_preorder",
"Options.skip_c_makefiles"
] | [] | false | true | false | false | false | let get_skip_c_makefiles () =
| !skip_c_makefiles | false |
Options.fst | Options.get_skip_o_rules | val get_skip_o_rules : unit -> ML bool | val get_skip_o_rules : unit -> ML bool | let get_skip_o_rules _ =
!skip_o_rules | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 15,
"end_line": 509,
"start_col": 0,
"start_line": 508
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"Prims.bool",
"FStar.Heap.trivial_preorder",
"Options.skip_o_rules"
] | [] | false | true | false | false | false | let get_skip_o_rules _ =
| !skip_o_rules | false |
Options.fst | Options.get_save_hashes | val get_save_hashes : unit -> ML bool | val get_save_hashes : unit -> ML bool | let get_save_hashes () =
!save_hashes | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 14,
"end_line": 470,
"start_col": 0,
"start_line": 469
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"Prims.bool",
"FStar.Heap.trivial_preorder",
"Options.save_hashes"
] | [] | false | true | false | false | false | let get_save_hashes () =
| !save_hashes | false |
Options.fst | Options.make_includes | val make_includes : unit -> ML string | val make_includes : unit -> ML string | let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 8,
"end_line": 548,
"start_col": 0,
"start_line": 538
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.string | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.List.Tot.Base.fold_left",
"Prims.string",
"FStar.Printf.sprintf",
"Prims.list",
"Options.get_add_include"
] | [] | false | true | false | false | false | let make_includes () =
| let incs = get_add_include () in
List.Tot.fold_left (fun accu inc -> Printf.sprintf "%s#include %s\n" accu inc) "" incs | false |
Options.fst | Options.get_skip_deps | val get_skip_deps : unit -> ML bool | val get_skip_deps : unit -> ML bool | let get_skip_deps _ =
!skip_deps | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 12,
"end_line": 495,
"start_col": 0,
"start_line": 494
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"Prims.bool",
"FStar.Heap.trivial_preorder",
"Options.skip_deps"
] | [] | false | true | false | false | false | let get_skip_deps _ =
| !skip_deps | false |
Options.fst | Options.get_json | val get_json : unit -> ML bool | val get_json : unit -> ML bool | let get_json () =
!json | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 7,
"end_line": 512,
"start_col": 0,
"start_line": 511
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"Prims.bool",
"FStar.Heap.trivial_preorder",
"Options.json"
] | [] | false | true | false | false | false | let get_json () =
| !json | false |
Options.fst | Options.get_emit_output_types_defs | val get_emit_output_types_defs : unit -> ML bool | val get_emit_output_types_defs : unit -> ML bool | let get_emit_output_types_defs () = !emit_output_types_defs | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 59,
"end_line": 528,
"start_col": 0,
"start_line": 528
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ()) | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"Prims.bool",
"FStar.Heap.trivial_preorder",
"Options.emit_output_types_defs"
] | [] | false | true | false | false | false | let get_emit_output_types_defs () =
| !emit_output_types_defs | false |
Options.fst | Options.cmd_option_name | val cmd_option_name (a: cmd_option) : Tot string | val cmd_option_name (a: cmd_option) : Tot string | let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name' | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 12,
"end_line": 175,
"start_col": 0,
"start_line": 171
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Options.cmd_option -> Prims.string | Prims.Tot | [
"total"
] | [] | [
"Options.cmd_option",
"FStar.Char.char",
"Prims.string",
"FStar.Getopt.opt_variant",
"Prims.unit",
"Options.cmd_option_kind",
"Prims.list"
] | [] | false | false | false | true | false | let cmd_option_name (a: cmd_option) : Tot string =
| match a with | CmdFStarOption ((_, name', _), _) | CmdOption name' _ _ _ -> name' | false |
Options.fst | Options.get_emit_smt_encoding | val get_emit_smt_encoding: unit -> ML bool | val get_emit_smt_encoding: unit -> ML bool | let get_emit_smt_encoding () =
!emit_smt_encoding | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 20,
"end_line": 556,
"start_col": 0,
"start_line": 555
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs
let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config") | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"Prims.bool",
"FStar.Heap.trivial_preorder",
"Options.emit_smt_encoding"
] | [] | false | true | false | false | false | let get_emit_smt_encoding () =
| !emit_smt_encoding | false |
Options.fst | Options.find_cmd_option | val find_cmd_option (name: string) (l: list cmd_option) : Tot (option cmd_option) | val find_cmd_option (name: string) (l: list cmd_option) : Tot (option cmd_option) | let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 71,
"end_line": 180,
"start_col": 0,
"start_line": 177
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name' | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | name: Prims.string -> l: Prims.list Options.cmd_option
-> FStar.Pervasives.Native.option Options.cmd_option | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Prims.list",
"Options.cmd_option",
"FStar.Pervasives.Native.None",
"Prims.op_Equality",
"Options.cmd_option_name",
"FStar.Pervasives.Native.Some",
"Prims.bool",
"Options.find_cmd_option",
"FStar.Pervasives.Native.option"
] | [
"recursion"
] | false | false | false | true | false | let rec find_cmd_option (name: string) (l: list cmd_option) : Tot (option cmd_option) =
| match l with
| [] -> None
| a :: q -> if name = cmd_option_name a then Some a else find_cmd_option name q | false |
Options.fst | Options.get_arg0 | val get_arg0: Prims.unit -> ML string | val get_arg0: Prims.unit -> ML string | let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 15,
"end_line": 332,
"start_col": 0,
"start_line": 329
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.string | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"Options.vstring",
"Prims.string",
"FStar.Pervasives.Native.option",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.arg0"
] | [] | false | true | false | false | false | let get_arg0 () : ML string =
| match !arg0 with
| None -> "3d"
| Some v -> v | false |
Options.fst | Options.set_implies | val set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit | val set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit | let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 11,
"end_line": 210,
"start_col": 0,
"start_line": 203
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | options: FStar.ST.ref (Prims.list Options.cmd_option) -> implies: Prims.list Prims.string
-> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"FStar.ST.ref",
"Prims.list",
"Options.cmd_option",
"Prims.string",
"FStar.List.iter",
"Prims.bool",
"FStar.ST.op_Colon_Equals",
"FStar.Heap.trivial_preorder",
"Prims.unit",
"FStar.Pervasives.Native.option",
"Options.find_cmd_option",
"FStar.ST.op_Bang"
] | [] | false | true | false | false | false | let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
| List.iter (fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ())
implies | false |
Options.fst | Options.cmd_option_description | val cmd_option_description (a: cmd_option) : Tot string | val cmd_option_description (a: cmd_option) : Tot string | let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 8,
"end_line": 186,
"start_col": 0,
"start_line": 182
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Options.cmd_option -> Prims.string | Prims.Tot | [
"total"
] | [] | [
"Options.cmd_option",
"Prims.string",
"Options.cmd_option_kind",
"Prims.list",
"FStar.Getopt.opt"
] | [] | false | false | false | true | false | let cmd_option_description (a: cmd_option) : Tot string =
| match a with | CmdOption _ _ desc _ | CmdFStarOption (_, desc) -> desc | false |
Options.fst | Options.get_z3_neg_test | val get_z3_neg_test: unit -> ML bool | val get_z3_neg_test: unit -> ML bool | let get_z3_neg_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "pos" -> false
| _ -> true | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 572,
"start_col": 0,
"start_line": 567
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs
let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config")
let get_emit_smt_encoding () =
!emit_smt_encoding
let get_z3_test () = !z3_test
let get_z3_pos_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "neg" -> false
| _ -> true | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"Prims.bool",
"FStar.Pervasives.Native.option",
"Options.vstring",
"Options.valid_string",
"Options.valid_z3_test_mode",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.z3_test_mode",
"Options.z3_test"
] | [] | false | true | false | false | false | let get_z3_neg_test () =
| match !z3_test with
| None -> false
| _ ->
match !z3_test_mode with
| Some "pos" -> false
| _ -> true | false |
Options.fst | Options.get_debug | val get_debug: unit -> ML bool | val get_debug: unit -> ML bool | let get_debug _ = !debug | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 24,
"end_line": 586,
"start_col": 0,
"start_line": 586
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs
let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config")
let get_emit_smt_encoding () =
!emit_smt_encoding
let get_z3_test () = !z3_test
let get_z3_pos_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "neg" -> false
| _ -> true
let get_z3_neg_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "pos" -> false
| _ -> true
let get_z3_witnesses () =
match !z3_witnesses with
| None -> 1
| Some s ->
try
let n = OS.int_of_string s in
if n < 1 then (1 <: pos) else begin
assert (n >= 1);
(n <: pos)
end
with _ -> 1 | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"Prims.bool",
"FStar.Heap.trivial_preorder",
"Options.debug"
] | [] | false | true | false | false | false | let get_debug _ =
| !debug | false |
Options.fst | Options.string_starts_with | val string_starts_with (big small: string) : Tot bool | val string_starts_with (big small: string) : Tot bool | let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 41,
"end_line": 216,
"start_col": 0,
"start_line": 212
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | big: Prims.string -> small: Prims.string -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Prims.op_LessThan",
"FStar.String.length",
"Prims.bool",
"Prims.op_Equality",
"FStar.String.sub",
"Prims.nat"
] | [] | false | false | false | true | false | let string_starts_with (big small: string) : Tot bool =
| let small_len = String.length small in
if String.length big < small_len then false else String.sub big 0 small_len = small | false |
Options.fst | Options.fstar_options_of_cmd_option | val fstar_options_of_cmd_option (options: ref (list cmd_option)) (o: cmd_option)
: Tot (list fstar_opt) | val fstar_options_of_cmd_option (options: ref (list cmd_option)) (o: cmd_option)
: Tot (list fstar_opt) | let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 7,
"end_line": 288,
"start_col": 0,
"start_line": 227
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not" | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | options: FStar.ST.ref (Prims.list Options.cmd_option) -> o: Options.cmd_option
-> Prims.list Options.fstar_opt | Prims.Tot | [
"total"
] | [] | [
"FStar.ST.ref",
"Prims.list",
"Options.cmd_option",
"Options.fstar_opt",
"Prims.Cons",
"Prims.Nil",
"Prims.string",
"Options.cmd_option_kind",
"Prims.bool",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Getopt.opt",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Char.char",
"FStar.Getopt.opt_variant",
"Prims.unit",
"FStar.Getopt.noshort",
"FStar.Getopt.ZeroArgs",
"FStar.ST.op_Colon_Equals",
"FStar.Heap.trivial_preorder",
"Options.set_implies",
"Options.negate_name",
"Options.negate_description",
"FStar.Pervasives.Native.option",
"Options.valid_string",
"FStar.Getopt.OneArg",
"FStar.Pervasives.Native.Some",
"FStar.All.failwith",
"FStar.Printf.sprintf",
"FStar.Pervasives.Native.None",
"FStar.ST.op_Bang"
] | [] | false | false | false | true | false | let fstar_options_of_cmd_option (options: ref (list cmd_option)) (o: cmd_option)
: Tot (list fstar_opt) =
| match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
match kind with
| OptBool v ->
[
((FStar.Getopt.noshort,
name,
FStar.Getopt.ZeroArgs
(fun _ ->
set_implies options implies;
v := true)),
desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)),
negate_description desc)
]
| OptStringOption arg_desc valid v ->
[
((FStar.Getopt.noshort,
name,
FStar.Getopt.OneArg
((fun (x: string) ->
if valid x
then
(set_implies options implies;
v := Some x)
else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc
)),
arg_desc)),
desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)),
negate_description desc)
]
| OptList arg_desc valid v ->
[
((FStar.Getopt.noshort,
name,
FStar.Getopt.OneArg
((fun (x: string) ->
if valid x
then
(set_implies options implies;
v := x :: !v)
else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc
)),
arg_desc)),
desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := [])), desc)
] | false |
Options.fst | Options.negate_string_gen | val negate_string_gen : s: Prims.string -> negation: Prims.string -> Prims.string | let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 19,
"end_line": 221,
"start_col": 0,
"start_line": 218
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.string -> negation: Prims.string -> Prims.string | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Options.string_starts_with",
"FStar.String.sub",
"FStar.String.length",
"Prims.op_Subtraction",
"Prims.bool",
"Prims.op_Hat"
] | [] | false | false | false | true | false | let negate_string_gen (s negation: string) =
| if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s | false |
|
Options.fst | Options.parse_cmd_line | val parse_cmd_line : unit -> ML (list string) | val parse_cmd_line : unit -> ML (list string) | let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2 | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 15,
"end_line": 413,
"start_col": 0,
"start_line": 406
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2 | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (Prims.list Prims.string) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"Prims.list",
"Prims.string",
"FStar.Heap.trivial_preorder",
"Options.input_file",
"FStar.All.exit",
"Options.display_usage",
"FStar.IO.print_string",
"FStar.Getopt.parse_cmdline_res",
"FStar.Getopt.parse_cmdline",
"FStar.List.Tot.Base.map",
"Options.fstar_opt",
"FStar.Getopt.opt",
"FStar.Pervasives.Native.fst",
"Options.fstar_options",
"FStar.Getopt.Success",
"FStar.ST.op_Colon_Equals",
"Prims.Cons"
] | [] | false | true | false | false | false | let parse_cmd_line () : ML (list string) =
| let open FStar.Getopt in
let res =
FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options)
(fun file ->
input_file := file :: !input_file;
Success)
in
match res with
| Success -> !input_file
| Help ->
display_usage ();
exit 0
| Error s ->
FStar.IO.print_string s;
exit 1
| _ -> exit 2 | false |
Options.fst | Options.get_module_name | val get_module_name (file: string) : ML string | val get_module_name (file: string) : ML string | let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file) | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 83,
"end_line": 429,
"start_col": 0,
"start_line": 423
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d" | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | file: Prims.string -> FStar.All.ML Prims.string | FStar.All.ML | [
"ml"
] | [] | [
"Prims.string",
"Options.split_3d_file_name",
"Options.starts_with_capital",
"Prims.bool",
"FStar.All.failwith",
"FStar.Printf.sprintf"
] | [] | false | true | false | false | false | let get_module_name (file: string) =
| match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file) | false |
LowStar.Lens.fsti | LowStar.Lens.get_t | val get_t : a: Type -> b: Type -> Type | let get_t a b = a -> GTot b | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 65,
"start_col": 0,
"start_line": 65
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> b: Type -> Type | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | true | let get_t a b =
| a -> GTot b | false |
|
Options.fst | Options.cmd_option_arg_desc | val cmd_option_arg_desc (a: cmd_option) : Tot string | val cmd_option_arg_desc (a: cmd_option) : Tot string | let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 7,
"end_line": 201,
"start_col": 0,
"start_line": 188
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Options.cmd_option -> Prims.string | Prims.Tot | [
"total"
] | [] | [
"Options.cmd_option",
"FStar.Char.char",
"Prims.string",
"FStar.Getopt.opt_variant",
"Prims.unit",
"Options.cmd_option_kind",
"Prims.list",
"Prims.bool",
"FStar.ST.ref",
"FStar.Pervasives.Native.option",
"Options.valid_string"
] | [] | false | false | false | true | false | let cmd_option_arg_desc (a: cmd_option) : Tot string =
| match a with
| CmdFStarOption ((_, _, arg), _) ->
(match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> "")
| CmdOption _ kind _ _ ->
match kind with
| OptStringOption argdesc _ _ | OptList argdesc _ _ -> argdesc
| _ -> "" | false |
LowStar.Lens.fsti | LowStar.Lens.put_t | val put_t : a: Type -> b: Type -> Type | let put_t a b = b -> a -> GTot a | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 66,
"start_col": 0,
"start_line": 66
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> b: Type -> Type | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | true | let put_t a b =
| b -> a -> GTot a | false |
|
Options.fst | Options.get_z3_pos_test | val get_z3_pos_test: unit -> ML bool | val get_z3_pos_test: unit -> ML bool | let get_z3_pos_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "neg" -> false
| _ -> true | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 565,
"start_col": 0,
"start_line": 560
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs
let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config")
let get_emit_smt_encoding () =
!emit_smt_encoding
let get_z3_test () = !z3_test | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"Prims.bool",
"FStar.Pervasives.Native.option",
"Options.vstring",
"Options.valid_string",
"Options.valid_z3_test_mode",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.z3_test_mode",
"Options.z3_test"
] | [] | false | true | false | false | false | let get_z3_pos_test () =
| match !z3_test with
| None -> false
| _ ->
match !z3_test_mode with
| Some "neg" -> false
| _ -> true | false |
Options.fst | Options.compute_current_options | val compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string | val compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string | let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 44,
"end_line": 327,
"start_col": 0,
"start_line": 290
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | options: FStar.ST.ref (Prims.list Options.cmd_option) -> ignore: Prims.list Prims.string
-> FStar.All.ML Prims.string | FStar.All.ML | [
"ml"
] | [] | [
"FStar.ST.ref",
"Prims.list",
"Options.cmd_option",
"Prims.string",
"FStar.List.fold_left",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Prims.bool",
"FStar.Printf.sprintf",
"Options.negate_name",
"Prims.op_Negation",
"FStar.List.Tot.Base.mem",
"Options.cmd_option_name",
"Options.cmd_option_kind",
"FStar.Pervasives.Native.option",
"Options.valid_string",
"FStar.List.Tot.Base.fold_left",
"FStar.List.Tot.Base.rev"
] | [] | false | true | false | false | false | let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
| let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
(match kind with
| OptBool v -> if !v then Printf.sprintf "%s --%s" msg name else msg
| OptStringOption _ _ v ->
(match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v)
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v))
| _ -> msg
in
let msg = List.fold_left print "" !options in
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options | false |
LowStar.Lens.fsti | LowStar.Lens.put_get | val put_get : get: LowStar.Lens.get_t 'a 'b -> put: LowStar.Lens.put_t 'a 'b -> Prims.logical | let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 78,
"start_col": 0,
"start_line": 76
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | get: LowStar.Lens.get_t 'a 'b -> put: LowStar.Lens.put_t 'a 'b -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"LowStar.Lens.get_t",
"LowStar.Lens.put_t",
"Prims.l_Forall",
"Prims.eq2",
"Prims.logical"
] | [] | false | false | false | true | true | let put_get (get: get_t 'a 'b) (put: put_t 'a 'b) =
| forall (a: 'a). {:pattern (put (get a) a)} put (get a) a == a | false |
|
LowStar.Lens.fsti | LowStar.Lens.get | val get (l: lens 'a 'b) (x: 'a) : GTot 'b | val get (l: lens 'a 'b) (x: 'a) : GTot 'b | let get (l:lens 'a 'b) (x:'a) : GTot 'b =
match l with
| {get=get} -> get x | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 102,
"start_col": 0,
"start_line": 100
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a
/// `put_put`: Another law for eliminating redundant writes
let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a
/// `lens`: A triple of a `get`, `put` and the laws
///
/// Note, so far, we only require the `get_put` law
noeq
type lens 'a 'b = {
get: get_t 'a 'b;
put: put_t 'a 'b;
lens_laws: squash (
get_put get put // /\
// put_get get put /\
// put_put get put
)
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: LowStar.Lens.lens 'a 'b -> x: 'a -> Prims.GTot 'b | Prims.GTot | [
"sometrivial"
] | [] | [
"LowStar.Lens.lens",
"LowStar.Lens.get_t",
"LowStar.Lens.put_t",
"Prims.squash",
"LowStar.Lens.get_put"
] | [] | false | false | false | false | false | let get (l: lens 'a 'b) (x: 'a) : GTot 'b =
| match l with | { get = get } -> get x | false |
LowStar.Lens.fsti | LowStar.Lens.get_put | val get_put : get: LowStar.Lens.get_t 'a 'b -> put: LowStar.Lens.put_t 'a 'b -> Prims.logical | let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 72,
"start_col": 0,
"start_line": 70
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | get: LowStar.Lens.get_t 'a 'b -> put: LowStar.Lens.put_t 'a 'b -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"LowStar.Lens.get_t",
"LowStar.Lens.put_t",
"Prims.l_Forall",
"Prims.eq2",
"Prims.logical"
] | [] | false | false | false | true | true | let get_put (get: get_t 'a 'b) (put: put_t 'a 'b) =
| forall (a: 'a) (b: 'b). {:pattern (get (put b a))} get (put b a) == b | false |
|
LowStar.Lens.fsti | LowStar.Lens.put | val put (l: lens 'a 'b) (x: 'a) (y: 'b) : GTot 'a | val put (l: lens 'a 'b) (x: 'a) (y: 'b) : GTot 'a | let put (l:lens 'a 'b) (x:'a) (y:'b) : GTot 'a =
match l with
| {put=put} -> put y x | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 107,
"start_col": 0,
"start_line": 105
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a
/// `put_put`: Another law for eliminating redundant writes
let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a
/// `lens`: A triple of a `get`, `put` and the laws
///
/// Note, so far, we only require the `get_put` law
noeq
type lens 'a 'b = {
get: get_t 'a 'b;
put: put_t 'a 'b;
lens_laws: squash (
get_put get put // /\
// put_get get put /\
// put_put get put
)
}
unfold
let get (l:lens 'a 'b) (x:'a) : GTot 'b =
match l with
| {get=get} -> get x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: LowStar.Lens.lens 'a 'b -> x: 'a -> y: 'b -> Prims.GTot 'a | Prims.GTot | [
"sometrivial"
] | [] | [
"LowStar.Lens.lens",
"LowStar.Lens.get_t",
"LowStar.Lens.put_t",
"Prims.squash",
"LowStar.Lens.get_put"
] | [] | false | false | false | false | false | let put (l: lens 'a 'b) (x: 'a) (y: 'b) : GTot 'a =
| match l with | { put = put } -> put y x | false |
LowStar.Lens.fsti | LowStar.Lens.eloc | val eloc : Type0 | let eloc = Ghost.erased B.loc | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 118,
"start_col": 0,
"start_line": 118
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a
/// `put_put`: Another law for eliminating redundant writes
let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a
/// `lens`: A triple of a `get`, `put` and the laws
///
/// Note, so far, we only require the `get_put` law
noeq
type lens 'a 'b = {
get: get_t 'a 'b;
put: put_t 'a 'b;
lens_laws: squash (
get_put get put // /\
// put_get get put /\
// put_put get put
)
}
unfold
let get (l:lens 'a 'b) (x:'a) : GTot 'b =
match l with
| {get=get} -> get x
unfold
let put (l:lens 'a 'b) (x:'a) (y:'b) : GTot 'a =
match l with
| {put=put} -> put y x
(* Now, we work towards defining `hs_lens`, a lens on hyperstacks *)
/// `imem inv`:
///
/// A refinement of hyperstacks satisifying the invariant `inv`
/// We will mainly use lenses between `imem inv` and some type `a`
let imem inv = m:HS.mem{inv m} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"LowStar.Monotonic.Buffer.loc"
] | [] | false | false | false | true | true | let eloc =
| Ghost.erased B.loc | false |
|
LowStar.Lens.fsti | LowStar.Lens.put_put | val put_put : get: LowStar.Lens.get_t 'a 'b -> put: LowStar.Lens.put_t 'a 'b -> Prims.logical | let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 83,
"start_col": 0,
"start_line": 81
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | get: LowStar.Lens.get_t 'a 'b -> put: LowStar.Lens.put_t 'a 'b -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"LowStar.Lens.get_t",
"LowStar.Lens.put_t",
"Prims.l_Forall",
"Prims.eq2",
"Prims.logical"
] | [] | false | false | false | true | true | let put_put (get: get_t 'a 'b) (put: put_t 'a 'b) =
| forall (a: 'a) (b1: 'b) (b2: 'b). {:pattern (put b2 (put b1 a))} put b2 (put b1 a) == put b2 a | false |
|
Options.fst | Options.get_output_dir | val get_output_dir : unit -> ML string | val get_output_dir : unit -> ML string | let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 15,
"end_line": 434,
"start_col": 0,
"start_line": 431
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file) | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.string | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"Options.vstring",
"Prims.string",
"FStar.Pervasives.Native.option",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.output_dir"
] | [] | false | true | false | false | false | let get_output_dir () =
| match !output_dir with
| None -> "."
| Some s -> s | false |
Options.fst | Options.get_equate_types_list | val get_equate_types_list : unit -> ML (list (string & string)) | val get_equate_types_list : unit -> ML (list (string & string)) | let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 22,
"end_line": 480,
"start_col": 0,
"start_line": 475
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (Prims.list (Prims.string * Prims.string)) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.List.map",
"Options.valid_string",
"Options.valid_equate_types",
"FStar.Pervasives.Native.tuple2",
"Prims.string",
"FStar.Pervasives.Native.Mktuple2",
"Prims.list",
"FStar.String.split",
"Prims.Cons",
"FStar.String.char",
"Prims.Nil",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.equate_types_list"
] | [] | false | true | false | false | false | let get_equate_types_list () =
| List.map (fun (x: valid_string valid_equate_types) ->
let [a ; b] = String.split [','] x in
(a, b))
!equate_types_list | false |
LowParse.SLow.DER.fst | LowParse.SLow.DER.size32_bounded_der_length32 | val size32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (size32 (serialize_bounded_der_length32 (vmin) (vmax))) | val size32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (size32 (serialize_bounded_der_length32 (vmin) (vmax))) | let size32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
: Tot (size32 (serialize_bounded_der_length32 (vmin) (vmax)))
= fun (y' : bounded_int32 (vmin) (vmax)) -> ((
[@inline_let]
let _ = serialize_bounded_der_length32_size (vmin) (vmax) y' in
if y' `U32.lt` 128ul
then 1ul
else if y' `U32.lt` 256ul
then 2ul
else if y' `U32.lt` 65536ul
then 3ul
else if y' `U32.lt` 16777216ul
then 4ul
else 5ul
) <: (res: _ { size32_postcond (serialize_bounded_der_length32 (vmin) (vmax)) y' res } )) | {
"file_name": "src/lowparse/LowParse.SLow.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 91,
"end_line": 147,
"start_col": 0,
"start_line": 131
} | module LowParse.SLow.DER
include LowParse.Spec.DER
include LowParse.SLow.Combinators
include LowParse.SLow.Int // for parse32_u8
include LowParse.SLow.BoundedInt // for bounded_integer
open FStar.Mul
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
module Math = LowParse.Math
module B32 = LowParse.Bytes32
module Cast = FStar.Int.Cast
#reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0"
#push-options "--z3rlimit 16"
inline_for_extraction
let parse32_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (parser32 (parse_der_length_payload32 x))
= fun (input: bytes32) -> ((
[@inline_let] let _ =
parse_der_length_payload32_unfold x (B32.reveal input);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then Some (Cast.uint8_to_uint32 x, 0ul)
else if x = 128uy || x = 255uy
then None
else if x = 129uy
then
match parse32_u8 input with
| None -> None
| Some (z, consumed) ->
if z `U8.lt` 128uy
then None
else Some ((Cast.uint8_to_uint32 z <: refine_with_tag tag_of_der_length32 x), consumed)
else
let len = x `U8.sub` 128uy in
if len = 2uy
then
match parse32_bounded_integer 2 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt `256ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
else if len = 3uy
then
match parse32_bounded_integer 3 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt `65536ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
else
match parse32_bounded_integer 4 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt` 16777216ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
) <: (res: _ { parser32_correct (parse_der_length_payload32 x) input res } ))
#push-options "--max_ifuel 2"
inline_for_extraction
let parse32_bounded_der_length32
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
: Tot (
parser32 (parse_bounded_der_length32 vmin vmax))
= [@inline_let] let _ = assert_norm (4294967296 <= der_length_max) in
fun (input: bytes32) -> ((
[@inline_let]
let _ =
parse_bounded_der_length32_unfold (U32.v min) (U32.v max) (B32.reveal input)
in
match parse32_u8 input with
| None -> None
| Some (x, consumed_x) ->
let len = der_length_payload_size_of_tag8 x in
let tg1 = (tag_of_der_length32_impl min) in
let l1 = der_length_payload_size_of_tag8 tg1 in
let tg2 = (tag_of_der_length32_impl max) in
let l2 = der_length_payload_size_of_tag8 tg2 in
if len `U8.lt` l1 || l2 `U8.lt` len
then None
else begin
let input' = B32.slice input consumed_x (B32.len input) in
match parse32_der_length_payload32 x input' with
| Some (y, consumed_y) ->
if y `U32.lt` min || max `U32.lt` y
then None
else Some (y, consumed_x `U32.add` consumed_y)
| None -> None
end
) <: (res : _ { parser32_correct (parse_bounded_der_length32 (U32.v min) (U32.v max)) input res } ))
#pop-options
inline_for_extraction
let serialize32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
: Tot (serializer32 (serialize_bounded_der_length32 (vmin) (vmax)))
= fun (y' : bounded_int32 (vmin) (vmax)) -> ((
[@inline_let]
let _ = serialize_bounded_der_length32_unfold (vmin) (vmax) y' in
let x = tag_of_der_length32_impl y' in
let sx = B32.create 1ul x in
if x `U8.lt` 128uy
then sx
else if x = 129uy
then sx `B32.b32append` B32.create 1ul (Cast.uint32_to_uint8 y')
else if x = 130uy
then sx `B32.b32append` serialize32_bounded_integer_2 y'
else if x = 131uy
then sx `B32.b32append` serialize32_bounded_integer_3 y'
else sx `B32.b32append` serialize32_bounded_integer_4 y'
) <: (res: _ { serializer32_correct (serialize_bounded_der_length32 (vmin) (vmax)) y' res } )) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.DER.fsti.checked",
"LowParse.SLow.Int.fsti.checked",
"LowParse.SLow.Combinators.fst.checked",
"LowParse.SLow.BoundedInt.fsti.checked",
"LowParse.Math.fst.checked",
"LowParse.Bytes32.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.DER.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowParse.Bytes32",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.DER",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
vmax: LowParse.Spec.DER.der_length_t{vmin <= vmax /\ vmax < 4294967296}
-> LowParse.SLow.Base.size32 (LowParse.Spec.DER.serialize_bounded_der_length32 vmin vmax) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.BoundedInt.bounded_int32",
"FStar.UInt32.lt",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"FStar.UInt32.t",
"LowParse.SLow.Base.size32_postcond",
"LowParse.Spec.DER.parse_bounded_der_length32_kind",
"LowParse.Spec.DER.parse_bounded_der_length32",
"LowParse.Spec.DER.serialize_bounded_der_length32",
"Prims.unit",
"LowParse.Spec.DER.serialize_bounded_der_length32_size",
"LowParse.SLow.Base.size32"
] | [] | false | false | false | false | false | let size32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (size32 (serialize_bounded_der_length32 (vmin) (vmax))) =
| fun (y': bounded_int32 (vmin) (vmax)) ->
(([@@ inline_let ]let _ = serialize_bounded_der_length32_size (vmin) (vmax) y' in
if y' `U32.lt` 128ul
then 1ul
else
if y' `U32.lt` 256ul
then 2ul
else if y' `U32.lt` 65536ul then 3ul else if y' `U32.lt` 16777216ul then 4ul else 5ul)
<:
(res: _{size32_postcond (serialize_bounded_der_length32 (vmin) (vmax)) y' res})) | false |
Options.fst | Options.get_config_file | val get_config_file : unit -> ML (option string) | val get_config_file : unit -> ML (option string) | let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 20,
"end_line": 533,
"start_col": 0,
"start_line": 530
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (FStar.Pervasives.Native.option Prims.string) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.Pervasives.Native.None",
"Prims.string",
"Options.valid_string",
"Options.check_config_file_name",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.option",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.config_file"
] | [] | false | true | false | false | false | let get_config_file () =
| match !config_file with
| None -> None
| Some s -> Some s | false |
LowStar.Lens.fsti | LowStar.Lens.imem | val imem : inv: (_: FStar.Monotonic.HyperStack.mem -> Type) -> Type | let imem inv = m:HS.mem{inv m} | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 30,
"end_line": 115,
"start_col": 0,
"start_line": 115
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a
/// `put_put`: Another law for eliminating redundant writes
let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a
/// `lens`: A triple of a `get`, `put` and the laws
///
/// Note, so far, we only require the `get_put` law
noeq
type lens 'a 'b = {
get: get_t 'a 'b;
put: put_t 'a 'b;
lens_laws: squash (
get_put get put // /\
// put_get get put /\
// put_put get put
)
}
unfold
let get (l:lens 'a 'b) (x:'a) : GTot 'b =
match l with
| {get=get} -> get x
unfold
let put (l:lens 'a 'b) (x:'a) (y:'b) : GTot 'a =
match l with
| {put=put} -> put y x
(* Now, we work towards defining `hs_lens`, a lens on hyperstacks *)
/// `imem inv`:
///
/// A refinement of hyperstacks satisifying the invariant `inv` | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | inv: (_: FStar.Monotonic.HyperStack.mem -> Type) -> Type | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem"
] | [] | false | false | false | true | true | let imem inv =
| m: HS.mem{inv m} | false |
|
Options.fst | Options.get_check_inplace_hashes | val get_check_inplace_hashes : unit -> ML (list string) | val get_check_inplace_hashes : unit -> ML (list string) | let get_check_inplace_hashes () =
List.rev !inplace_hashes | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 26,
"end_line": 473,
"start_col": 0,
"start_line": 472
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (Prims.list Prims.string) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.List.Tot.Base.rev",
"Options.vstring",
"Prims.list",
"Prims.string",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.inplace_hashes"
] | [] | false | true | false | false | false | let get_check_inplace_hashes () =
| List.rev !inplace_hashes | false |
Options.fst | Options.get_clang_format_executable | val get_clang_format_executable : unit -> ML string | val get_clang_format_executable : unit -> ML string | let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 15,
"end_line": 450,
"start_col": 0,
"start_line": 447
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.string | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"Options.vstring",
"Prims.string",
"FStar.Pervasives.Native.option",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.clang_format_executable"
] | [] | false | true | false | false | false | let get_clang_format_executable () =
| match !clang_format_executable with
| None -> ""
| Some s -> s | false |
LowStar.Lens.fsti | LowStar.Lens.get_reads_loc | val get_reads_loc : el: LowStar.Lens.eloc -> get: LowStar.Lens.get_t (LowStar.Lens.imem inv) b -> Prims.logical | let get_reads_loc #b #inv (el:eloc) (get:get_t (imem inv) b) =
forall (h0 h1:imem inv) loc. {:pattern (B.modifies loc h0 h1); (get h1)}
B.loc_disjoint (as_loc el) loc /\
B.modifies loc h0 h1 ==>
get h0 == get h1 | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 134,
"start_col": 0,
"start_line": 130
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a
/// `put_put`: Another law for eliminating redundant writes
let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a
/// `lens`: A triple of a `get`, `put` and the laws
///
/// Note, so far, we only require the `get_put` law
noeq
type lens 'a 'b = {
get: get_t 'a 'b;
put: put_t 'a 'b;
lens_laws: squash (
get_put get put // /\
// put_get get put /\
// put_put get put
)
}
unfold
let get (l:lens 'a 'b) (x:'a) : GTot 'b =
match l with
| {get=get} -> get x
unfold
let put (l:lens 'a 'b) (x:'a) (y:'b) : GTot 'a =
match l with
| {put=put} -> put y x
(* Now, we work towards defining `hs_lens`, a lens on hyperstacks *)
/// `imem inv`:
///
/// A refinement of hyperstacks satisifying the invariant `inv`
/// We will mainly use lenses between `imem inv` and some type `a`
let imem inv = m:HS.mem{inv m}
/// `eloc` : A convenient abbreviation for an erased location
let eloc = Ghost.erased B.loc
/// `as_loc`: Coercing an `eloc` to a `loc`
let as_loc (x:eloc) : GTot B.loc = Ghost.reveal x
(* Rather than the lens laws, more useful in the Low* setting are laws
that describe the action of `get` and `put` in terms of existing
Low* concepts, e.g., footprints in terms of `loc`; modifies clauses
etc. *)
/// `get_reads_loc el get`: States that `get` only depends on the `el` | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | el: LowStar.Lens.eloc -> get: LowStar.Lens.get_t (LowStar.Lens.imem inv) b -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"LowStar.Lens.eloc",
"LowStar.Lens.get_t",
"LowStar.Lens.imem",
"Prims.l_Forall",
"LowStar.Monotonic.Buffer.loc",
"Prims.l_imp",
"Prims.l_and",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowStar.Lens.as_loc",
"LowStar.Monotonic.Buffer.modifies",
"Prims.eq2",
"Prims.logical"
] | [] | false | false | false | false | true | let get_reads_loc #b #inv (el: eloc) (get: get_t (imem inv) b) =
| forall (h0: imem inv) (h1: imem inv) loc. {:pattern (B.modifies loc h0 h1); (get h1)}
B.loc_disjoint (as_loc el) loc /\ B.modifies loc h0 h1 ==> get h0 == get h1 | false |
|
LowStar.Lens.fsti | LowStar.Lens.imem_lens | val imem_lens : inv: (_: FStar.Monotonic.HyperStack.mem -> Type0) -> b: Type -> loc: LowStar.Lens.eloc -> Type | let imem_lens inv b loc =
l:lens (imem inv) b {
get_reads_loc loc l.get /\
put_modifies_loc loc l.put /\
invariant_reads_loc inv loc
} | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 158,
"start_col": 0,
"start_line": 153
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a
/// `put_put`: Another law for eliminating redundant writes
let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a
/// `lens`: A triple of a `get`, `put` and the laws
///
/// Note, so far, we only require the `get_put` law
noeq
type lens 'a 'b = {
get: get_t 'a 'b;
put: put_t 'a 'b;
lens_laws: squash (
get_put get put // /\
// put_get get put /\
// put_put get put
)
}
unfold
let get (l:lens 'a 'b) (x:'a) : GTot 'b =
match l with
| {get=get} -> get x
unfold
let put (l:lens 'a 'b) (x:'a) (y:'b) : GTot 'a =
match l with
| {put=put} -> put y x
(* Now, we work towards defining `hs_lens`, a lens on hyperstacks *)
/// `imem inv`:
///
/// A refinement of hyperstacks satisifying the invariant `inv`
/// We will mainly use lenses between `imem inv` and some type `a`
let imem inv = m:HS.mem{inv m}
/// `eloc` : A convenient abbreviation for an erased location
let eloc = Ghost.erased B.loc
/// `as_loc`: Coercing an `eloc` to a `loc`
let as_loc (x:eloc) : GTot B.loc = Ghost.reveal x
(* Rather than the lens laws, more useful in the Low* setting are laws
that describe the action of `get` and `put` in terms of existing
Low* concepts, e.g., footprints in terms of `loc`; modifies clauses
etc. *)
/// `get_reads_loc el get`: States that `get` only depends on the `el`
/// fragment of a hyperstack
let get_reads_loc #b #inv (el:eloc) (get:get_t (imem inv) b) =
forall (h0 h1:imem inv) loc. {:pattern (B.modifies loc h0 h1); (get h1)}
B.loc_disjoint (as_loc el) loc /\
B.modifies loc h0 h1 ==>
get h0 == get h1
/// `put_modifies_loc el put`: States that `put` only mutates the `el`
/// fragment of a hyperstack
let put_modifies_loc #b #inv (el:eloc) (put:put_t (imem inv) b) =
forall (h0:imem inv) (v:b).{:pattern (put v h0)}
B.modifies (as_loc el) h0 (put v h0)
/// `invariant_reads_loc el inv`: States that the invariant `inv`
/// only depends on the `el` fragment of a hyperstack
let invariant_reads_loc inv (el:eloc) =
forall h0 h1 loc.{:pattern (B.modifies loc h0 h1); (inv h1)}
inv h0 /\
B.loc_disjoint (as_loc el) loc /\
B.modifies loc h0 h1 ==>
inv h1
/// `imem_lens inv b loc` is a lens between an `imem inv` and `b` | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | inv: (_: FStar.Monotonic.HyperStack.mem -> Type0) -> b: Type -> loc: LowStar.Lens.eloc -> Type | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"LowStar.Lens.eloc",
"LowStar.Lens.lens",
"LowStar.Lens.imem",
"Prims.l_and",
"LowStar.Lens.get_reads_loc",
"LowStar.Lens.__proj__Mklens__item__get",
"LowStar.Lens.put_modifies_loc",
"LowStar.Lens.__proj__Mklens__item__put",
"LowStar.Lens.invariant_reads_loc"
] | [] | false | false | false | true | true | let imem_lens inv b loc =
| l:
lens (imem inv) b
{get_reads_loc loc l.get /\ put_modifies_loc loc l.put /\ invariant_reads_loc inv loc} | false |
|
LowStar.Lens.fsti | LowStar.Lens.invariant_reads_loc | val invariant_reads_loc : inv: (_: FStar.Monotonic.HyperStack.mem -> Prims.logical) -> el: LowStar.Lens.eloc -> Prims.logical | let invariant_reads_loc inv (el:eloc) =
forall h0 h1 loc.{:pattern (B.modifies loc h0 h1); (inv h1)}
inv h0 /\
B.loc_disjoint (as_loc el) loc /\
B.modifies loc h0 h1 ==>
inv h1 | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 10,
"end_line": 149,
"start_col": 0,
"start_line": 144
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a
/// `put_put`: Another law for eliminating redundant writes
let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a
/// `lens`: A triple of a `get`, `put` and the laws
///
/// Note, so far, we only require the `get_put` law
noeq
type lens 'a 'b = {
get: get_t 'a 'b;
put: put_t 'a 'b;
lens_laws: squash (
get_put get put // /\
// put_get get put /\
// put_put get put
)
}
unfold
let get (l:lens 'a 'b) (x:'a) : GTot 'b =
match l with
| {get=get} -> get x
unfold
let put (l:lens 'a 'b) (x:'a) (y:'b) : GTot 'a =
match l with
| {put=put} -> put y x
(* Now, we work towards defining `hs_lens`, a lens on hyperstacks *)
/// `imem inv`:
///
/// A refinement of hyperstacks satisifying the invariant `inv`
/// We will mainly use lenses between `imem inv` and some type `a`
let imem inv = m:HS.mem{inv m}
/// `eloc` : A convenient abbreviation for an erased location
let eloc = Ghost.erased B.loc
/// `as_loc`: Coercing an `eloc` to a `loc`
let as_loc (x:eloc) : GTot B.loc = Ghost.reveal x
(* Rather than the lens laws, more useful in the Low* setting are laws
that describe the action of `get` and `put` in terms of existing
Low* concepts, e.g., footprints in terms of `loc`; modifies clauses
etc. *)
/// `get_reads_loc el get`: States that `get` only depends on the `el`
/// fragment of a hyperstack
let get_reads_loc #b #inv (el:eloc) (get:get_t (imem inv) b) =
forall (h0 h1:imem inv) loc. {:pattern (B.modifies loc h0 h1); (get h1)}
B.loc_disjoint (as_loc el) loc /\
B.modifies loc h0 h1 ==>
get h0 == get h1
/// `put_modifies_loc el put`: States that `put` only mutates the `el`
/// fragment of a hyperstack
let put_modifies_loc #b #inv (el:eloc) (put:put_t (imem inv) b) =
forall (h0:imem inv) (v:b).{:pattern (put v h0)}
B.modifies (as_loc el) h0 (put v h0)
/// `invariant_reads_loc el inv`: States that the invariant `inv` | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | inv: (_: FStar.Monotonic.HyperStack.mem -> Prims.logical) -> el: LowStar.Lens.eloc -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.logical",
"LowStar.Lens.eloc",
"Prims.l_Forall",
"LowStar.Monotonic.Buffer.loc",
"Prims.l_imp",
"Prims.l_and",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowStar.Lens.as_loc",
"LowStar.Monotonic.Buffer.modifies"
] | [] | false | false | false | true | true | let invariant_reads_loc inv (el: eloc) =
| forall h0 h1 loc. {:pattern (B.modifies loc h0 h1); (inv h1)}
inv h0 /\ B.loc_disjoint (as_loc el) loc /\ B.modifies loc h0 h1 ==> inv h1 | false |
|
LowStar.Lens.fsti | LowStar.Lens.put_modifies_loc | val put_modifies_loc : el: LowStar.Lens.eloc -> put: LowStar.Lens.put_t (LowStar.Lens.imem inv) b -> Prims.logical | let put_modifies_loc #b #inv (el:eloc) (put:put_t (imem inv) b) =
forall (h0:imem inv) (v:b).{:pattern (put v h0)}
B.modifies (as_loc el) h0 (put v h0) | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 140,
"start_col": 0,
"start_line": 138
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a
/// `put_put`: Another law for eliminating redundant writes
let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a
/// `lens`: A triple of a `get`, `put` and the laws
///
/// Note, so far, we only require the `get_put` law
noeq
type lens 'a 'b = {
get: get_t 'a 'b;
put: put_t 'a 'b;
lens_laws: squash (
get_put get put // /\
// put_get get put /\
// put_put get put
)
}
unfold
let get (l:lens 'a 'b) (x:'a) : GTot 'b =
match l with
| {get=get} -> get x
unfold
let put (l:lens 'a 'b) (x:'a) (y:'b) : GTot 'a =
match l with
| {put=put} -> put y x
(* Now, we work towards defining `hs_lens`, a lens on hyperstacks *)
/// `imem inv`:
///
/// A refinement of hyperstacks satisifying the invariant `inv`
/// We will mainly use lenses between `imem inv` and some type `a`
let imem inv = m:HS.mem{inv m}
/// `eloc` : A convenient abbreviation for an erased location
let eloc = Ghost.erased B.loc
/// `as_loc`: Coercing an `eloc` to a `loc`
let as_loc (x:eloc) : GTot B.loc = Ghost.reveal x
(* Rather than the lens laws, more useful in the Low* setting are laws
that describe the action of `get` and `put` in terms of existing
Low* concepts, e.g., footprints in terms of `loc`; modifies clauses
etc. *)
/// `get_reads_loc el get`: States that `get` only depends on the `el`
/// fragment of a hyperstack
let get_reads_loc #b #inv (el:eloc) (get:get_t (imem inv) b) =
forall (h0 h1:imem inv) loc. {:pattern (B.modifies loc h0 h1); (get h1)}
B.loc_disjoint (as_loc el) loc /\
B.modifies loc h0 h1 ==>
get h0 == get h1
/// `put_modifies_loc el put`: States that `put` only mutates the `el` | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | el: LowStar.Lens.eloc -> put: LowStar.Lens.put_t (LowStar.Lens.imem inv) b -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"LowStar.Lens.eloc",
"LowStar.Lens.put_t",
"LowStar.Lens.imem",
"Prims.l_Forall",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Lens.as_loc",
"Prims.logical"
] | [] | false | false | false | false | true | let put_modifies_loc #b #inv (el: eloc) (put: put_t (imem inv) b) =
| forall (h0: imem inv) (v: b). {:pattern (put v h0)} B.modifies (as_loc el) h0 (put v h0) | false |
|
LowStar.Lens.fsti | LowStar.Lens.as_loc | val as_loc (x: eloc) : GTot B.loc | val as_loc (x: eloc) : GTot B.loc | let as_loc (x:eloc) : GTot B.loc = Ghost.reveal x | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 49,
"end_line": 121,
"start_col": 0,
"start_line": 121
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a
/// `put_put`: Another law for eliminating redundant writes
let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a
/// `lens`: A triple of a `get`, `put` and the laws
///
/// Note, so far, we only require the `get_put` law
noeq
type lens 'a 'b = {
get: get_t 'a 'b;
put: put_t 'a 'b;
lens_laws: squash (
get_put get put // /\
// put_get get put /\
// put_put get put
)
}
unfold
let get (l:lens 'a 'b) (x:'a) : GTot 'b =
match l with
| {get=get} -> get x
unfold
let put (l:lens 'a 'b) (x:'a) (y:'b) : GTot 'a =
match l with
| {put=put} -> put y x
(* Now, we work towards defining `hs_lens`, a lens on hyperstacks *)
/// `imem inv`:
///
/// A refinement of hyperstacks satisifying the invariant `inv`
/// We will mainly use lenses between `imem inv` and some type `a`
let imem inv = m:HS.mem{inv m}
/// `eloc` : A convenient abbreviation for an erased location
let eloc = Ghost.erased B.loc | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: LowStar.Lens.eloc -> Prims.GTot LowStar.Monotonic.Buffer.loc | Prims.GTot | [
"sometrivial"
] | [] | [
"LowStar.Lens.eloc",
"FStar.Ghost.reveal",
"LowStar.Monotonic.Buffer.loc"
] | [] | false | false | false | false | false | let as_loc (x: eloc) : GTot B.loc =
| Ghost.reveal x | false |
Options.fst | Options.get_makefile | val get_makefile : unit -> ML (option makefile_type) | val get_makefile : unit -> ML (option makefile_type) | let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 38,
"end_line": 501,
"start_col": 0,
"start_line": 497
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (FStar.Pervasives.Native.option HashingOptions.makefile_type) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.Pervasives.Native.None",
"HashingOptions.makefile_type",
"FStar.Pervasives.Native.Some",
"HashingOptions.MakefileGMake",
"HashingOptions.MakefileNMake",
"FStar.Pervasives.Native.option",
"Options.valid_string",
"Options.valid_makefile",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.makefile"
] | [] | false | true | false | false | false | let get_makefile _ =
| match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake | false |
Options.fst | Options.get_makefile_name | val get_makefile_name : unit -> ML string | val get_makefile_name : unit -> ML string | let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 17,
"end_line": 506,
"start_col": 0,
"start_line": 503
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.string | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"OS.concat",
"Prims.string",
"Options.get_output_dir",
"Options.vstring",
"FStar.Pervasives.Native.option",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.makefile_name"
] | [] | false | true | false | false | false | let get_makefile_name _ =
| match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf | false |
LowStar.Lens.fsti | LowStar.Lens.snap | val snap (l: hs_lens 'a 'b) (h: imem (l.invariant l.x)) : hs_lens 'a 'b | val snap (l: hs_lens 'a 'b) (h: imem (l.invariant l.x)) : hs_lens 'a 'b | let snap (l:hs_lens 'a 'b) (h:imem (l.invariant l.x))
: hs_lens 'a 'b
= {l with snapshot = h} | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 25,
"end_line": 188,
"start_col": 0,
"start_line": 186
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a
/// `put_put`: Another law for eliminating redundant writes
let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a
/// `lens`: A triple of a `get`, `put` and the laws
///
/// Note, so far, we only require the `get_put` law
noeq
type lens 'a 'b = {
get: get_t 'a 'b;
put: put_t 'a 'b;
lens_laws: squash (
get_put get put // /\
// put_get get put /\
// put_put get put
)
}
unfold
let get (l:lens 'a 'b) (x:'a) : GTot 'b =
match l with
| {get=get} -> get x
unfold
let put (l:lens 'a 'b) (x:'a) (y:'b) : GTot 'a =
match l with
| {put=put} -> put y x
(* Now, we work towards defining `hs_lens`, a lens on hyperstacks *)
/// `imem inv`:
///
/// A refinement of hyperstacks satisifying the invariant `inv`
/// We will mainly use lenses between `imem inv` and some type `a`
let imem inv = m:HS.mem{inv m}
/// `eloc` : A convenient abbreviation for an erased location
let eloc = Ghost.erased B.loc
/// `as_loc`: Coercing an `eloc` to a `loc`
let as_loc (x:eloc) : GTot B.loc = Ghost.reveal x
(* Rather than the lens laws, more useful in the Low* setting are laws
that describe the action of `get` and `put` in terms of existing
Low* concepts, e.g., footprints in terms of `loc`; modifies clauses
etc. *)
/// `get_reads_loc el get`: States that `get` only depends on the `el`
/// fragment of a hyperstack
let get_reads_loc #b #inv (el:eloc) (get:get_t (imem inv) b) =
forall (h0 h1:imem inv) loc. {:pattern (B.modifies loc h0 h1); (get h1)}
B.loc_disjoint (as_loc el) loc /\
B.modifies loc h0 h1 ==>
get h0 == get h1
/// `put_modifies_loc el put`: States that `put` only mutates the `el`
/// fragment of a hyperstack
let put_modifies_loc #b #inv (el:eloc) (put:put_t (imem inv) b) =
forall (h0:imem inv) (v:b).{:pattern (put v h0)}
B.modifies (as_loc el) h0 (put v h0)
/// `invariant_reads_loc el inv`: States that the invariant `inv`
/// only depends on the `el` fragment of a hyperstack
let invariant_reads_loc inv (el:eloc) =
forall h0 h1 loc.{:pattern (B.modifies loc h0 h1); (inv h1)}
inv h0 /\
B.loc_disjoint (as_loc el) loc /\
B.modifies loc h0 h1 ==>
inv h1
/// `imem_lens inv b loc` is a lens between an `imem inv` and `b`
/// whose footprint is loc
let imem_lens inv b loc =
l:lens (imem inv) b {
get_reads_loc loc l.get /\
put_modifies_loc loc l.put /\
invariant_reads_loc inv loc
}
(* A distinctive feature of the setup here is the encapsulation of
modifies clauses. See the definition of the `RST` effect for more
details on how it is used.
The main idea is that when creating an `hs_lens`, we record within
it a memory snapshot. All state modifications are stated with
respect to this snapshot, rather than relating the pre/post states
of each sub-computation. This frees client programs from reasoning
about the transitive composition of the modifies clauses.
*)
/// `hs_lens a b`:
///
/// Encapsulates an `imem_lens` between a fragment of a hyperstack
/// reachable from `x:a` and its view `b`.
noeq
type hs_lens a b = {
footprint: eloc; //footprint of get, put, inv
invariant: a -> HS.mem -> Type0; //invariant, typically liveness
x:a; //root of the hyperstack fragment
snapshot:imem (invariant x); //initial state (see above and LowStar.Lens.Effect)
l:imem_lens (invariant x) b footprint //the imem_lens itself
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: LowStar.Lens.hs_lens 'a 'b -> h: LowStar.Lens.imem (Mkhs_lens?.invariant l (Mkhs_lens?.x l))
-> LowStar.Lens.hs_lens 'a 'b | Prims.Tot | [
"total"
] | [] | [
"LowStar.Lens.hs_lens",
"LowStar.Lens.imem",
"LowStar.Lens.__proj__Mkhs_lens__item__invariant",
"LowStar.Lens.__proj__Mkhs_lens__item__x",
"LowStar.Lens.Mkhs_lens",
"LowStar.Lens.__proj__Mkhs_lens__item__footprint",
"LowStar.Lens.__proj__Mkhs_lens__item__l"
] | [] | false | false | false | false | false | let snap (l: hs_lens 'a 'b) (h: imem (l.invariant l.x)) : hs_lens 'a 'b =
| { l with snapshot = h } | false |
Options.fst | Options.get_check_hashes | val get_check_hashes : unit -> ML (option check_hashes_t) | val get_check_hashes : unit -> ML (option check_hashes_t) | let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 11,
"end_line": 467,
"start_col": 0,
"start_line": 461
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (FStar.Pervasives.Native.option HashingOptions.check_hashes_t) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.Pervasives.Native.None",
"HashingOptions.check_hashes_t",
"FStar.Pervasives.Native.Some",
"HashingOptions.WeakHashes",
"HashingOptions.StrongHashes",
"HashingOptions.InplaceHashes",
"FStar.Pervasives.Native.option",
"Options.valid_string",
"Options.valid_check_hashes",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.check_hashes",
"Prims.bool",
"Options.batch"
] | [] | false | true | false | false | false | let get_check_hashes () =
| if !batch
then
match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None | false |
Options.fst | Options.get_z3_test | val get_z3_test: unit -> ML (option string) | val get_z3_test: unit -> ML (option string) | let get_z3_test () = !z3_test | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 29,
"end_line": 558,
"start_col": 0,
"start_line": 558
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs
let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config")
let get_emit_smt_encoding () =
!emit_smt_encoding | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (FStar.Pervasives.Native.option Prims.string) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"FStar.Pervasives.Native.option",
"Options.vstring",
"FStar.Heap.trivial_preorder",
"Options.z3_test",
"Prims.string"
] | [] | false | true | false | false | false | let get_z3_test () =
| !z3_test | false |
Options.fst | Options.get_add_include | val get_add_include : unit -> ML (list string) | val get_add_include : unit -> ML (list string) | let get_add_include () =
!add_include | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 14,
"end_line": 536,
"start_col": 0,
"start_line": 535
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (Prims.list Prims.string) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"Prims.list",
"Options.vstring",
"FStar.Heap.trivial_preorder",
"Options.add_include",
"Prims.string"
] | [] | false | true | false | false | false | let get_add_include () =
| !add_include | false |
LowStar.Lens.fsti | LowStar.Lens.with_snapshot | val with_snapshot : lens: LowStar.Lens.hs_lens a b ->
result: Type ->
pre: (_: b -> Type0) ->
post: (_: b -> _: result -> _: b -> Type0)
-> Type | let with_snapshot #a #b (lens:hs_lens a b) result pre post =
s:imem (lens.invariant lens.x) ->
LensST result (snap lens s) pre post | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 247,
"start_col": 0,
"start_line": 245
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a
/// `put_put`: Another law for eliminating redundant writes
let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a
/// `lens`: A triple of a `get`, `put` and the laws
///
/// Note, so far, we only require the `get_put` law
noeq
type lens 'a 'b = {
get: get_t 'a 'b;
put: put_t 'a 'b;
lens_laws: squash (
get_put get put // /\
// put_get get put /\
// put_put get put
)
}
unfold
let get (l:lens 'a 'b) (x:'a) : GTot 'b =
match l with
| {get=get} -> get x
unfold
let put (l:lens 'a 'b) (x:'a) (y:'b) : GTot 'a =
match l with
| {put=put} -> put y x
(* Now, we work towards defining `hs_lens`, a lens on hyperstacks *)
/// `imem inv`:
///
/// A refinement of hyperstacks satisifying the invariant `inv`
/// We will mainly use lenses between `imem inv` and some type `a`
let imem inv = m:HS.mem{inv m}
/// `eloc` : A convenient abbreviation for an erased location
let eloc = Ghost.erased B.loc
/// `as_loc`: Coercing an `eloc` to a `loc`
let as_loc (x:eloc) : GTot B.loc = Ghost.reveal x
(* Rather than the lens laws, more useful in the Low* setting are laws
that describe the action of `get` and `put` in terms of existing
Low* concepts, e.g., footprints in terms of `loc`; modifies clauses
etc. *)
/// `get_reads_loc el get`: States that `get` only depends on the `el`
/// fragment of a hyperstack
let get_reads_loc #b #inv (el:eloc) (get:get_t (imem inv) b) =
forall (h0 h1:imem inv) loc. {:pattern (B.modifies loc h0 h1); (get h1)}
B.loc_disjoint (as_loc el) loc /\
B.modifies loc h0 h1 ==>
get h0 == get h1
/// `put_modifies_loc el put`: States that `put` only mutates the `el`
/// fragment of a hyperstack
let put_modifies_loc #b #inv (el:eloc) (put:put_t (imem inv) b) =
forall (h0:imem inv) (v:b).{:pattern (put v h0)}
B.modifies (as_loc el) h0 (put v h0)
/// `invariant_reads_loc el inv`: States that the invariant `inv`
/// only depends on the `el` fragment of a hyperstack
let invariant_reads_loc inv (el:eloc) =
forall h0 h1 loc.{:pattern (B.modifies loc h0 h1); (inv h1)}
inv h0 /\
B.loc_disjoint (as_loc el) loc /\
B.modifies loc h0 h1 ==>
inv h1
/// `imem_lens inv b loc` is a lens between an `imem inv` and `b`
/// whose footprint is loc
let imem_lens inv b loc =
l:lens (imem inv) b {
get_reads_loc loc l.get /\
put_modifies_loc loc l.put /\
invariant_reads_loc inv loc
}
(* A distinctive feature of the setup here is the encapsulation of
modifies clauses. See the definition of the `RST` effect for more
details on how it is used.
The main idea is that when creating an `hs_lens`, we record within
it a memory snapshot. All state modifications are stated with
respect to this snapshot, rather than relating the pre/post states
of each sub-computation. This frees client programs from reasoning
about the transitive composition of the modifies clauses.
*)
/// `hs_lens a b`:
///
/// Encapsulates an `imem_lens` between a fragment of a hyperstack
/// reachable from `x:a` and its view `b`.
noeq
type hs_lens a b = {
footprint: eloc; //footprint of get, put, inv
invariant: a -> HS.mem -> Type0; //invariant, typically liveness
x:a; //root of the hyperstack fragment
snapshot:imem (invariant x); //initial state (see above and LowStar.Lens.Effect)
l:imem_lens (invariant x) b footprint //the imem_lens itself
}
/// `snap`: Updating the memory snapshot
let snap (l:hs_lens 'a 'b) (h:imem (l.invariant l.x))
: hs_lens 'a 'b
= {l with snapshot = h}
/// `mods l h`: Abstract modifies, relating a lens for a hyperstack
///
/// I see `mods l` as a unary invariant on hyperstack's rather than
/// the usual binary relation `modifies loc`.
///
/// The unary relation frees clients from reasoning about composition
/// of adjacent modifies clauses
val mods (l:hs_lens 'a 'b) (h:HS.mem) : Type0
(* We now get to the definition of the lens-indexed effect, LensST *)
/// `inv`: a slightly more abstract way to state the invariant
/// of an `hs_lens`
val inv (#roots:_) (#view:_) (l:hs_lens roots view) (h:HS.mem) : Type0
/// `view`: a slightly more abstract way to apply the lens's view to a
/// hyperstack
val view (#roots:_) (#view:_) (l:hs_lens roots view) (h:imem (inv l)) : GTot view
/// The main computation type provided by this module
/// `LensST a r pre post`
/// An abstract computation on pairs layered on top of HyperStack.STATE
effect LensST (a:Type)
(#roots:Type0)
(#v:Type0)
(l:hs_lens roots v)
(pre: v -> Type)
(post: v -> a -> v -> Type) =
STATE a
(fun (k:a -> HS.mem -> Type)
(h0:HS.mem) ->
inv l h0 /\ //Require the lens invariant
pre (view l h0) /\ //Require the pre-condition on the view
(forall (x:a) (h1:HS.mem).
inv l h1 /\ //Ensure the lens invariant
post (view l h0) x (view l h1) ==> //Ensure the post-condition on the view
k x h1)) //prove the continuation under this hypothesis
/// `reveal_inv`: Revealing the abstract invariant
val reveal_inv (_:unit)
: Lemma ((forall #a #b (l:hs_lens a b) h. {:pattern inv l h}
inv l h <==>
(l.invariant l.x h /\
B.modifies (as_loc l.footprint) l.snapshot h /\
FStar.HyperStack.ST.equal_domains l.snapshot h)) /\
(forall #a #b (l:hs_lens a b) h. {:pattern view l h}
view l h == l.l.get h))
/// `with_snapshot t pre post`:
///
/// A computation in `LensST` which supports updating the snapshot
///
/// This is a technical device, not intended for typical use in
/// client code, but is useful in libraries that provide support for | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
lens: LowStar.Lens.hs_lens a b ->
result: Type ->
pre: (_: b -> Type0) ->
post: (_: b -> _: result -> _: b -> Type0)
-> Type | Prims.Tot | [
"total"
] | [] | [
"LowStar.Lens.hs_lens",
"LowStar.Lens.imem",
"LowStar.Lens.__proj__Mkhs_lens__item__invariant",
"LowStar.Lens.__proj__Mkhs_lens__item__x",
"LowStar.Lens.snap"
] | [] | false | false | false | true | true | let with_snapshot #a #b (lens: hs_lens a b) result pre post =
| s: imem (lens.invariant lens.x) -> LensST result (snap lens s) pre post | false |
|
Options.fst | Options.get_micro_step | val get_micro_step : unit -> ML (option micro_step_t) | val get_micro_step : unit -> ML (option micro_step_t) | let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 50,
"end_line": 489,
"start_col": 0,
"start_line": 482
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (FStar.Pervasives.Native.option HashingOptions.micro_step_t) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.Pervasives.Native.None",
"HashingOptions.micro_step_t",
"FStar.Pervasives.Native.Some",
"HashingOptions.MicroStepVerify",
"HashingOptions.MicroStepExtract",
"HashingOptions.MicroStepCopyClangFormat",
"HashingOptions.MicroStepCopyEverParseH",
"HashingOptions.MicroStepEmitConfig",
"FStar.Pervasives.Native.option",
"Options.valid_string",
"Options.valid_micro_step",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.micro_step"
] | [] | false | true | false | false | false | let get_micro_step _ =
| match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig | false |
Options.fst | Options.config_module_name | val config_module_name : unit -> ML (option string) | val config_module_name : unit -> ML (option string) | let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config") | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 62,
"end_line": 553,
"start_col": 0,
"start_line": 550
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (FStar.Pervasives.Native.option Prims.string) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.Pervasives.Native.None",
"Prims.string",
"Options.valid_string",
"Options.check_config_file_name",
"FStar.Pervasives.Native.Some",
"Options.strip_suffix",
"OS.basename",
"FStar.Pervasives.Native.option",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.config_file"
] | [] | false | true | false | false | false | let config_module_name () =
| match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config") | false |
Options.fst | Options.get_input_stream_binding | val get_input_stream_binding : unit -> ML input_stream_binding_t | val get_input_stream_binding : unit -> ML input_stream_binding_t | let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ()) | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 38,
"end_line": 526,
"start_col": 0,
"start_line": 514
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML HashingOptions.input_stream_binding_t | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"HashingOptions.InputStreamBuffer",
"HashingOptions.input_stream_binding_t",
"HashingOptions.InputStreamExtern",
"Prims.string",
"HashingOptions.InputStreamStatic",
"FStar.Pervasives.Native.option",
"Options.valid_string",
"Options.valid_input_stream_binding",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.input_stream_binding",
"FStar.Pervasives.st_post_h",
"FStar.Monotonic.Heap.heap",
"Prims.l_Forall",
"Prims.pure_post",
"Prims.l_imp",
"Prims.guard_free",
"Prims.l_and",
"Prims.l_not",
"Prims.b2t",
"Options.vstring",
"Options.input_stream_include"
] | [] | false | true | false | false | false | let get_input_stream_binding _ =
| let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None | Some "buffer" -> InputStreamBuffer
| Some "extern" -> InputStreamExtern (get_include ())
| Some "static" -> InputStreamStatic (get_include ()) | false |
Options.fst | Options.get_z3_diff_test | val get_z3_diff_test: unit -> ML (option (string & string)) | val get_z3_diff_test: unit -> ML (option (string & string)) | let get_z3_diff_test _ =
match !z3_diff_test with
| None -> None
| Some s -> let [p1; p2] = String.split [','] s in Some (p1, p2) | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 66,
"end_line": 591,
"start_col": 0,
"start_line": 588
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs
let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config")
let get_emit_smt_encoding () =
!emit_smt_encoding
let get_z3_test () = !z3_test
let get_z3_pos_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "neg" -> false
| _ -> true
let get_z3_neg_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "pos" -> false
| _ -> true
let get_z3_witnesses () =
match !z3_witnesses with
| None -> 1
| Some s ->
try
let n = OS.int_of_string s in
if n < 1 then (1 <: pos) else begin
assert (n >= 1);
(n <: pos)
end
with _ -> 1
let get_debug _ = !debug | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (FStar.Pervasives.Native.option (Prims.string * Prims.string)) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.tuple2",
"Prims.string",
"Options.valid_string",
"Options.valid_equate_types",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.option",
"Prims.list",
"FStar.String.split",
"Prims.Cons",
"FStar.String.char",
"Prims.Nil",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.z3_diff_test"
] | [] | false | true | false | false | false | let get_z3_diff_test _ =
| match !z3_diff_test with
| None -> None
| Some s ->
let [p1 ; p2] = String.split [','] s in
Some (p1, p2) | false |
Options.fst | Options.get_save_z3_transcript | val get_save_z3_transcript: unit -> ML (option string) | val get_save_z3_transcript: unit -> ML (option string) | let get_save_z3_transcript () = !save_z3_transcript | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 598,
"start_col": 0,
"start_line": 598
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs
let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config")
let get_emit_smt_encoding () =
!emit_smt_encoding
let get_z3_test () = !z3_test
let get_z3_pos_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "neg" -> false
| _ -> true
let get_z3_neg_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "pos" -> false
| _ -> true
let get_z3_witnesses () =
match !z3_witnesses with
| None -> 1
| Some s ->
try
let n = OS.int_of_string s in
if n < 1 then (1 <: pos) else begin
assert (n >= 1);
(n <: pos)
end
with _ -> 1
let get_debug _ = !debug
let get_z3_diff_test _ =
match !z3_diff_test with
| None -> None
| Some s -> let [p1; p2] = String.split [','] s in Some (p1, p2)
let get_z3_executable () =
match !z3_executable with
| None -> "z3"
| Some z3 -> z3 | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (FStar.Pervasives.Native.option Prims.string) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"FStar.Pervasives.Native.option",
"Options.vstring",
"FStar.Heap.trivial_preorder",
"Options.save_z3_transcript",
"Prims.string"
] | [] | false | true | false | false | false | let get_save_z3_transcript () =
| !save_z3_transcript | false |
Options.fst | Options.get_z3_executable | val get_z3_executable : _: Prims.unit -> FStar.ST.STATE Prims.string | let get_z3_executable () =
match !z3_executable with
| None -> "z3"
| Some z3 -> z3 | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 17,
"end_line": 596,
"start_col": 0,
"start_line": 593
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs
let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config")
let get_emit_smt_encoding () =
!emit_smt_encoding
let get_z3_test () = !z3_test
let get_z3_pos_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "neg" -> false
| _ -> true
let get_z3_neg_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "pos" -> false
| _ -> true
let get_z3_witnesses () =
match !z3_witnesses with
| None -> 1
| Some s ->
try
let n = OS.int_of_string s in
if n < 1 then (1 <: pos) else begin
assert (n >= 1);
(n <: pos)
end
with _ -> 1
let get_debug _ = !debug
let get_z3_diff_test _ =
match !z3_diff_test with
| None -> None
| Some s -> let [p1; p2] = String.split [','] s in Some (p1, p2) | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.ST.STATE Prims.string | FStar.ST.STATE | [] | [] | [
"Prims.unit",
"Options.vstring",
"Prims.string",
"FStar.Pervasives.Native.option",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.z3_executable"
] | [] | false | true | false | false | false | let get_z3_executable () =
| match !z3_executable with
| None -> "z3"
| Some z3 -> z3 | false |
|
Options.fst | Options.get_z3_branch_depth | val get_z3_branch_depth: unit -> ML nat | val get_z3_branch_depth: unit -> ML nat | let get_z3_branch_depth () =
match !z3_branch_depth with
| None -> 0
| Some s ->
try
let n = OS.int_of_string s in
if n < 0 then (0 <: nat) else begin
assert (n >= 0);
(n <: nat)
end
with _ -> 0 | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 612,
"start_col": 0,
"start_line": 602
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs
let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config")
let get_emit_smt_encoding () =
!emit_smt_encoding
let get_z3_test () = !z3_test
let get_z3_pos_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "neg" -> false
| _ -> true
let get_z3_neg_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "pos" -> false
| _ -> true
let get_z3_witnesses () =
match !z3_witnesses with
| None -> 1
| Some s ->
try
let n = OS.int_of_string s in
if n < 1 then (1 <: pos) else begin
assert (n >= 1);
(n <: pos)
end
with _ -> 1
let get_debug _ = !debug
let get_z3_diff_test _ =
match !z3_diff_test with
| None -> None
| Some s -> let [p1; p2] = String.split [','] s in Some (p1, p2)
let get_z3_executable () =
match !z3_executable with
| None -> "z3"
| Some z3 -> z3
let get_save_z3_transcript () = !save_z3_transcript
let get_test_checker () = !test_checker | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.nat | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"Prims.nat",
"Options.vstring",
"FStar.All.try_with",
"Prims.op_LessThan",
"Prims.bool",
"Prims._assert",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.int",
"OS.int_of_string",
"Prims.exn",
"FStar.Pervasives.Native.option",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.z3_branch_depth"
] | [] | false | true | false | false | false | let get_z3_branch_depth () =
| match !z3_branch_depth with
| None -> 0
| Some s ->
try
let n = OS.int_of_string s in
if n < 0
then (0 <: nat)
else
(assert (n >= 0);
(n <: nat))
with
| _ -> 0 | false |
LowParse.SLow.DER.fst | LowParse.SLow.DER.serialize32_bounded_der_length32 | val serialize32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (serializer32 (serialize_bounded_der_length32 (vmin) (vmax))) | val serialize32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (serializer32 (serialize_bounded_der_length32 (vmin) (vmax))) | let serialize32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
: Tot (serializer32 (serialize_bounded_der_length32 (vmin) (vmax)))
= fun (y' : bounded_int32 (vmin) (vmax)) -> ((
[@inline_let]
let _ = serialize_bounded_der_length32_unfold (vmin) (vmax) y' in
let x = tag_of_der_length32_impl y' in
let sx = B32.create 1ul x in
if x `U8.lt` 128uy
then sx
else if x = 129uy
then sx `B32.b32append` B32.create 1ul (Cast.uint32_to_uint8 y')
else if x = 130uy
then sx `B32.b32append` serialize32_bounded_integer_2 y'
else if x = 131uy
then sx `B32.b32append` serialize32_bounded_integer_3 y'
else sx `B32.b32append` serialize32_bounded_integer_4 y'
) <: (res: _ { serializer32_correct (serialize_bounded_der_length32 (vmin) (vmax)) y' res } )) | {
"file_name": "src/lowparse/LowParse.SLow.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 96,
"end_line": 128,
"start_col": 0,
"start_line": 110
} | module LowParse.SLow.DER
include LowParse.Spec.DER
include LowParse.SLow.Combinators
include LowParse.SLow.Int // for parse32_u8
include LowParse.SLow.BoundedInt // for bounded_integer
open FStar.Mul
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
module Math = LowParse.Math
module B32 = LowParse.Bytes32
module Cast = FStar.Int.Cast
#reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0"
#push-options "--z3rlimit 16"
inline_for_extraction
let parse32_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (parser32 (parse_der_length_payload32 x))
= fun (input: bytes32) -> ((
[@inline_let] let _ =
parse_der_length_payload32_unfold x (B32.reveal input);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then Some (Cast.uint8_to_uint32 x, 0ul)
else if x = 128uy || x = 255uy
then None
else if x = 129uy
then
match parse32_u8 input with
| None -> None
| Some (z, consumed) ->
if z `U8.lt` 128uy
then None
else Some ((Cast.uint8_to_uint32 z <: refine_with_tag tag_of_der_length32 x), consumed)
else
let len = x `U8.sub` 128uy in
if len = 2uy
then
match parse32_bounded_integer 2 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt `256ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
else if len = 3uy
then
match parse32_bounded_integer 3 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt `65536ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
else
match parse32_bounded_integer 4 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt` 16777216ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
) <: (res: _ { parser32_correct (parse_der_length_payload32 x) input res } ))
#push-options "--max_ifuel 2"
inline_for_extraction
let parse32_bounded_der_length32
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
: Tot (
parser32 (parse_bounded_der_length32 vmin vmax))
= [@inline_let] let _ = assert_norm (4294967296 <= der_length_max) in
fun (input: bytes32) -> ((
[@inline_let]
let _ =
parse_bounded_der_length32_unfold (U32.v min) (U32.v max) (B32.reveal input)
in
match parse32_u8 input with
| None -> None
| Some (x, consumed_x) ->
let len = der_length_payload_size_of_tag8 x in
let tg1 = (tag_of_der_length32_impl min) in
let l1 = der_length_payload_size_of_tag8 tg1 in
let tg2 = (tag_of_der_length32_impl max) in
let l2 = der_length_payload_size_of_tag8 tg2 in
if len `U8.lt` l1 || l2 `U8.lt` len
then None
else begin
let input' = B32.slice input consumed_x (B32.len input) in
match parse32_der_length_payload32 x input' with
| Some (y, consumed_y) ->
if y `U32.lt` min || max `U32.lt` y
then None
else Some (y, consumed_x `U32.add` consumed_y)
| None -> None
end
) <: (res : _ { parser32_correct (parse_bounded_der_length32 (U32.v min) (U32.v max)) input res } ))
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.DER.fsti.checked",
"LowParse.SLow.Int.fsti.checked",
"LowParse.SLow.Combinators.fst.checked",
"LowParse.SLow.BoundedInt.fsti.checked",
"LowParse.Math.fst.checked",
"LowParse.Bytes32.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.DER.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowParse.Bytes32",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.DER",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
vmax: LowParse.Spec.DER.der_length_t{vmin <= vmax /\ vmax < 4294967296}
-> LowParse.SLow.Base.serializer32 (LowParse.Spec.DER.serialize_bounded_der_length32 vmin vmax) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.BoundedInt.bounded_int32",
"FStar.UInt8.lt",
"FStar.UInt8.__uint_to_t",
"Prims.bool",
"Prims.op_Equality",
"FStar.UInt8.t",
"LowParse.Bytes32.b32append",
"FStar.Bytes.create",
"FStar.UInt32.__uint_to_t",
"FStar.Int.Cast.uint32_to_uint8",
"LowParse.SLow.BoundedInt.serialize32_bounded_integer_2",
"LowParse.SLow.BoundedInt.serialize32_bounded_integer_3",
"LowParse.SLow.BoundedInt.serialize32_bounded_integer_4",
"LowParse.SLow.Base.bytes32",
"LowParse.SLow.Base.serializer32_correct",
"LowParse.Spec.DER.parse_bounded_der_length32_kind",
"LowParse.Spec.DER.parse_bounded_der_length32",
"LowParse.Spec.DER.serialize_bounded_der_length32",
"FStar.Bytes.lbytes",
"FStar.UInt32.v",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Prims.l_Forall",
"FStar.UInt32.lt",
"Prims.eq2",
"FStar.Bytes.get",
"LowParse.Spec.DER.der_length_max",
"LowParse.Spec.DER.tag_of_der_length",
"LowParse.Spec.DER.tag_of_der_length32_impl",
"Prims.unit",
"LowParse.Spec.DER.serialize_bounded_der_length32_unfold",
"LowParse.SLow.Base.serializer32"
] | [] | false | false | false | false | false | let serialize32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (serializer32 (serialize_bounded_der_length32 (vmin) (vmax))) =
| fun (y': bounded_int32 (vmin) (vmax)) ->
(([@@ inline_let ]let _ = serialize_bounded_der_length32_unfold (vmin) (vmax) y' in
let x = tag_of_der_length32_impl y' in
let sx = B32.create 1ul x in
if x `U8.lt` 128uy
then sx
else
if x = 129uy
then sx `B32.b32append` (B32.create 1ul (Cast.uint32_to_uint8 y'))
else
if x = 130uy
then sx `B32.b32append` (serialize32_bounded_integer_2 y')
else
if x = 131uy
then sx `B32.b32append` (serialize32_bounded_integer_3 y')
else sx `B32.b32append` (serialize32_bounded_integer_4 y'))
<:
(res: _{serializer32_correct (serialize_bounded_der_length32 (vmin) (vmax)) y' res})) | false |
StructUpdate.fst | StructUpdate.pcm_t | val pcm_t (#a #b: _) : pcm (t a b) | val pcm_t (#a #b: _) : pcm (t a b) | let pcm_t #a #b : pcm (t a b) = FStar.PCM.({
p = {
composable=comp;
op=combine;
one=Neither
};
comm = (fun _ _ -> ());
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun x -> Both? x \/ Neither? x)
}) | {
"file_name": "share/steel/examples/steel/StructUpdate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 2,
"end_line": 38,
"start_col": 0,
"start_line": 27
} | module StructUpdate
module P = FStar.PCM
module M = Steel.Memory
open FStar.PCM
type t (a:Type) (b:Type) =
| Both : a -> b -> t a b
| First : a -> t a b
| Second : b -> t a b
| Neither : t a b
let comp #a #b (x y:t a b) : prop =
match x, y with
| Neither, _
| _, Neither
| First _, Second _
| Second _, First _ -> True
| _ -> False
let combine #a #b (x: t a b) (y:t a b{comp x y}) : t a b =
match x, y with
| First a, Second b
| Second b, First a -> Both a b
| Neither, z
| z, Neither -> z | {
"checked_file": "/",
"dependencies": [
"Steel.PCMReference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "StructUpdate.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.PCM",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.PCM.pcm (StructUpdate.t a b) | Prims.Tot | [
"total"
] | [] | [
"FStar.PCM.Mkpcm",
"StructUpdate.t",
"FStar.PCM.Mkpcm'",
"StructUpdate.comp",
"StructUpdate.combine",
"StructUpdate.Neither",
"FStar.PCM.__proj__Mkpcm'__item__composable",
"Prims.unit",
"Prims.l_and",
"FStar.PCM.__proj__Mkpcm'__item__op",
"Prims.l_or",
"Prims.b2t",
"StructUpdate.uu___is_Both",
"StructUpdate.uu___is_Neither",
"Prims.prop",
"FStar.PCM.pcm"
] | [] | false | false | false | true | false | let pcm_t #a #b : pcm (t a b) =
| let open FStar.PCM in
{
p = { composable = comp; op = combine; one = Neither };
comm = (fun _ _ -> ());
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun x -> Both? x \/ Neither? x)
} | false |
Options.fst | Options.get_z3_options | val get_z3_options: Prims.unit -> ML string | val get_z3_options: Prims.unit -> ML string | let get_z3_options () : ML string =
match !z3_options with
| None -> ""
| Some s -> s | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 15,
"end_line": 617,
"start_col": 0,
"start_line": 614
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs
let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config")
let get_emit_smt_encoding () =
!emit_smt_encoding
let get_z3_test () = !z3_test
let get_z3_pos_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "neg" -> false
| _ -> true
let get_z3_neg_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "pos" -> false
| _ -> true
let get_z3_witnesses () =
match !z3_witnesses with
| None -> 1
| Some s ->
try
let n = OS.int_of_string s in
if n < 1 then (1 <: pos) else begin
assert (n >= 1);
(n <: pos)
end
with _ -> 1
let get_debug _ = !debug
let get_z3_diff_test _ =
match !z3_diff_test with
| None -> None
| Some s -> let [p1; p2] = String.split [','] s in Some (p1, p2)
let get_z3_executable () =
match !z3_executable with
| None -> "z3"
| Some z3 -> z3
let get_save_z3_transcript () = !save_z3_transcript
let get_test_checker () = !test_checker
let get_z3_branch_depth () =
match !z3_branch_depth with
| None -> 0
| Some s ->
try
let n = OS.int_of_string s in
if n < 0 then (0 <: nat) else begin
assert (n >= 0);
(n <: nat)
end
with _ -> 0 | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.string | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"Options.vstring",
"Prims.string",
"FStar.Pervasives.Native.option",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.z3_options"
] | [] | false | true | false | false | false | let get_z3_options () : ML string =
| match !z3_options with
| None -> ""
| Some s -> s | false |
Options.fst | Options.get_test_checker | val get_test_checker: unit -> ML (option string) | val get_test_checker: unit -> ML (option string) | let get_test_checker () = !test_checker | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 39,
"end_line": 600,
"start_col": 0,
"start_line": 600
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs
let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config")
let get_emit_smt_encoding () =
!emit_smt_encoding
let get_z3_test () = !z3_test
let get_z3_pos_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "neg" -> false
| _ -> true
let get_z3_neg_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "pos" -> false
| _ -> true
let get_z3_witnesses () =
match !z3_witnesses with
| None -> 1
| Some s ->
try
let n = OS.int_of_string s in
if n < 1 then (1 <: pos) else begin
assert (n >= 1);
(n <: pos)
end
with _ -> 1
let get_debug _ = !debug
let get_z3_diff_test _ =
match !z3_diff_test with
| None -> None
| Some s -> let [p1; p2] = String.split [','] s in Some (p1, p2)
let get_z3_executable () =
match !z3_executable with
| None -> "z3"
| Some z3 -> z3
let get_save_z3_transcript () = !save_z3_transcript | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML (FStar.Pervasives.Native.option Prims.string) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"FStar.ST.op_Bang",
"FStar.Pervasives.Native.option",
"Options.vstring",
"FStar.Heap.trivial_preorder",
"Options.test_checker",
"Prims.string"
] | [] | false | true | false | false | false | let get_test_checker () =
| !test_checker | false |
Options.fst | Options.get_z3_witnesses | val get_z3_witnesses: unit -> ML pos | val get_z3_witnesses: unit -> ML pos | let get_z3_witnesses () =
match !z3_witnesses with
| None -> 1
| Some s ->
try
let n = OS.int_of_string s in
if n < 1 then (1 <: pos) else begin
assert (n >= 1);
(n <: pos)
end
with _ -> 1 | {
"file_name": "src/3d/Options.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 584,
"start_col": 0,
"start_line": 574
} | module Options
open HashingOptions
open FStar.All
open FStar.ST
module U8 = FStar.UInt8
module OS = OS
#push-options "--warn_error -272" //top-level effects are okay
inline_for_extraction
let valid_string
(valid: (string -> Tot bool))
: Tot Type0
= (s: string { valid s == true })
let always_valid (_: string) : Tot bool = true
let starts_with_capital (s: string) : Tot bool =
String.length s >= 1 &&
begin let first = String.sub s 0 1 in
String.compare first "A" >= 0 && String.compare first "Z" <= 0
end
let ends_with (s:string) (suffix:string) : bool =
let l = String.length s in
let sl = String.length suffix in
if sl > l || sl = 0
then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'
let check_config_file_name (fn:string)
: bool
= let fn = OS.basename fn in
starts_with_capital fn &&
ends_with fn ".3d.config"
let strip_suffix (fn:string) (sfx:string { ends_with fn sfx })
: string
= String.sub fn 0 (String.length fn - String.length sfx)
inline_for_extraction
let vstring = valid_string always_valid
(* NOTE: default arguments here MUST be set to false, [] or None *)
let arg0 : ref (option vstring) = alloc None
let add_include : ref (list vstring) = alloc []
let batch : ref bool = alloc false
let clang_format : ref bool = alloc false
let clang_format_executable : ref (option vstring) = alloc None
let cleanup : ref bool = alloc false
let config_file : ref (option (valid_string check_config_file_name)) = alloc None
let debug : ref bool = alloc false
let inplace_hashes : ref (list vstring) = alloc []
let input_file : ref (list string) = alloc []
let json : ref bool = alloc false
let no_copy_everparse_h : ref bool = alloc false
let output_dir : ref (option vstring) = alloc None
let save_hashes : ref bool = alloc false
let save_z3_transcript: ref (option vstring) = alloc None
let skip_c_makefiles : ref bool = alloc false
let skip_deps: ref bool = alloc false
let skip_o_rules: ref bool = alloc false
let valid_micro_step (str: string) : Tot bool = match str with
| "verify"
| "extract"
| "copy_clang_format"
| "copy_everparse_h"
| "emit_config"
-> true
| _ -> false
let micro_step : ref (option (valid_string valid_micro_step)) = alloc None
let produce_c_from_existing_krml : ref bool = alloc false
let valid_makefile (str: string) : Tot bool = match str with
| "gmake"
| "nmake"
-> true
| _ -> false
let makefile : ref (option (valid_string valid_makefile)) = alloc None
let makefile_name : ref (option vstring) = alloc None
let valid_equate_types (str: string) : Tot bool =
let l = String.split [','] str in
match l with
| [m1;m2] -> true
| _ -> false
let equate_types_list : ref (list (valid_string valid_equate_types)) = alloc []
let valid_check_hashes : string -> Tot bool = function
| "weak"
| "strong"
| "inplace"
-> true
| _ -> false
let check_hashes : ref (option (valid_string valid_check_hashes)) = alloc None
let valid_input_stream_binding : string -> Tot bool = function
| "buffer"
| "extern"
| "static"
-> true
| _ -> false
let input_stream_binding : ref (option (valid_string valid_input_stream_binding)) = alloc None
let input_stream_include : ref (option vstring) = alloc None
let emit_output_types_defs : ref bool = alloc true
let emit_smt_encoding : ref bool = alloc false
let z3_diff_test: ref (option (valid_string valid_equate_types)) = alloc None
let z3_test : ref (option vstring) = alloc None
let valid_z3_test_mode : string -> Tot bool = function
| "pos"
| "neg"
| "all"
-> true
| _ -> false
let z3_test_mode : ref (option (valid_string valid_z3_test_mode)) = alloc None
let z3_witnesses : ref (option vstring) = alloc None
let z3_executable : ref (option vstring) = alloc None
let test_checker : ref (option vstring) = alloc None
let z3_branch_depth : ref (option vstring) = alloc None
let z3_options : ref (option vstring) = alloc None
noeq
type cmd_option_kind =
| OptBool:
(v: ref bool) ->
cmd_option_kind
| OptStringOption:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (option (valid_string valid))) ->
cmd_option_kind
| OptList:
(arg_desc: string) ->
(valid: (string -> Tot bool)) ->
(v: ref (list (valid_string valid))) ->
cmd_option_kind
let fstar_opt = FStar.Getopt.opt & string
noeq
type cmd_option
= | CmdOption:
(name: string) ->
(kind: cmd_option_kind) ->
(desc: string) ->
(implies: list string) (* name of OptBool to set to true *) ->
cmd_option
| CmdFStarOption of fstar_opt
let cmd_option_name (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, name', _), _)
| CmdOption name' _ _ _
-> name'
let rec find_cmd_option (name: string) (l: list cmd_option): Tot (option cmd_option) = match l with
| [] -> None
| a :: q ->
if name = cmd_option_name a then Some a else find_cmd_option name q
let cmd_option_description (a: cmd_option) : Tot string =
match a with
| CmdOption _ _ desc _
| CmdFStarOption (_, desc) ->
desc
let cmd_option_arg_desc (a: cmd_option) : Tot string =
match a with
| CmdFStarOption ((_, _, arg), _) ->
begin match arg with
| FStar.Getopt.OneArg (_, argdesc) -> argdesc
| _ -> ""
end
| CmdOption _ kind _ _ ->
begin match kind with
| OptStringOption argdesc _ _
| OptList argdesc _ _
-> argdesc
| _ -> ""
end
let set_implies (options: ref (list cmd_option)) (implies: list string) : ML unit =
List.iter
(fun name ->
match find_cmd_option name !options with
| Some (CmdOption _ (OptBool x) _ _) -> x := true
| _ -> ()
)
implies
let string_starts_with (big small: string) : Tot bool =
let small_len = String.length small in
if String.length big < small_len
then false
else String.sub big 0 small_len = small
let negate_string_gen (s: string) (negation: string) =
if s `string_starts_with` negation
then String.sub s (String.length negation) (String.length s - String.length negation)
else negation ^ s
let name_is_negated (s: string) : Tot bool = s `string_starts_with` "no_"
let negate_name (s: string) : Tot string = negate_string_gen s "no_"
let negate_description (s: string) : Tot string = negate_string_gen s "Do not"
let fstar_options_of_cmd_option
(options: ref (list cmd_option))
(o: cmd_option)
: Tot (list fstar_opt)
= match o with
| CmdFStarOption f -> [f]
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
[
((FStar.Getopt.noshort, name, FStar.Getopt.ZeroArgs (fun _ -> set_implies options implies; v := true)), desc);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := false)), negate_description desc);
]
| OptStringOption arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := Some x
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
((FStar.Getopt.noshort, negate_name name, FStar.Getopt.ZeroArgs (fun _ -> v := None)), negate_description desc)
]
| OptList arg_desc valid v ->
[
(
(
FStar.Getopt.noshort, name,
FStar.Getopt.OneArg (
(fun (x: string) ->
if valid x
then begin
set_implies options implies;
v := x :: !v
end else
failwith (Printf.sprintf "Bad argument to %s: got %s, expected %s" name x arg_desc)
),
arg_desc
)
),
desc
);
(
(
FStar.Getopt.noshort, negate_name name,
FStar.Getopt.ZeroArgs (fun _ -> v := [])
),
desc
);
]
end
let compute_current_options (options: ref (list cmd_option)) (ignore: list string) : ML string =
(* we would like to output a normalized sequence of options so that its semantics does not depend on whether any other options are prepended (i.e. whether 3d is run from 3d or from everparse.cmd or from everparse.sh *)
(* first print the values of current options except untoggled boolean options *)
let print (msg: string) (opt: cmd_option) : ML string =
if List.Tot.mem (cmd_option_name opt) ignore
then msg
else
match opt with
| CmdOption name kind desc implies ->
begin match kind with
| OptBool v ->
if !v
then Printf.sprintf "%s --%s" msg name
else msg
| OptStringOption _ _ v ->
begin match !v with
| None -> Printf.sprintf "%s --%s" msg (negate_name name)
| Some v -> Printf.sprintf "%s --%s %s" msg name v
end
| OptList _ _ v ->
let v = !v in
let msg = Printf.sprintf "%s --%s" msg (negate_name name) in
let app (msg: string) (s: string) = Printf.sprintf "%s --%s %s" msg name s in
List.Tot.fold_left app msg (List.Tot.rev v) (* list was accumulated as a fifo *)
end
| _ -> msg
in
let msg = List.fold_left print "" !options in
(* then print the untoggled boolean options *)
let print_untoggle (msg: string) (opt: cmd_option) : ML string =
match opt with
| CmdOption name (OptBool v) _ _ ->
if (if not (List.Tot.mem name ignore) then not !v else false)
then Printf.sprintf "%s --%s" msg (negate_name name)
else msg
| _ -> msg
in
List.fold_left print_untoggle msg !options
let get_arg0 () : ML string =
match !arg0 with
| None -> "3d"
| Some v -> v
let display_usage_1 (options: ref (list cmd_option)) : ML unit =
FStar.IO.print_string "EverParse/3d: verified data validation with dependent data descriptions\n";
FStar.IO.print_string "\n";
FStar.IO.print_string (Printf.sprintf "Usage: %s [options] path_to_input_file1.3d path_to_input_file2.3d ... \n" (get_arg0 ()));
FStar.IO.print_string "\n";
FStar.IO.print_string "Options:\n";
List.iter
(fun x ->
let m = cmd_option_name x in
let desc = cmd_option_description x in
let argdesc = cmd_option_arg_desc x in
let argdesc = if argdesc = "" then "" else Printf.sprintf " <%s>" argdesc in
let negate = if CmdOption? x then Printf.sprintf " (opposite is --%s)" (negate_name m) else "" in
let visible = not (m `string_starts_with` "__") in
if visible then FStar.IO.print_string (Printf.sprintf "--%s%s%s\n\t%s\n" m argdesc negate desc)
)
!options
;
FStar.IO.print_string (Printf.sprintf "\nCurrent options are:%s\n" (compute_current_options options []))
let (display_usage_2, compute_options_2, fstar_options) =
let options : ref (list cmd_option) = alloc [] in
let display_usage () = display_usage_1 options in
let compute_options = compute_current_options options in
options := [
CmdOption "add_include" (OptList "<include.h>|\"include.h\"" always_valid add_include) "Prepend #include ... to generated .c/.h files" [];
CmdOption "batch" (OptBool batch) "Verify the generated F* code and extract C code" [];
CmdOption "check_hashes" (OptStringOption "weak|strong|inplace" valid_check_hashes check_hashes) "Check hashes" ["batch"];
CmdOption "check_inplace_hash" (OptList "file.3d=file.h" always_valid inplace_hashes) "Check hashes stored in one .h/.c file" [];
CmdOption "clang_format" (OptBool clang_format) "Call clang-format on extracted .c/.h files (--batch only)" ["batch"];
CmdOption "clang_format_executable" (OptStringOption "clang-format full path" always_valid clang_format_executable) "Set the path to clang-format if not reachable through PATH" ["batch"; "clang_format"];
CmdOption "cleanup" (OptBool cleanup) "Remove *.fst*, *.krml and krml-args.rsp (--batch only)" [];
CmdOption "config" (OptStringOption "config file" check_config_file_name config_file) "The name of a JSON formatted file containing configuration options" [];
CmdOption "emit_output_types_defs" (OptBool emit_output_types_defs) "Emit definitions of output types in a .h file" [];
CmdOption "emit_smt_encoding" (OptBool emit_smt_encoding) "Emit an SMT encoding of parser specifications" [];
CmdOption "input_stream" (OptStringOption "buffer|extern|static" valid_input_stream_binding input_stream_binding) "Input stream binding (default buffer)" [];
CmdOption "input_stream_include" (OptStringOption ".h file" always_valid input_stream_include) "Include file defining the EverParseInputStreamBase type (only for --input_stream extern or static)" [];
CmdOption "no_copy_everparse_h" (OptBool no_copy_everparse_h) "Do not Copy EverParse.h (--batch only)" [];
CmdOption "debug" (OptBool debug) "Emit a lot of debugging output" [];
CmdFStarOption (('h', "help", FStar.Getopt.ZeroArgs (fun _ -> display_usage (); exit 0)), "Show this help message");
CmdOption "json" (OptBool json) "Dump the AST in JSON format" [];
CmdOption "makefile" (OptStringOption "gmake|nmake" valid_makefile makefile) "Do not produce anything, other than a Makefile to produce everything" [];
CmdOption "makefile_name" (OptStringOption "some file name" always_valid makefile_name) "Name of the Makefile to produce (with --makefile, default <output directory>/EverParse.Makefile" [];
CmdOption "odir" (OptStringOption "output directory" always_valid output_dir) "output directory (default '.'); writes <module_name>.fst and <module_name>_wrapper.c to the output directory" [];
CmdOption "save_hashes" (OptBool save_hashes) "Save hashes" [];
CmdOption "save_z3_transcript" (OptStringOption "some file name" always_valid save_z3_transcript) "Save the Z3 transcript (input and output) to a file" [];
CmdOption "skip_c_makefiles" (OptBool skip_c_makefiles) "Do not Generate Makefile.basic, Makefile.include" [];
CmdOption "skip_o_rules" (OptBool skip_o_rules) "With --makefile, do not generate rules for .o files" [];
CmdOption "test_checker" (OptStringOption "parser name" always_valid test_checker) "produce a test checker executable" [];
CmdFStarOption ((let open FStar.Getopt in noshort, "version", ZeroArgs (fun _ -> FStar.IO.print_string (Printf.sprintf "EverParse/3d %s\nCopyright 2018, 2019, 2020 Microsoft Corporation\n" Version.everparse_version); exit 0)), "Show this version of EverParse");
CmdOption "equate_types" (OptList "an argument of the form A,B, to generate asserts of the form (A.t == B.t)" valid_equate_types equate_types_list) "Takes an argument of the form A,B and then for each entrypoint definition in B, it generates an assert (A.t == B.t) in the B.Types file, useful when refactoring specs, you can provide multiple equate_types on the command line" [];
CmdOption "z3_branch_depth" (OptStringOption "nb" always_valid z3_branch_depth) "enumerate branch choices up to depth nb (default 0)" [];
CmdOption "z3_diff_test" (OptStringOption "parser1,parser2" valid_equate_types z3_diff_test) "produce differential tests for two parsers" [];
CmdOption "z3_executable" (OptStringOption "path/to/z3" always_valid z3_executable) "z3 executable for test case generation (default `z3`; does not affect verification of generated F* code)" [];
CmdOption "z3_options" (OptStringOption "'options to z3'" always_valid z3_options) "command-line options to pass to z3 for test case generation (does not affect verification of generated F* code)" [];
CmdOption "z3_test" (OptStringOption "parser name" always_valid z3_test) "produce positive and/or negative test cases for a given parser" [];
CmdOption "z3_test_mode" (OptStringOption "pos|neg|all" valid_z3_test_mode z3_test_mode) "produce positive, negative, or all kinds of test cases (default all)" [];
CmdOption "z3_witnesses" (OptStringOption "nb" always_valid z3_witnesses) "ask for nb distinct test witnesses per branch case (default 1)" [];
CmdOption "__arg0" (OptStringOption "executable name" always_valid arg0) "executable name to use for the help message" [];
CmdOption "__micro_step" (OptStringOption "verify|extract|copy_clang_format|copy_everparse_h|emit_config" valid_micro_step micro_step) "micro step" [];
CmdOption "__produce_c_from_existing_krml" (OptBool produce_c_from_existing_krml) "produce C from .krml files" [];
CmdOption "__skip_deps" (OptBool skip_deps) "skip dependency analysis, assume all dependencies are specified on the command line" [];
];
let fstar_options =
List.Tot.concatMap (fstar_options_of_cmd_option options) !options
in
(display_usage, compute_options, fstar_options)
let display_usage = display_usage_2
let compute_options = compute_options_2
let parse_cmd_line () : ML (list string) =
let open FStar.Getopt in
let res = FStar.Getopt.parse_cmdline (List.Tot.map fst fstar_options) (fun file -> input_file := file :: !input_file; Success) in
match res with
| Success -> !input_file
| Help -> display_usage(); exit 0
| Error s -> FStar.IO.print_string s; exit 1
| _ -> exit 2
let split_3d_file_name fn =
let fn = OS.basename fn in
if OS.extension fn = ".3d"
then Some (OS.remove_extension fn)
else None
let get_file_name mname = mname ^ ".3d"
let get_module_name (file: string) =
match split_3d_file_name file with
| Some nm ->
if starts_with_capital nm
then nm
else failwith (Printf.sprintf "Input file name %s must start with a capital letter" file)
| None -> failwith (Printf.sprintf "Input file name %s must end with .3d" file)
let get_output_dir () =
match !output_dir with
| None -> "."
| Some s -> s
let debug_print_string (s:string): ML unit =
if !debug
then FStar.IO.print_string s
else ()
let get_batch () =
!batch
let get_clang_format () =
!clang_format
let get_clang_format_executable () =
match !clang_format_executable with
| None -> ""
| Some s -> s
let get_cleanup () =
!cleanup
let get_skip_c_makefiles () =
!skip_c_makefiles
let get_no_everparse_h () =
!no_copy_everparse_h
let get_check_hashes () =
if !batch then match !check_hashes with
| None -> None
| Some "weak" -> Some WeakHashes
| Some "strong" -> Some StrongHashes
| Some "inplace" -> Some InplaceHashes
else None
let get_save_hashes () =
!save_hashes
let get_check_inplace_hashes () =
List.rev !inplace_hashes
let get_equate_types_list () =
List.map
(fun (x: valid_string valid_equate_types) ->
let [a; b] = String.split [','] x in (a, b)
)
!equate_types_list
let get_micro_step _ =
match !micro_step with
| None -> None
| Some "verify" -> Some MicroStepVerify
| Some "extract" -> Some MicroStepExtract
| Some "copy_clang_format" -> Some MicroStepCopyClangFormat
| Some "copy_everparse_h" -> Some MicroStepCopyEverParseH
| Some "emit_config" -> Some MicroStepEmitConfig
let get_produce_c_from_existing_krml _ =
!produce_c_from_existing_krml
let get_skip_deps _ =
!skip_deps
let get_makefile _ =
match !makefile with
| None -> None
| Some "gmake" -> Some MakefileGMake
| Some "nmake" -> Some MakefileNMake
let get_makefile_name _ =
match !makefile_name with
| None -> OS.concat (get_output_dir ()) "EverParse.Makefile"
| Some mf -> mf
let get_skip_o_rules _ =
!skip_o_rules
let get_json () =
!json
let get_input_stream_binding _ =
let get_include () =
match !input_stream_include with
| None -> ""
| Some s -> s
in
match !input_stream_binding with
| None
| Some "buffer" -> InputStreamBuffer
| Some "extern" ->
InputStreamExtern (get_include ())
| Some "static" ->
InputStreamStatic (get_include ())
let get_emit_output_types_defs () = !emit_output_types_defs
let get_config_file () =
match !config_file with
| None -> None
| Some s -> Some s
let get_add_include () =
!add_include
let make_includes () =
let incs = get_add_include () in
List.Tot.fold_left
(fun accu inc ->
Printf.sprintf
"%s#include %s\n"
accu
inc
)
""
incs
let config_module_name () =
match !config_file with
| None -> None
| Some s -> Some (strip_suffix (OS.basename s) ".3d.config")
let get_emit_smt_encoding () =
!emit_smt_encoding
let get_z3_test () = !z3_test
let get_z3_pos_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "neg" -> false
| _ -> true
let get_z3_neg_test () =
match !z3_test with
| None -> false
| _ -> match !z3_test_mode with
| Some "pos" -> false
| _ -> true | {
"checked_file": "/",
"dependencies": [
"Version.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"HashingOptions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Getopt.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": true,
"source_file": "Options.fst"
} | [
{
"abbrev": true,
"full_module": "OS",
"short_module": "OS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HashingOptions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.pos | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"Prims.pos",
"Options.vstring",
"FStar.All.try_with",
"Prims.op_LessThan",
"Prims.bool",
"Prims._assert",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.int",
"OS.int_of_string",
"Prims.exn",
"FStar.Pervasives.Native.option",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.z3_witnesses"
] | [] | false | true | false | false | false | let get_z3_witnesses () =
| match !z3_witnesses with
| None -> 1
| Some s ->
try
let n = OS.int_of_string s in
if n < 1
then (1 <: pos)
else
(assert (n >= 1);
(n <: pos))
with
| _ -> 1 | false |
LowParse.SLow.DER.fst | LowParse.SLow.DER.parse32_der_length_payload32 | val parse32_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4})
: Tot (parser32 (parse_der_length_payload32 x)) | val parse32_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4})
: Tot (parser32 (parse_der_length_payload32 x)) | let parse32_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (parser32 (parse_der_length_payload32 x))
= fun (input: bytes32) -> ((
[@inline_let] let _ =
parse_der_length_payload32_unfold x (B32.reveal input);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then Some (Cast.uint8_to_uint32 x, 0ul)
else if x = 128uy || x = 255uy
then None
else if x = 129uy
then
match parse32_u8 input with
| None -> None
| Some (z, consumed) ->
if z `U8.lt` 128uy
then None
else Some ((Cast.uint8_to_uint32 z <: refine_with_tag tag_of_der_length32 x), consumed)
else
let len = x `U8.sub` 128uy in
if len = 2uy
then
match parse32_bounded_integer 2 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt `256ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
else if len = 3uy
then
match parse32_bounded_integer 3 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt `65536ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
else
match parse32_bounded_integer 4 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt` 16777216ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
) <: (res: _ { parser32_correct (parse_der_length_payload32 x) input res } )) | {
"file_name": "src/lowparse/LowParse.SLow.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 79,
"end_line": 68,
"start_col": 0,
"start_line": 20
} | module LowParse.SLow.DER
include LowParse.Spec.DER
include LowParse.SLow.Combinators
include LowParse.SLow.Int // for parse32_u8
include LowParse.SLow.BoundedInt // for bounded_integer
open FStar.Mul
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
module Math = LowParse.Math
module B32 = LowParse.Bytes32
module Cast = FStar.Int.Cast
#reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0"
#push-options "--z3rlimit 16" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.DER.fsti.checked",
"LowParse.SLow.Int.fsti.checked",
"LowParse.SLow.Combinators.fst.checked",
"LowParse.SLow.BoundedInt.fsti.checked",
"LowParse.Math.fst.checked",
"LowParse.Bytes32.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.DER.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowParse.Bytes32",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.DER",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt8.t{LowParse.Spec.DER.der_length_payload_size_of_tag x <= 4}
-> LowParse.SLow.Base.parser32 (LowParse.Spec.DER.parse_der_length_payload32 x) | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.DER.der_length_payload_size_of_tag",
"LowParse.SLow.Base.bytes32",
"FStar.UInt8.lt",
"FStar.UInt8.__uint_to_t",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.refine_with_tag",
"FStar.UInt32.t",
"LowParse.Spec.DER.tag_of_der_length32",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Int.Cast.uint8_to_uint32",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"Prims.op_BarBar",
"Prims.op_Equality",
"FStar.Pervasives.Native.None",
"LowParse.SLow.Int.parse32_u8",
"FStar.Pervasives.Native.option",
"LowParse.SLow.Base.parser32_correct",
"LowParse.Spec.DER.parse_der_length_payload_kind",
"LowParse.Spec.DER.parse_der_length_payload32",
"LowParse.SLow.BoundedInt.parse32_bounded_integer",
"LowParse.Spec.BoundedInt.bounded_integer",
"FStar.UInt32.lt",
"FStar.UInt8.sub",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.pow2",
"FStar.Mul.op_Star",
"LowParse.Spec.DER.parse_der_length_payload32_unfold",
"FStar.Bytes.reveal",
"LowParse.SLow.Base.parser32"
] | [] | false | false | false | false | false | let parse32_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4})
: Tot (parser32 (parse_der_length_payload32 x)) =
| fun (input: bytes32) ->
(([@@ inline_let ]let _ =
parse_der_length_payload32_unfold x (B32.reveal input);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then Some (Cast.uint8_to_uint32 x, 0ul)
else
if x = 128uy || x = 255uy
then None
else
if x = 129uy
then
match parse32_u8 input with
| None -> None
| Some (z, consumed) ->
if z `U8.lt` 128uy
then None
else
Some ((Cast.uint8_to_uint32 z <: refine_with_tag tag_of_der_length32 x), consumed)
else
let len = x `U8.sub` 128uy in
if len = 2uy
then
match parse32_bounded_integer 2 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt` 256ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
else
if len = 3uy
then
match parse32_bounded_integer 3 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt` 65536ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
else
match parse32_bounded_integer 4 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt` 16777216ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed))
<:
(res: _{parser32_correct (parse_der_length_payload32 x) input res})) | false |
LowStar.Lens.fsti | LowStar.Lens.for_n | val for_n
(#a #b: _)
(#lens: hs_lens a b)
(n: nat)
(inv: (i: nat{i <= n} -> b -> prop))
(f:
(i: nat{i < n}
-> LensST unit
lens
(requires fun b -> inv i b)
(ensures fun b0 _ b1 -> inv (i + 1) b1)))
: LensST unit lens (requires fun b0 -> inv 0 b0) (ensures fun b0 _ b1 -> inv n b1) | val for_n
(#a #b: _)
(#lens: hs_lens a b)
(n: nat)
(inv: (i: nat{i <= n} -> b -> prop))
(f:
(i: nat{i < n}
-> LensST unit
lens
(requires fun b -> inv i b)
(ensures fun b0 _ b1 -> inv (i + 1) b1)))
: LensST unit lens (requires fun b0 -> inv 0 b0) (ensures fun b0 _ b1 -> inv n b1) | let for_n (#a #b:_) (#lens:hs_lens a b)
(n:nat)
(inv: (i:nat{i<=n} -> b -> prop))
(f: (i:nat{i<n}
-> LensST unit lens
(requires fun b -> inv i b)
(ensures fun b0 _ b1 -> inv (i + 1) b1)))
: LensST unit lens
(requires fun b0 -> inv 0 b0)
(ensures fun b0 _ b1 -> inv n b1)
= let rec aux (i:nat{i <= n})
: LensST unit lens
(inv i)
(fun _ _ -> inv n)
= if i = n then ()
else (f i; aux (i + 1))
in
aux 0 | {
"file_name": "examples/data_structures/LowStar.Lens.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 10,
"end_line": 267,
"start_col": 0,
"start_line": 250
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Lens
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(* This module provides a more abstract way of verifying Low*
programs.
Rather than working directly with hyperstacks, one can reason via a
`lens` that provides a view of a hyperstack as a store containing
just a n-tuple of a user's choice.
The main technical idea is to use a lens-indexed effect, `LensST`,
a thin layer on top of FStar.HyperStack.ST.Stack, which allows
writing specification using just the view on the hyperstack, rather
than the full hyperstack itself, while also systematically
enforcing the invariants of the lens.
So far, we do not require the full generality of lenses. However,
the framework is setup to permit moving in that direction, should
we need it.
We focus primarily on the `get` operation, to support viewing a
hyperstack fragment more abstractly and operations that mutate the
hyperstack are specified in terms of `get` operation on the new
state rather than a `put`.
The main type of this module is an `hs_lens a b`, a hyperstack
lens. The first index `a` is typically some set of "roots" into a
hyperstack, e.g, one or more pointers. The second index `b` is the
view of the hyperstack reachable from those roots.
An `hs_lens` also encapsulates various invariants on the
hyperstack, e.g., the liveness of the roots etc. and is done in a
way to enable composition via products: i.e., given an `h1:hs_lens
a b` and `h2:hs_lens c d`, under suitable separation conditions,
one can build a product lens `hs_lens (a & c) (b & d)`.
Finally, the module provides the hs_lens-indexed effect `LensST`.
*)
(* We start with the basic definitions of lenses *)
/// `get_t` and `put_t`:
///
/// The type of the lens operations between a pair of types Note,
/// these lenses are for specification only, i.e., they are ghost
/// operators
let get_t a b = a -> GTot b
let put_t a b = b -> a -> GTot a
/// `get_put`: The main useful law
/// You get what you put
let get_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b:'b).{:pattern (get (put b a))}
get (put b a) == b
/// `put_get`: A law for eliminating redundant writes
/// Putting what you got is a noop
let put_get (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a).{:pattern (put (get a) a)}
put (get a) a == a
/// `put_put`: Another law for eliminating redundant writes
let put_put (get:get_t 'a 'b) (put:put_t 'a 'b) =
forall (a:'a) (b1 b2:'b). {:pattern (put b2 (put b1 a))}
put b2 (put b1 a) == put b2 a
/// `lens`: A triple of a `get`, `put` and the laws
///
/// Note, so far, we only require the `get_put` law
noeq
type lens 'a 'b = {
get: get_t 'a 'b;
put: put_t 'a 'b;
lens_laws: squash (
get_put get put // /\
// put_get get put /\
// put_put get put
)
}
unfold
let get (l:lens 'a 'b) (x:'a) : GTot 'b =
match l with
| {get=get} -> get x
unfold
let put (l:lens 'a 'b) (x:'a) (y:'b) : GTot 'a =
match l with
| {put=put} -> put y x
(* Now, we work towards defining `hs_lens`, a lens on hyperstacks *)
/// `imem inv`:
///
/// A refinement of hyperstacks satisifying the invariant `inv`
/// We will mainly use lenses between `imem inv` and some type `a`
let imem inv = m:HS.mem{inv m}
/// `eloc` : A convenient abbreviation for an erased location
let eloc = Ghost.erased B.loc
/// `as_loc`: Coercing an `eloc` to a `loc`
let as_loc (x:eloc) : GTot B.loc = Ghost.reveal x
(* Rather than the lens laws, more useful in the Low* setting are laws
that describe the action of `get` and `put` in terms of existing
Low* concepts, e.g., footprints in terms of `loc`; modifies clauses
etc. *)
/// `get_reads_loc el get`: States that `get` only depends on the `el`
/// fragment of a hyperstack
let get_reads_loc #b #inv (el:eloc) (get:get_t (imem inv) b) =
forall (h0 h1:imem inv) loc. {:pattern (B.modifies loc h0 h1); (get h1)}
B.loc_disjoint (as_loc el) loc /\
B.modifies loc h0 h1 ==>
get h0 == get h1
/// `put_modifies_loc el put`: States that `put` only mutates the `el`
/// fragment of a hyperstack
let put_modifies_loc #b #inv (el:eloc) (put:put_t (imem inv) b) =
forall (h0:imem inv) (v:b).{:pattern (put v h0)}
B.modifies (as_loc el) h0 (put v h0)
/// `invariant_reads_loc el inv`: States that the invariant `inv`
/// only depends on the `el` fragment of a hyperstack
let invariant_reads_loc inv (el:eloc) =
forall h0 h1 loc.{:pattern (B.modifies loc h0 h1); (inv h1)}
inv h0 /\
B.loc_disjoint (as_loc el) loc /\
B.modifies loc h0 h1 ==>
inv h1
/// `imem_lens inv b loc` is a lens between an `imem inv` and `b`
/// whose footprint is loc
let imem_lens inv b loc =
l:lens (imem inv) b {
get_reads_loc loc l.get /\
put_modifies_loc loc l.put /\
invariant_reads_loc inv loc
}
(* A distinctive feature of the setup here is the encapsulation of
modifies clauses. See the definition of the `RST` effect for more
details on how it is used.
The main idea is that when creating an `hs_lens`, we record within
it a memory snapshot. All state modifications are stated with
respect to this snapshot, rather than relating the pre/post states
of each sub-computation. This frees client programs from reasoning
about the transitive composition of the modifies clauses.
*)
/// `hs_lens a b`:
///
/// Encapsulates an `imem_lens` between a fragment of a hyperstack
/// reachable from `x:a` and its view `b`.
noeq
type hs_lens a b = {
footprint: eloc; //footprint of get, put, inv
invariant: a -> HS.mem -> Type0; //invariant, typically liveness
x:a; //root of the hyperstack fragment
snapshot:imem (invariant x); //initial state (see above and LowStar.Lens.Effect)
l:imem_lens (invariant x) b footprint //the imem_lens itself
}
/// `snap`: Updating the memory snapshot
let snap (l:hs_lens 'a 'b) (h:imem (l.invariant l.x))
: hs_lens 'a 'b
= {l with snapshot = h}
/// `mods l h`: Abstract modifies, relating a lens for a hyperstack
///
/// I see `mods l` as a unary invariant on hyperstack's rather than
/// the usual binary relation `modifies loc`.
///
/// The unary relation frees clients from reasoning about composition
/// of adjacent modifies clauses
val mods (l:hs_lens 'a 'b) (h:HS.mem) : Type0
(* We now get to the definition of the lens-indexed effect, LensST *)
/// `inv`: a slightly more abstract way to state the invariant
/// of an `hs_lens`
val inv (#roots:_) (#view:_) (l:hs_lens roots view) (h:HS.mem) : Type0
/// `view`: a slightly more abstract way to apply the lens's view to a
/// hyperstack
val view (#roots:_) (#view:_) (l:hs_lens roots view) (h:imem (inv l)) : GTot view
/// The main computation type provided by this module
/// `LensST a r pre post`
/// An abstract computation on pairs layered on top of HyperStack.STATE
effect LensST (a:Type)
(#roots:Type0)
(#v:Type0)
(l:hs_lens roots v)
(pre: v -> Type)
(post: v -> a -> v -> Type) =
STATE a
(fun (k:a -> HS.mem -> Type)
(h0:HS.mem) ->
inv l h0 /\ //Require the lens invariant
pre (view l h0) /\ //Require the pre-condition on the view
(forall (x:a) (h1:HS.mem).
inv l h1 /\ //Ensure the lens invariant
post (view l h0) x (view l h1) ==> //Ensure the post-condition on the view
k x h1)) //prove the continuation under this hypothesis
/// `reveal_inv`: Revealing the abstract invariant
val reveal_inv (_:unit)
: Lemma ((forall #a #b (l:hs_lens a b) h. {:pattern inv l h}
inv l h <==>
(l.invariant l.x h /\
B.modifies (as_loc l.footprint) l.snapshot h /\
FStar.HyperStack.ST.equal_domains l.snapshot h)) /\
(forall #a #b (l:hs_lens a b) h. {:pattern view l h}
view l h == l.l.get h))
/// `with_snapshot t pre post`:
///
/// A computation in `LensST` which supports updating the snapshot
///
/// This is a technical device, not intended for typical use in
/// client code, but is useful in libraries that provide support for
/// composing and de-composing hs_lenses.
let with_snapshot #a #b (lens:hs_lens a b) result pre post =
s:imem (lens.invariant lens.x) ->
LensST result (snap lens s) pre post | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Lens.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: Prims.nat ->
inv: (i: Prims.nat{i <= n} -> _: b -> Prims.prop) ->
f: (i: Prims.nat{i < n} -> LowStar.Lens.LensST Prims.unit)
-> LowStar.Lens.LensST Prims.unit | LowStar.Lens.LensST | [] | [] | [
"LowStar.Lens.hs_lens",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.prop",
"Prims.op_LessThan",
"Prims.unit",
"Prims.op_Addition",
"Prims.op_Equality",
"Prims.bool"
] | [] | false | true | false | false | false | let for_n
(#a #b: _)
(#lens: hs_lens a b)
(n: nat)
(inv: (i: nat{i <= n} -> b -> prop))
(f:
(i: nat{i < n}
-> LensST unit
lens
(requires fun b -> inv i b)
(ensures fun b0 _ b1 -> inv (i + 1) b1)))
: LensST unit lens (requires fun b0 -> inv 0 b0) (ensures fun b0 _ b1 -> inv n b1) =
| let rec aux (i: nat{i <= n}) : LensST unit lens (inv i) (fun _ _ -> inv n) =
if i = n
then ()
else
(f i;
aux (i + 1))
in
aux 0 | false |
LowParse.SLow.DER.fst | LowParse.SLow.DER.parse32_bounded_der_length32 | val parse32_bounded_der_length32
(vmin: der_length_t)
(min: U32.t{U32.v min == vmin})
(vmax: der_length_t)
(max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max})
: Tot (parser32 (parse_bounded_der_length32 vmin vmax)) | val parse32_bounded_der_length32
(vmin: der_length_t)
(min: U32.t{U32.v min == vmin})
(vmax: der_length_t)
(max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max})
: Tot (parser32 (parse_bounded_der_length32 vmin vmax)) | let parse32_bounded_der_length32
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
: Tot (
parser32 (parse_bounded_der_length32 vmin vmax))
= [@inline_let] let _ = assert_norm (4294967296 <= der_length_max) in
fun (input: bytes32) -> ((
[@inline_let]
let _ =
parse_bounded_der_length32_unfold (U32.v min) (U32.v max) (B32.reveal input)
in
match parse32_u8 input with
| None -> None
| Some (x, consumed_x) ->
let len = der_length_payload_size_of_tag8 x in
let tg1 = (tag_of_der_length32_impl min) in
let l1 = der_length_payload_size_of_tag8 tg1 in
let tg2 = (tag_of_der_length32_impl max) in
let l2 = der_length_payload_size_of_tag8 tg2 in
if len `U8.lt` l1 || l2 `U8.lt` len
then None
else begin
let input' = B32.slice input consumed_x (B32.len input) in
match parse32_der_length_payload32 x input' with
| Some (y, consumed_y) ->
if y `U32.lt` min || max `U32.lt` y
then None
else Some (y, consumed_x `U32.add` consumed_y)
| None -> None
end
) <: (res : _ { parser32_correct (parse_bounded_der_length32 (U32.v min) (U32.v max)) input res } )) | {
"file_name": "src/lowparse/LowParse.SLow.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 102,
"end_line": 105,
"start_col": 0,
"start_line": 73
} | module LowParse.SLow.DER
include LowParse.Spec.DER
include LowParse.SLow.Combinators
include LowParse.SLow.Int // for parse32_u8
include LowParse.SLow.BoundedInt // for bounded_integer
open FStar.Mul
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
module Math = LowParse.Math
module B32 = LowParse.Bytes32
module Cast = FStar.Int.Cast
#reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0"
#push-options "--z3rlimit 16"
inline_for_extraction
let parse32_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (parser32 (parse_der_length_payload32 x))
= fun (input: bytes32) -> ((
[@inline_let] let _ =
parse_der_length_payload32_unfold x (B32.reveal input);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then Some (Cast.uint8_to_uint32 x, 0ul)
else if x = 128uy || x = 255uy
then None
else if x = 129uy
then
match parse32_u8 input with
| None -> None
| Some (z, consumed) ->
if z `U8.lt` 128uy
then None
else Some ((Cast.uint8_to_uint32 z <: refine_with_tag tag_of_der_length32 x), consumed)
else
let len = x `U8.sub` 128uy in
if len = 2uy
then
match parse32_bounded_integer 2 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt `256ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
else if len = 3uy
then
match parse32_bounded_integer 3 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt `65536ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
else
match parse32_bounded_integer 4 input with
| None -> None
| Some (y, consumed) ->
if y `U32.lt` 16777216ul
then None
else Some ((y <: refine_with_tag tag_of_der_length32 x), consumed)
) <: (res: _ { parser32_correct (parse_der_length_payload32 x) input res } ))
#push-options "--max_ifuel 2" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.DER.fsti.checked",
"LowParse.SLow.Int.fsti.checked",
"LowParse.SLow.Combinators.fst.checked",
"LowParse.SLow.BoundedInt.fsti.checked",
"LowParse.Math.fst.checked",
"LowParse.Bytes32.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.DER.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowParse.Bytes32",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.DER",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
min: FStar.UInt32.t{FStar.UInt32.v min == vmin} ->
vmax: LowParse.Spec.DER.der_length_t ->
max: FStar.UInt32.t{FStar.UInt32.v max == vmax /\ FStar.UInt32.v min <= FStar.UInt32.v max}
-> LowParse.SLow.Base.parser32 (LowParse.Spec.DER.parse_bounded_der_length32 vmin vmax) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"FStar.UInt32.t",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.DER.der_length_max",
"FStar.UInt32.v",
"LowParse.SLow.Base.bytes32",
"LowParse.SLow.Int.parse32_u8",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.BoundedInt.bounded_int32",
"FStar.UInt8.t",
"Prims.op_BarBar",
"FStar.UInt8.lt",
"Prims.bool",
"LowParse.SLow.DER.parse32_der_length_payload32",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.DER.tag_of_der_length32",
"FStar.UInt32.lt",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"FStar.UInt32.add",
"FStar.Pervasives.Native.option",
"LowParse.SLow.Base.parser32_correct",
"LowParse.Spec.DER.parse_bounded_der_length32_kind",
"LowParse.Spec.DER.parse_bounded_der_length32",
"FStar.Bytes.bytes",
"FStar.Seq.Base.seq",
"FStar.Bytes.reveal",
"FStar.Seq.Base.slice",
"FStar.Bytes.len",
"FStar.Bytes.slice",
"FStar.UInt8.v",
"LowParse.Spec.DER.der_length_payload_size_of_tag",
"LowParse.Spec.DER.der_length_payload_size_of_tag8",
"Prims.op_LessThan",
"LowParse.Spec.DER.tag_of_der_length",
"LowParse.Spec.DER.tag_of_der_length32_impl",
"Prims.unit",
"LowParse.Spec.DER.parse_bounded_der_length32_unfold",
"FStar.Pervasives.assert_norm",
"LowParse.SLow.Base.parser32"
] | [] | false | false | false | false | false | let parse32_bounded_der_length32
(vmin: der_length_t)
(min: U32.t{U32.v min == vmin})
(vmax: der_length_t)
(max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max})
: Tot (parser32 (parse_bounded_der_length32 vmin vmax)) =
| [@@ inline_let ]let _ = assert_norm (4294967296 <= der_length_max) in
fun (input: bytes32) ->
(([@@ inline_let ]let _ =
parse_bounded_der_length32_unfold (U32.v min) (U32.v max) (B32.reveal input)
in
match parse32_u8 input with
| None -> None
| Some (x, consumed_x) ->
let len = der_length_payload_size_of_tag8 x in
let tg1 = (tag_of_der_length32_impl min) in
let l1 = der_length_payload_size_of_tag8 tg1 in
let tg2 = (tag_of_der_length32_impl max) in
let l2 = der_length_payload_size_of_tag8 tg2 in
if len `U8.lt` l1 || l2 `U8.lt` len
then None
else
let input' = B32.slice input consumed_x (B32.len input) in
match parse32_der_length_payload32 x input' with
| Some (y, consumed_y) ->
if y `U32.lt` min || max `U32.lt` y
then None
else Some (y, consumed_x `U32.add` consumed_y)
| None -> None)
<:
(res: _{parser32_correct (parse_bounded_der_length32 (U32.v min) (U32.v max)) input res})) | false |
SteelLoops.fst | SteelLoops.main | val main: Prims.unit -> SteelT Int32.t emp (fun _ -> emp) | val main: Prims.unit -> SteelT Int32.t emp (fun _ -> emp) | let main () : SteelT Int32.t emp (fun _ -> emp) =
let r = malloc 0ul in
sum_to_n_for r;
sum_to_n_while r;
free r;
return 0l | {
"file_name": "share/steel/tests/krml/SteelLoops.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 11,
"end_line": 46,
"start_col": 0,
"start_line": 41
} | module SteelLoops
open Steel.Effect.Atomic
open Steel.Effect
open Steel.Reference
open Steel.Loops
let sum_to_n_for (r:ref UInt32.t) : SteelT unit (vptr r) (fun _ -> vptr r) =
for_loop
0sz
10sz
(fun _ -> vptr r)
(fun _ -> let x = read r in write r (x `FStar.UInt32.add_mod` 1ul))
let sum_to_n_for_2 (r:ref UInt32.t) : Steel unit (vptr r) (fun _ -> vptr r)
(requires fun h -> sel r h == 0ul)
(ensures fun h0 _ h1 -> sel r h1 == 10ul)
=
for_loop_full
0sz
10sz
(fun _ -> vptr r)
(fun i v -> v == UInt32.uint_to_t i)
(fun _ -> let x = read r in write r (x `FStar.UInt32.add_mod` 1ul))
let sum_to_n_while (r:ref UInt32.t) : SteelT unit (vptr r) (fun _ -> vptr r) =
intro_exists (Ghost.hide true) (fun _ -> vptr r);
while_loop
(fun _ -> vptr r)
(fun _ ->
let _ = witness_exists () in
let n = read r in
FStar.UInt32.lt n 10ul
)
(fun _ ->
let n = read r in
write r (n `FStar.UInt32.add_mod` 1ul);
intro_exists (Ghost.hide true) (fun _ -> vptr r)
) | {
"checked_file": "/",
"dependencies": [
"Steel.Reference.fsti.checked",
"Steel.Loops.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "SteelLoops.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.Loops",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Steel.Effect.SteelT FStar.Int32.t | Steel.Effect.SteelT | [] | [] | [
"Prims.unit",
"Steel.Effect.Atomic.return",
"FStar.Int32.t",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__mult",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.req",
"Steel.Effect.Common.rm",
"FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__unit",
"Steel.Effect.Common.emp",
"FStar.Int32.__int_to_t",
"Steel.Reference.free",
"FStar.UInt32.t",
"SteelLoops.sum_to_n_while",
"SteelLoops.sum_to_n_for",
"Steel.Reference.ref",
"Steel.Reference.malloc",
"FStar.UInt32.__uint_to_t"
] | [] | false | true | false | false | false | let main () : SteelT Int32.t emp (fun _ -> emp) =
| let r = malloc 0ul in
sum_to_n_for r;
sum_to_n_while r;
free r;
return 0l | false |
StructUpdate.fst | StructUpdate.upd_first | val upd_first (#a #b: Type u#1) (r: ref (t a b) pcm_t) (x: Ghost.erased a) (y: a)
: SteelT unit (pts_to r (First #a #b x)) (fun _ -> pts_to r (First #a #b y)) | val upd_first (#a #b: Type u#1) (r: ref (t a b) pcm_t) (x: Ghost.erased a) (y: a)
: SteelT unit (pts_to r (First #a #b x)) (fun _ -> pts_to r (First #a #b y)) | let upd_first (#a #b:Type u#1) (r:ref (t a b) pcm_t) (x:Ghost.erased a) (y:a)
: SteelT unit
(pts_to r (First #a #b x))
(fun _ -> pts_to r (First #a #b y))
= let f
: frame_preserving_upd
pcm_t
(Ghost.hide (First #a #b x))
(First #a #b y)
= fun old_v ->
match old_v with
| Both _ z -> Both y z
in
upd_gen r (First #a #b x) (First #a #b y) f | {
"file_name": "share/steel/examples/steel/StructUpdate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 47,
"end_line": 57,
"start_col": 0,
"start_line": 44
} | module StructUpdate
module P = FStar.PCM
module M = Steel.Memory
open FStar.PCM
type t (a:Type) (b:Type) =
| Both : a -> b -> t a b
| First : a -> t a b
| Second : b -> t a b
| Neither : t a b
let comp #a #b (x y:t a b) : prop =
match x, y with
| Neither, _
| _, Neither
| First _, Second _
| Second _, First _ -> True
| _ -> False
let combine #a #b (x: t a b) (y:t a b{comp x y}) : t a b =
match x, y with
| First a, Second b
| Second b, First a -> Both a b
| Neither, z
| z, Neither -> z
let pcm_t #a #b : pcm (t a b) = FStar.PCM.({
p = {
composable=comp;
op=combine;
one=Neither
};
comm = (fun _ _ -> ());
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun x -> Both? x \/ Neither? x)
})
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.PCMReference | {
"checked_file": "/",
"dependencies": [
"Steel.PCMReference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "StructUpdate.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.PCMReference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.PCM",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Steel.Memory.ref (StructUpdate.t a b) StructUpdate.pcm_t -> x: FStar.Ghost.erased a -> y: a
-> Steel.Effect.SteelT Prims.unit | Steel.Effect.SteelT | [] | [] | [
"Steel.Memory.ref",
"StructUpdate.t",
"StructUpdate.pcm_t",
"FStar.Ghost.erased",
"Steel.PCMReference.upd_gen",
"FStar.Ghost.hide",
"StructUpdate.First",
"FStar.Ghost.reveal",
"Prims.unit",
"FStar.PCM.frame_preserving_upd",
"Prims.l_and",
"FStar.PCM.__proj__Mkpcm__item__refine",
"FStar.PCM.compatible",
"StructUpdate.Both",
"Prims.l_Forall",
"FStar.PCM.composable",
"Prims.l_imp",
"Prims.eq2",
"FStar.PCM.op",
"Steel.PCMReference.pts_to",
"Steel.Effect.Common.vprop"
] | [] | false | true | false | false | false | let upd_first (#a #b: Type u#1) (r: ref (t a b) pcm_t) (x: Ghost.erased a) (y: a)
: SteelT unit (pts_to r (First #a #b x)) (fun _ -> pts_to r (First #a #b y)) =
| let f:frame_preserving_upd pcm_t (Ghost.hide (First #a #b x)) (First #a #b y) =
function | Both _ z -> Both y z
in
upd_gen r (First #a #b x) (First #a #b y) f | false |
StructUpdate.fst | StructUpdate.upd_second | val upd_second (#a #b: Type u#1) (r: ref (t a b) pcm_t) (x: Ghost.erased b) (y: b)
: SteelT unit (pts_to r (Second #a #b x)) (fun _ -> pts_to r (Second #a #b y)) | val upd_second (#a #b: Type u#1) (r: ref (t a b) pcm_t) (x: Ghost.erased b) (y: b)
: SteelT unit (pts_to r (Second #a #b x)) (fun _ -> pts_to r (Second #a #b y)) | let upd_second (#a #b:Type u#1) (r:ref (t a b) pcm_t) (x:Ghost.erased b) (y:b)
: SteelT unit
(pts_to r (Second #a #b x))
(fun _ -> pts_to r (Second #a #b y))
= let f
: frame_preserving_upd
pcm_t
(Second #a #b x)
(Second #a #b y)
= fun old_v ->
match old_v with
| Both z _ -> Both z y
in
upd_gen r (Second #a #b x) (Second #a #b y) f | {
"file_name": "share/steel/examples/steel/StructUpdate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 49,
"end_line": 72,
"start_col": 0,
"start_line": 59
} | module StructUpdate
module P = FStar.PCM
module M = Steel.Memory
open FStar.PCM
type t (a:Type) (b:Type) =
| Both : a -> b -> t a b
| First : a -> t a b
| Second : b -> t a b
| Neither : t a b
let comp #a #b (x y:t a b) : prop =
match x, y with
| Neither, _
| _, Neither
| First _, Second _
| Second _, First _ -> True
| _ -> False
let combine #a #b (x: t a b) (y:t a b{comp x y}) : t a b =
match x, y with
| First a, Second b
| Second b, First a -> Both a b
| Neither, z
| z, Neither -> z
let pcm_t #a #b : pcm (t a b) = FStar.PCM.({
p = {
composable=comp;
op=combine;
one=Neither
};
comm = (fun _ _ -> ());
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun x -> Both? x \/ Neither? x)
})
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.PCMReference
let upd_first (#a #b:Type u#1) (r:ref (t a b) pcm_t) (x:Ghost.erased a) (y:a)
: SteelT unit
(pts_to r (First #a #b x))
(fun _ -> pts_to r (First #a #b y))
= let f
: frame_preserving_upd
pcm_t
(Ghost.hide (First #a #b x))
(First #a #b y)
= fun old_v ->
match old_v with
| Both _ z -> Both y z
in
upd_gen r (First #a #b x) (First #a #b y) f | {
"checked_file": "/",
"dependencies": [
"Steel.PCMReference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "StructUpdate.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.PCMReference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.PCM",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Steel.Memory.ref (StructUpdate.t a b) StructUpdate.pcm_t -> x: FStar.Ghost.erased b -> y: b
-> Steel.Effect.SteelT Prims.unit | Steel.Effect.SteelT | [] | [] | [
"Steel.Memory.ref",
"StructUpdate.t",
"StructUpdate.pcm_t",
"FStar.Ghost.erased",
"Steel.PCMReference.upd_gen",
"FStar.Ghost.hide",
"StructUpdate.Second",
"FStar.Ghost.reveal",
"Prims.unit",
"FStar.PCM.frame_preserving_upd",
"Prims.l_and",
"FStar.PCM.__proj__Mkpcm__item__refine",
"FStar.PCM.compatible",
"StructUpdate.Both",
"Prims.l_Forall",
"FStar.PCM.composable",
"Prims.l_imp",
"Prims.eq2",
"FStar.PCM.op",
"Steel.PCMReference.pts_to",
"Steel.Effect.Common.vprop"
] | [] | false | true | false | false | false | let upd_second (#a #b: Type u#1) (r: ref (t a b) pcm_t) (x: Ghost.erased b) (y: b)
: SteelT unit (pts_to r (Second #a #b x)) (fun _ -> pts_to r (Second #a #b y)) =
| let f:frame_preserving_upd pcm_t (Second #a #b x) (Second #a #b y) =
function | Both z _ -> Both z y
in
upd_gen r (Second #a #b x) (Second #a #b y) f | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_pow_nat | val lemma_pow_nat (a:nat) (b:nat) : Lemma (0 <= pow_int a b) | val lemma_pow_nat (a:nat) (b:nat) : Lemma (0 <= pow_int a b) | let rec lemma_pow_nat a b =
if b > 0 then (
lemma_pow_nat a (b - 1);
FStar.Math.Lemmas.nat_times_nat_is_nat a (pow_int a (b - 1))
) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 18,
"start_col": 0,
"start_line": 14
} | module Vale.Bignum.Lemmas
open FStar.Mul
let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k
let lemma_sum_seq_left_right s i j =
lemma_sum_seq_left_right_rec s i j j | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.nat -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures 0 <= Vale.Bignum.Defs.pow_int a b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.op_GreaterThan",
"FStar.Math.Lemmas.nat_times_nat_is_nat",
"Vale.Bignum.Defs.pow_int",
"Prims.op_Subtraction",
"Prims.unit",
"Vale.Bignum.Lemmas.lemma_pow_nat",
"Prims.bool"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_pow_nat a b =
| if b > 0
then
(lemma_pow_nat a (b - 1);
FStar.Math.Lemmas.nat_times_nat_is_nat a (pow_int a (b - 1))) | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_sum_seq_left_right | val lemma_sum_seq_left_right (s:seq int) (i j:nat) : Lemma
(requires i <= j /\ j <= length s)
(ensures sum_seq_left s i j == sum_seq_right s i j) | val lemma_sum_seq_left_right (s:seq int) (i j:nat) : Lemma
(requires i <= j /\ j <= length s)
(ensures sum_seq_left s i j == sum_seq_right s i j) | let lemma_sum_seq_left_right s i j =
lemma_sum_seq_left_right_rec s i j j | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 12,
"start_col": 0,
"start_line": 11
} | module Vale.Bignum.Lemmas
open FStar.Mul
let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Prims.int -> i: Prims.nat -> j: Prims.nat
-> FStar.Pervasives.Lemma (requires i <= j /\ j <= FStar.Seq.Base.length s)
(ensures Vale.Bignum.Defs.sum_seq_left s i j == Vale.Bignum.Defs.sum_seq_right s i j) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Prims.int",
"Prims.nat",
"Vale.Bignum.Lemmas.lemma_sum_seq_left_right_rec",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_sum_seq_left_right s i j =
| lemma_sum_seq_left_right_rec s i j j | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_sum_seq_left_right_rec | val lemma_sum_seq_left_right_rec (s: seq int) (i j k: nat)
: Lemma (requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j) | val lemma_sum_seq_left_right_rec (s: seq int) (i j k: nat)
: Lemma (requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j) | let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 9,
"start_col": 0,
"start_line": 4
} | module Vale.Bignum.Lemmas
open FStar.Mul | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Prims.int -> i: Prims.nat -> j: Prims.nat -> k: Prims.nat
-> FStar.Pervasives.Lemma (requires i <= j /\ j <= k /\ k <= FStar.Seq.Base.length s)
(ensures
Vale.Bignum.Defs.sum_seq_left s i j + Vale.Bignum.Defs.sum_seq_right s j k ==
Vale.Bignum.Defs.sum_seq_right s i k)
(decreases j) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"FStar.Seq.Base.seq",
"Prims.int",
"Prims.nat",
"Prims.op_LessThan",
"Vale.Bignum.Lemmas.lemma_sum_seq_left_right_rec",
"Prims.op_Subtraction",
"Prims.bool",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.squash",
"Prims.eq2",
"Prims.op_Addition",
"Vale.Bignum.Defs.sum_seq_left",
"Vale.Bignum.Defs.sum_seq_right",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_sum_seq_left_right_rec (s: seq int) (i j k: nat)
: Lemma (requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j) =
| if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_seq_scale_carry | val lemma_seq_scale_carry (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : Lemma
(ensures (
snd (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0) == 0
)) | val lemma_seq_scale_carry (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : Lemma
(ensures (
snd (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0) == 0
)) | let lemma_seq_scale_carry #n a bs d =
reveal_add_hi_all ();
reveal_mul_lo_all ();
reveal_mul_hi_all ();
let l = length bs in
if l = 0 then assert (seq_add_c (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 0 == 0)
else if n = 1 then lemma_seq_scale_carry1 a bs d (l + 1)
else (
lemma_mul_n_bound a bs.[l - 1];
lemma_mul_div_n_lt a bs.[l - 1];
()
) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 137,
"start_col": 0,
"start_line": 126
} | module Vale.Bignum.Lemmas
open FStar.Mul
let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k
let lemma_sum_seq_left_right s i j =
lemma_sum_seq_left_right_rec s i j j
let rec lemma_pow_nat a b =
if b > 0 then (
lemma_pow_nat a (b - 1);
FStar.Math.Lemmas.nat_times_nat_is_nat a (pow_int a (b - 1))
)
let rec lemma_sum_pow_seq_bound_rec (#n:nat) (s:seq (natN n)) (i:nat{i <= length s}) : Lemma
(ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i)
=
let open FStar.Math.Lemmas in
if i > 0 then (
calc (<=) {
0;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
sum_pow_seq_left s (i - 1);
<= {lemma_pow_nat n (i - 1); nat_times_nat_is_nat s.[i - 1] (pow_int n (i - 1))}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1);
== {}
sum_pow_seq_left s i;
};
calc (<=) {
sum_pow_seq_left s i + 1;
== {}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1) + 1;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
s.[i - 1] * pow_int n (i - 1) + pow_int n (i - 1);
<= {lemma_pow_nat n (i - 1); lemma_mult_le_right (pow_int n (i - 1)) s.[i - 1] (n - 1)}
(n - 1) * pow_int n (i - 1) + pow_int n (i - 1);
== {}
pow_int n i;
}
)
let lemma_sum_pow_seq_bound #n s =
lemma_sum_pow_seq_bound_rec s (length s)
let lemma_seq_add_is_norm #n as0 bs c0 i =
()
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_last_carry_mul a b c =
()
#pop-options
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_add_lo_mul_right #n a b c m =
reveal_add_lo_all ()
#pop-options
let rec lemma_seq_add_rec (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Lemma
(requires i <= length as0 /\ length bs == length as0)
(ensures (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
sum_pow_seq_left xs i + last_carry n i ci == sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0
))
(decreases i)
=
if (i > 0) then (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
let i' = i - 1 in
let ci' = seq_add_c as0 bs c0 i' in
calc (==) {
sum_pow_seq_left xs i + last_carry n i ci;
== {}
xs.[i'] * pow_int n i' + sum_pow_seq_left xs i' + last_carry n i ci;
== {lemma_seq_add_rec as0 bs c0 i'}
xs.[i'] * pow_int n i' + sum_pow_seq_left as0 i' + sum_pow_seq_left bs i' + c0 - last_carry n i' ci' + last_carry n i ci;
== {
reveal_add_hi_all ();
lemma_last_carry_mul n i' ci';
lemma_add_lo_mul_right as0.[i'] bs.[i'] ci' (pow_int n i')
}
sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0;
}
)
let lemma_seq_add #n as0 bs c0 =
lemma_seq_add_rec as0 bs c0 (length as0)
#push-options "--z3rlimit 100 --z3cliopt smt.arith.nl=true --max_ifuel 0"
#restart-solver
let rec lemma_seq_scale_rec (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) (i:nat) : Lemma
(requires i <= length bs)
(ensures (
a * sum_pow_seq_left bs i + d ==
sum_pow_seq_left (seq_scale_lo a bs) i + sum_pow_seq_left (seq_scale_hi a bs d) (i + 1)
))
(decreases i)
=
reveal_mul_lo_all ();
reveal_mul_hi_all ();
if i = 0 then (
assert (sum_pow_seq_left (seq_scale_hi a bs d) 0 == 0);
assert (sum_pow_seq_left (seq_scale_hi a bs d) 1 == d)
) else (
lemma_seq_scale_rec a bs d (i - 1)
)
#pop-options
let rec lemma_seq_scale_carry1 (a:natN 1) (bs:seq (natN 1)) (d:natN 1) (i:nat) : Lemma
(requires i <= length bs + 1)
(ensures (
seq_add_c (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 i == 0
))
=
reveal_add_hi_all ();
if i > 0 then lemma_seq_scale_carry1 a bs d (i - 1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Vale.Def.Words_s.natN n ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
d: Vale.Def.Words_s.natN n
-> FStar.Pervasives.Lemma
(ensures
FStar.Pervasives.Native.snd (Vale.Bignum.Lemmas.seq_add (Vale.Bignum.Lemmas.seq_scale_lo a bs)
(Vale.Bignum.Lemmas.seq_scale_hi a bs d)
0) ==
0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.natN",
"FStar.Seq.Base.seq",
"Prims.op_Equality",
"Prims.int",
"Prims._assert",
"Prims.eq2",
"Vale.Bignum.Lemmas.seq_add_c",
"Vale.Bignum.Lemmas.seq_scale_lo",
"Vale.Bignum.Lemmas.seq_scale_hi",
"Prims.bool",
"Vale.Bignum.Lemmas.lemma_seq_scale_carry1",
"Prims.op_Addition",
"Prims.unit",
"Vale.Bignum.Defs.lemma_mul_div_n_lt",
"Vale.Bignum.Lemmas.op_String_Access",
"Prims.op_Subtraction",
"Vale.Bignum.Defs.lemma_mul_n_bound",
"FStar.Seq.Base.length",
"Vale.Bignum.Defs.reveal_mul_hi_all",
"Vale.Bignum.Defs.reveal_mul_lo_all",
"Vale.Bignum.Defs.reveal_add_hi_all"
] | [] | false | false | true | false | false | let lemma_seq_scale_carry #n a bs d =
| reveal_add_hi_all ();
reveal_mul_lo_all ();
reveal_mul_hi_all ();
let l = length bs in
if l = 0
then assert (seq_add_c (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 0 == 0)
else
if n = 1
then lemma_seq_scale_carry1 a bs d (l + 1)
else
(lemma_mul_n_bound a bs.[ l - 1 ];
lemma_mul_div_n_lt a bs.[ l - 1 ];
()) | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_sum_pow_seq_bound_rec | val lemma_sum_pow_seq_bound_rec (#n: nat) (s: seq (natN n)) (i: nat{i <= length s})
: Lemma (ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i) | val lemma_sum_pow_seq_bound_rec (#n: nat) (s: seq (natN n)) (i: nat{i <= length s})
: Lemma (ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i) | let rec lemma_sum_pow_seq_bound_rec (#n:nat) (s:seq (natN n)) (i:nat{i <= length s}) : Lemma
(ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i)
=
let open FStar.Math.Lemmas in
if i > 0 then (
calc (<=) {
0;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
sum_pow_seq_left s (i - 1);
<= {lemma_pow_nat n (i - 1); nat_times_nat_is_nat s.[i - 1] (pow_int n (i - 1))}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1);
== {}
sum_pow_seq_left s i;
};
calc (<=) {
sum_pow_seq_left s i + 1;
== {}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1) + 1;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
s.[i - 1] * pow_int n (i - 1) + pow_int n (i - 1);
<= {lemma_pow_nat n (i - 1); lemma_mult_le_right (pow_int n (i - 1)) s.[i - 1] (n - 1)}
(n - 1) * pow_int n (i - 1) + pow_int n (i - 1);
== {}
pow_int n i;
}
) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 45,
"start_col": 0,
"start_line": 20
} | module Vale.Bignum.Lemmas
open FStar.Mul
let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k
let lemma_sum_seq_left_right s i j =
lemma_sum_seq_left_right_rec s i j j
let rec lemma_pow_nat a b =
if b > 0 then (
lemma_pow_nat a (b - 1);
FStar.Math.Lemmas.nat_times_nat_is_nat a (pow_int a (b - 1))
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) -> i: Prims.nat{i <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
0 <= Vale.Bignum.Defs.sum_pow_seq_left s i /\
Vale.Bignum.Defs.sum_pow_seq_left s i < Vale.Bignum.Defs.pow_int n i) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.natN",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.op_GreaterThan",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.op_Addition",
"Vale.Bignum.Defs.sum_pow_seq_left",
"Vale.Bignum.Defs.pow_int",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.eq2",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Mul.op_Star",
"Prims.op_Subtraction",
"Vale.Bignum.Lemmas.op_String_Access",
"Vale.Bignum.Defs.sum_seq_left",
"Vale.Bignum.Defs.pow_seq",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"Vale.Bignum.Lemmas.lemma_sum_pow_seq_bound_rec",
"FStar.Math.Lemmas.lemma_mult_le_right",
"Vale.Bignum.Lemmas.lemma_pow_nat",
"FStar.Math.Lemmas.nat_times_nat_is_nat",
"Prims.bool",
"Prims.l_True",
"Prims.l_and",
"Prims.op_LessThan",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_sum_pow_seq_bound_rec (#n: nat) (s: seq (natN n)) (i: nat{i <= length s})
: Lemma (ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i) =
| let open FStar.Math.Lemmas in
if i > 0
then
(calc ( <= ) {
0;
( <= ) { lemma_sum_pow_seq_bound_rec s (i - 1) }
sum_pow_seq_left s (i - 1);
( <= ) { (lemma_pow_nat n (i - 1);
nat_times_nat_is_nat s.[ i - 1 ] (pow_int n (i - 1))) }
s.[ i - 1 ] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1);
( == ) { () }
sum_pow_seq_left s i;
};
calc ( <= ) {
sum_pow_seq_left s i + 1;
( == ) { () }
s.[ i - 1 ] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1) + 1;
( <= ) { lemma_sum_pow_seq_bound_rec s (i - 1) }
s.[ i - 1 ] * pow_int n (i - 1) + pow_int n (i - 1);
( <= ) { (lemma_pow_nat n (i - 1);
lemma_mult_le_right (pow_int n (i - 1)) s.[ i - 1 ] (n - 1)) }
(n - 1) * pow_int n (i - 1) + pow_int n (i - 1);
( == ) { () }
pow_int n i;
}) | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_seq_add | val lemma_seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Lemma
(requires length bs == length as0)
(ensures (
let (xs, ci) = seq_add as0 bs c0 in
sum_pow_seq xs + last_carry n (length as0) ci == sum_pow_seq as0 + sum_pow_seq bs + c0
)) | val lemma_seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Lemma
(requires length bs == length as0)
(ensures (
let (xs, ci) = seq_add as0 bs c0 in
sum_pow_seq xs + last_carry n (length as0) ci == sum_pow_seq as0 + sum_pow_seq bs + c0
)) | let lemma_seq_add #n as0 bs c0 =
lemma_seq_add_rec as0 bs c0 (length as0) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 95,
"start_col": 0,
"start_line": 94
} | module Vale.Bignum.Lemmas
open FStar.Mul
let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k
let lemma_sum_seq_left_right s i j =
lemma_sum_seq_left_right_rec s i j j
let rec lemma_pow_nat a b =
if b > 0 then (
lemma_pow_nat a (b - 1);
FStar.Math.Lemmas.nat_times_nat_is_nat a (pow_int a (b - 1))
)
let rec lemma_sum_pow_seq_bound_rec (#n:nat) (s:seq (natN n)) (i:nat{i <= length s}) : Lemma
(ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i)
=
let open FStar.Math.Lemmas in
if i > 0 then (
calc (<=) {
0;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
sum_pow_seq_left s (i - 1);
<= {lemma_pow_nat n (i - 1); nat_times_nat_is_nat s.[i - 1] (pow_int n (i - 1))}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1);
== {}
sum_pow_seq_left s i;
};
calc (<=) {
sum_pow_seq_left s i + 1;
== {}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1) + 1;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
s.[i - 1] * pow_int n (i - 1) + pow_int n (i - 1);
<= {lemma_pow_nat n (i - 1); lemma_mult_le_right (pow_int n (i - 1)) s.[i - 1] (n - 1)}
(n - 1) * pow_int n (i - 1) + pow_int n (i - 1);
== {}
pow_int n i;
}
)
let lemma_sum_pow_seq_bound #n s =
lemma_sum_pow_seq_bound_rec s (length s)
let lemma_seq_add_is_norm #n as0 bs c0 i =
()
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_last_carry_mul a b c =
()
#pop-options
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_add_lo_mul_right #n a b c m =
reveal_add_lo_all ()
#pop-options
let rec lemma_seq_add_rec (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Lemma
(requires i <= length as0 /\ length bs == length as0)
(ensures (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
sum_pow_seq_left xs i + last_carry n i ci == sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0
))
(decreases i)
=
if (i > 0) then (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
let i' = i - 1 in
let ci' = seq_add_c as0 bs c0 i' in
calc (==) {
sum_pow_seq_left xs i + last_carry n i ci;
== {}
xs.[i'] * pow_int n i' + sum_pow_seq_left xs i' + last_carry n i ci;
== {lemma_seq_add_rec as0 bs c0 i'}
xs.[i'] * pow_int n i' + sum_pow_seq_left as0 i' + sum_pow_seq_left bs i' + c0 - last_carry n i' ci' + last_carry n i ci;
== {
reveal_add_hi_all ();
lemma_last_carry_mul n i' ci';
lemma_add_lo_mul_right as0.[i'] bs.[i'] ci' (pow_int n i')
}
sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0;
}
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
as0: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
c0: Vale.Def.Words_s.nat1
-> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length bs == FStar.Seq.Base.length as0)
(ensures
(let _ = Vale.Bignum.Lemmas.seq_add as0 bs c0 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ xs ci = _ in
Vale.Bignum.Defs.sum_pow_seq xs +
Vale.Bignum.Lemmas.last_carry n (FStar.Seq.Base.length as0) ci ==
Vale.Bignum.Defs.sum_pow_seq as0 + Vale.Bignum.Defs.sum_pow_seq bs + c0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.nat1",
"Vale.Bignum.Lemmas.lemma_seq_add_rec",
"FStar.Seq.Base.length",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_seq_add #n as0 bs c0 =
| lemma_seq_add_rec as0 bs c0 (length as0) | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_sum_pow_seq_bound | val lemma_sum_pow_seq_bound (#n:nat) (s:seq (natN n)) : Lemma
(ensures 0 <= sum_pow_seq s /\ sum_pow_seq s < pow_int n (length s)) | val lemma_sum_pow_seq_bound (#n:nat) (s:seq (natN n)) : Lemma
(ensures 0 <= sum_pow_seq s /\ sum_pow_seq s < pow_int n (length s)) | let lemma_sum_pow_seq_bound #n s =
lemma_sum_pow_seq_bound_rec s (length s) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 48,
"start_col": 0,
"start_line": 47
} | module Vale.Bignum.Lemmas
open FStar.Mul
let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k
let lemma_sum_seq_left_right s i j =
lemma_sum_seq_left_right_rec s i j j
let rec lemma_pow_nat a b =
if b > 0 then (
lemma_pow_nat a (b - 1);
FStar.Math.Lemmas.nat_times_nat_is_nat a (pow_int a (b - 1))
)
let rec lemma_sum_pow_seq_bound_rec (#n:nat) (s:seq (natN n)) (i:nat{i <= length s}) : Lemma
(ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i)
=
let open FStar.Math.Lemmas in
if i > 0 then (
calc (<=) {
0;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
sum_pow_seq_left s (i - 1);
<= {lemma_pow_nat n (i - 1); nat_times_nat_is_nat s.[i - 1] (pow_int n (i - 1))}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1);
== {}
sum_pow_seq_left s i;
};
calc (<=) {
sum_pow_seq_left s i + 1;
== {}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1) + 1;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
s.[i - 1] * pow_int n (i - 1) + pow_int n (i - 1);
<= {lemma_pow_nat n (i - 1); lemma_mult_le_right (pow_int n (i - 1)) s.[i - 1] (n - 1)}
(n - 1) * pow_int n (i - 1) + pow_int n (i - 1);
== {}
pow_int n i;
}
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n)
-> FStar.Pervasives.Lemma
(ensures
0 <= Vale.Bignum.Defs.sum_pow_seq s /\
Vale.Bignum.Defs.sum_pow_seq s < Vale.Bignum.Defs.pow_int n (FStar.Seq.Base.length s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.natN",
"Vale.Bignum.Lemmas.lemma_sum_pow_seq_bound_rec",
"FStar.Seq.Base.length",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_sum_pow_seq_bound #n s =
| lemma_sum_pow_seq_bound_rec s (length s) | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_seq_scale_carry1 | val lemma_seq_scale_carry1 (a: natN 1) (bs: seq (natN 1)) (d: natN 1) (i: nat)
: Lemma (requires i <= length bs + 1)
(ensures (seq_add_c (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 i == 0)) | val lemma_seq_scale_carry1 (a: natN 1) (bs: seq (natN 1)) (d: natN 1) (i: nat)
: Lemma (requires i <= length bs + 1)
(ensures (seq_add_c (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 i == 0)) | let rec lemma_seq_scale_carry1 (a:natN 1) (bs:seq (natN 1)) (d:natN 1) (i:nat) : Lemma
(requires i <= length bs + 1)
(ensures (
seq_add_c (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 i == 0
))
=
reveal_add_hi_all ();
if i > 0 then lemma_seq_scale_carry1 a bs d (i - 1) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 124,
"start_col": 0,
"start_line": 117
} | module Vale.Bignum.Lemmas
open FStar.Mul
let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k
let lemma_sum_seq_left_right s i j =
lemma_sum_seq_left_right_rec s i j j
let rec lemma_pow_nat a b =
if b > 0 then (
lemma_pow_nat a (b - 1);
FStar.Math.Lemmas.nat_times_nat_is_nat a (pow_int a (b - 1))
)
let rec lemma_sum_pow_seq_bound_rec (#n:nat) (s:seq (natN n)) (i:nat{i <= length s}) : Lemma
(ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i)
=
let open FStar.Math.Lemmas in
if i > 0 then (
calc (<=) {
0;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
sum_pow_seq_left s (i - 1);
<= {lemma_pow_nat n (i - 1); nat_times_nat_is_nat s.[i - 1] (pow_int n (i - 1))}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1);
== {}
sum_pow_seq_left s i;
};
calc (<=) {
sum_pow_seq_left s i + 1;
== {}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1) + 1;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
s.[i - 1] * pow_int n (i - 1) + pow_int n (i - 1);
<= {lemma_pow_nat n (i - 1); lemma_mult_le_right (pow_int n (i - 1)) s.[i - 1] (n - 1)}
(n - 1) * pow_int n (i - 1) + pow_int n (i - 1);
== {}
pow_int n i;
}
)
let lemma_sum_pow_seq_bound #n s =
lemma_sum_pow_seq_bound_rec s (length s)
let lemma_seq_add_is_norm #n as0 bs c0 i =
()
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_last_carry_mul a b c =
()
#pop-options
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_add_lo_mul_right #n a b c m =
reveal_add_lo_all ()
#pop-options
let rec lemma_seq_add_rec (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Lemma
(requires i <= length as0 /\ length bs == length as0)
(ensures (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
sum_pow_seq_left xs i + last_carry n i ci == sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0
))
(decreases i)
=
if (i > 0) then (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
let i' = i - 1 in
let ci' = seq_add_c as0 bs c0 i' in
calc (==) {
sum_pow_seq_left xs i + last_carry n i ci;
== {}
xs.[i'] * pow_int n i' + sum_pow_seq_left xs i' + last_carry n i ci;
== {lemma_seq_add_rec as0 bs c0 i'}
xs.[i'] * pow_int n i' + sum_pow_seq_left as0 i' + sum_pow_seq_left bs i' + c0 - last_carry n i' ci' + last_carry n i ci;
== {
reveal_add_hi_all ();
lemma_last_carry_mul n i' ci';
lemma_add_lo_mul_right as0.[i'] bs.[i'] ci' (pow_int n i')
}
sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0;
}
)
let lemma_seq_add #n as0 bs c0 =
lemma_seq_add_rec as0 bs c0 (length as0)
#push-options "--z3rlimit 100 --z3cliopt smt.arith.nl=true --max_ifuel 0"
#restart-solver
let rec lemma_seq_scale_rec (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) (i:nat) : Lemma
(requires i <= length bs)
(ensures (
a * sum_pow_seq_left bs i + d ==
sum_pow_seq_left (seq_scale_lo a bs) i + sum_pow_seq_left (seq_scale_hi a bs d) (i + 1)
))
(decreases i)
=
reveal_mul_lo_all ();
reveal_mul_hi_all ();
if i = 0 then (
assert (sum_pow_seq_left (seq_scale_hi a bs d) 0 == 0);
assert (sum_pow_seq_left (seq_scale_hi a bs d) 1 == d)
) else (
lemma_seq_scale_rec a bs d (i - 1)
)
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Vale.Def.Words_s.natN 1 ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN 1) ->
d: Vale.Def.Words_s.natN 1 ->
i: Prims.nat
-> FStar.Pervasives.Lemma (requires i <= FStar.Seq.Base.length bs + 1)
(ensures
Vale.Bignum.Lemmas.seq_add_c (Vale.Bignum.Lemmas.seq_scale_lo a bs)
(Vale.Bignum.Lemmas.seq_scale_hi a bs d)
0
i ==
0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words_s.natN",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.op_GreaterThan",
"Vale.Bignum.Lemmas.lemma_seq_scale_carry1",
"Prims.op_Subtraction",
"Prims.bool",
"Prims.unit",
"Vale.Bignum.Defs.reveal_add_hi_all",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Seq.Base.length",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Vale.Bignum.Lemmas.seq_add_c",
"Vale.Bignum.Lemmas.seq_scale_lo",
"Vale.Bignum.Lemmas.seq_scale_hi",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_seq_scale_carry1 (a: natN 1) (bs: seq (natN 1)) (d: natN 1) (i: nat)
: Lemma (requires i <= length bs + 1)
(ensures (seq_add_c (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 i == 0)) =
| reveal_add_hi_all ();
if i > 0 then lemma_seq_scale_carry1 a bs d (i - 1) | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_seq_scale | val lemma_seq_scale (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : Lemma
(ensures (
sum_pow_seq (seq_scale a bs d) == sum_pow_seq (seq_scale_lo a bs) + sum_pow_seq (seq_scale_hi a bs d) /\
sum_pow_seq (seq_scale a bs d) == a * sum_pow_seq bs + d
)) | val lemma_seq_scale (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : Lemma
(ensures (
sum_pow_seq (seq_scale a bs d) == sum_pow_seq (seq_scale_lo a bs) + sum_pow_seq (seq_scale_hi a bs d) /\
sum_pow_seq (seq_scale a bs d) == a * sum_pow_seq bs + d
)) | let lemma_seq_scale #n a bs d =
let l = length bs in
calc (==) {
sum_pow_seq (seq_scale a bs d);
== {
lemma_seq_scale_carry a bs d;
lemma_seq_add_rec (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 (l + 1)
}
sum_pow_seq (seq_scale_lo a bs) + sum_pow_seq (seq_scale_hi a bs d);
};
calc (==) {
sum_pow_seq (seq_scale_lo a bs) + sum_pow_seq (seq_scale_hi a bs d);
== {assert (0 * pow_int n l == 0)}
sum_pow_seq_left (seq_scale_lo a bs) l + sum_pow_seq (seq_scale_hi a bs d);
== {lemma_seq_scale_rec a bs d (length bs)}
a * sum_pow_seq bs + d;
} | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 155,
"start_col": 0,
"start_line": 139
} | module Vale.Bignum.Lemmas
open FStar.Mul
let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k
let lemma_sum_seq_left_right s i j =
lemma_sum_seq_left_right_rec s i j j
let rec lemma_pow_nat a b =
if b > 0 then (
lemma_pow_nat a (b - 1);
FStar.Math.Lemmas.nat_times_nat_is_nat a (pow_int a (b - 1))
)
let rec lemma_sum_pow_seq_bound_rec (#n:nat) (s:seq (natN n)) (i:nat{i <= length s}) : Lemma
(ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i)
=
let open FStar.Math.Lemmas in
if i > 0 then (
calc (<=) {
0;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
sum_pow_seq_left s (i - 1);
<= {lemma_pow_nat n (i - 1); nat_times_nat_is_nat s.[i - 1] (pow_int n (i - 1))}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1);
== {}
sum_pow_seq_left s i;
};
calc (<=) {
sum_pow_seq_left s i + 1;
== {}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1) + 1;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
s.[i - 1] * pow_int n (i - 1) + pow_int n (i - 1);
<= {lemma_pow_nat n (i - 1); lemma_mult_le_right (pow_int n (i - 1)) s.[i - 1] (n - 1)}
(n - 1) * pow_int n (i - 1) + pow_int n (i - 1);
== {}
pow_int n i;
}
)
let lemma_sum_pow_seq_bound #n s =
lemma_sum_pow_seq_bound_rec s (length s)
let lemma_seq_add_is_norm #n as0 bs c0 i =
()
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_last_carry_mul a b c =
()
#pop-options
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_add_lo_mul_right #n a b c m =
reveal_add_lo_all ()
#pop-options
let rec lemma_seq_add_rec (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Lemma
(requires i <= length as0 /\ length bs == length as0)
(ensures (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
sum_pow_seq_left xs i + last_carry n i ci == sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0
))
(decreases i)
=
if (i > 0) then (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
let i' = i - 1 in
let ci' = seq_add_c as0 bs c0 i' in
calc (==) {
sum_pow_seq_left xs i + last_carry n i ci;
== {}
xs.[i'] * pow_int n i' + sum_pow_seq_left xs i' + last_carry n i ci;
== {lemma_seq_add_rec as0 bs c0 i'}
xs.[i'] * pow_int n i' + sum_pow_seq_left as0 i' + sum_pow_seq_left bs i' + c0 - last_carry n i' ci' + last_carry n i ci;
== {
reveal_add_hi_all ();
lemma_last_carry_mul n i' ci';
lemma_add_lo_mul_right as0.[i'] bs.[i'] ci' (pow_int n i')
}
sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0;
}
)
let lemma_seq_add #n as0 bs c0 =
lemma_seq_add_rec as0 bs c0 (length as0)
#push-options "--z3rlimit 100 --z3cliopt smt.arith.nl=true --max_ifuel 0"
#restart-solver
let rec lemma_seq_scale_rec (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) (i:nat) : Lemma
(requires i <= length bs)
(ensures (
a * sum_pow_seq_left bs i + d ==
sum_pow_seq_left (seq_scale_lo a bs) i + sum_pow_seq_left (seq_scale_hi a bs d) (i + 1)
))
(decreases i)
=
reveal_mul_lo_all ();
reveal_mul_hi_all ();
if i = 0 then (
assert (sum_pow_seq_left (seq_scale_hi a bs d) 0 == 0);
assert (sum_pow_seq_left (seq_scale_hi a bs d) 1 == d)
) else (
lemma_seq_scale_rec a bs d (i - 1)
)
#pop-options
let rec lemma_seq_scale_carry1 (a:natN 1) (bs:seq (natN 1)) (d:natN 1) (i:nat) : Lemma
(requires i <= length bs + 1)
(ensures (
seq_add_c (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 i == 0
))
=
reveal_add_hi_all ();
if i > 0 then lemma_seq_scale_carry1 a bs d (i - 1)
let lemma_seq_scale_carry #n a bs d =
reveal_add_hi_all ();
reveal_mul_lo_all ();
reveal_mul_hi_all ();
let l = length bs in
if l = 0 then assert (seq_add_c (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 0 == 0)
else if n = 1 then lemma_seq_scale_carry1 a bs d (l + 1)
else (
lemma_mul_n_bound a bs.[l - 1];
lemma_mul_div_n_lt a bs.[l - 1];
()
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Vale.Def.Words_s.natN n ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
d: Vale.Def.Words_s.natN n
-> FStar.Pervasives.Lemma
(ensures
Vale.Bignum.Defs.sum_pow_seq (Vale.Bignum.Lemmas.seq_scale a bs d) ==
Vale.Bignum.Defs.sum_pow_seq (Vale.Bignum.Lemmas.seq_scale_lo a bs) +
Vale.Bignum.Defs.sum_pow_seq (Vale.Bignum.Lemmas.seq_scale_hi a bs d) /\
Vale.Bignum.Defs.sum_pow_seq (Vale.Bignum.Lemmas.seq_scale a bs d) ==
a * Vale.Bignum.Defs.sum_pow_seq bs + d) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.natN",
"FStar.Seq.Base.seq",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"Vale.Bignum.Defs.sum_pow_seq",
"Vale.Bignum.Lemmas.seq_scale_lo",
"Vale.Bignum.Lemmas.seq_scale_hi",
"FStar.Mul.op_Star",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Vale.Bignum.Defs.sum_pow_seq_left",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims._assert",
"Vale.Bignum.Defs.pow_int",
"Prims.squash",
"Vale.Bignum.Lemmas.lemma_seq_scale_rec",
"FStar.Seq.Base.length",
"Vale.Bignum.Lemmas.seq_scale",
"Vale.Bignum.Lemmas.lemma_seq_add_rec",
"Vale.Bignum.Lemmas.lemma_seq_scale_carry"
] | [] | false | false | true | false | false | let lemma_seq_scale #n a bs d =
| let l = length bs in
calc ( == ) {
sum_pow_seq (seq_scale a bs d);
( == ) { (lemma_seq_scale_carry a bs d;
lemma_seq_add_rec (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 (l + 1)) }
sum_pow_seq (seq_scale_lo a bs) + sum_pow_seq (seq_scale_hi a bs d);
};
calc ( == ) {
sum_pow_seq (seq_scale_lo a bs) + sum_pow_seq (seq_scale_hi a bs d);
( == ) { assert (0 * pow_int n l == 0) }
sum_pow_seq_left (seq_scale_lo a bs) l + sum_pow_seq (seq_scale_hi a bs d);
( == ) { lemma_seq_scale_rec a bs d (length bs) }
a * sum_pow_seq bs + d;
} | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_add_lo_mul_right | val lemma_add_lo_mul_right (#n:nat) (a b:natN n) (c:nat1) (m:int) : Lemma
(add_lo a b c * m == (let x = a * m + b * m + c * m in if a + b + c < n then x else x - n * m)) | val lemma_add_lo_mul_right (#n:nat) (a b:natN n) (c:nat1) (m:int) : Lemma
(add_lo a b c * m == (let x = a * m + b * m + c * m in if a + b + c < n then x else x - n * m)) | let lemma_add_lo_mul_right #n a b c m =
reveal_add_lo_all () | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 62,
"start_col": 0,
"start_line": 61
} | module Vale.Bignum.Lemmas
open FStar.Mul
let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k
let lemma_sum_seq_left_right s i j =
lemma_sum_seq_left_right_rec s i j j
let rec lemma_pow_nat a b =
if b > 0 then (
lemma_pow_nat a (b - 1);
FStar.Math.Lemmas.nat_times_nat_is_nat a (pow_int a (b - 1))
)
let rec lemma_sum_pow_seq_bound_rec (#n:nat) (s:seq (natN n)) (i:nat{i <= length s}) : Lemma
(ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i)
=
let open FStar.Math.Lemmas in
if i > 0 then (
calc (<=) {
0;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
sum_pow_seq_left s (i - 1);
<= {lemma_pow_nat n (i - 1); nat_times_nat_is_nat s.[i - 1] (pow_int n (i - 1))}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1);
== {}
sum_pow_seq_left s i;
};
calc (<=) {
sum_pow_seq_left s i + 1;
== {}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1) + 1;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
s.[i - 1] * pow_int n (i - 1) + pow_int n (i - 1);
<= {lemma_pow_nat n (i - 1); lemma_mult_le_right (pow_int n (i - 1)) s.[i - 1] (n - 1)}
(n - 1) * pow_int n (i - 1) + pow_int n (i - 1);
== {}
pow_int n i;
}
)
let lemma_sum_pow_seq_bound #n s =
lemma_sum_pow_seq_bound_rec s (length s)
let lemma_seq_add_is_norm #n as0 bs c0 i =
()
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_last_carry_mul a b c =
()
#pop-options
#push-options "--z3cliopt smt.arith.nl=true" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.arith.nl=true"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Vale.Def.Words_s.natN n -> b: Vale.Def.Words_s.natN n -> c: Vale.Def.Words_s.nat1 -> m: Prims.int
-> FStar.Pervasives.Lemma
(ensures
Vale.Bignum.Defs.add_lo a b c * m ==
(let x = a * m + b * m + c * m in
(match a + b + c < n with
| true -> x
| _ -> x - n * m)
<:
Prims.int)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.nat1",
"Prims.int",
"Vale.Bignum.Defs.reveal_add_lo_all",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_add_lo_mul_right #n a b c m =
| reveal_add_lo_all () | false |
Pulse.Readback.fst | Pulse.Readback.debug_log | val debug_log (f: (unit -> T.Tac unit)) : T.Tac unit | val debug_log (f: (unit -> T.Tac unit)) : T.Tac unit | let debug_log (f: unit -> T.Tac unit) : T.Tac unit = if RU.debug_at_level_no_module "readback" then f() | {
"file_name": "lib/steel/pulse/Pulse.Readback.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 103,
"end_line": 24,
"start_col": 0,
"start_line": 24
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Readback
module R = FStar.Reflection.V2
open Pulse.Syntax.Base
open Pulse.Reflection.Util
module RU = Pulse.RuntimeUtils
module T = FStar.Tactics | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Readback.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"Pulse.RuntimeUtils.debug_at_level_no_module",
"Prims.bool"
] | [] | false | true | false | false | false | let debug_log (f: (unit -> T.Tac unit)) : T.Tac unit =
| if RU.debug_at_level_no_module "readback" then f () | false |
Pulse.Readback.fst | Pulse.Readback.readback_qual | val readback_qual (q:R.aqualv)
: option qualifier | val readback_qual (q:R.aqualv)
: option qualifier | let readback_qual = function
| R.Q_Implicit -> Some Implicit
| _ -> None | {
"file_name": "lib/steel/pulse/Pulse.Readback.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 13,
"end_line": 124,
"start_col": 0,
"start_line": 122
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Readback
module R = FStar.Reflection.V2
open Pulse.Syntax.Base
open Pulse.Reflection.Util
module RU = Pulse.RuntimeUtils
module T = FStar.Tactics
module P = Pulse.Syntax.Printer
let debug_log (f: unit -> T.Tac unit) : T.Tac unit = if RU.debug_at_level_no_module "readback" then f()
let (let?) (f:option 'a) (g:'a -> option 'b) : option 'b =
match f with
| None -> None
| Some x -> g x
let readback_observability (t:R.term)
: option (obs:observability { elab_observability obs == t })
= let open R in
match inspect_ln t with
| R.Tv_FVar fv ->
let fv_lid = inspect_fv fv in
if fv_lid = observable_lid
then Some Observable
else if fv_lid = unobservable_lid
then Some Unobservable
else if fv_lid = neutral_lid
then Some Neutral
else None
| _ -> None
#push-options "--z3rlimit_factor 20"
// TODO: FIXME: may be mark as opaque_to_smt
let try_readback_st_comp
(t:R.term)
(readback_ty:(t':R.term ->
option (ty:term { elab_term ty == t' })))
: option (c:comp{elab_comp c == t}) =
let open R in
let hd, args = collect_app_ln t in
match inspect_ln hd with
| Tv_UInst fv [u] ->
let fv_lid = inspect_fv fv in
if fv_lid = stt_lid
then match args with
| [res; pre; post] ->
(match inspect_ln (fst post) with
| Tv_Abs b body ->
let { qual=aq; attrs=attrs; sort=sort } =
inspect_binder b
in
assume (fv == stt_fv);
assume (aq == Q_Explicit /\
attrs == [] /\
sort == fst res /\
snd res == Q_Explicit /\
snd pre == Q_Explicit /\
snd post == Q_Explicit);
assume (t == mk_stt_comp u (fst res) (fst pre) (mk_abs (fst res) R.Q_Explicit body));
let? res' = readback_ty (fst res) in
let? pre' = readback_ty (fst pre) in
let? post' = readback_ty body in
let c = C_ST {u; res=res'; pre=pre';post=post'} in
Some (c <: c:Pulse.Syntax.Base.comp{ elab_comp c == t })
| _ -> None)
| _ -> None
else if fv_lid = stt_atomic_lid
then match args with
| [res; obs; opened; pre; post] ->
(match inspect_ln (fst post) with
| Tv_Abs b body ->
let { qual=aq; attrs=attrs }
= inspect_binder b
in
let? res' = readback_ty (fst res) in
let? obs' = readback_observability (fst obs) in
let? opened' = readback_ty (fst opened) in
let? pre' = readback_ty (fst pre) in
let? post' = readback_ty body in
assume (t == mk_stt_atomic_comp (fst obs) u (fst res) (fst opened) (fst pre) (mk_abs (fst res) R.Q_Explicit body));
let c = C_STAtomic opened' obs' ({u; res=res'; pre=pre';post=post'}) in
Some (c <: c:Pulse.Syntax.Base.comp { elab_comp c == t })
| _ -> None)
| _ -> None
else if fv_lid = stt_ghost_lid
then match args with
| [res; pre; post] ->
(match inspect_ln (fst post) with
| Tv_Abs b body ->
let { qual=aq; attrs=attrs }
= inspect_binder b
in
let? res' = readback_ty (fst res) in
let? pre' = readback_ty (fst pre) in
let? post' = readback_ty body in
assume (t == mk_stt_ghost_comp u (fst res) (fst pre) (mk_abs (fst res) R.Q_Explicit body));
let c = C_STGhost ({u; res=res'; pre=pre';post=post'}) in
Some (c <: c:Pulse.Syntax.Base.comp { elab_comp c == t })
| _ -> None)
| _ -> None
else None
| _ -> None
#pop-options | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Readback.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: FStar.Stubs.Reflection.V2.Data.aqualv
-> FStar.Pervasives.Native.option Pulse.Syntax.Base.qualifier | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Data.aqualv",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Base.Implicit",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | true | false | let readback_qual =
| function
| R.Q_Implicit -> Some Implicit
| _ -> None | false |
Vale.Math.Bits.fst | Vale.Math.Bits.lemma_pow2_le | val lemma_pow2_le (m n:nat) : Lemma (requires m <= n) (ensures pow2 m <= pow2 n) | val lemma_pow2_le (m n:nat) : Lemma (requires m <= n) (ensures pow2 m <= pow2 n) | let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 4,
"start_col": 0,
"start_line": 4
} | module Vale.Math.Bits
open FStar.Mul | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Prims.nat -> n: Prims.nat
-> FStar.Pervasives.Lemma (requires m <= n) (ensures Prims.pow2 m <= Prims.pow2 n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Math.Lemmas.pow2_le_compat",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_pow2_le m n =
| FStar.Math.Lemmas.pow2_le_compat n m | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_scale_add | val lemma_scale_add (#n:nat) (l:nat) (a d:natN n) (bs rs ys zs qs xs:seq (natN n)) : Lemma
(requires length bs == l /\ length rs == l + 1 /\ rs.[l] == 0)
(ensures (
let c0 = 0 in
let ys = init (l + 1) (ys_init a bs) in
let zs = init (l + 1) (zs_init a bs d) in
let (qs, qc) = seq_add rs zs c0 in
let (xs, xc) = seq_add qs ys c0 in
sum_pow_seq xs == sum_pow_seq rs + a * sum_pow_seq bs + d /\ qc == 0 /\ xc == 0
)) | val lemma_scale_add (#n:nat) (l:nat) (a d:natN n) (bs rs ys zs qs xs:seq (natN n)) : Lemma
(requires length bs == l /\ length rs == l + 1 /\ rs.[l] == 0)
(ensures (
let c0 = 0 in
let ys = init (l + 1) (ys_init a bs) in
let zs = init (l + 1) (zs_init a bs d) in
let (qs, qc) = seq_add rs zs c0 in
let (xs, xc) = seq_add qs ys c0 in
sum_pow_seq xs == sum_pow_seq rs + a * sum_pow_seq bs + d /\ qc == 0 /\ xc == 0
)) | let lemma_scale_add #n l a d bs rs ys zs qs xs =
let ys = init (l + 1) (ys_init a bs) in
let zs = init (l + 1) (zs_init a bs d) in
let c0 = 0 in
let o1 = 0 in
let (qs, _) = seq_add rs zs c0 in
let (xs, _) = seq_add qs ys c0 in
assert (equal ys (seq_scale_lo a bs));
assert (equal zs (seq_scale_hi a bs d));
lemma_sum_pow_seq_bound bs;
lemma_sum_pow_seq_bound xs;
lemma_sum_pow_seq_bound qs;
lemma_sum_pow_seq_bound_rec rs l;
lemma_mul_nat_bound a (n - 1) (sum_pow_seq bs) (pow_int n l - 1);
lemma_seq_add qs ys c0;
lemma_seq_add rs zs o1;
lemma_seq_scale a bs d;
() | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 174,
"start_col": 0,
"start_line": 157
} | module Vale.Bignum.Lemmas
open FStar.Mul
let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k
let lemma_sum_seq_left_right s i j =
lemma_sum_seq_left_right_rec s i j j
let rec lemma_pow_nat a b =
if b > 0 then (
lemma_pow_nat a (b - 1);
FStar.Math.Lemmas.nat_times_nat_is_nat a (pow_int a (b - 1))
)
let rec lemma_sum_pow_seq_bound_rec (#n:nat) (s:seq (natN n)) (i:nat{i <= length s}) : Lemma
(ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i)
=
let open FStar.Math.Lemmas in
if i > 0 then (
calc (<=) {
0;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
sum_pow_seq_left s (i - 1);
<= {lemma_pow_nat n (i - 1); nat_times_nat_is_nat s.[i - 1] (pow_int n (i - 1))}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1);
== {}
sum_pow_seq_left s i;
};
calc (<=) {
sum_pow_seq_left s i + 1;
== {}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1) + 1;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
s.[i - 1] * pow_int n (i - 1) + pow_int n (i - 1);
<= {lemma_pow_nat n (i - 1); lemma_mult_le_right (pow_int n (i - 1)) s.[i - 1] (n - 1)}
(n - 1) * pow_int n (i - 1) + pow_int n (i - 1);
== {}
pow_int n i;
}
)
let lemma_sum_pow_seq_bound #n s =
lemma_sum_pow_seq_bound_rec s (length s)
let lemma_seq_add_is_norm #n as0 bs c0 i =
()
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_last_carry_mul a b c =
()
#pop-options
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_add_lo_mul_right #n a b c m =
reveal_add_lo_all ()
#pop-options
let rec lemma_seq_add_rec (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Lemma
(requires i <= length as0 /\ length bs == length as0)
(ensures (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
sum_pow_seq_left xs i + last_carry n i ci == sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0
))
(decreases i)
=
if (i > 0) then (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
let i' = i - 1 in
let ci' = seq_add_c as0 bs c0 i' in
calc (==) {
sum_pow_seq_left xs i + last_carry n i ci;
== {}
xs.[i'] * pow_int n i' + sum_pow_seq_left xs i' + last_carry n i ci;
== {lemma_seq_add_rec as0 bs c0 i'}
xs.[i'] * pow_int n i' + sum_pow_seq_left as0 i' + sum_pow_seq_left bs i' + c0 - last_carry n i' ci' + last_carry n i ci;
== {
reveal_add_hi_all ();
lemma_last_carry_mul n i' ci';
lemma_add_lo_mul_right as0.[i'] bs.[i'] ci' (pow_int n i')
}
sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0;
}
)
let lemma_seq_add #n as0 bs c0 =
lemma_seq_add_rec as0 bs c0 (length as0)
#push-options "--z3rlimit 100 --z3cliopt smt.arith.nl=true --max_ifuel 0"
#restart-solver
let rec lemma_seq_scale_rec (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) (i:nat) : Lemma
(requires i <= length bs)
(ensures (
a * sum_pow_seq_left bs i + d ==
sum_pow_seq_left (seq_scale_lo a bs) i + sum_pow_seq_left (seq_scale_hi a bs d) (i + 1)
))
(decreases i)
=
reveal_mul_lo_all ();
reveal_mul_hi_all ();
if i = 0 then (
assert (sum_pow_seq_left (seq_scale_hi a bs d) 0 == 0);
assert (sum_pow_seq_left (seq_scale_hi a bs d) 1 == d)
) else (
lemma_seq_scale_rec a bs d (i - 1)
)
#pop-options
let rec lemma_seq_scale_carry1 (a:natN 1) (bs:seq (natN 1)) (d:natN 1) (i:nat) : Lemma
(requires i <= length bs + 1)
(ensures (
seq_add_c (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 i == 0
))
=
reveal_add_hi_all ();
if i > 0 then lemma_seq_scale_carry1 a bs d (i - 1)
let lemma_seq_scale_carry #n a bs d =
reveal_add_hi_all ();
reveal_mul_lo_all ();
reveal_mul_hi_all ();
let l = length bs in
if l = 0 then assert (seq_add_c (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 0 == 0)
else if n = 1 then lemma_seq_scale_carry1 a bs d (l + 1)
else (
lemma_mul_n_bound a bs.[l - 1];
lemma_mul_div_n_lt a bs.[l - 1];
()
)
let lemma_seq_scale #n a bs d =
let l = length bs in
calc (==) {
sum_pow_seq (seq_scale a bs d);
== {
lemma_seq_scale_carry a bs d;
lemma_seq_add_rec (seq_scale_lo a bs) (seq_scale_hi a bs d) 0 (l + 1)
}
sum_pow_seq (seq_scale_lo a bs) + sum_pow_seq (seq_scale_hi a bs d);
};
calc (==) {
sum_pow_seq (seq_scale_lo a bs) + sum_pow_seq (seq_scale_hi a bs d);
== {assert (0 * pow_int n l == 0)}
sum_pow_seq_left (seq_scale_lo a bs) l + sum_pow_seq (seq_scale_hi a bs d);
== {lemma_seq_scale_rec a bs d (length bs)}
a * sum_pow_seq bs + d;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
l: Prims.nat ->
a: Vale.Def.Words_s.natN n ->
d: Vale.Def.Words_s.natN n ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
rs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
ys: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
zs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
qs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
xs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n)
-> FStar.Pervasives.Lemma
(requires FStar.Seq.Base.length bs == l /\ FStar.Seq.Base.length rs == l + 1 /\ rs.[ l ] == 0)
(ensures
(let c0 = 0 in
let ys = FStar.Seq.Base.init (l + 1) (Vale.Bignum.Lemmas.ys_init a bs) in
let zs = FStar.Seq.Base.init (l + 1) (Vale.Bignum.Lemmas.zs_init a bs d) in
let _ = Vale.Bignum.Lemmas.seq_add rs zs c0 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ qs qc = _ in
let _ = Vale.Bignum.Lemmas.seq_add qs ys c0 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ xs xc = _ in
Vale.Bignum.Defs.sum_pow_seq xs ==
Vale.Bignum.Defs.sum_pow_seq rs + a * Vale.Bignum.Defs.sum_pow_seq bs + d /\ qc == 0 /\
xc == 0)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.natN",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat1",
"Prims.unit",
"Vale.Bignum.Lemmas.lemma_seq_scale",
"Vale.Bignum.Lemmas.lemma_seq_add",
"Vale.Bignum.Defs.lemma_mul_nat_bound",
"Prims.op_Subtraction",
"Vale.Bignum.Defs.sum_pow_seq",
"Vale.Bignum.Defs.pow_int",
"Vale.Bignum.Lemmas.lemma_sum_pow_seq_bound_rec",
"Vale.Bignum.Lemmas.lemma_sum_pow_seq_bound",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Bignum.Lemmas.seq_scale_hi",
"Vale.Bignum.Lemmas.seq_scale_lo",
"FStar.Pervasives.Native.tuple2",
"Vale.Bignum.Lemmas.seq_add",
"Prims.int",
"FStar.Seq.Base.init",
"Prims.op_Addition",
"Vale.Bignum.Lemmas.zs_init",
"Vale.Bignum.Lemmas.ys_init"
] | [] | false | false | true | false | false | let lemma_scale_add #n l a d bs rs ys zs qs xs =
| let ys = init (l + 1) (ys_init a bs) in
let zs = init (l + 1) (zs_init a bs d) in
let c0 = 0 in
let o1 = 0 in
let qs, _ = seq_add rs zs c0 in
let xs, _ = seq_add qs ys c0 in
assert (equal ys (seq_scale_lo a bs));
assert (equal zs (seq_scale_hi a bs d));
lemma_sum_pow_seq_bound bs;
lemma_sum_pow_seq_bound xs;
lemma_sum_pow_seq_bound qs;
lemma_sum_pow_seq_bound_rec rs l;
lemma_mul_nat_bound a (n - 1) (sum_pow_seq bs) (pow_int n l - 1);
lemma_seq_add qs ys c0;
lemma_seq_add rs zs o1;
lemma_seq_scale a bs d;
() | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_seq_scale_rec | val lemma_seq_scale_rec (#n: nat) (a: natN n) (bs: seq (natN n)) (d: natN n) (i: nat)
: Lemma (requires i <= length bs)
(ensures
(a * sum_pow_seq_left bs i + d ==
sum_pow_seq_left (seq_scale_lo a bs) i + sum_pow_seq_left (seq_scale_hi a bs d) (i + 1)))
(decreases i) | val lemma_seq_scale_rec (#n: nat) (a: natN n) (bs: seq (natN n)) (d: natN n) (i: nat)
: Lemma (requires i <= length bs)
(ensures
(a * sum_pow_seq_left bs i + d ==
sum_pow_seq_left (seq_scale_lo a bs) i + sum_pow_seq_left (seq_scale_hi a bs d) (i + 1)))
(decreases i) | let rec lemma_seq_scale_rec (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) (i:nat) : Lemma
(requires i <= length bs)
(ensures (
a * sum_pow_seq_left bs i + d ==
sum_pow_seq_left (seq_scale_lo a bs) i + sum_pow_seq_left (seq_scale_hi a bs d) (i + 1)
))
(decreases i)
=
reveal_mul_lo_all ();
reveal_mul_hi_all ();
if i = 0 then (
assert (sum_pow_seq_left (seq_scale_hi a bs d) 0 == 0);
assert (sum_pow_seq_left (seq_scale_hi a bs d) 1 == d)
) else (
lemma_seq_scale_rec a bs d (i - 1)
) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 114,
"start_col": 0,
"start_line": 99
} | module Vale.Bignum.Lemmas
open FStar.Mul
let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k
let lemma_sum_seq_left_right s i j =
lemma_sum_seq_left_right_rec s i j j
let rec lemma_pow_nat a b =
if b > 0 then (
lemma_pow_nat a (b - 1);
FStar.Math.Lemmas.nat_times_nat_is_nat a (pow_int a (b - 1))
)
let rec lemma_sum_pow_seq_bound_rec (#n:nat) (s:seq (natN n)) (i:nat{i <= length s}) : Lemma
(ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i)
=
let open FStar.Math.Lemmas in
if i > 0 then (
calc (<=) {
0;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
sum_pow_seq_left s (i - 1);
<= {lemma_pow_nat n (i - 1); nat_times_nat_is_nat s.[i - 1] (pow_int n (i - 1))}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1);
== {}
sum_pow_seq_left s i;
};
calc (<=) {
sum_pow_seq_left s i + 1;
== {}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1) + 1;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
s.[i - 1] * pow_int n (i - 1) + pow_int n (i - 1);
<= {lemma_pow_nat n (i - 1); lemma_mult_le_right (pow_int n (i - 1)) s.[i - 1] (n - 1)}
(n - 1) * pow_int n (i - 1) + pow_int n (i - 1);
== {}
pow_int n i;
}
)
let lemma_sum_pow_seq_bound #n s =
lemma_sum_pow_seq_bound_rec s (length s)
let lemma_seq_add_is_norm #n as0 bs c0 i =
()
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_last_carry_mul a b c =
()
#pop-options
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_add_lo_mul_right #n a b c m =
reveal_add_lo_all ()
#pop-options
let rec lemma_seq_add_rec (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Lemma
(requires i <= length as0 /\ length bs == length as0)
(ensures (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
sum_pow_seq_left xs i + last_carry n i ci == sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0
))
(decreases i)
=
if (i > 0) then (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
let i' = i - 1 in
let ci' = seq_add_c as0 bs c0 i' in
calc (==) {
sum_pow_seq_left xs i + last_carry n i ci;
== {}
xs.[i'] * pow_int n i' + sum_pow_seq_left xs i' + last_carry n i ci;
== {lemma_seq_add_rec as0 bs c0 i'}
xs.[i'] * pow_int n i' + sum_pow_seq_left as0 i' + sum_pow_seq_left bs i' + c0 - last_carry n i' ci' + last_carry n i ci;
== {
reveal_add_hi_all ();
lemma_last_carry_mul n i' ci';
lemma_add_lo_mul_right as0.[i'] bs.[i'] ci' (pow_int n i')
}
sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0;
}
)
let lemma_seq_add #n as0 bs c0 =
lemma_seq_add_rec as0 bs c0 (length as0)
#push-options "--z3rlimit 100 --z3cliopt smt.arith.nl=true --max_ifuel 0" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.arith.nl=true"
],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Vale.Def.Words_s.natN n ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
d: Vale.Def.Words_s.natN n ->
i: Prims.nat
-> FStar.Pervasives.Lemma (requires i <= FStar.Seq.Base.length bs)
(ensures
a * Vale.Bignum.Defs.sum_pow_seq_left bs i + d ==
Vale.Bignum.Defs.sum_pow_seq_left (Vale.Bignum.Lemmas.seq_scale_lo a bs) i +
Vale.Bignum.Defs.sum_pow_seq_left (Vale.Bignum.Lemmas.seq_scale_hi a bs d) (i + 1))
(decreases i) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.natN",
"FStar.Seq.Base.seq",
"Prims.op_Equality",
"Prims.int",
"Prims._assert",
"Prims.eq2",
"Vale.Bignum.Defs.sum_pow_seq_left",
"Vale.Bignum.Lemmas.seq_scale_hi",
"Prims.unit",
"Prims.bool",
"Vale.Bignum.Lemmas.lemma_seq_scale_rec",
"Prims.op_Subtraction",
"Vale.Bignum.Defs.reveal_mul_hi_all",
"Vale.Bignum.Defs.reveal_mul_lo_all",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.squash",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Vale.Bignum.Lemmas.seq_scale_lo",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_seq_scale_rec (#n: nat) (a: natN n) (bs: seq (natN n)) (d: natN n) (i: nat)
: Lemma (requires i <= length bs)
(ensures
(a * sum_pow_seq_left bs i + d ==
sum_pow_seq_left (seq_scale_lo a bs) i + sum_pow_seq_left (seq_scale_hi a bs d) (i + 1)))
(decreases i) =
| reveal_mul_lo_all ();
reveal_mul_hi_all ();
if i = 0
then
(assert (sum_pow_seq_left (seq_scale_hi a bs d) 0 == 0);
assert (sum_pow_seq_left (seq_scale_hi a bs d) 1 == d))
else (lemma_seq_scale_rec a bs d (i - 1)) | false |
Vale.Bignum.Lemmas.fst | Vale.Bignum.Lemmas.lemma_seq_add_rec | val lemma_seq_add_rec (#n: nat) (as0 bs: seq (natN n)) (c0: nat1) (i: nat)
: Lemma (requires i <= length as0 /\ length bs == length as0)
(ensures
(let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
sum_pow_seq_left xs i + last_carry n i ci ==
sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0))
(decreases i) | val lemma_seq_add_rec (#n: nat) (as0 bs: seq (natN n)) (c0: nat1) (i: nat)
: Lemma (requires i <= length as0 /\ length bs == length as0)
(ensures
(let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
sum_pow_seq_left xs i + last_carry n i ci ==
sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0))
(decreases i) | let rec lemma_seq_add_rec (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Lemma
(requires i <= length as0 /\ length bs == length as0)
(ensures (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
sum_pow_seq_left xs i + last_carry n i ci == sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0
))
(decreases i)
=
if (i > 0) then (
let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
let i' = i - 1 in
let ci' = seq_add_c as0 bs c0 i' in
calc (==) {
sum_pow_seq_left xs i + last_carry n i ci;
== {}
xs.[i'] * pow_int n i' + sum_pow_seq_left xs i' + last_carry n i ci;
== {lemma_seq_add_rec as0 bs c0 i'}
xs.[i'] * pow_int n i' + sum_pow_seq_left as0 i' + sum_pow_seq_left bs i' + c0 - last_carry n i' ci' + last_carry n i ci;
== {
reveal_add_hi_all ();
lemma_last_carry_mul n i' ci';
lemma_add_lo_mul_right as0.[i'] bs.[i'] ci' (pow_int n i')
}
sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0;
}
) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 92,
"start_col": 0,
"start_line": 65
} | module Vale.Bignum.Lemmas
open FStar.Mul
let rec lemma_sum_seq_left_right_rec (s:seq int) (i j k:nat) : Lemma
(requires i <= j /\ j <= k /\ k <= length s)
(ensures sum_seq_left s i j + sum_seq_right s j k == sum_seq_right s i k)
(decreases j)
=
if i < j then lemma_sum_seq_left_right_rec s i (j - 1) k
let lemma_sum_seq_left_right s i j =
lemma_sum_seq_left_right_rec s i j j
let rec lemma_pow_nat a b =
if b > 0 then (
lemma_pow_nat a (b - 1);
FStar.Math.Lemmas.nat_times_nat_is_nat a (pow_int a (b - 1))
)
let rec lemma_sum_pow_seq_bound_rec (#n:nat) (s:seq (natN n)) (i:nat{i <= length s}) : Lemma
(ensures 0 <= sum_pow_seq_left s i /\ sum_pow_seq_left s i < pow_int n i)
=
let open FStar.Math.Lemmas in
if i > 0 then (
calc (<=) {
0;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
sum_pow_seq_left s (i - 1);
<= {lemma_pow_nat n (i - 1); nat_times_nat_is_nat s.[i - 1] (pow_int n (i - 1))}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1);
== {}
sum_pow_seq_left s i;
};
calc (<=) {
sum_pow_seq_left s i + 1;
== {}
s.[i - 1] * pow_int n (i - 1) + sum_seq_left (pow_seq s) 0 (i - 1) + 1;
<= {lemma_sum_pow_seq_bound_rec s (i - 1)}
s.[i - 1] * pow_int n (i - 1) + pow_int n (i - 1);
<= {lemma_pow_nat n (i - 1); lemma_mult_le_right (pow_int n (i - 1)) s.[i - 1] (n - 1)}
(n - 1) * pow_int n (i - 1) + pow_int n (i - 1);
== {}
pow_int n i;
}
)
let lemma_sum_pow_seq_bound #n s =
lemma_sum_pow_seq_bound_rec s (length s)
let lemma_seq_add_is_norm #n as0 bs c0 i =
()
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_last_carry_mul a b c =
()
#pop-options
#push-options "--z3cliopt smt.arith.nl=true"
#restart-solver
let lemma_add_lo_mul_right #n a b c m =
reveal_add_lo_all ()
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Bignum.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
as0: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
c0: Vale.Def.Words_s.nat1 ->
i: Prims.nat
-> FStar.Pervasives.Lemma
(requires
i <= FStar.Seq.Base.length as0 /\ FStar.Seq.Base.length bs == FStar.Seq.Base.length as0)
(ensures
(let xs = FStar.Pervasives.Native.fst (Vale.Bignum.Lemmas.seq_add as0 bs c0) in
let ci = Vale.Bignum.Lemmas.seq_add_c as0 bs c0 i in
Vale.Bignum.Defs.sum_pow_seq_left xs i + Vale.Bignum.Lemmas.last_carry n i ci ==
Vale.Bignum.Defs.sum_pow_seq_left as0 i + Vale.Bignum.Defs.sum_pow_seq_left bs i + c0))
(decreases i) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.nat1",
"Prims.op_GreaterThan",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"Vale.Bignum.Defs.sum_pow_seq_left",
"Vale.Bignum.Lemmas.last_carry",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Subtraction",
"FStar.Mul.op_Star",
"Vale.Bignum.Lemmas.op_String_Access",
"Vale.Bignum.Defs.pow_int",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"Vale.Bignum.Lemmas.lemma_seq_add_rec",
"Vale.Bignum.Lemmas.lemma_add_lo_mul_right",
"Vale.Bignum.Lemmas.lemma_last_carry_mul",
"Vale.Bignum.Defs.reveal_add_hi_all",
"Vale.Bignum.Lemmas.seq_add_c",
"FStar.Pervasives.Native.fst",
"Vale.Bignum.Lemmas.seq_add",
"Prims.bool",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_seq_add_rec (#n: nat) (as0 bs: seq (natN n)) (c0: nat1) (i: nat)
: Lemma (requires i <= length as0 /\ length bs == length as0)
(ensures
(let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
sum_pow_seq_left xs i + last_carry n i ci ==
sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0))
(decreases i) =
| if (i > 0)
then
(let xs = fst (seq_add as0 bs c0) in
let ci = seq_add_c as0 bs c0 i in
let i' = i - 1 in
let ci' = seq_add_c as0 bs c0 i' in
calc ( == ) {
sum_pow_seq_left xs i + last_carry n i ci;
( == ) { () }
xs.[ i' ] * pow_int n i' + sum_pow_seq_left xs i' + last_carry n i ci;
( == ) { lemma_seq_add_rec as0 bs c0 i' }
xs.[ i' ] * pow_int n i' + sum_pow_seq_left as0 i' + sum_pow_seq_left bs i' + c0 -
last_carry n i' ci' +
last_carry n i ci;
( == ) { (reveal_add_hi_all ();
lemma_last_carry_mul n i' ci';
lemma_add_lo_mul_right as0.[ i' ] bs.[ i' ] ci' (pow_int n i')) }
sum_pow_seq_left as0 i + sum_pow_seq_left bs i + c0;
}) | false |
Vale.Math.Bits.fst | Vale.Math.Bits.lemma_i2b_eq | val lemma_i2b_eq (#n:pos) (a b:uint_t n) : Lemma
(requires b_i2b a == b_i2b b)
(ensures a == b) | val lemma_i2b_eq (#n:pos) (a b:uint_t n) : Lemma
(requires b_i2b a == b_i2b b)
(ensures a == b) | let lemma_i2b_eq #n a b =
assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 8,
"start_col": 0,
"start_line": 6
} | module Vale.Math.Bits
open FStar.Mul
let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (requires Vale.Math.Bits.b_i2b a == Vale.Math.Bits.b_i2b b)
(ensures a == b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.BV.int2bv_lemma_2",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.l_imp",
"Prims.eq2",
"FStar.BV.bv_t",
"Vale.Math.Bits.b_i2b",
"FStar.BV.int2bv"
] | [] | true | false | true | false | false | let lemma_i2b_eq #n a b =
| assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b | false |
Vale.Math.Bits.fst | Vale.Math.Bits.lemma_i2b_and | val lemma_i2b_and (#n:pos) (a b:uint_t n) : Lemma
(b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b)) | val lemma_i2b_and (#n:pos) (a b:uint_t n) : Lemma
(b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b)) | let lemma_i2b_and #n a b =
int2bv_logand #n #a #b #(bvand #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b)) | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 72,
"end_line": 16,
"start_col": 0,
"start_line": 14
} | module Vale.Math.Bits
open FStar.Mul
let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m
let lemma_i2b_eq #n a b =
assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b
let lemma_i2b_uext #n m a =
Vale.Lib.Bv_s.int2bv_uext #n #m a (uext #n #m a);
assert_norm (b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a)) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures
Vale.Math.Bits.b_i2b (FStar.UInt.logand a b) ==
Vale.Math.Bits.b_and (Vale.Math.Bits.b_i2b a) (Vale.Math.Bits.b_i2b b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.BV.bv_t",
"Vale.Math.Bits.b_i2b",
"FStar.UInt.logand",
"Vale.Math.Bits.b_and",
"Prims.unit",
"FStar.BV.int2bv_logand",
"FStar.BV.bvand",
"FStar.BV.int2bv"
] | [] | true | false | true | false | false | let lemma_i2b_and #n a b =
| int2bv_logand #n #a #b #(bvand #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b)) | false |
Vale.Math.Bits.fst | Vale.Math.Bits.lemma_i2b_shl | val lemma_i2b_shl (#n:pos) (a:uint_t n) (b:uint_t n) : Lemma
(b_i2b #n (shift_left #n a b) == b_shl #n (b_i2b a) b) | val lemma_i2b_shl (#n:pos) (a:uint_t n) (b:uint_t n) : Lemma
(b_i2b #n (shift_left #n a b) == b_shl #n (b_i2b a) b) | let lemma_i2b_shl #n a b =
int2bv_shl #n #a #b #(bvshl #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_left #n a b) == b_shl #n (b_i2b a) b) | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 28,
"start_col": 0,
"start_line": 26
} | module Vale.Math.Bits
open FStar.Mul
let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m
let lemma_i2b_eq #n a b =
assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b
let lemma_i2b_uext #n m a =
Vale.Lib.Bv_s.int2bv_uext #n #m a (uext #n #m a);
assert_norm (b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a))
let lemma_i2b_and #n a b =
int2bv_logand #n #a #b #(bvand #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b))
let lemma_i2b_or #n a b =
int2bv_logor #n #a #b #(bvor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logor #n a b) == b_or #n (b_i2b a) (b_i2b b))
let lemma_i2b_xor #n a b =
int2bv_logxor #n #a #b #(bvxor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logxor #n a b) == b_xor #n (b_i2b a) (b_i2b b)) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures
Vale.Math.Bits.b_i2b (FStar.UInt.shift_left a b) ==
Vale.Math.Bits.b_shl (Vale.Math.Bits.b_i2b a) b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.BV.bv_t",
"Vale.Math.Bits.b_i2b",
"FStar.UInt.shift_left",
"Vale.Math.Bits.b_shl",
"Prims.unit",
"FStar.BV.int2bv_shl",
"FStar.BV.bvshl",
"FStar.BV.int2bv"
] | [] | true | false | true | false | false | let lemma_i2b_shl #n a b =
| int2bv_shl #n #a #b #(bvshl #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_left #n a b) == b_shl #n (b_i2b a) b) | false |
Vale.Math.Bits.fst | Vale.Math.Bits.lemma_i2b_xor | val lemma_i2b_xor (#n:pos) (a b:uint_t n) : Lemma
(b_i2b #n (logxor #n a b) == b_xor #n (b_i2b a) (b_i2b b)) | val lemma_i2b_xor (#n:pos) (a b:uint_t n) : Lemma
(b_i2b #n (logxor #n a b) == b_xor #n (b_i2b a) (b_i2b b)) | let lemma_i2b_xor #n a b =
int2bv_logxor #n #a #b #(bvxor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logxor #n a b) == b_xor #n (b_i2b a) (b_i2b b)) | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 72,
"end_line": 24,
"start_col": 0,
"start_line": 22
} | module Vale.Math.Bits
open FStar.Mul
let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m
let lemma_i2b_eq #n a b =
assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b
let lemma_i2b_uext #n m a =
Vale.Lib.Bv_s.int2bv_uext #n #m a (uext #n #m a);
assert_norm (b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a))
let lemma_i2b_and #n a b =
int2bv_logand #n #a #b #(bvand #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b))
let lemma_i2b_or #n a b =
int2bv_logor #n #a #b #(bvor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logor #n a b) == b_or #n (b_i2b a) (b_i2b b)) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures
Vale.Math.Bits.b_i2b (FStar.UInt.logxor a b) ==
Vale.Math.Bits.b_xor (Vale.Math.Bits.b_i2b a) (Vale.Math.Bits.b_i2b b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.BV.bv_t",
"Vale.Math.Bits.b_i2b",
"FStar.UInt.logxor",
"Vale.Math.Bits.b_xor",
"Prims.unit",
"FStar.BV.int2bv_logxor",
"FStar.BV.bvxor",
"FStar.BV.int2bv"
] | [] | true | false | true | false | false | let lemma_i2b_xor #n a b =
| int2bv_logxor #n #a #b #(bvxor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logxor #n a b) == b_xor #n (b_i2b a) (b_i2b b)) | false |
Vale.Math.Bits.fst | Vale.Math.Bits.lemma_i2b_uext | val lemma_i2b_uext (#n m:pos) (a:uint_t n) : Lemma
(b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a)) | val lemma_i2b_uext (#n m:pos) (a:uint_t n) : Lemma
(b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a)) | let lemma_i2b_uext #n m a =
Vale.Lib.Bv_s.int2bv_uext #n #m a (uext #n #m a);
assert_norm (b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a)) | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 12,
"start_col": 0,
"start_line": 10
} | module Vale.Math.Bits
open FStar.Mul
let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m
let lemma_i2b_eq #n a b =
assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Prims.pos -> a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures
Vale.Math.Bits.b_i2b (Vale.Math.Bits.uext a) == Vale.Math.Bits.b_uext (Vale.Math.Bits.b_i2b a)
) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.BV.bv_t",
"Prims.op_Addition",
"Vale.Math.Bits.b_i2b",
"Vale.Math.Bits.uext",
"Vale.Math.Bits.b_uext",
"Prims.unit",
"Vale.Lib.Bv_s.int2bv_uext"
] | [] | true | false | true | false | false | let lemma_i2b_uext #n m a =
| Vale.Lib.Bv_s.int2bv_uext #n #m a (uext #n #m a);
assert_norm (b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a)) | false |
Vale.Math.Bits.fst | Vale.Math.Bits.lemma_i2b_or | val lemma_i2b_or (#n:pos) (a b:uint_t n) : Lemma
(b_i2b #n (logor #n a b) == b_or #n (b_i2b a) (b_i2b b)) | val lemma_i2b_or (#n:pos) (a b:uint_t n) : Lemma
(b_i2b #n (logor #n a b) == b_or #n (b_i2b a) (b_i2b b)) | let lemma_i2b_or #n a b =
int2bv_logor #n #a #b #(bvor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logor #n a b) == b_or #n (b_i2b a) (b_i2b b)) | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 70,
"end_line": 20,
"start_col": 0,
"start_line": 18
} | module Vale.Math.Bits
open FStar.Mul
let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m
let lemma_i2b_eq #n a b =
assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b
let lemma_i2b_uext #n m a =
Vale.Lib.Bv_s.int2bv_uext #n #m a (uext #n #m a);
assert_norm (b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a))
let lemma_i2b_and #n a b =
int2bv_logand #n #a #b #(bvand #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b)) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures
Vale.Math.Bits.b_i2b (FStar.UInt.logor a b) ==
Vale.Math.Bits.b_or (Vale.Math.Bits.b_i2b a) (Vale.Math.Bits.b_i2b b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.BV.bv_t",
"Vale.Math.Bits.b_i2b",
"FStar.UInt.logor",
"Vale.Math.Bits.b_or",
"Prims.unit",
"FStar.BV.int2bv_logor",
"FStar.BV.bvor",
"FStar.BV.int2bv"
] | [] | true | false | true | false | false | let lemma_i2b_or #n a b =
| int2bv_logor #n #a #b #(bvor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logor #n a b) == b_or #n (b_i2b a) (b_i2b b)) | false |
Vale.Math.Bits.fst | Vale.Math.Bits.lemma_i2b_sub | val lemma_i2b_sub (#n:pos) (a b:uint_t n) : Lemma
(b_i2b #n (sub_mod #n a b) == b_sub #n (b_i2b a) (b_i2b b)) | val lemma_i2b_sub (#n:pos) (a b:uint_t n) : Lemma
(b_i2b #n (sub_mod #n a b) == b_sub #n (b_i2b a) (b_i2b b)) | let lemma_i2b_sub #n a b =
int2bv_sub #n #a #b #(bvsub #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (sub_mod #n a b) == b_sub #n (b_i2b a) (b_i2b b)) | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 40,
"start_col": 0,
"start_line": 38
} | module Vale.Math.Bits
open FStar.Mul
let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m
let lemma_i2b_eq #n a b =
assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b
let lemma_i2b_uext #n m a =
Vale.Lib.Bv_s.int2bv_uext #n #m a (uext #n #m a);
assert_norm (b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a))
let lemma_i2b_and #n a b =
int2bv_logand #n #a #b #(bvand #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b))
let lemma_i2b_or #n a b =
int2bv_logor #n #a #b #(bvor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logor #n a b) == b_or #n (b_i2b a) (b_i2b b))
let lemma_i2b_xor #n a b =
int2bv_logxor #n #a #b #(bvxor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logxor #n a b) == b_xor #n (b_i2b a) (b_i2b b))
let lemma_i2b_shl #n a b =
int2bv_shl #n #a #b #(bvshl #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_left #n a b) == b_shl #n (b_i2b a) b)
let lemma_i2b_shr #n a b =
int2bv_shr #n #a #b #(bvshr #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_right #n a b) == b_shr #n (b_i2b a) b)
let lemma_i2b_add #n a b =
int2bv_add #n #a #b #(bvadd #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (add_mod #n a b) == b_add #n (b_i2b a) (b_i2b b)) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures
Vale.Math.Bits.b_i2b (FStar.UInt.sub_mod a b) ==
Vale.Math.Bits.b_sub (Vale.Math.Bits.b_i2b a) (Vale.Math.Bits.b_i2b b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.BV.bv_t",
"Vale.Math.Bits.b_i2b",
"FStar.UInt.sub_mod",
"Vale.Math.Bits.b_sub",
"Prims.unit",
"FStar.BV.int2bv_sub",
"FStar.BV.bvsub",
"FStar.BV.int2bv"
] | [] | true | false | true | false | false | let lemma_i2b_sub #n a b =
| int2bv_sub #n #a #b #(bvsub #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (sub_mod #n a b) == b_sub #n (b_i2b a) (b_i2b b)) | false |
Vale.Math.Bits.fst | Vale.Math.Bits.lemma_i2b_shr | val lemma_i2b_shr (#n:pos) (a:uint_t n) (b:uint_t n) : Lemma
(b_i2b #n (shift_right #n a b) == b_shr #n (b_i2b a) b) | val lemma_i2b_shr (#n:pos) (a:uint_t n) (b:uint_t n) : Lemma
(b_i2b #n (shift_right #n a b) == b_shr #n (b_i2b a) b) | let lemma_i2b_shr #n a b =
int2bv_shr #n #a #b #(bvshr #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_right #n a b) == b_shr #n (b_i2b a) b) | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 32,
"start_col": 0,
"start_line": 30
} | module Vale.Math.Bits
open FStar.Mul
let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m
let lemma_i2b_eq #n a b =
assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b
let lemma_i2b_uext #n m a =
Vale.Lib.Bv_s.int2bv_uext #n #m a (uext #n #m a);
assert_norm (b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a))
let lemma_i2b_and #n a b =
int2bv_logand #n #a #b #(bvand #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b))
let lemma_i2b_or #n a b =
int2bv_logor #n #a #b #(bvor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logor #n a b) == b_or #n (b_i2b a) (b_i2b b))
let lemma_i2b_xor #n a b =
int2bv_logxor #n #a #b #(bvxor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logxor #n a b) == b_xor #n (b_i2b a) (b_i2b b))
let lemma_i2b_shl #n a b =
int2bv_shl #n #a #b #(bvshl #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_left #n a b) == b_shl #n (b_i2b a) b) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures
Vale.Math.Bits.b_i2b (FStar.UInt.shift_right a b) ==
Vale.Math.Bits.b_shr (Vale.Math.Bits.b_i2b a) b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.BV.bv_t",
"Vale.Math.Bits.b_i2b",
"FStar.UInt.shift_right",
"Vale.Math.Bits.b_shr",
"Prims.unit",
"FStar.BV.int2bv_shr",
"FStar.BV.bvshr",
"FStar.BV.int2bv"
] | [] | true | false | true | false | false | let lemma_i2b_shr #n a b =
| int2bv_shr #n #a #b #(bvshr #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_right #n a b) == b_shr #n (b_i2b a) b) | false |
Vale.Math.Bits.fst | Vale.Math.Bits.lemma_i2b_add | val lemma_i2b_add (#n:pos) (a b:uint_t n) : Lemma
(b_i2b #n (add_mod #n a b) == b_add #n (b_i2b a) (b_i2b b)) | val lemma_i2b_add (#n:pos) (a b:uint_t n) : Lemma
(b_i2b #n (add_mod #n a b) == b_add #n (b_i2b a) (b_i2b b)) | let lemma_i2b_add #n a b =
int2bv_add #n #a #b #(bvadd #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (add_mod #n a b) == b_add #n (b_i2b a) (b_i2b b)) | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 36,
"start_col": 0,
"start_line": 34
} | module Vale.Math.Bits
open FStar.Mul
let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m
let lemma_i2b_eq #n a b =
assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b
let lemma_i2b_uext #n m a =
Vale.Lib.Bv_s.int2bv_uext #n #m a (uext #n #m a);
assert_norm (b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a))
let lemma_i2b_and #n a b =
int2bv_logand #n #a #b #(bvand #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b))
let lemma_i2b_or #n a b =
int2bv_logor #n #a #b #(bvor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logor #n a b) == b_or #n (b_i2b a) (b_i2b b))
let lemma_i2b_xor #n a b =
int2bv_logxor #n #a #b #(bvxor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logxor #n a b) == b_xor #n (b_i2b a) (b_i2b b))
let lemma_i2b_shl #n a b =
int2bv_shl #n #a #b #(bvshl #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_left #n a b) == b_shl #n (b_i2b a) b)
let lemma_i2b_shr #n a b =
int2bv_shr #n #a #b #(bvshr #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_right #n a b) == b_shr #n (b_i2b a) b) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures
Vale.Math.Bits.b_i2b (FStar.UInt.add_mod a b) ==
Vale.Math.Bits.b_add (Vale.Math.Bits.b_i2b a) (Vale.Math.Bits.b_i2b b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.BV.bv_t",
"Vale.Math.Bits.b_i2b",
"FStar.UInt.add_mod",
"Vale.Math.Bits.b_add",
"Prims.unit",
"FStar.BV.int2bv_add",
"FStar.BV.bvadd",
"FStar.BV.int2bv"
] | [] | true | false | true | false | false | let lemma_i2b_add #n a b =
| int2bv_add #n #a #b #(bvadd #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (add_mod #n a b) == b_add #n (b_i2b a) (b_i2b b)) | false |
Vale.Math.Bits.fst | Vale.Math.Bits.sub_hide | val sub_hide (#n:pos) (a b:uint_t n) : Pure (uint_t n)
(requires True)
(ensures fun x -> 0 <= a - b ==> x == a - b) | val sub_hide (#n:pos) (a b:uint_t n) : Pure (uint_t n)
(requires True)
(ensures fun x -> 0 <= a - b ==> x == a - b) | let sub_hide #n a b =
if 0 <= a - b then FStar.Math.Lemmas.modulo_lemma (a - b) (pow2 n);
sub_mod a b | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 62,
"start_col": 0,
"start_line": 60
} | module Vale.Math.Bits
open FStar.Mul
let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m
let lemma_i2b_eq #n a b =
assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b
let lemma_i2b_uext #n m a =
Vale.Lib.Bv_s.int2bv_uext #n #m a (uext #n #m a);
assert_norm (b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a))
let lemma_i2b_and #n a b =
int2bv_logand #n #a #b #(bvand #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b))
let lemma_i2b_or #n a b =
int2bv_logor #n #a #b #(bvor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logor #n a b) == b_or #n (b_i2b a) (b_i2b b))
let lemma_i2b_xor #n a b =
int2bv_logxor #n #a #b #(bvxor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logxor #n a b) == b_xor #n (b_i2b a) (b_i2b b))
let lemma_i2b_shl #n a b =
int2bv_shl #n #a #b #(bvshl #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_left #n a b) == b_shl #n (b_i2b a) b)
let lemma_i2b_shr #n a b =
int2bv_shr #n #a #b #(bvshr #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_right #n a b) == b_shr #n (b_i2b a) b)
let lemma_i2b_add #n a b =
int2bv_add #n #a #b #(bvadd #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (add_mod #n a b) == b_add #n (b_i2b a) (b_i2b b))
let lemma_i2b_sub #n a b =
int2bv_sub #n #a #b #(bvsub #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (sub_mod #n a b) == b_sub #n (b_i2b a) (b_i2b b))
let lemma_i2b_mul #n a b =
int2bv_mul #n #a #b #(bvmul #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (mul_mod #n a b) == b_mul #n (b_i2b a) b)
let lemma_i2b_div #n a b =
int2bv_div #n #a #b #(bvdiv #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (udiv #n a b) == b_div #n (b_i2b a) b)
let lemma_i2b_mod #n a b =
int2bv_mod #n #a #b #(bvmod #n (int2bv #n a) b) ();
assert_norm (bvmod #n (int2bv a) b == b_mod #n (b_i2b a) b);
assert_norm (int2bv #n (mod #n a b) == b_i2b #n (mod #n a b));
()
let add_hide #n a b =
if a + b < pow2 n then FStar.Math.Lemmas.modulo_lemma (a + b) (pow2 n);
add_mod a b | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> Prims.Pure (FStar.UInt.uint_t n) | Prims.Pure | [] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.sub_mod",
"Prims.unit",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"FStar.Math.Lemmas.modulo_lemma",
"Prims.pow2",
"Prims.bool"
] | [] | false | false | false | false | false | let sub_hide #n a b =
| if 0 <= a - b then FStar.Math.Lemmas.modulo_lemma (a - b) (pow2 n);
sub_mod a b | false |
Vale.Math.Bits.fst | Vale.Math.Bits.mul_hide | val mul_hide (#n:pos) (a b:uint_t n) : Pure (uint_t n)
(requires True)
(ensures fun x -> 0 <= a * b /\ (a * b < pow2 n ==> x == a * b)) | val mul_hide (#n:pos) (a b:uint_t n) : Pure (uint_t n)
(requires True)
(ensures fun x -> 0 <= a * b /\ (a * b < pow2 n ==> x == a * b)) | let mul_hide #n a b =
FStar.Math.Lemmas.nat_times_nat_is_nat a b;
if a * b < pow2 n then FStar.Math.Lemmas.modulo_lemma (a * b) (pow2 n);
assert_norm (mul_mod a b == (a * b) % pow2 n);
mul_mod a b | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 68,
"start_col": 0,
"start_line": 64
} | module Vale.Math.Bits
open FStar.Mul
let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m
let lemma_i2b_eq #n a b =
assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b
let lemma_i2b_uext #n m a =
Vale.Lib.Bv_s.int2bv_uext #n #m a (uext #n #m a);
assert_norm (b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a))
let lemma_i2b_and #n a b =
int2bv_logand #n #a #b #(bvand #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b))
let lemma_i2b_or #n a b =
int2bv_logor #n #a #b #(bvor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logor #n a b) == b_or #n (b_i2b a) (b_i2b b))
let lemma_i2b_xor #n a b =
int2bv_logxor #n #a #b #(bvxor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logxor #n a b) == b_xor #n (b_i2b a) (b_i2b b))
let lemma_i2b_shl #n a b =
int2bv_shl #n #a #b #(bvshl #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_left #n a b) == b_shl #n (b_i2b a) b)
let lemma_i2b_shr #n a b =
int2bv_shr #n #a #b #(bvshr #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_right #n a b) == b_shr #n (b_i2b a) b)
let lemma_i2b_add #n a b =
int2bv_add #n #a #b #(bvadd #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (add_mod #n a b) == b_add #n (b_i2b a) (b_i2b b))
let lemma_i2b_sub #n a b =
int2bv_sub #n #a #b #(bvsub #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (sub_mod #n a b) == b_sub #n (b_i2b a) (b_i2b b))
let lemma_i2b_mul #n a b =
int2bv_mul #n #a #b #(bvmul #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (mul_mod #n a b) == b_mul #n (b_i2b a) b)
let lemma_i2b_div #n a b =
int2bv_div #n #a #b #(bvdiv #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (udiv #n a b) == b_div #n (b_i2b a) b)
let lemma_i2b_mod #n a b =
int2bv_mod #n #a #b #(bvmod #n (int2bv #n a) b) ();
assert_norm (bvmod #n (int2bv a) b == b_mod #n (b_i2b a) b);
assert_norm (int2bv #n (mod #n a b) == b_i2b #n (mod #n a b));
()
let add_hide #n a b =
if a + b < pow2 n then FStar.Math.Lemmas.modulo_lemma (a + b) (pow2 n);
add_mod a b
let sub_hide #n a b =
if 0 <= a - b then FStar.Math.Lemmas.modulo_lemma (a - b) (pow2 n);
sub_mod a b | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> Prims.Pure (FStar.UInt.uint_t n) | Prims.Pure | [] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.mul_mod",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_LessThan",
"FStar.Math.Lemmas.modulo_lemma",
"Prims.bool",
"FStar.Math.Lemmas.nat_times_nat_is_nat"
] | [] | false | false | false | false | false | let mul_hide #n a b =
| FStar.Math.Lemmas.nat_times_nat_is_nat a b;
if a * b < pow2 n then FStar.Math.Lemmas.modulo_lemma (a * b) (pow2 n);
assert_norm (mul_mod a b == (a * b) % pow2 n);
mul_mod a b | false |
Vale.Math.Bits.fst | Vale.Math.Bits.lemma_i2b_mod | val lemma_i2b_mod (#n:pos) (a:uint_t n) (b:uint_t n{b <> 0}) : Lemma
(b_i2b #n (mod #n a b) == b_mod #n (b_i2b a) b) | val lemma_i2b_mod (#n:pos) (a:uint_t n) (b:uint_t n{b <> 0}) : Lemma
(b_i2b #n (mod #n a b) == b_mod #n (b_i2b a) b) | let lemma_i2b_mod #n a b =
int2bv_mod #n #a #b #(bvmod #n (int2bv #n a) b) ();
assert_norm (bvmod #n (int2bv a) b == b_mod #n (b_i2b a) b);
assert_norm (int2bv #n (mod #n a b) == b_i2b #n (mod #n a b));
() | {
"file_name": "vale/code/lib/math/Vale.Math.Bits.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 54,
"start_col": 0,
"start_line": 50
} | module Vale.Math.Bits
open FStar.Mul
let lemma_pow2_le m n = FStar.Math.Lemmas.pow2_le_compat n m
let lemma_i2b_eq #n a b =
assert_norm (b_i2b a == b_i2b b ==> int2bv a == int2bv b);
int2bv_lemma_2 #n a b
let lemma_i2b_uext #n m a =
Vale.Lib.Bv_s.int2bv_uext #n #m a (uext #n #m a);
assert_norm (b_i2b (uext #n #m a) == b_uext #n #m (b_i2b #n a))
let lemma_i2b_and #n a b =
int2bv_logand #n #a #b #(bvand #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logand #n a b) == b_and #n (b_i2b a) (b_i2b b))
let lemma_i2b_or #n a b =
int2bv_logor #n #a #b #(bvor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logor #n a b) == b_or #n (b_i2b a) (b_i2b b))
let lemma_i2b_xor #n a b =
int2bv_logxor #n #a #b #(bvxor #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (logxor #n a b) == b_xor #n (b_i2b a) (b_i2b b))
let lemma_i2b_shl #n a b =
int2bv_shl #n #a #b #(bvshl #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_left #n a b) == b_shl #n (b_i2b a) b)
let lemma_i2b_shr #n a b =
int2bv_shr #n #a #b #(bvshr #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (shift_right #n a b) == b_shr #n (b_i2b a) b)
let lemma_i2b_add #n a b =
int2bv_add #n #a #b #(bvadd #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (add_mod #n a b) == b_add #n (b_i2b a) (b_i2b b))
let lemma_i2b_sub #n a b =
int2bv_sub #n #a #b #(bvsub #n (int2bv #n a) (int2bv #n b)) ();
assert_norm (b_i2b #n (sub_mod #n a b) == b_sub #n (b_i2b a) (b_i2b b))
let lemma_i2b_mul #n a b =
int2bv_mul #n #a #b #(bvmul #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (mul_mod #n a b) == b_mul #n (b_i2b a) b)
let lemma_i2b_div #n a b =
int2bv_div #n #a #b #(bvdiv #n (int2bv #n a) b) ();
assert_norm (b_i2b #n (udiv #n a b) == b_div #n (b_i2b a) b) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Math.Bits.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n {b <> 0}
-> FStar.Pervasives.Lemma
(ensures
Vale.Math.Bits.b_i2b (FStar.UInt.mod a b) == Vale.Math.Bits.b_mod (Vale.Math.Bits.b_i2b a) b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.BV.bv_t",
"FStar.BV.int2bv",
"FStar.UInt.mod",
"Vale.Math.Bits.b_i2b",
"FStar.BV.bvmod",
"Vale.Math.Bits.b_mod",
"FStar.BV.int2bv_mod"
] | [] | true | false | true | false | false | let lemma_i2b_mod #n a b =
| int2bv_mod #n #a #b #(bvmod #n (int2bv #n a) b) ();
assert_norm (bvmod #n (int2bv a) b == b_mod #n (b_i2b a) b);
assert_norm (int2bv #n (mod #n a b) == b_i2b #n (mod #n a b));
() | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.