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
Target.fst
Target.print_action
val print_action (mname:string) (a:action) : ML string
val print_action (mname:string) (a:action) : ML string
let rec print_action (mname:string) (a:action) : ML string = let print_atomic_action (a:atomic_action) : ML string = match a with | Action_return e -> Printf.sprintf "(action_return %s)" (print_expr mname e) | Action_abort -> "(action_abort())" | Action_field_pos_64 -> "(action_field_pos_64())" | Action_field_pos_32 -> "(action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr -> "(action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr_after sz write_to -> Printf.sprintf "(action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)" (print_expr mname sz) (print_ident write_to) | Action_field_ptr_after_with_setter sz write_to_field write_to_obj -> Printf.sprintf "(action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))" (print_expr mname sz) (print_ident write_to_field) (print_expr mname write_to_obj) | Action_deref i -> Printf.sprintf "(action_deref %s)" (print_ident i) | Action_assignment lhs rhs -> Printf.sprintf "(action_assignment %s %s)" (print_ident lhs) (print_expr mname rhs) | Action_call f args -> Printf.sprintf "(mk_extern_action (%s %s))" (print_ident f) (String.concat " " (List.map (print_expr mname) args)) in match a with | Atomic_action a -> print_atomic_action a | Action_seq hd tl -> Printf.sprintf "(action_seq %s %s)" (print_atomic_action hd) (print_action mname tl) | Action_ite hd then_ else_ -> Printf.sprintf "(action_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname hd) (print_action mname then_) (print_action mname else_) | Action_let i a k -> Printf.sprintf "(action_bind \"%s\" %s (fun %s -> %s))" (print_ident i) (print_atomic_action a) (print_ident i) (print_action mname k) | Action_act a -> Printf.sprintf "(action_act %s)" (print_action mname a)
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 28, "end_line": 511, "start_col": 0, "start_line": 467 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl let print_lam (#a:Type) (f:a -> ML string) (x:lam a) : ML string = match x with | Some x, y -> Printf.sprintf ("(fun %s -> %s)") (print_ident x) (f y) | None, y -> f y let print_expr_lam (mname:string) (x:lam expr) : ML string = print_lam (print_expr mname) x let rec is_output_type (t:typ) : bool = match t with | T_app _ A.KindOutput [] -> true | T_pointer t -> is_output_type t | _ -> false let rec is_extern_type (t:typ) : bool = match t with | T_app _ A.KindExtern [] -> true | T_pointer t -> is_extern_type t | _ -> false (* * An output type is printed as the ident, or p_<ident> * * They are abstract types in the emitted F* code *) let print_output_type (qual:bool) (t:typ) : ML string = let rec aux (t:typ) : ML (option string & string) = match t with | T_app id _ _ -> id.v.modul_name, print_ident id | T_pointer t -> let m, i = aux t in m, Printf.sprintf "p_%s" i | _ -> failwith "Print: not an output type" in let mopt, i = aux t in if qual then match mopt with | None -> i | Some m -> Printf.sprintf "%s.ExternalTypes.%s" m i else i let rec print_typ (mname:string) (t:typ) : ML string = //(decreases t) = if is_output_type t then print_output_type true t else match t with | T_false -> "False" | T_app hd _ args -> //output types are already handled at the beginning of print_typ Printf.sprintf "(%s %s)" (print_maybe_qualified_ident mname hd) (String.concat " " (print_indexes mname args)) | T_dep_pair t1 (x, t2) -> Printf.sprintf "(%s:%s & %s)" (print_ident x) (print_typ mname t1) (print_typ mname t2) | T_refine t e -> Printf.sprintf "(refine %s %s)" (print_typ mname t) (print_expr_lam mname e) | T_if_else e t1 t2 -> Printf.sprintf "(t_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname e) (print_typ mname t1) (print_typ mname t2) | T_pointer t -> Printf.sprintf "bpointer (%s)" (print_typ mname t) | T_with_action t _ | T_with_dep_action t _ | T_with_comment t _ -> print_typ mname t | T_with_probe t _ _ _ -> Printf.sprintf "bpointer (%s)" (print_typ mname t) and print_indexes (mname:string) (is:list index) : ML (list string) = //(decreases is) = match is with | [] -> [] | Inl t::is -> print_typ mname t::print_indexes mname is | Inr e::is -> print_expr mname e::print_indexes mname is let rec print_kind (mname:string) (k:parser_kind) : Tot string = match k.pk_kind with | PK_base hd -> Printf.sprintf "%skind_%s" (maybe_mname_prefix mname hd) (print_ident hd) | PK_list -> "kind_nlist" | PK_t_at_most -> "kind_t_at_most" | PK_t_exact -> "kind_t_exact" | PK_return -> "ret_kind" | PK_impos -> "impos_kind" | PK_and_then k1 k2 -> Printf.sprintf "(and_then_kind %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_glb k1 k2 -> Printf.sprintf "(glb %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_filter k -> Printf.sprintf "(filter_kind %s)" (print_kind mname k) | PK_string -> "parse_string_kind"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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 -> a: Target.action -> FStar.All.ML Prims.string
FStar.All.ML
[ "ml" ]
[]
[ "Prims.string", "Target.action", "Target.atomic_action", "FStar.Printf.sprintf", "Target.print_action", "Target.expr", "Target.print_expr", "Ast.ident", "Target.print_ident", "Prims.list", "FStar.String.concat", "FStar.List.map" ]
[ "recursion" ]
false
true
false
false
false
let rec print_action (mname: string) (a: action) : ML string =
let print_atomic_action (a: atomic_action) : ML string = match a with | Action_return e -> Printf.sprintf "(action_return %s)" (print_expr mname e) | Action_abort -> "(action_abort())" | Action_field_pos_64 -> "(action_field_pos_64())" | Action_field_pos_32 -> "(action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr -> "(action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr_after sz write_to -> Printf.sprintf "(action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)" (print_expr mname sz) (print_ident write_to) | Action_field_ptr_after_with_setter sz write_to_field write_to_obj -> Printf.sprintf "(action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))" (print_expr mname sz) (print_ident write_to_field) (print_expr mname write_to_obj) | Action_deref i -> Printf.sprintf "(action_deref %s)" (print_ident i) | Action_assignment lhs rhs -> Printf.sprintf "(action_assignment %s %s)" (print_ident lhs) (print_expr mname rhs) | Action_call f args -> Printf.sprintf "(mk_extern_action (%s %s))" (print_ident f) (String.concat " " (List.map (print_expr mname) args)) in match a with | Atomic_action a -> print_atomic_action a | Action_seq hd tl -> Printf.sprintf "(action_seq %s %s)" (print_atomic_action hd) (print_action mname tl) | Action_ite hd then_ else_ -> Printf.sprintf "(action_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname hd) (print_action mname then_) (print_action mname else_) | Action_let i a k -> Printf.sprintf "(action_bind \"%s\" %s (fun %s -> %s))" (print_ident i) (print_atomic_action a) (print_ident i) (print_action mname k) | Action_act a -> Printf.sprintf "(action_act %s)" (print_action mname a)
false
Steel.GhostMonotonicHigherReference.fst
Steel.GhostMonotonicHigherReference.witnessed
val witnessed (#a:Type u#1) (#p:Preorder.preorder a) (r:ref a p) (fact:property a) : Type0
val witnessed (#a:Type u#1) (#p:Preorder.preorder a) (r:ref a p) (fact:property a) : Type0
let witnessed #a #p r fact = PR.witnessed r (lift_fact fact)
{ "file_name": "lib/steel/Steel.GhostMonotonicHigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 33, "end_line": 113, "start_col": 0, "start_line": 112 }
(* Copyright 2020 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 Steel.GhostMonotonicHigherReference open FStar.Ghost open FStar.PCM open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.GhostPCMReference open Steel.FractionalPermission open Steel.Preorder module Preorder = FStar.Preorder module Q = Steel.Preorder module M = Steel.Memory module PR = Steel.GhostPCMReference module A = Steel.Effect.Atomic open FStar.Real #set-options "--ide_id_info_off" let ref a p = PR.ref (history a p) pcm_history [@@__reduce__] let pts_to_body #a #p (r:ref a p) (f:perm) (v:a) (h:history a p) = PR.pts_to r h `star` pure (history_val h v f) let pts_to' (#a:Type) (#p:Preorder.preorder a) (r:ref a p) (f:perm) (v: a) = h_exists (pts_to_body r f v) let pts_to_sl r f v = hp_of (pts_to' r f v) let intro_pure #opened #a #p #f (r:ref a p) (v:a) (h:history a p { history_val h v f }) : SteelGhostT unit opened (PR.pts_to r h) (fun _ -> pts_to_body r f v h) = A.intro_pure (history_val h v f) let intro_pure_full #opened #a #p #f (r:ref a p) (v:a) (h:history a p { history_val h v f }) : SteelGhostT unit opened (PR.pts_to r h) (fun _ -> pts_to r f v) = intro_pure #_ #a #p #f r v h; intro_exists h (pts_to_body r f v) let alloc #_ (#a:Type) (p:Preorder.preorder a) (v:a) = let h = Current [v] full_perm in assert (compatible pcm_history h h); let x : ref a p = alloc h in intro_pure_full x v h; x let extract_pure #a #uses #p #f (r:ref a p) (v:a) (h:(history a p)) : SteelGhostT (_:unit{history_val h v f}) uses (pts_to_body r f v h) (fun _ -> pts_to_body r f v h) = elim_pure (history_val h v f); A.intro_pure (history_val h v f) let elim_pure #a #uses #p #f (r:ref a p) (v:a) (h:(history a p)) : SteelGhostT (_:unit{history_val h v f}) uses (pts_to_body r f v h) (fun _ -> PR.pts_to r h) = let _ = extract_pure r v h in drop (pure (history_val h v f)) let write (#opened: _) (#a:Type) (#p:Preorder.preorder a) (#v:a) (r:ref a p) (x:a) : SteelGhost unit opened (pts_to r full_perm v) (fun v -> pts_to r full_perm x) (requires fun _ -> p v x /\ True) (ensures fun _ _ _ -> True) = let h_old_e = witness_exists #_ #_ #(pts_to_body r full_perm v) () in let _ = elim_pure r v h_old_e in let h_old = read r in let h: history a p = extend_history' h_old x in write r h_old_e h; intro_pure_full r x h
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.Memory.fsti.checked", "Steel.GhostPCMReference.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.GhostMonotonicHigherReference.fst" }
[ { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": true, "full_module": "Steel.Effect.Atomic", "short_module": "A" }, { "abbrev": true, "full_module": "Steel.GhostPCMReference", "short_module": "PR" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "M" }, { "abbrev": true, "full_module": "Steel.Preorder", "short_module": "Q" }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "Steel.GhostPCMReference", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "Preorder" }, { "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": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "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
r: Steel.GhostMonotonicHigherReference.ref a p -> fact: Steel.GhostMonotonicHigherReference.property a -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.GhostMonotonicHigherReference.ref", "Steel.GhostMonotonicHigherReference.property", "Steel.GhostPCMReference.witnessed", "Steel.Preorder.history", "Steel.Preorder.pcm_history", "Steel.Preorder.lift_fact" ]
[]
false
false
false
false
true
let witnessed #a #p r fact =
PR.witnessed r (lift_fact fact)
false
Pulse.Lib.Forall.fst
Pulse.Lib.Forall.token
val token : v: Pulse.Lib.Core.vprop -> Pulse.Lib.Core.vprop
let token (v:vprop) = v
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.Forall.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 23, "end_line": 6, "start_col": 0, "start_line": 6 }
module Pulse.Lib.Forall open Pulse.Main open Pulse.Lib.Core module F = FStar.FunctionalExtensionality
{ "checked_file": "/", "dependencies": [ "Pulse.Main.fsti.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.Forall.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "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
v: Pulse.Lib.Core.vprop -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Core.vprop" ]
[]
false
false
false
true
false
let token (v: vprop) =
v
false
Pulse.Lib.Forall.fst
Pulse.Lib.Forall.is_forall
val is_forall : v: Pulse.Lib.Core.vprop -> p: (_: a -> Pulse.Lib.Core.vprop) -> Type0
let is_forall #a (v:vprop) (p:a -> vprop) = squash (universal_quantifier #a v p)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.Forall.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 38, "end_line": 12, "start_col": 0, "start_line": 11 }
module Pulse.Lib.Forall open Pulse.Main open Pulse.Lib.Core module F = FStar.FunctionalExtensionality let token (v:vprop) = v let universal_quantifier #a (v:vprop) (p: a -> vprop) = x:a -> stt_ghost unit v (fun _ -> p x)
{ "checked_file": "/", "dependencies": [ "Pulse.Main.fsti.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.Forall.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "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
v: Pulse.Lib.Core.vprop -> p: (_: a -> Pulse.Lib.Core.vprop) -> Type0
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Core.vprop", "Prims.squash", "Pulse.Lib.Forall.universal_quantifier" ]
[]
false
false
false
true
true
let is_forall #a (v: vprop) (p: (a -> vprop)) =
squash (universal_quantifier #a v p)
false
Pulse.Lib.Forall.fst
Pulse.Lib.Forall.universal_quantifier
val universal_quantifier : v: Pulse.Lib.Core.vprop -> p: (_: a -> Pulse.Lib.Core.vprop) -> Type
let universal_quantifier #a (v:vprop) (p: a -> vprop) = x:a -> stt_ghost unit v (fun _ -> p x)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.Forall.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 40, "end_line": 9, "start_col": 0, "start_line": 8 }
module Pulse.Lib.Forall open Pulse.Main open Pulse.Lib.Core module F = FStar.FunctionalExtensionality let token (v:vprop) = v
{ "checked_file": "/", "dependencies": [ "Pulse.Main.fsti.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.Forall.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "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
v: Pulse.Lib.Core.vprop -> p: (_: a -> Pulse.Lib.Core.vprop) -> Type
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Core.vprop", "Pulse.Lib.Core.stt_ghost", "Prims.unit" ]
[]
false
false
false
true
true
let universal_quantifier #a (v: vprop) (p: (a -> vprop)) =
x: a -> stt_ghost unit v (fun _ -> p x)
false
Target.fst
Target.print_output_type_val
val print_output_type_val (tbl: set) (t: typ) : ML string
val print_output_type_val (tbl: set) (t: typ) : ML string
let rec print_output_type_val (tbl:set) (t:typ) : ML string = let open A in if is_output_type t then let s = print_output_type false t in if H.try_find tbl s <> None then "" else let _ = H.insert tbl s () in assert (is_output_type t); match t with | T_app id KindOutput [] -> Printf.sprintf "\n\nval %s : Type0\n\n" s | T_pointer bt -> let bs = print_output_type_val tbl bt in bs ^ (Printf.sprintf "\n\ninline_for_extraction noextract type %s = bpointer %s\n\n" s (print_output_type false bt)) else ""
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 9, "end_line": 1081, "start_col": 0, "start_line": 1068 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl let print_lam (#a:Type) (f:a -> ML string) (x:lam a) : ML string = match x with | Some x, y -> Printf.sprintf ("(fun %s -> %s)") (print_ident x) (f y) | None, y -> f y let print_expr_lam (mname:string) (x:lam expr) : ML string = print_lam (print_expr mname) x let rec is_output_type (t:typ) : bool = match t with | T_app _ A.KindOutput [] -> true | T_pointer t -> is_output_type t | _ -> false let rec is_extern_type (t:typ) : bool = match t with | T_app _ A.KindExtern [] -> true | T_pointer t -> is_extern_type t | _ -> false (* * An output type is printed as the ident, or p_<ident> * * They are abstract types in the emitted F* code *) let print_output_type (qual:bool) (t:typ) : ML string = let rec aux (t:typ) : ML (option string & string) = match t with | T_app id _ _ -> id.v.modul_name, print_ident id | T_pointer t -> let m, i = aux t in m, Printf.sprintf "p_%s" i | _ -> failwith "Print: not an output type" in let mopt, i = aux t in if qual then match mopt with | None -> i | Some m -> Printf.sprintf "%s.ExternalTypes.%s" m i else i let rec print_typ (mname:string) (t:typ) : ML string = //(decreases t) = if is_output_type t then print_output_type true t else match t with | T_false -> "False" | T_app hd _ args -> //output types are already handled at the beginning of print_typ Printf.sprintf "(%s %s)" (print_maybe_qualified_ident mname hd) (String.concat " " (print_indexes mname args)) | T_dep_pair t1 (x, t2) -> Printf.sprintf "(%s:%s & %s)" (print_ident x) (print_typ mname t1) (print_typ mname t2) | T_refine t e -> Printf.sprintf "(refine %s %s)" (print_typ mname t) (print_expr_lam mname e) | T_if_else e t1 t2 -> Printf.sprintf "(t_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname e) (print_typ mname t1) (print_typ mname t2) | T_pointer t -> Printf.sprintf "bpointer (%s)" (print_typ mname t) | T_with_action t _ | T_with_dep_action t _ | T_with_comment t _ -> print_typ mname t | T_with_probe t _ _ _ -> Printf.sprintf "bpointer (%s)" (print_typ mname t) and print_indexes (mname:string) (is:list index) : ML (list string) = //(decreases is) = match is with | [] -> [] | Inl t::is -> print_typ mname t::print_indexes mname is | Inr e::is -> print_expr mname e::print_indexes mname is let rec print_kind (mname:string) (k:parser_kind) : Tot string = match k.pk_kind with | PK_base hd -> Printf.sprintf "%skind_%s" (maybe_mname_prefix mname hd) (print_ident hd) | PK_list -> "kind_nlist" | PK_t_at_most -> "kind_t_at_most" | PK_t_exact -> "kind_t_exact" | PK_return -> "ret_kind" | PK_impos -> "impos_kind" | PK_and_then k1 k2 -> Printf.sprintf "(and_then_kind %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_glb k1 k2 -> Printf.sprintf "(glb %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_filter k -> Printf.sprintf "(filter_kind %s)" (print_kind mname k) | PK_string -> "parse_string_kind" let rec print_action (mname:string) (a:action) : ML string = let print_atomic_action (a:atomic_action) : ML string = match a with | Action_return e -> Printf.sprintf "(action_return %s)" (print_expr mname e) | Action_abort -> "(action_abort())" | Action_field_pos_64 -> "(action_field_pos_64())" | Action_field_pos_32 -> "(action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr -> "(action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr_after sz write_to -> Printf.sprintf "(action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)" (print_expr mname sz) (print_ident write_to) | Action_field_ptr_after_with_setter sz write_to_field write_to_obj -> Printf.sprintf "(action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))" (print_expr mname sz) (print_ident write_to_field) (print_expr mname write_to_obj) | Action_deref i -> Printf.sprintf "(action_deref %s)" (print_ident i) | Action_assignment lhs rhs -> Printf.sprintf "(action_assignment %s %s)" (print_ident lhs) (print_expr mname rhs) | Action_call f args -> Printf.sprintf "(mk_extern_action (%s %s))" (print_ident f) (String.concat " " (List.map (print_expr mname) args)) in match a with | Atomic_action a -> print_atomic_action a | Action_seq hd tl -> Printf.sprintf "(action_seq %s %s)" (print_atomic_action hd) (print_action mname tl) | Action_ite hd then_ else_ -> Printf.sprintf "(action_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname hd) (print_action mname then_) (print_action mname else_) | Action_let i a k -> Printf.sprintf "(action_bind \"%s\" %s (fun %s -> %s))" (print_ident i) (print_atomic_action a) (print_ident i) (print_action mname k) | Action_act a -> Printf.sprintf "(action_act %s)" (print_action mname a) let print_typedef_name (mname:string) (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> Printf.sprintf "(%s:%s)" (print_ident id) (print_typ mname t)) tdn.td_params)) let print_typedef_typ (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> (print_ident id)) tdn.td_params)) let print_typedef_body (mname:string) (b:typedef_body) : ML string = match b with | TD_abbrev t -> print_typ mname t | TD_struct fields -> let print_field (sf:field) : ML string = Printf.sprintf "%s : %s%s" (print_ident sf.sf_ident) (print_typ mname sf.sf_typ) (if sf.sf_dependence then " (*dep*)" else "") in let fields = String.concat ";\n" (List.map print_field fields) in Printf.sprintf "{\n%s\n}" fields let print_typedef_actions_inv_and_fp (td:type_decl) = //we need to add output loc to the modifies locs //if there is an output type type parameter let should_add_output_loc = List.Tot.existsb (fun (_, t) -> is_output_type t || is_extern_type t) td.decl_name.td_params in let pointers = //get only non output type pointers List.Tot.filter (fun (x, t) -> T_pointer? t && not (is_output_type t || is_extern_type t)) td.decl_name.td_params in let inv = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "((ptr_inv %s) `conj_inv` %s)" (print_ident x) out) pointers "true_inv" in let fp = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "(eloc_union (ptr_loc %s) %s)" (print_ident x) out) pointers (if should_add_output_loc then "output_loc" else "eloc_none") in inv, fp let print_comments (cs:list string) : string = match cs with | [] -> "" | _ -> let c = String.concat "\\n\\\n" cs in Printf.sprintf " (Comment \"%s\")" c let print_attributes (entrypoint:bool) (attrs:decl_attributes) : string = match attrs.comments with | [] -> if entrypoint || attrs.is_exported then "" else if attrs.should_inline then "inline_for_extraction noextract\n" else "[@ (CInline)]\n" | cs -> Printf.sprintf "[@ %s %s]\n%s" (print_comments cs) (if not entrypoint && not attrs.is_exported && not attrs.should_inline then "(CInline)" else "") (if attrs.should_inline then "inline_for_extraction\n" else "") /// Printing a decl for M.Types.fst /// /// Print all the definitions, and for a Type_decl, only the type definition let maybe_print_type_equality (mname:string) (td:type_decl) : ML string = if td.decl_name.td_entrypoint then let equate_types_list = Options.get_equate_types_list () in (match (List.tryFind (fun (_, m) -> m = mname) equate_types_list) with | Some (a, _) -> let typname = A.ident_name td.decl_name.td_name in Printf.sprintf "\n\nlet _ = assert (%s.Types.%s == %s) by (FStar.Tactics.trefl ())\n\n" a typname typname | None -> "") else "" let print_definition (mname:string) (d:decl { Definition? (fst d)} ) : ML string = match fst d with | Definition (x, [], T_app ({Ast.v={Ast.name="field_id"}}) _ _, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot field_id by (FStar.Tactics.trivial())\n\n" (print_comments (snd d).comments) (print_field_id_name x) (A.print_constant c) | Definition (x, [], t, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot %s\n\n" (print_comments (snd d).comments) (print_ident x) (A.print_constant c) (print_typ mname t) | Definition (x, params, typ, expr) -> let x_ps = { td_name = x; td_params = params; td_entrypoint = false } in Printf.sprintf "%slet %s : %s = %s\n\n" (print_attributes false (snd d)) (print_typedef_name mname x_ps) (print_typ mname typ) (print_expr mname expr) let print_assumption (mname:string) (d:decl { Assumption? (fst d) } ) : ML string = match fst d with | Assumption (x, t) -> Printf.sprintf "%sassume\nval %s : %s\n\n" (if (snd d).is_if_def then "[@@ CIfDef ]\n" else "") (print_ident x) (print_typ mname t) let print_decl_for_types (mname:string) (d:decl) : ML string = match fst d with | Assumption _ -> "" | Definition _ -> print_definition mname d | Type_decl td -> Printf.sprintf "noextract\ninline_for_extraction\ntype %s = %s\n\n" (print_typedef_name mname td.decl_name) (print_typedef_body mname td.decl_typ) `strcat` maybe_print_type_equality mname td | Output_type _ | Output_type_expr _ _ | Extern_type _ | Extern_fn _ _ _ | Extern_probe _ -> "" /// Print a decl for M.fst /// /// No need to print Definition(s), they are `include`d from M.Types.fst /// /// For a Type_decl, if it is an entry point, we need to emit a definition since /// there is a corresponding declaration in the .fsti /// We make the definition as simply the definition in M.Types.fst let is_type_abbreviation (td:type_decl) : bool = match td.decl_typ with | TD_abbrev _ -> true | TD_struct _ -> false let external_api_include (modul:string) (ds:list decl) : string = if has_external_api ds then Printf.sprintf "open %s.ExternalAPI\n\n" modul else "" #push-options "--z3rlimit_factor 4" let pascal_case name : ML string = let chars = String.list_of_string name in let has_underscore = List.mem '_' chars in let keep, up, low = 0, 1, 2 in if has_underscore then let what_next : ref int = alloc up in let rewrite_char c : ML (list FStar.Char.char) = match c with | '_' -> what_next := up; [] | c -> let c_next = let n = !what_next in if n = keep then c else if n = up then FStar.Char.uppercase c else FStar.Char.lowercase c in let _ = if Char.uppercase c = c then what_next := low else if Char.lowercase c = c then what_next := keep in [c_next] in let chars = List.collect rewrite_char (String.list_of_string name) in String.string_of_list chars else if String.length name = 0 then name else String.uppercase (String.sub name 0 1) ^ String.sub name 1 (String.length name - 1) let uppercase (name:string) : string = String.uppercase name let rec print_as_c_type (t:typ) : ML string = let open Ast in match t with | T_pointer t -> Printf.sprintf "%s*" (print_as_c_type t) | T_app {v={name="Bool"}} _ [] -> "BOOLEAN" | T_app {v={name="UINT8"}} _ [] -> "uint8_t" | T_app {v={name="UINT16"}} _ [] -> "uint16_t" | T_app {v={name="UINT32"}} _ [] -> "uint32_t" | T_app {v={name="UINT64"}} _ [] -> "uint64_t" | T_app {v={name="PUINT8"}} _ [] -> "uint8_t*" | T_app {v={name=x}} KindSpec [] -> x | T_app {v={name=x}} _ [] -> uppercase x | _ -> "__UNKNOWN__" let error_code_macros = //To be kept consistent with EverParse3d.ErrorCode.error_reason_of_result "#define EVERPARSE_ERROR_GENERIC 1uL\n\ #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL\n\ #define EVERPARSE_ERROR_IMPOSSIBLE 3uL\n\ #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL\n\ #define EVERPARSE_ERROR_ACTION_FAILED 5uL\n\ #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL\n\ #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL\n" let rec get_output_typ_dep (modul:string) (t:typ) : ML (option string) = match t with | T_app {v={modul_name=None}} _ _ -> None | T_app {v={modul_name=Some m}} _ _ -> if m = modul then None else Some m | T_pointer t -> get_output_typ_dep modul t | _ -> failwith "get_typ_deps: unexpected output type" let wrapper_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_check_%s" modul fn |> pascal_case let validator_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_validate_%s" modul fn |> pascal_case let print_c_entry (produce_everparse_error: opt_produce_everparse_error) (modul: string) (env: global_env) (ds:list decl) : ML (string & string) = let default_error_handler = "static\n\ void DefaultErrorHandler(\n\t\ const char *typename_s,\n\t\ const char *fieldname,\n\t\ const char *reason,\n\t\ uint64_t error_code,\n\t\ uint8_t *context,\n\t\ EVERPARSE_INPUT_BUFFER input,\n\t\ uint64_t start_pos)\n\ {\n\t\ EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context;\n\t\ EverParseDefaultErrorHandler(\n\t\t\ typename_s,\n\t\t\ fieldname,\n\t\t\ reason,\n\t\t\ error_code,\n\t\t\ frame,\n\t\t\ input,\n\t\t\ start_pos\n\t\ );\n\ }" in let input_stream_binding = Options.get_input_stream_binding () in let is_input_stream_buffer = HashingOptions.InputStreamBuffer? input_stream_binding in let wrapped_call_buffer name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame;\n\t\ frame.filled = FALSE;\n\t\ %s\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0);\n\t\ if (EverParseIsError(result))\n\t\ {\n\t\t\ if (frame.filled)\n\t\t\ {\n\t\t\t\ %sEverParseError(frame.typename_s, frame.fieldname, frame.reason);\n\t\t\ }\n\t\t\ return FALSE;\n\t\ }\n\t\ return TRUE;" (if is_input_stream_buffer then "" else "EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t") name params modul in let wrapped_call_stream name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame =\n\t\ { .filled = FALSE,\n\t\ .typename_s = \"UNKNOWN\",\n\t\ .fieldname = \"UNKNOWN\",\n\t\ .reason = \"UNKNOWN\",\n\t\ .error_code = 0uL\n\ };\n\ EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, input, 0);\n\t\ uint64_t parsedSize = EverParseGetValidatorErrorPos(result);\n\ if (EverParseIsError(result))\n\t\ {\n\t\t\ EverParseHandleError(_extra, parsedSize, frame.typename_s, frame.fieldname, frame.reason, frame.error_code);\n\t\t\ }\n\t\ EverParseRetreat(_extra, base, parsedSize);\n\ return parsedSize;" name params in let mk_param (name: string) (typ: string) : Tot param = (A.with_range (A.to_ident' name) A.dummy_range, T_app (A.with_range (A.to_ident' typ) A.dummy_range) A.KindSpec []) in let print_one_validator (d:type_decl) : ML (string & string) = let params = d.decl_name.td_params @ (if is_input_stream_buffer then [] else [mk_param "_extra" "EVERPARSE_EXTRA_T"]) in let print_params (ps:list param) : ML string = let params = String.concat ", " (List.map (fun (id, t) -> Printf.sprintf "%s %s" (print_as_c_type t) (print_ident id)) ps) in match ps with | [] -> params | _ -> params ^ ", " in let print_arguments (ps:list param) : Tot string = let params = String.concat ", " (List.Tot.map (fun (id, t) -> if is_output_type t //output type pointers are uint8_t* in the F* generated code then (print_ident id) else print_ident id) ps) in match ps with | [] -> params | _ -> params ^ ", " in let wrapper_name = wrapper_name modul d.decl_name.td_name.A.v.A.name in let signature = if is_input_stream_buffer then Printf.sprintf "BOOLEAN %s(%suint8_t *base, uint32_t len)" wrapper_name (print_params params) else Printf.sprintf "uint64_t %s(%sEVERPARSE_INPUT_STREAM_BASE base)" wrapper_name (print_params params) in let validator_name = validator_name modul d.decl_name.td_name.A.v.A.name in let impl = let body = if is_input_stream_buffer then wrapped_call_buffer validator_name (print_arguments params) else wrapped_call_stream validator_name (print_arguments params) in Printf.sprintf "%s {\n\t%s\n}" signature body in signature ^";", impl in let signatures_output_typ_deps = List.fold_left (fun deps (d, _) -> match d with | Type_decl d -> if d.decl_name.td_entrypoint then let params = d.decl_name.td_params in List.fold_left (fun deps (_, t) -> match get_output_typ_dep modul t with | Some dep -> if List.mem dep deps then deps else deps@[dep] | _ -> deps) deps params else deps | _ -> deps) [] ds in let signatures, impls = List.split (List.collect (fun d -> match fst d with | Type_decl d -> if d.decl_name.td_entrypoint then [print_one_validator d] else [] | _ -> []) ds) in let external_defs_includes = if not (Options.get_emit_output_types_defs ()) then "" else let deps = if List.length signatures_output_typ_deps = 0 then "" else String.concat "" (List.map (fun dep -> Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" dep) signatures_output_typ_deps) in let self = if has_output_types ds || has_extern_types ds then Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n" modul else "" in Printf.sprintf "%s\n%s\n\n" deps self in let header = Printf.sprintf "#include \"EverParseEndianness.h\"\n\ %s\n\ %s\ #ifdef __cplusplus\n\ extern \"C\" {\n\ #endif\n\ %s\n\ #ifdef __cplusplus\n\ }\n\ #endif\n" error_code_macros external_defs_includes (signatures |> String.concat "\n\n") in let input_stream_include = HashingOptions.input_stream_include input_stream_binding in let header = if input_stream_include = "" then header else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include header in let add_includes = Options.make_includes () in let header = Printf.sprintf "%s%s" add_includes header in let error_callback_proto = if HashingOptions.InputStreamBuffer? input_stream_binding then Printf.sprintf "void %sEverParseError(const char *StructName, const char *FieldName, const char *Reason)%s" modul (if produce_everparse_error = Some ProduceEverParseError then "{(void) StructName; (void) FieldName; (void) Reason;}" else ";") else "" in let impl = Printf.sprintf "#include \"%sWrapper.h\"\n\ #include \"EverParse.h\"\n\ #include \"%s.h\"\n\ %s\n\n\ %s\n\n\ %s\n" modul modul error_callback_proto default_error_handler (impls |> String.concat "\n\n") in let impl = if input_stream_include = "" then impl else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include impl in let impl = Printf.sprintf "%s%s" add_includes impl in header, impl /// Functions for printing setters and getters for output expressions let rec out_bt_name (t:typ) : ML string = match t with | T_app i _ _ -> A.ident_name i | T_pointer t -> out_bt_name t | _ -> failwith "Impossible, out_bt_name received a non output type!" let out_expr_bt_name (oe:output_expr) : ML string = out_bt_name oe.oe_bt (* * Walks over the output expressions AST and constructs a string *) let rec out_fn_name (oe:output_expr) : ML string = match oe.oe_expr with | T_OE_id _ -> out_expr_bt_name oe | T_OE_star oe -> Printf.sprintf "%s_star" (out_fn_name oe) | T_OE_addrof oe -> Printf.sprintf "%s_addrof" (out_fn_name oe) | T_OE_deref oe f -> Printf.sprintf "%s_deref_%s" (out_fn_name oe) (A.ident_name f) | T_OE_dot oe f -> Printf.sprintf "%s_dot_%s" (out_fn_name oe) (A.ident_name f) module H = Hashtable type set = H.t string unit (* * In the printing functions, a hashtable tracks that we print a defn. only once * * E.g. multiple output expressions may require a val decl. for types, * we need to print them only once each *) let rec base_output_type (t:typ) : ML A.ident = match t with | T_app id A.KindOutput [] -> id | T_pointer t -> base_output_type t | _ -> failwith "Target.base_output_type called with a non-output type"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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": 1, "initial_ifuel": 1, "max_fuel": 1, "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": 4, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
tbl: Target.set -> t: Target.typ -> FStar.All.ML Prims.string
FStar.All.ML
[ "ml" ]
[]
[ "Target.set", "Target.typ", "Target.is_output_type", "Prims.string", "Prims.bool", "Ast.ident", "FStar.Printf.sprintf", "Prims.op_Hat", "Target.print_output_type", "Target.print_output_type_val", "Prims.unit", "Prims._assert", "Prims.b2t", "Hashtable.insert", "Prims.op_disEquality", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.None", "Hashtable.try_find" ]
[ "recursion" ]
false
true
false
false
false
let rec print_output_type_val (tbl: set) (t: typ) : ML string =
let open A in if is_output_type t then let s = print_output_type false t in if H.try_find tbl s <> None then "" else let _ = H.insert tbl s () in assert (is_output_type t); match t with | T_app id KindOutput [] -> Printf.sprintf "\n\nval %s : Type0\n\n" s | T_pointer bt -> let bs = print_output_type_val tbl bt in bs ^ (Printf.sprintf "\n\ninline_for_extraction noextract type %s = bpointer %s\n\n" s (print_output_type false bt)) else ""
false
Target.fst
Target.print_decl_for_types
val print_decl_for_types (mname: string) (d: decl) : ML string
val print_decl_for_types (mname: string) (d: decl) : ML string
let print_decl_for_types (mname:string) (d:decl) : ML string = match fst d with | Assumption _ -> "" | Definition _ -> print_definition mname d | Type_decl td -> Printf.sprintf "noextract\ninline_for_extraction\ntype %s = %s\n\n" (print_typedef_name mname td.decl_name) (print_typedef_body mname td.decl_typ) `strcat` maybe_print_type_equality mname td | Output_type _ | Output_type_expr _ _ | Extern_type _ | Extern_fn _ _ _ | Extern_probe _ -> ""
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 24, "end_line": 670, "start_col": 0, "start_line": 648 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl let print_lam (#a:Type) (f:a -> ML string) (x:lam a) : ML string = match x with | Some x, y -> Printf.sprintf ("(fun %s -> %s)") (print_ident x) (f y) | None, y -> f y let print_expr_lam (mname:string) (x:lam expr) : ML string = print_lam (print_expr mname) x let rec is_output_type (t:typ) : bool = match t with | T_app _ A.KindOutput [] -> true | T_pointer t -> is_output_type t | _ -> false let rec is_extern_type (t:typ) : bool = match t with | T_app _ A.KindExtern [] -> true | T_pointer t -> is_extern_type t | _ -> false (* * An output type is printed as the ident, or p_<ident> * * They are abstract types in the emitted F* code *) let print_output_type (qual:bool) (t:typ) : ML string = let rec aux (t:typ) : ML (option string & string) = match t with | T_app id _ _ -> id.v.modul_name, print_ident id | T_pointer t -> let m, i = aux t in m, Printf.sprintf "p_%s" i | _ -> failwith "Print: not an output type" in let mopt, i = aux t in if qual then match mopt with | None -> i | Some m -> Printf.sprintf "%s.ExternalTypes.%s" m i else i let rec print_typ (mname:string) (t:typ) : ML string = //(decreases t) = if is_output_type t then print_output_type true t else match t with | T_false -> "False" | T_app hd _ args -> //output types are already handled at the beginning of print_typ Printf.sprintf "(%s %s)" (print_maybe_qualified_ident mname hd) (String.concat " " (print_indexes mname args)) | T_dep_pair t1 (x, t2) -> Printf.sprintf "(%s:%s & %s)" (print_ident x) (print_typ mname t1) (print_typ mname t2) | T_refine t e -> Printf.sprintf "(refine %s %s)" (print_typ mname t) (print_expr_lam mname e) | T_if_else e t1 t2 -> Printf.sprintf "(t_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname e) (print_typ mname t1) (print_typ mname t2) | T_pointer t -> Printf.sprintf "bpointer (%s)" (print_typ mname t) | T_with_action t _ | T_with_dep_action t _ | T_with_comment t _ -> print_typ mname t | T_with_probe t _ _ _ -> Printf.sprintf "bpointer (%s)" (print_typ mname t) and print_indexes (mname:string) (is:list index) : ML (list string) = //(decreases is) = match is with | [] -> [] | Inl t::is -> print_typ mname t::print_indexes mname is | Inr e::is -> print_expr mname e::print_indexes mname is let rec print_kind (mname:string) (k:parser_kind) : Tot string = match k.pk_kind with | PK_base hd -> Printf.sprintf "%skind_%s" (maybe_mname_prefix mname hd) (print_ident hd) | PK_list -> "kind_nlist" | PK_t_at_most -> "kind_t_at_most" | PK_t_exact -> "kind_t_exact" | PK_return -> "ret_kind" | PK_impos -> "impos_kind" | PK_and_then k1 k2 -> Printf.sprintf "(and_then_kind %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_glb k1 k2 -> Printf.sprintf "(glb %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_filter k -> Printf.sprintf "(filter_kind %s)" (print_kind mname k) | PK_string -> "parse_string_kind" let rec print_action (mname:string) (a:action) : ML string = let print_atomic_action (a:atomic_action) : ML string = match a with | Action_return e -> Printf.sprintf "(action_return %s)" (print_expr mname e) | Action_abort -> "(action_abort())" | Action_field_pos_64 -> "(action_field_pos_64())" | Action_field_pos_32 -> "(action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr -> "(action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr_after sz write_to -> Printf.sprintf "(action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)" (print_expr mname sz) (print_ident write_to) | Action_field_ptr_after_with_setter sz write_to_field write_to_obj -> Printf.sprintf "(action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))" (print_expr mname sz) (print_ident write_to_field) (print_expr mname write_to_obj) | Action_deref i -> Printf.sprintf "(action_deref %s)" (print_ident i) | Action_assignment lhs rhs -> Printf.sprintf "(action_assignment %s %s)" (print_ident lhs) (print_expr mname rhs) | Action_call f args -> Printf.sprintf "(mk_extern_action (%s %s))" (print_ident f) (String.concat " " (List.map (print_expr mname) args)) in match a with | Atomic_action a -> print_atomic_action a | Action_seq hd tl -> Printf.sprintf "(action_seq %s %s)" (print_atomic_action hd) (print_action mname tl) | Action_ite hd then_ else_ -> Printf.sprintf "(action_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname hd) (print_action mname then_) (print_action mname else_) | Action_let i a k -> Printf.sprintf "(action_bind \"%s\" %s (fun %s -> %s))" (print_ident i) (print_atomic_action a) (print_ident i) (print_action mname k) | Action_act a -> Printf.sprintf "(action_act %s)" (print_action mname a) let print_typedef_name (mname:string) (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> Printf.sprintf "(%s:%s)" (print_ident id) (print_typ mname t)) tdn.td_params)) let print_typedef_typ (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> (print_ident id)) tdn.td_params)) let print_typedef_body (mname:string) (b:typedef_body) : ML string = match b with | TD_abbrev t -> print_typ mname t | TD_struct fields -> let print_field (sf:field) : ML string = Printf.sprintf "%s : %s%s" (print_ident sf.sf_ident) (print_typ mname sf.sf_typ) (if sf.sf_dependence then " (*dep*)" else "") in let fields = String.concat ";\n" (List.map print_field fields) in Printf.sprintf "{\n%s\n}" fields let print_typedef_actions_inv_and_fp (td:type_decl) = //we need to add output loc to the modifies locs //if there is an output type type parameter let should_add_output_loc = List.Tot.existsb (fun (_, t) -> is_output_type t || is_extern_type t) td.decl_name.td_params in let pointers = //get only non output type pointers List.Tot.filter (fun (x, t) -> T_pointer? t && not (is_output_type t || is_extern_type t)) td.decl_name.td_params in let inv = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "((ptr_inv %s) `conj_inv` %s)" (print_ident x) out) pointers "true_inv" in let fp = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "(eloc_union (ptr_loc %s) %s)" (print_ident x) out) pointers (if should_add_output_loc then "output_loc" else "eloc_none") in inv, fp let print_comments (cs:list string) : string = match cs with | [] -> "" | _ -> let c = String.concat "\\n\\\n" cs in Printf.sprintf " (Comment \"%s\")" c let print_attributes (entrypoint:bool) (attrs:decl_attributes) : string = match attrs.comments with | [] -> if entrypoint || attrs.is_exported then "" else if attrs.should_inline then "inline_for_extraction noextract\n" else "[@ (CInline)]\n" | cs -> Printf.sprintf "[@ %s %s]\n%s" (print_comments cs) (if not entrypoint && not attrs.is_exported && not attrs.should_inline then "(CInline)" else "") (if attrs.should_inline then "inline_for_extraction\n" else "") /// Printing a decl for M.Types.fst /// /// Print all the definitions, and for a Type_decl, only the type definition let maybe_print_type_equality (mname:string) (td:type_decl) : ML string = if td.decl_name.td_entrypoint then let equate_types_list = Options.get_equate_types_list () in (match (List.tryFind (fun (_, m) -> m = mname) equate_types_list) with | Some (a, _) -> let typname = A.ident_name td.decl_name.td_name in Printf.sprintf "\n\nlet _ = assert (%s.Types.%s == %s) by (FStar.Tactics.trefl ())\n\n" a typname typname | None -> "") else "" let print_definition (mname:string) (d:decl { Definition? (fst d)} ) : ML string = match fst d with | Definition (x, [], T_app ({Ast.v={Ast.name="field_id"}}) _ _, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot field_id by (FStar.Tactics.trivial())\n\n" (print_comments (snd d).comments) (print_field_id_name x) (A.print_constant c) | Definition (x, [], t, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot %s\n\n" (print_comments (snd d).comments) (print_ident x) (A.print_constant c) (print_typ mname t) | Definition (x, params, typ, expr) -> let x_ps = { td_name = x; td_params = params; td_entrypoint = false } in Printf.sprintf "%slet %s : %s = %s\n\n" (print_attributes false (snd d)) (print_typedef_name mname x_ps) (print_typ mname typ) (print_expr mname expr) let print_assumption (mname:string) (d:decl { Assumption? (fst d) } ) : ML string = match fst d with | Assumption (x, t) -> Printf.sprintf "%sassume\nval %s : %s\n\n" (if (snd d).is_if_def then "[@@ CIfDef ]\n" else "") (print_ident x) (print_typ mname t)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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 -> d: Target.decl -> FStar.All.ML Prims.string
FStar.All.ML
[ "ml" ]
[]
[ "Prims.string", "Target.decl", "FStar.Pervasives.Native.fst", "Target.decl'", "Target.decl_attributes", "Target.assumption", "Target.definition", "Target.print_definition", "Target.type_decl", "Prims.strcat", "Target.maybe_print_type_equality", "FStar.Printf.sprintf", "Target.print_typedef_name", "Target.__proj__Mktype_decl__item__decl_name", "Target.print_typedef_body", "Target.__proj__Mktype_decl__item__decl_typ", "Ast.out_typ", "Target.output_expr", "Prims.bool", "Ast.ident", "Target.typ", "Prims.list", "Target.param" ]
[]
false
true
false
false
false
let print_decl_for_types (mname: string) (d: decl) : ML string =
match fst d with | Assumption _ -> "" | Definition _ -> print_definition mname d | Type_decl td -> (Printf.sprintf "noextract\ninline_for_extraction\ntype %s = %s\n\n" (print_typedef_name mname td.decl_name) (print_typedef_body mname td.decl_typ)) `strcat` (maybe_print_type_equality mname td) | Output_type _ | Output_type_expr _ _ | Extern_type _ | Extern_fn _ _ _ | Extern_probe _ -> ""
false
Spec.Blake2.Alternative.fsti
Spec.Blake2.Alternative.blake2_update'
val blake2_update' (a: alg) (kk: size_nat{kk <= max_key a}) (k: lbytes kk) (d: bytes{if kk = 0 then length d <= max_limb a else length d + (size_block a) <= max_limb a}) (s: state a) : Tot (state a)
val blake2_update' (a: alg) (kk: size_nat{kk <= max_key a}) (k: lbytes kk) (d: bytes{if kk = 0 then length d <= max_limb a else length d + (size_block a) <= max_limb a}) (s: state a) : Tot (state a)
let blake2_update' (a:alg) (kk:size_nat{kk <= max_key a}) (k:lbytes kk) (d:bytes{if kk = 0 then length d <= max_limb a else length d + (size_block a) <= max_limb a}) (s:state a): Tot (state a) = let ll = length d in let key_block: bytes = if kk > 0 then blake2_key_block a kk k else Seq.empty in blake2_update_blocks a 0 (key_block `Seq.append` d) s
{ "file_name": "specs/lemmas/Spec.Blake2.Alternative.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 17, "start_col": 0, "start_line": 9 }
module Spec.Blake2.Alternative open Spec.Blake2 open Lib.IntTypes open Lib.ByteSequence open Lib.Sequence
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Spec.Blake2.Alternative.fsti" }
[ { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Blake2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Blake2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Blake2", "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
a: Spec.Blake2.Definitions.alg -> kk: Lib.IntTypes.size_nat{kk <= Spec.Blake2.Definitions.max_key a} -> k: Lib.ByteSequence.lbytes kk -> d: Lib.ByteSequence.bytes { (match kk = 0 with | true -> Lib.Sequence.length d <= Spec.Blake2.Definitions.max_limb a | _ -> Lib.Sequence.length d + Spec.Blake2.Definitions.size_block a <= Spec.Blake2.Definitions.max_limb a) <: Type0 } -> s: Spec.Blake2.Definitions.state a -> Spec.Blake2.Definitions.state a
Prims.Tot
[ "total" ]
[]
[ "Spec.Blake2.Definitions.alg", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Spec.Blake2.Definitions.max_key", "Lib.ByteSequence.lbytes", "Lib.ByteSequence.bytes", "Prims.op_Equality", "Prims.int", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Spec.Blake2.Definitions.max_limb", "Prims.bool", "Prims.op_Addition", "Spec.Blake2.Definitions.size_block", "Spec.Blake2.Definitions.state", "Spec.Blake2.blake2_update_blocks", "FStar.Seq.Base.append", "Lib.IntTypes.int_t", "Lib.Sequence.seq", "Prims.op_GreaterThan", "Spec.Blake2.blake2_key_block", "FStar.Seq.Base.empty", "Prims.nat" ]
[]
false
false
false
false
false
let blake2_update' (a: alg) (kk: size_nat{kk <= max_key a}) (k: lbytes kk) (d: bytes{if kk = 0 then length d <= max_limb a else length d + (size_block a) <= max_limb a}) (s: state a) : Tot (state a) =
let ll = length d in let key_block:bytes = if kk > 0 then blake2_key_block a kk k else Seq.empty in blake2_update_blocks a 0 (key_block `Seq.append` d) s
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.prime
val prime : Prims.pos
let prime = Scalar.prime
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 24, "start_col": 0, "start_line": 24 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime)
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.pos
Prims.Tot
[ "total" ]
[]
[ "Spec.Poly1305.prime" ]
[]
false
false
false
true
false
let prime =
Scalar.prime
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.pfelem
val pfelem : Type0
let pfelem = Scalar.felem
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 25, "start_col": 0, "start_line": 25 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime)
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Poly1305.felem" ]
[]
false
false
false
true
true
let pfelem =
Scalar.felem
false
Target.fst
Target.print_out_expr_set_fstar
val print_out_expr_set_fstar (tbl: set) (mname: string) (oe: output_expr) : ML string
val print_out_expr_set_fstar (tbl: set) (mname: string) (oe: output_expr) : ML string
let print_out_expr_set_fstar (tbl:set) (mname:string) (oe:output_expr) : ML string = let fn_name = Printf.sprintf "set_%s" (out_fn_name oe) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); //TODO: module name? let fn_arg1_t = print_typ mname oe.oe_bt in let fn_arg2_t = (* * If bitwidth is not None, * then output the size restriction in the refinement * Is there a better way to output it? *) if oe.oe_bitwidth = None then print_typ mname oe.oe_t else begin Printf.sprintf "(i:%s{FStar.UInt.size (FStar.Integers.v i) %d})" (print_typ mname oe.oe_t) (Some?.v oe.oe_bitwidth) end in Printf.sprintf "\n\nval %s (_:%s) (_:%s) : extern_action (NonTrivial output_loc)\n\n" fn_name fn_arg1_t fn_arg2_t
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 17, "end_line": 1122, "start_col": 0, "start_line": 1097 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl let print_lam (#a:Type) (f:a -> ML string) (x:lam a) : ML string = match x with | Some x, y -> Printf.sprintf ("(fun %s -> %s)") (print_ident x) (f y) | None, y -> f y let print_expr_lam (mname:string) (x:lam expr) : ML string = print_lam (print_expr mname) x let rec is_output_type (t:typ) : bool = match t with | T_app _ A.KindOutput [] -> true | T_pointer t -> is_output_type t | _ -> false let rec is_extern_type (t:typ) : bool = match t with | T_app _ A.KindExtern [] -> true | T_pointer t -> is_extern_type t | _ -> false (* * An output type is printed as the ident, or p_<ident> * * They are abstract types in the emitted F* code *) let print_output_type (qual:bool) (t:typ) : ML string = let rec aux (t:typ) : ML (option string & string) = match t with | T_app id _ _ -> id.v.modul_name, print_ident id | T_pointer t -> let m, i = aux t in m, Printf.sprintf "p_%s" i | _ -> failwith "Print: not an output type" in let mopt, i = aux t in if qual then match mopt with | None -> i | Some m -> Printf.sprintf "%s.ExternalTypes.%s" m i else i let rec print_typ (mname:string) (t:typ) : ML string = //(decreases t) = if is_output_type t then print_output_type true t else match t with | T_false -> "False" | T_app hd _ args -> //output types are already handled at the beginning of print_typ Printf.sprintf "(%s %s)" (print_maybe_qualified_ident mname hd) (String.concat " " (print_indexes mname args)) | T_dep_pair t1 (x, t2) -> Printf.sprintf "(%s:%s & %s)" (print_ident x) (print_typ mname t1) (print_typ mname t2) | T_refine t e -> Printf.sprintf "(refine %s %s)" (print_typ mname t) (print_expr_lam mname e) | T_if_else e t1 t2 -> Printf.sprintf "(t_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname e) (print_typ mname t1) (print_typ mname t2) | T_pointer t -> Printf.sprintf "bpointer (%s)" (print_typ mname t) | T_with_action t _ | T_with_dep_action t _ | T_with_comment t _ -> print_typ mname t | T_with_probe t _ _ _ -> Printf.sprintf "bpointer (%s)" (print_typ mname t) and print_indexes (mname:string) (is:list index) : ML (list string) = //(decreases is) = match is with | [] -> [] | Inl t::is -> print_typ mname t::print_indexes mname is | Inr e::is -> print_expr mname e::print_indexes mname is let rec print_kind (mname:string) (k:parser_kind) : Tot string = match k.pk_kind with | PK_base hd -> Printf.sprintf "%skind_%s" (maybe_mname_prefix mname hd) (print_ident hd) | PK_list -> "kind_nlist" | PK_t_at_most -> "kind_t_at_most" | PK_t_exact -> "kind_t_exact" | PK_return -> "ret_kind" | PK_impos -> "impos_kind" | PK_and_then k1 k2 -> Printf.sprintf "(and_then_kind %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_glb k1 k2 -> Printf.sprintf "(glb %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_filter k -> Printf.sprintf "(filter_kind %s)" (print_kind mname k) | PK_string -> "parse_string_kind" let rec print_action (mname:string) (a:action) : ML string = let print_atomic_action (a:atomic_action) : ML string = match a with | Action_return e -> Printf.sprintf "(action_return %s)" (print_expr mname e) | Action_abort -> "(action_abort())" | Action_field_pos_64 -> "(action_field_pos_64())" | Action_field_pos_32 -> "(action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr -> "(action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr_after sz write_to -> Printf.sprintf "(action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)" (print_expr mname sz) (print_ident write_to) | Action_field_ptr_after_with_setter sz write_to_field write_to_obj -> Printf.sprintf "(action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))" (print_expr mname sz) (print_ident write_to_field) (print_expr mname write_to_obj) | Action_deref i -> Printf.sprintf "(action_deref %s)" (print_ident i) | Action_assignment lhs rhs -> Printf.sprintf "(action_assignment %s %s)" (print_ident lhs) (print_expr mname rhs) | Action_call f args -> Printf.sprintf "(mk_extern_action (%s %s))" (print_ident f) (String.concat " " (List.map (print_expr mname) args)) in match a with | Atomic_action a -> print_atomic_action a | Action_seq hd tl -> Printf.sprintf "(action_seq %s %s)" (print_atomic_action hd) (print_action mname tl) | Action_ite hd then_ else_ -> Printf.sprintf "(action_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname hd) (print_action mname then_) (print_action mname else_) | Action_let i a k -> Printf.sprintf "(action_bind \"%s\" %s (fun %s -> %s))" (print_ident i) (print_atomic_action a) (print_ident i) (print_action mname k) | Action_act a -> Printf.sprintf "(action_act %s)" (print_action mname a) let print_typedef_name (mname:string) (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> Printf.sprintf "(%s:%s)" (print_ident id) (print_typ mname t)) tdn.td_params)) let print_typedef_typ (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> (print_ident id)) tdn.td_params)) let print_typedef_body (mname:string) (b:typedef_body) : ML string = match b with | TD_abbrev t -> print_typ mname t | TD_struct fields -> let print_field (sf:field) : ML string = Printf.sprintf "%s : %s%s" (print_ident sf.sf_ident) (print_typ mname sf.sf_typ) (if sf.sf_dependence then " (*dep*)" else "") in let fields = String.concat ";\n" (List.map print_field fields) in Printf.sprintf "{\n%s\n}" fields let print_typedef_actions_inv_and_fp (td:type_decl) = //we need to add output loc to the modifies locs //if there is an output type type parameter let should_add_output_loc = List.Tot.existsb (fun (_, t) -> is_output_type t || is_extern_type t) td.decl_name.td_params in let pointers = //get only non output type pointers List.Tot.filter (fun (x, t) -> T_pointer? t && not (is_output_type t || is_extern_type t)) td.decl_name.td_params in let inv = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "((ptr_inv %s) `conj_inv` %s)" (print_ident x) out) pointers "true_inv" in let fp = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "(eloc_union (ptr_loc %s) %s)" (print_ident x) out) pointers (if should_add_output_loc then "output_loc" else "eloc_none") in inv, fp let print_comments (cs:list string) : string = match cs with | [] -> "" | _ -> let c = String.concat "\\n\\\n" cs in Printf.sprintf " (Comment \"%s\")" c let print_attributes (entrypoint:bool) (attrs:decl_attributes) : string = match attrs.comments with | [] -> if entrypoint || attrs.is_exported then "" else if attrs.should_inline then "inline_for_extraction noextract\n" else "[@ (CInline)]\n" | cs -> Printf.sprintf "[@ %s %s]\n%s" (print_comments cs) (if not entrypoint && not attrs.is_exported && not attrs.should_inline then "(CInline)" else "") (if attrs.should_inline then "inline_for_extraction\n" else "") /// Printing a decl for M.Types.fst /// /// Print all the definitions, and for a Type_decl, only the type definition let maybe_print_type_equality (mname:string) (td:type_decl) : ML string = if td.decl_name.td_entrypoint then let equate_types_list = Options.get_equate_types_list () in (match (List.tryFind (fun (_, m) -> m = mname) equate_types_list) with | Some (a, _) -> let typname = A.ident_name td.decl_name.td_name in Printf.sprintf "\n\nlet _ = assert (%s.Types.%s == %s) by (FStar.Tactics.trefl ())\n\n" a typname typname | None -> "") else "" let print_definition (mname:string) (d:decl { Definition? (fst d)} ) : ML string = match fst d with | Definition (x, [], T_app ({Ast.v={Ast.name="field_id"}}) _ _, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot field_id by (FStar.Tactics.trivial())\n\n" (print_comments (snd d).comments) (print_field_id_name x) (A.print_constant c) | Definition (x, [], t, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot %s\n\n" (print_comments (snd d).comments) (print_ident x) (A.print_constant c) (print_typ mname t) | Definition (x, params, typ, expr) -> let x_ps = { td_name = x; td_params = params; td_entrypoint = false } in Printf.sprintf "%slet %s : %s = %s\n\n" (print_attributes false (snd d)) (print_typedef_name mname x_ps) (print_typ mname typ) (print_expr mname expr) let print_assumption (mname:string) (d:decl { Assumption? (fst d) } ) : ML string = match fst d with | Assumption (x, t) -> Printf.sprintf "%sassume\nval %s : %s\n\n" (if (snd d).is_if_def then "[@@ CIfDef ]\n" else "") (print_ident x) (print_typ mname t) let print_decl_for_types (mname:string) (d:decl) : ML string = match fst d with | Assumption _ -> "" | Definition _ -> print_definition mname d | Type_decl td -> Printf.sprintf "noextract\ninline_for_extraction\ntype %s = %s\n\n" (print_typedef_name mname td.decl_name) (print_typedef_body mname td.decl_typ) `strcat` maybe_print_type_equality mname td | Output_type _ | Output_type_expr _ _ | Extern_type _ | Extern_fn _ _ _ | Extern_probe _ -> "" /// Print a decl for M.fst /// /// No need to print Definition(s), they are `include`d from M.Types.fst /// /// For a Type_decl, if it is an entry point, we need to emit a definition since /// there is a corresponding declaration in the .fsti /// We make the definition as simply the definition in M.Types.fst let is_type_abbreviation (td:type_decl) : bool = match td.decl_typ with | TD_abbrev _ -> true | TD_struct _ -> false let external_api_include (modul:string) (ds:list decl) : string = if has_external_api ds then Printf.sprintf "open %s.ExternalAPI\n\n" modul else "" #push-options "--z3rlimit_factor 4" let pascal_case name : ML string = let chars = String.list_of_string name in let has_underscore = List.mem '_' chars in let keep, up, low = 0, 1, 2 in if has_underscore then let what_next : ref int = alloc up in let rewrite_char c : ML (list FStar.Char.char) = match c with | '_' -> what_next := up; [] | c -> let c_next = let n = !what_next in if n = keep then c else if n = up then FStar.Char.uppercase c else FStar.Char.lowercase c in let _ = if Char.uppercase c = c then what_next := low else if Char.lowercase c = c then what_next := keep in [c_next] in let chars = List.collect rewrite_char (String.list_of_string name) in String.string_of_list chars else if String.length name = 0 then name else String.uppercase (String.sub name 0 1) ^ String.sub name 1 (String.length name - 1) let uppercase (name:string) : string = String.uppercase name let rec print_as_c_type (t:typ) : ML string = let open Ast in match t with | T_pointer t -> Printf.sprintf "%s*" (print_as_c_type t) | T_app {v={name="Bool"}} _ [] -> "BOOLEAN" | T_app {v={name="UINT8"}} _ [] -> "uint8_t" | T_app {v={name="UINT16"}} _ [] -> "uint16_t" | T_app {v={name="UINT32"}} _ [] -> "uint32_t" | T_app {v={name="UINT64"}} _ [] -> "uint64_t" | T_app {v={name="PUINT8"}} _ [] -> "uint8_t*" | T_app {v={name=x}} KindSpec [] -> x | T_app {v={name=x}} _ [] -> uppercase x | _ -> "__UNKNOWN__" let error_code_macros = //To be kept consistent with EverParse3d.ErrorCode.error_reason_of_result "#define EVERPARSE_ERROR_GENERIC 1uL\n\ #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL\n\ #define EVERPARSE_ERROR_IMPOSSIBLE 3uL\n\ #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL\n\ #define EVERPARSE_ERROR_ACTION_FAILED 5uL\n\ #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL\n\ #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL\n" let rec get_output_typ_dep (modul:string) (t:typ) : ML (option string) = match t with | T_app {v={modul_name=None}} _ _ -> None | T_app {v={modul_name=Some m}} _ _ -> if m = modul then None else Some m | T_pointer t -> get_output_typ_dep modul t | _ -> failwith "get_typ_deps: unexpected output type" let wrapper_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_check_%s" modul fn |> pascal_case let validator_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_validate_%s" modul fn |> pascal_case let print_c_entry (produce_everparse_error: opt_produce_everparse_error) (modul: string) (env: global_env) (ds:list decl) : ML (string & string) = let default_error_handler = "static\n\ void DefaultErrorHandler(\n\t\ const char *typename_s,\n\t\ const char *fieldname,\n\t\ const char *reason,\n\t\ uint64_t error_code,\n\t\ uint8_t *context,\n\t\ EVERPARSE_INPUT_BUFFER input,\n\t\ uint64_t start_pos)\n\ {\n\t\ EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context;\n\t\ EverParseDefaultErrorHandler(\n\t\t\ typename_s,\n\t\t\ fieldname,\n\t\t\ reason,\n\t\t\ error_code,\n\t\t\ frame,\n\t\t\ input,\n\t\t\ start_pos\n\t\ );\n\ }" in let input_stream_binding = Options.get_input_stream_binding () in let is_input_stream_buffer = HashingOptions.InputStreamBuffer? input_stream_binding in let wrapped_call_buffer name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame;\n\t\ frame.filled = FALSE;\n\t\ %s\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0);\n\t\ if (EverParseIsError(result))\n\t\ {\n\t\t\ if (frame.filled)\n\t\t\ {\n\t\t\t\ %sEverParseError(frame.typename_s, frame.fieldname, frame.reason);\n\t\t\ }\n\t\t\ return FALSE;\n\t\ }\n\t\ return TRUE;" (if is_input_stream_buffer then "" else "EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t") name params modul in let wrapped_call_stream name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame =\n\t\ { .filled = FALSE,\n\t\ .typename_s = \"UNKNOWN\",\n\t\ .fieldname = \"UNKNOWN\",\n\t\ .reason = \"UNKNOWN\",\n\t\ .error_code = 0uL\n\ };\n\ EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, input, 0);\n\t\ uint64_t parsedSize = EverParseGetValidatorErrorPos(result);\n\ if (EverParseIsError(result))\n\t\ {\n\t\t\ EverParseHandleError(_extra, parsedSize, frame.typename_s, frame.fieldname, frame.reason, frame.error_code);\n\t\t\ }\n\t\ EverParseRetreat(_extra, base, parsedSize);\n\ return parsedSize;" name params in let mk_param (name: string) (typ: string) : Tot param = (A.with_range (A.to_ident' name) A.dummy_range, T_app (A.with_range (A.to_ident' typ) A.dummy_range) A.KindSpec []) in let print_one_validator (d:type_decl) : ML (string & string) = let params = d.decl_name.td_params @ (if is_input_stream_buffer then [] else [mk_param "_extra" "EVERPARSE_EXTRA_T"]) in let print_params (ps:list param) : ML string = let params = String.concat ", " (List.map (fun (id, t) -> Printf.sprintf "%s %s" (print_as_c_type t) (print_ident id)) ps) in match ps with | [] -> params | _ -> params ^ ", " in let print_arguments (ps:list param) : Tot string = let params = String.concat ", " (List.Tot.map (fun (id, t) -> if is_output_type t //output type pointers are uint8_t* in the F* generated code then (print_ident id) else print_ident id) ps) in match ps with | [] -> params | _ -> params ^ ", " in let wrapper_name = wrapper_name modul d.decl_name.td_name.A.v.A.name in let signature = if is_input_stream_buffer then Printf.sprintf "BOOLEAN %s(%suint8_t *base, uint32_t len)" wrapper_name (print_params params) else Printf.sprintf "uint64_t %s(%sEVERPARSE_INPUT_STREAM_BASE base)" wrapper_name (print_params params) in let validator_name = validator_name modul d.decl_name.td_name.A.v.A.name in let impl = let body = if is_input_stream_buffer then wrapped_call_buffer validator_name (print_arguments params) else wrapped_call_stream validator_name (print_arguments params) in Printf.sprintf "%s {\n\t%s\n}" signature body in signature ^";", impl in let signatures_output_typ_deps = List.fold_left (fun deps (d, _) -> match d with | Type_decl d -> if d.decl_name.td_entrypoint then let params = d.decl_name.td_params in List.fold_left (fun deps (_, t) -> match get_output_typ_dep modul t with | Some dep -> if List.mem dep deps then deps else deps@[dep] | _ -> deps) deps params else deps | _ -> deps) [] ds in let signatures, impls = List.split (List.collect (fun d -> match fst d with | Type_decl d -> if d.decl_name.td_entrypoint then [print_one_validator d] else [] | _ -> []) ds) in let external_defs_includes = if not (Options.get_emit_output_types_defs ()) then "" else let deps = if List.length signatures_output_typ_deps = 0 then "" else String.concat "" (List.map (fun dep -> Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" dep) signatures_output_typ_deps) in let self = if has_output_types ds || has_extern_types ds then Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n" modul else "" in Printf.sprintf "%s\n%s\n\n" deps self in let header = Printf.sprintf "#include \"EverParseEndianness.h\"\n\ %s\n\ %s\ #ifdef __cplusplus\n\ extern \"C\" {\n\ #endif\n\ %s\n\ #ifdef __cplusplus\n\ }\n\ #endif\n" error_code_macros external_defs_includes (signatures |> String.concat "\n\n") in let input_stream_include = HashingOptions.input_stream_include input_stream_binding in let header = if input_stream_include = "" then header else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include header in let add_includes = Options.make_includes () in let header = Printf.sprintf "%s%s" add_includes header in let error_callback_proto = if HashingOptions.InputStreamBuffer? input_stream_binding then Printf.sprintf "void %sEverParseError(const char *StructName, const char *FieldName, const char *Reason)%s" modul (if produce_everparse_error = Some ProduceEverParseError then "{(void) StructName; (void) FieldName; (void) Reason;}" else ";") else "" in let impl = Printf.sprintf "#include \"%sWrapper.h\"\n\ #include \"EverParse.h\"\n\ #include \"%s.h\"\n\ %s\n\n\ %s\n\n\ %s\n" modul modul error_callback_proto default_error_handler (impls |> String.concat "\n\n") in let impl = if input_stream_include = "" then impl else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include impl in let impl = Printf.sprintf "%s%s" add_includes impl in header, impl /// Functions for printing setters and getters for output expressions let rec out_bt_name (t:typ) : ML string = match t with | T_app i _ _ -> A.ident_name i | T_pointer t -> out_bt_name t | _ -> failwith "Impossible, out_bt_name received a non output type!" let out_expr_bt_name (oe:output_expr) : ML string = out_bt_name oe.oe_bt (* * Walks over the output expressions AST and constructs a string *) let rec out_fn_name (oe:output_expr) : ML string = match oe.oe_expr with | T_OE_id _ -> out_expr_bt_name oe | T_OE_star oe -> Printf.sprintf "%s_star" (out_fn_name oe) | T_OE_addrof oe -> Printf.sprintf "%s_addrof" (out_fn_name oe) | T_OE_deref oe f -> Printf.sprintf "%s_deref_%s" (out_fn_name oe) (A.ident_name f) | T_OE_dot oe f -> Printf.sprintf "%s_dot_%s" (out_fn_name oe) (A.ident_name f) module H = Hashtable type set = H.t string unit (* * In the printing functions, a hashtable tracks that we print a defn. only once * * E.g. multiple output expressions may require a val decl. for types, * we need to print them only once each *) let rec base_output_type (t:typ) : ML A.ident = match t with | T_app id A.KindOutput [] -> id | T_pointer t -> base_output_type t | _ -> failwith "Target.base_output_type called with a non-output type" #push-options "--fuel 1" let rec print_output_type_val (tbl:set) (t:typ) : ML string = let open A in if is_output_type t then let s = print_output_type false t in if H.try_find tbl s <> None then "" else let _ = H.insert tbl s () in assert (is_output_type t); match t with | T_app id KindOutput [] -> Printf.sprintf "\n\nval %s : Type0\n\n" s | T_pointer bt -> let bs = print_output_type_val tbl bt in bs ^ (Printf.sprintf "\n\ninline_for_extraction noextract type %s = bpointer %s\n\n" s (print_output_type false bt)) else "" #pop-options let rec print_out_expr' (oe:output_expr') : ML string = match oe with | T_OE_id id -> A.ident_to_string id | T_OE_star o -> Printf.sprintf "*(%s)" (print_out_expr' o.oe_expr) | T_OE_addrof o -> Printf.sprintf "&(%s)" (print_out_expr' o.oe_expr) | T_OE_deref o i -> Printf.sprintf "(%s)->%s" (print_out_expr' o.oe_expr) (A.ident_to_string i) | T_OE_dot o i -> Printf.sprintf "(%s).%s" (print_out_expr' o.oe_expr) (A.ident_to_string i) (* * F* val for the setter for the output expression *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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": 4, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
tbl: Target.set -> mname: Prims.string -> oe: Target.output_expr -> FStar.All.ML Prims.string
FStar.All.ML
[ "ml" ]
[]
[ "Target.set", "Prims.string", "Target.output_expr", "Prims.unit", "FStar.Pervasives.Native.option", "FStar.Printf.sprintf", "Prims.op_Equality", "Prims.int", "Target.__proj__Mkoutput_expr__item__oe_bitwidth", "FStar.Pervasives.Native.None", "Target.print_typ", "Target.__proj__Mkoutput_expr__item__oe_t", "Prims.bool", "FStar.Pervasives.Native.__proj__Some__item__v", "Target.__proj__Mkoutput_expr__item__oe_bt", "Hashtable.insert", "Hashtable.try_find", "Target.out_fn_name" ]
[]
false
true
false
false
false
let print_out_expr_set_fstar (tbl: set) (mname: string) (oe: output_expr) : ML string =
let fn_name = Printf.sprintf "set_%s" (out_fn_name oe) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); let fn_arg1_t = print_typ mname oe.oe_bt in let fn_arg2_t = if oe.oe_bitwidth = None then print_typ mname oe.oe_t else Printf.sprintf "(i:%s{FStar.UInt.size (FStar.Integers.v i) %d})" (print_typ mname oe.oe_t) (Some?.v oe.oe_bitwidth) in Printf.sprintf "\n\nval %s (_:%s) (_:%s) : extern_action (NonTrivial output_loc)\n\n" fn_name fn_arg1_t fn_arg2_t
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.lanes
val lanes : Type0
let lanes = w:width{w == 1 \/ w == 2 \/ w == 4}
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 29, "start_col": 0, "start_line": 29 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Lib.IntVector.width", "Prims.l_or", "Prims.eq2", "Prims.int" ]
[]
false
false
false
true
true
let lanes =
w: width{w == 1 \/ w == 2 \/ w == 4}
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.pfmul
val pfmul (x y: pfelem) : pfelem
val pfmul (x y: pfelem) : pfelem
let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 27, "start_col": 0, "start_line": 27 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Hacl.Spec.Poly1305.Vec.pfelem -> y: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.pfelem
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.pfelem", "Spec.Poly1305.fmul" ]
[]
false
false
false
true
false
let pfmul (x y: pfelem) : pfelem =
Scalar.fmul x y
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.pfadd
val pfadd (x y: pfelem) : pfelem
val pfadd (x y: pfelem) : pfelem
let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 26, "start_col": 0, "start_line": 26 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Hacl.Spec.Poly1305.Vec.pfelem -> y: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.pfelem
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.pfelem", "Spec.Poly1305.fadd" ]
[]
false
false
false
true
false
let pfadd (x y: pfelem) : pfelem =
Scalar.fadd x y
false
Target.fst
Target.print_expr
val print_expr (mname:string) (e:expr) : ML string
val print_expr (mname:string) (e:expr) : ML string
let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 28, "end_line": 353, "start_col": 0, "start_line": 307 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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 -> e: Target.expr -> FStar.All.ML Prims.string
FStar.All.ML
[ "ml" ]
[ "print_expr", "print_exprs", "print_fields" ]
[ "Prims.string", "Target.expr", "FStar.Pervasives.Native.fst", "Target.expr'", "Ast.range", "Ast.constant", "Ast.print_constant", "Ast.ident", "Target.print_maybe_qualified_ident", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Printf.sprintf", "FStar.String.concat", "Target.print_fields", "Target.op", "Target.is_infix", "Target.print_expr", "Target.print_op_with_range", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.snd", "Target.__proj__App__item__hd", "Prims.bool", "Target.print_op", "Ast.integer_type", "Prims.int", "Ast.bitfield_bit_order", "Target.BitFieldOf", "Target.print_exprs" ]
[ "mutual recursion" ]
false
true
false
false
false
let rec print_expr (mname: string) (e: expr) : ML string =
match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1 ; e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1 ; e2 ; e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1 ; e2 ; e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es))
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.fmul
val fmul (#w: lanes) (x y: elem w) : elem w
val fmul (#w: lanes) (x y: elem w) : elem w
let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 40, "start_col": 0, "start_line": 39 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w =
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Hacl.Spec.Poly1305.Vec.elem w -> y: Hacl.Spec.Poly1305.Vec.elem w -> Hacl.Spec.Poly1305.Vec.elem w
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Hacl.Spec.Poly1305.Vec.elem", "Lib.Sequence.map2", "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.pfmul" ]
[]
false
false
false
false
false
let fmul (#w: lanes) (x y: elem w) : elem w =
map2 pfmul x y
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.to_elem
val to_elem (w: lanes) (x: pfelem) : elem w
val to_elem (w: lanes) (x: pfelem) : elem w
let to_elem (w:lanes) (x:pfelem) : elem w = create w x
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 33, "start_col": 0, "start_line": 33 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
w: Hacl.Spec.Poly1305.Vec.lanes -> x: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.elem w
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Hacl.Spec.Poly1305.Vec.pfelem", "Lib.Sequence.create", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let to_elem (w: lanes) (x: pfelem) : elem w =
create w x
false
FStar.OrdSetProps.fst
FStar.OrdSetProps.insert
val insert : x: a -> s: FStar.OrdSet.ordset a f -> FStar.OrdSet.ordset a f
let insert (#a:eqtype) (#f:cmp a) (x:a) (s:ordset a f) = union #a #f (singleton #a #f x) s
{ "file_name": "ulib/FStar.OrdSetProps.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 90, "end_line": 31, "start_col": 0, "start_line": 31 }
(* Copyright 2008-2018 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 FStar.OrdSetProps open FStar.OrdSet val fold: #a:eqtype -> #b:Type -> #f:cmp a -> (a -> b -> Tot b) -> s:ordset a f -> b -> Tot b (decreases (size s)) let rec fold (#a:eqtype) (#b:Type) #f g s x = if s = empty then x else let Some e = choose s in let a_rest = fold g (remove e s) x in g e a_rest (**********)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.OrdSet.fsti.checked" ], "interface_file": false, "source_file": "FStar.OrdSetProps.fst" }
[ { "abbrev": false, "full_module": "FStar.OrdSet", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "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: a -> s: FStar.OrdSet.ordset a f -> FStar.OrdSet.ordset a f
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.OrdSet.cmp", "FStar.OrdSet.ordset", "FStar.OrdSet.union", "FStar.OrdSet.singleton" ]
[]
false
false
false
false
false
let insert (#a: eqtype) (#f: cmp a) (x: a) (s: ordset a f) =
union #a #f (singleton #a #f x) s
false
FStar.OrdSetProps.fst
FStar.OrdSetProps.union'
val union':#a:eqtype -> #f:cmp a -> ordset a f -> ordset a f -> Tot (ordset a f)
val union':#a:eqtype -> #f:cmp a -> ordset a f -> ordset a f -> Tot (ordset a f)
let union' (#a:eqtype) #f s1 s2 = fold (fun e (s:ordset a f) -> insert e s) s1 s2
{ "file_name": "ulib/FStar.OrdSetProps.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 81, "end_line": 34, "start_col": 0, "start_line": 34 }
(* Copyright 2008-2018 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 FStar.OrdSetProps open FStar.OrdSet val fold: #a:eqtype -> #b:Type -> #f:cmp a -> (a -> b -> Tot b) -> s:ordset a f -> b -> Tot b (decreases (size s)) let rec fold (#a:eqtype) (#b:Type) #f g s x = if s = empty then x else let Some e = choose s in let a_rest = fold g (remove e s) x in g e a_rest (**********) let insert (#a:eqtype) (#f:cmp a) (x:a) (s:ordset a f) = union #a #f (singleton #a #f x) s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.OrdSet.fsti.checked" ], "interface_file": false, "source_file": "FStar.OrdSetProps.fst" }
[ { "abbrev": false, "full_module": "FStar.OrdSet", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "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
s1: FStar.OrdSet.ordset a f -> s2: FStar.OrdSet.ordset a f -> FStar.OrdSet.ordset a f
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.OrdSet.cmp", "FStar.OrdSet.ordset", "FStar.OrdSetProps.fold", "FStar.OrdSetProps.insert" ]
[]
false
false
false
false
false
let union' (#a: eqtype) #f s1 s2 =
fold (fun e (s: ordset a f) -> insert e s) s1 s2
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.size_block
val size_block:size_nat
val size_block:size_nat
let size_block : size_nat = Scalar.size_block
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 43, "start_col": 0, "start_line": 43 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat{n <= Prims.pow2 32 - 1}
Prims.Tot
[ "total" ]
[]
[ "Spec.Poly1305.size_block" ]
[]
false
false
false
false
false
let size_block:size_nat =
Scalar.size_block
false
Target.fst
Target.base_id_of_output_expr
val base_id_of_output_expr (oe: output_expr) : A.ident
val base_id_of_output_expr (oe: output_expr) : A.ident
let rec base_id_of_output_expr (oe:output_expr) : A.ident = match oe.oe_expr with | T_OE_id id -> id | T_OE_star oe | T_OE_addrof oe | T_OE_deref oe _ | T_OE_dot oe _ -> base_id_of_output_expr oe
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 46, "end_line": 1130, "start_col": 0, "start_line": 1124 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl let print_lam (#a:Type) (f:a -> ML string) (x:lam a) : ML string = match x with | Some x, y -> Printf.sprintf ("(fun %s -> %s)") (print_ident x) (f y) | None, y -> f y let print_expr_lam (mname:string) (x:lam expr) : ML string = print_lam (print_expr mname) x let rec is_output_type (t:typ) : bool = match t with | T_app _ A.KindOutput [] -> true | T_pointer t -> is_output_type t | _ -> false let rec is_extern_type (t:typ) : bool = match t with | T_app _ A.KindExtern [] -> true | T_pointer t -> is_extern_type t | _ -> false (* * An output type is printed as the ident, or p_<ident> * * They are abstract types in the emitted F* code *) let print_output_type (qual:bool) (t:typ) : ML string = let rec aux (t:typ) : ML (option string & string) = match t with | T_app id _ _ -> id.v.modul_name, print_ident id | T_pointer t -> let m, i = aux t in m, Printf.sprintf "p_%s" i | _ -> failwith "Print: not an output type" in let mopt, i = aux t in if qual then match mopt with | None -> i | Some m -> Printf.sprintf "%s.ExternalTypes.%s" m i else i let rec print_typ (mname:string) (t:typ) : ML string = //(decreases t) = if is_output_type t then print_output_type true t else match t with | T_false -> "False" | T_app hd _ args -> //output types are already handled at the beginning of print_typ Printf.sprintf "(%s %s)" (print_maybe_qualified_ident mname hd) (String.concat " " (print_indexes mname args)) | T_dep_pair t1 (x, t2) -> Printf.sprintf "(%s:%s & %s)" (print_ident x) (print_typ mname t1) (print_typ mname t2) | T_refine t e -> Printf.sprintf "(refine %s %s)" (print_typ mname t) (print_expr_lam mname e) | T_if_else e t1 t2 -> Printf.sprintf "(t_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname e) (print_typ mname t1) (print_typ mname t2) | T_pointer t -> Printf.sprintf "bpointer (%s)" (print_typ mname t) | T_with_action t _ | T_with_dep_action t _ | T_with_comment t _ -> print_typ mname t | T_with_probe t _ _ _ -> Printf.sprintf "bpointer (%s)" (print_typ mname t) and print_indexes (mname:string) (is:list index) : ML (list string) = //(decreases is) = match is with | [] -> [] | Inl t::is -> print_typ mname t::print_indexes mname is | Inr e::is -> print_expr mname e::print_indexes mname is let rec print_kind (mname:string) (k:parser_kind) : Tot string = match k.pk_kind with | PK_base hd -> Printf.sprintf "%skind_%s" (maybe_mname_prefix mname hd) (print_ident hd) | PK_list -> "kind_nlist" | PK_t_at_most -> "kind_t_at_most" | PK_t_exact -> "kind_t_exact" | PK_return -> "ret_kind" | PK_impos -> "impos_kind" | PK_and_then k1 k2 -> Printf.sprintf "(and_then_kind %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_glb k1 k2 -> Printf.sprintf "(glb %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_filter k -> Printf.sprintf "(filter_kind %s)" (print_kind mname k) | PK_string -> "parse_string_kind" let rec print_action (mname:string) (a:action) : ML string = let print_atomic_action (a:atomic_action) : ML string = match a with | Action_return e -> Printf.sprintf "(action_return %s)" (print_expr mname e) | Action_abort -> "(action_abort())" | Action_field_pos_64 -> "(action_field_pos_64())" | Action_field_pos_32 -> "(action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr -> "(action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr_after sz write_to -> Printf.sprintf "(action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)" (print_expr mname sz) (print_ident write_to) | Action_field_ptr_after_with_setter sz write_to_field write_to_obj -> Printf.sprintf "(action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))" (print_expr mname sz) (print_ident write_to_field) (print_expr mname write_to_obj) | Action_deref i -> Printf.sprintf "(action_deref %s)" (print_ident i) | Action_assignment lhs rhs -> Printf.sprintf "(action_assignment %s %s)" (print_ident lhs) (print_expr mname rhs) | Action_call f args -> Printf.sprintf "(mk_extern_action (%s %s))" (print_ident f) (String.concat " " (List.map (print_expr mname) args)) in match a with | Atomic_action a -> print_atomic_action a | Action_seq hd tl -> Printf.sprintf "(action_seq %s %s)" (print_atomic_action hd) (print_action mname tl) | Action_ite hd then_ else_ -> Printf.sprintf "(action_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname hd) (print_action mname then_) (print_action mname else_) | Action_let i a k -> Printf.sprintf "(action_bind \"%s\" %s (fun %s -> %s))" (print_ident i) (print_atomic_action a) (print_ident i) (print_action mname k) | Action_act a -> Printf.sprintf "(action_act %s)" (print_action mname a) let print_typedef_name (mname:string) (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> Printf.sprintf "(%s:%s)" (print_ident id) (print_typ mname t)) tdn.td_params)) let print_typedef_typ (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> (print_ident id)) tdn.td_params)) let print_typedef_body (mname:string) (b:typedef_body) : ML string = match b with | TD_abbrev t -> print_typ mname t | TD_struct fields -> let print_field (sf:field) : ML string = Printf.sprintf "%s : %s%s" (print_ident sf.sf_ident) (print_typ mname sf.sf_typ) (if sf.sf_dependence then " (*dep*)" else "") in let fields = String.concat ";\n" (List.map print_field fields) in Printf.sprintf "{\n%s\n}" fields let print_typedef_actions_inv_and_fp (td:type_decl) = //we need to add output loc to the modifies locs //if there is an output type type parameter let should_add_output_loc = List.Tot.existsb (fun (_, t) -> is_output_type t || is_extern_type t) td.decl_name.td_params in let pointers = //get only non output type pointers List.Tot.filter (fun (x, t) -> T_pointer? t && not (is_output_type t || is_extern_type t)) td.decl_name.td_params in let inv = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "((ptr_inv %s) `conj_inv` %s)" (print_ident x) out) pointers "true_inv" in let fp = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "(eloc_union (ptr_loc %s) %s)" (print_ident x) out) pointers (if should_add_output_loc then "output_loc" else "eloc_none") in inv, fp let print_comments (cs:list string) : string = match cs with | [] -> "" | _ -> let c = String.concat "\\n\\\n" cs in Printf.sprintf " (Comment \"%s\")" c let print_attributes (entrypoint:bool) (attrs:decl_attributes) : string = match attrs.comments with | [] -> if entrypoint || attrs.is_exported then "" else if attrs.should_inline then "inline_for_extraction noextract\n" else "[@ (CInline)]\n" | cs -> Printf.sprintf "[@ %s %s]\n%s" (print_comments cs) (if not entrypoint && not attrs.is_exported && not attrs.should_inline then "(CInline)" else "") (if attrs.should_inline then "inline_for_extraction\n" else "") /// Printing a decl for M.Types.fst /// /// Print all the definitions, and for a Type_decl, only the type definition let maybe_print_type_equality (mname:string) (td:type_decl) : ML string = if td.decl_name.td_entrypoint then let equate_types_list = Options.get_equate_types_list () in (match (List.tryFind (fun (_, m) -> m = mname) equate_types_list) with | Some (a, _) -> let typname = A.ident_name td.decl_name.td_name in Printf.sprintf "\n\nlet _ = assert (%s.Types.%s == %s) by (FStar.Tactics.trefl ())\n\n" a typname typname | None -> "") else "" let print_definition (mname:string) (d:decl { Definition? (fst d)} ) : ML string = match fst d with | Definition (x, [], T_app ({Ast.v={Ast.name="field_id"}}) _ _, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot field_id by (FStar.Tactics.trivial())\n\n" (print_comments (snd d).comments) (print_field_id_name x) (A.print_constant c) | Definition (x, [], t, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot %s\n\n" (print_comments (snd d).comments) (print_ident x) (A.print_constant c) (print_typ mname t) | Definition (x, params, typ, expr) -> let x_ps = { td_name = x; td_params = params; td_entrypoint = false } in Printf.sprintf "%slet %s : %s = %s\n\n" (print_attributes false (snd d)) (print_typedef_name mname x_ps) (print_typ mname typ) (print_expr mname expr) let print_assumption (mname:string) (d:decl { Assumption? (fst d) } ) : ML string = match fst d with | Assumption (x, t) -> Printf.sprintf "%sassume\nval %s : %s\n\n" (if (snd d).is_if_def then "[@@ CIfDef ]\n" else "") (print_ident x) (print_typ mname t) let print_decl_for_types (mname:string) (d:decl) : ML string = match fst d with | Assumption _ -> "" | Definition _ -> print_definition mname d | Type_decl td -> Printf.sprintf "noextract\ninline_for_extraction\ntype %s = %s\n\n" (print_typedef_name mname td.decl_name) (print_typedef_body mname td.decl_typ) `strcat` maybe_print_type_equality mname td | Output_type _ | Output_type_expr _ _ | Extern_type _ | Extern_fn _ _ _ | Extern_probe _ -> "" /// Print a decl for M.fst /// /// No need to print Definition(s), they are `include`d from M.Types.fst /// /// For a Type_decl, if it is an entry point, we need to emit a definition since /// there is a corresponding declaration in the .fsti /// We make the definition as simply the definition in M.Types.fst let is_type_abbreviation (td:type_decl) : bool = match td.decl_typ with | TD_abbrev _ -> true | TD_struct _ -> false let external_api_include (modul:string) (ds:list decl) : string = if has_external_api ds then Printf.sprintf "open %s.ExternalAPI\n\n" modul else "" #push-options "--z3rlimit_factor 4" let pascal_case name : ML string = let chars = String.list_of_string name in let has_underscore = List.mem '_' chars in let keep, up, low = 0, 1, 2 in if has_underscore then let what_next : ref int = alloc up in let rewrite_char c : ML (list FStar.Char.char) = match c with | '_' -> what_next := up; [] | c -> let c_next = let n = !what_next in if n = keep then c else if n = up then FStar.Char.uppercase c else FStar.Char.lowercase c in let _ = if Char.uppercase c = c then what_next := low else if Char.lowercase c = c then what_next := keep in [c_next] in let chars = List.collect rewrite_char (String.list_of_string name) in String.string_of_list chars else if String.length name = 0 then name else String.uppercase (String.sub name 0 1) ^ String.sub name 1 (String.length name - 1) let uppercase (name:string) : string = String.uppercase name let rec print_as_c_type (t:typ) : ML string = let open Ast in match t with | T_pointer t -> Printf.sprintf "%s*" (print_as_c_type t) | T_app {v={name="Bool"}} _ [] -> "BOOLEAN" | T_app {v={name="UINT8"}} _ [] -> "uint8_t" | T_app {v={name="UINT16"}} _ [] -> "uint16_t" | T_app {v={name="UINT32"}} _ [] -> "uint32_t" | T_app {v={name="UINT64"}} _ [] -> "uint64_t" | T_app {v={name="PUINT8"}} _ [] -> "uint8_t*" | T_app {v={name=x}} KindSpec [] -> x | T_app {v={name=x}} _ [] -> uppercase x | _ -> "__UNKNOWN__" let error_code_macros = //To be kept consistent with EverParse3d.ErrorCode.error_reason_of_result "#define EVERPARSE_ERROR_GENERIC 1uL\n\ #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL\n\ #define EVERPARSE_ERROR_IMPOSSIBLE 3uL\n\ #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL\n\ #define EVERPARSE_ERROR_ACTION_FAILED 5uL\n\ #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL\n\ #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL\n" let rec get_output_typ_dep (modul:string) (t:typ) : ML (option string) = match t with | T_app {v={modul_name=None}} _ _ -> None | T_app {v={modul_name=Some m}} _ _ -> if m = modul then None else Some m | T_pointer t -> get_output_typ_dep modul t | _ -> failwith "get_typ_deps: unexpected output type" let wrapper_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_check_%s" modul fn |> pascal_case let validator_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_validate_%s" modul fn |> pascal_case let print_c_entry (produce_everparse_error: opt_produce_everparse_error) (modul: string) (env: global_env) (ds:list decl) : ML (string & string) = let default_error_handler = "static\n\ void DefaultErrorHandler(\n\t\ const char *typename_s,\n\t\ const char *fieldname,\n\t\ const char *reason,\n\t\ uint64_t error_code,\n\t\ uint8_t *context,\n\t\ EVERPARSE_INPUT_BUFFER input,\n\t\ uint64_t start_pos)\n\ {\n\t\ EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context;\n\t\ EverParseDefaultErrorHandler(\n\t\t\ typename_s,\n\t\t\ fieldname,\n\t\t\ reason,\n\t\t\ error_code,\n\t\t\ frame,\n\t\t\ input,\n\t\t\ start_pos\n\t\ );\n\ }" in let input_stream_binding = Options.get_input_stream_binding () in let is_input_stream_buffer = HashingOptions.InputStreamBuffer? input_stream_binding in let wrapped_call_buffer name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame;\n\t\ frame.filled = FALSE;\n\t\ %s\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0);\n\t\ if (EverParseIsError(result))\n\t\ {\n\t\t\ if (frame.filled)\n\t\t\ {\n\t\t\t\ %sEverParseError(frame.typename_s, frame.fieldname, frame.reason);\n\t\t\ }\n\t\t\ return FALSE;\n\t\ }\n\t\ return TRUE;" (if is_input_stream_buffer then "" else "EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t") name params modul in let wrapped_call_stream name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame =\n\t\ { .filled = FALSE,\n\t\ .typename_s = \"UNKNOWN\",\n\t\ .fieldname = \"UNKNOWN\",\n\t\ .reason = \"UNKNOWN\",\n\t\ .error_code = 0uL\n\ };\n\ EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, input, 0);\n\t\ uint64_t parsedSize = EverParseGetValidatorErrorPos(result);\n\ if (EverParseIsError(result))\n\t\ {\n\t\t\ EverParseHandleError(_extra, parsedSize, frame.typename_s, frame.fieldname, frame.reason, frame.error_code);\n\t\t\ }\n\t\ EverParseRetreat(_extra, base, parsedSize);\n\ return parsedSize;" name params in let mk_param (name: string) (typ: string) : Tot param = (A.with_range (A.to_ident' name) A.dummy_range, T_app (A.with_range (A.to_ident' typ) A.dummy_range) A.KindSpec []) in let print_one_validator (d:type_decl) : ML (string & string) = let params = d.decl_name.td_params @ (if is_input_stream_buffer then [] else [mk_param "_extra" "EVERPARSE_EXTRA_T"]) in let print_params (ps:list param) : ML string = let params = String.concat ", " (List.map (fun (id, t) -> Printf.sprintf "%s %s" (print_as_c_type t) (print_ident id)) ps) in match ps with | [] -> params | _ -> params ^ ", " in let print_arguments (ps:list param) : Tot string = let params = String.concat ", " (List.Tot.map (fun (id, t) -> if is_output_type t //output type pointers are uint8_t* in the F* generated code then (print_ident id) else print_ident id) ps) in match ps with | [] -> params | _ -> params ^ ", " in let wrapper_name = wrapper_name modul d.decl_name.td_name.A.v.A.name in let signature = if is_input_stream_buffer then Printf.sprintf "BOOLEAN %s(%suint8_t *base, uint32_t len)" wrapper_name (print_params params) else Printf.sprintf "uint64_t %s(%sEVERPARSE_INPUT_STREAM_BASE base)" wrapper_name (print_params params) in let validator_name = validator_name modul d.decl_name.td_name.A.v.A.name in let impl = let body = if is_input_stream_buffer then wrapped_call_buffer validator_name (print_arguments params) else wrapped_call_stream validator_name (print_arguments params) in Printf.sprintf "%s {\n\t%s\n}" signature body in signature ^";", impl in let signatures_output_typ_deps = List.fold_left (fun deps (d, _) -> match d with | Type_decl d -> if d.decl_name.td_entrypoint then let params = d.decl_name.td_params in List.fold_left (fun deps (_, t) -> match get_output_typ_dep modul t with | Some dep -> if List.mem dep deps then deps else deps@[dep] | _ -> deps) deps params else deps | _ -> deps) [] ds in let signatures, impls = List.split (List.collect (fun d -> match fst d with | Type_decl d -> if d.decl_name.td_entrypoint then [print_one_validator d] else [] | _ -> []) ds) in let external_defs_includes = if not (Options.get_emit_output_types_defs ()) then "" else let deps = if List.length signatures_output_typ_deps = 0 then "" else String.concat "" (List.map (fun dep -> Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" dep) signatures_output_typ_deps) in let self = if has_output_types ds || has_extern_types ds then Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n" modul else "" in Printf.sprintf "%s\n%s\n\n" deps self in let header = Printf.sprintf "#include \"EverParseEndianness.h\"\n\ %s\n\ %s\ #ifdef __cplusplus\n\ extern \"C\" {\n\ #endif\n\ %s\n\ #ifdef __cplusplus\n\ }\n\ #endif\n" error_code_macros external_defs_includes (signatures |> String.concat "\n\n") in let input_stream_include = HashingOptions.input_stream_include input_stream_binding in let header = if input_stream_include = "" then header else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include header in let add_includes = Options.make_includes () in let header = Printf.sprintf "%s%s" add_includes header in let error_callback_proto = if HashingOptions.InputStreamBuffer? input_stream_binding then Printf.sprintf "void %sEverParseError(const char *StructName, const char *FieldName, const char *Reason)%s" modul (if produce_everparse_error = Some ProduceEverParseError then "{(void) StructName; (void) FieldName; (void) Reason;}" else ";") else "" in let impl = Printf.sprintf "#include \"%sWrapper.h\"\n\ #include \"EverParse.h\"\n\ #include \"%s.h\"\n\ %s\n\n\ %s\n\n\ %s\n" modul modul error_callback_proto default_error_handler (impls |> String.concat "\n\n") in let impl = if input_stream_include = "" then impl else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include impl in let impl = Printf.sprintf "%s%s" add_includes impl in header, impl /// Functions for printing setters and getters for output expressions let rec out_bt_name (t:typ) : ML string = match t with | T_app i _ _ -> A.ident_name i | T_pointer t -> out_bt_name t | _ -> failwith "Impossible, out_bt_name received a non output type!" let out_expr_bt_name (oe:output_expr) : ML string = out_bt_name oe.oe_bt (* * Walks over the output expressions AST and constructs a string *) let rec out_fn_name (oe:output_expr) : ML string = match oe.oe_expr with | T_OE_id _ -> out_expr_bt_name oe | T_OE_star oe -> Printf.sprintf "%s_star" (out_fn_name oe) | T_OE_addrof oe -> Printf.sprintf "%s_addrof" (out_fn_name oe) | T_OE_deref oe f -> Printf.sprintf "%s_deref_%s" (out_fn_name oe) (A.ident_name f) | T_OE_dot oe f -> Printf.sprintf "%s_dot_%s" (out_fn_name oe) (A.ident_name f) module H = Hashtable type set = H.t string unit (* * In the printing functions, a hashtable tracks that we print a defn. only once * * E.g. multiple output expressions may require a val decl. for types, * we need to print them only once each *) let rec base_output_type (t:typ) : ML A.ident = match t with | T_app id A.KindOutput [] -> id | T_pointer t -> base_output_type t | _ -> failwith "Target.base_output_type called with a non-output type" #push-options "--fuel 1" let rec print_output_type_val (tbl:set) (t:typ) : ML string = let open A in if is_output_type t then let s = print_output_type false t in if H.try_find tbl s <> None then "" else let _ = H.insert tbl s () in assert (is_output_type t); match t with | T_app id KindOutput [] -> Printf.sprintf "\n\nval %s : Type0\n\n" s | T_pointer bt -> let bs = print_output_type_val tbl bt in bs ^ (Printf.sprintf "\n\ninline_for_extraction noextract type %s = bpointer %s\n\n" s (print_output_type false bt)) else "" #pop-options let rec print_out_expr' (oe:output_expr') : ML string = match oe with | T_OE_id id -> A.ident_to_string id | T_OE_star o -> Printf.sprintf "*(%s)" (print_out_expr' o.oe_expr) | T_OE_addrof o -> Printf.sprintf "&(%s)" (print_out_expr' o.oe_expr) | T_OE_deref o i -> Printf.sprintf "(%s)->%s" (print_out_expr' o.oe_expr) (A.ident_to_string i) | T_OE_dot o i -> Printf.sprintf "(%s).%s" (print_out_expr' o.oe_expr) (A.ident_to_string i) (* * F* val for the setter for the output expression *) let print_out_expr_set_fstar (tbl:set) (mname:string) (oe:output_expr) : ML string = let fn_name = Printf.sprintf "set_%s" (out_fn_name oe) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); //TODO: module name? let fn_arg1_t = print_typ mname oe.oe_bt in let fn_arg2_t = (* * If bitwidth is not None, * then output the size restriction in the refinement * Is there a better way to output it? *) if oe.oe_bitwidth = None then print_typ mname oe.oe_t else begin Printf.sprintf "(i:%s{FStar.UInt.size (FStar.Integers.v i) %d})" (print_typ mname oe.oe_t) (Some?.v oe.oe_bitwidth) end in Printf.sprintf "\n\nval %s (_:%s) (_:%s) : extern_action (NonTrivial output_loc)\n\n" fn_name fn_arg1_t fn_arg2_t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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": 4, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
oe: Target.output_expr -> Ast.ident
Prims.Tot
[ "total" ]
[]
[ "Target.output_expr", "Target.__proj__Mkoutput_expr__item__oe_expr", "Ast.ident", "Target.base_id_of_output_expr" ]
[ "recursion" ]
false
false
false
true
false
let rec base_id_of_output_expr (oe: output_expr) : A.ident =
match oe.oe_expr with | T_OE_id id -> id | T_OE_star oe | T_OE_addrof oe | T_OE_deref oe _ | T_OE_dot oe _ -> base_id_of_output_expr oe
false
Target.fst
Target.print_out_expr'
val print_out_expr' (oe: output_expr') : ML string
val print_out_expr' (oe: output_expr') : ML string
let rec print_out_expr' (oe:output_expr') : ML string = match oe with | T_OE_id id -> A.ident_to_string id | T_OE_star o -> Printf.sprintf "*(%s)" (print_out_expr' o.oe_expr) | T_OE_addrof o -> Printf.sprintf "&(%s)" (print_out_expr' o.oe_expr) | T_OE_deref o i -> Printf.sprintf "(%s)->%s" (print_out_expr' o.oe_expr) (A.ident_to_string i) | T_OE_dot o i -> Printf.sprintf "(%s).%s" (print_out_expr' o.oe_expr) (A.ident_to_string i)
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 94, "end_line": 1090, "start_col": 0, "start_line": 1084 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl let print_lam (#a:Type) (f:a -> ML string) (x:lam a) : ML string = match x with | Some x, y -> Printf.sprintf ("(fun %s -> %s)") (print_ident x) (f y) | None, y -> f y let print_expr_lam (mname:string) (x:lam expr) : ML string = print_lam (print_expr mname) x let rec is_output_type (t:typ) : bool = match t with | T_app _ A.KindOutput [] -> true | T_pointer t -> is_output_type t | _ -> false let rec is_extern_type (t:typ) : bool = match t with | T_app _ A.KindExtern [] -> true | T_pointer t -> is_extern_type t | _ -> false (* * An output type is printed as the ident, or p_<ident> * * They are abstract types in the emitted F* code *) let print_output_type (qual:bool) (t:typ) : ML string = let rec aux (t:typ) : ML (option string & string) = match t with | T_app id _ _ -> id.v.modul_name, print_ident id | T_pointer t -> let m, i = aux t in m, Printf.sprintf "p_%s" i | _ -> failwith "Print: not an output type" in let mopt, i = aux t in if qual then match mopt with | None -> i | Some m -> Printf.sprintf "%s.ExternalTypes.%s" m i else i let rec print_typ (mname:string) (t:typ) : ML string = //(decreases t) = if is_output_type t then print_output_type true t else match t with | T_false -> "False" | T_app hd _ args -> //output types are already handled at the beginning of print_typ Printf.sprintf "(%s %s)" (print_maybe_qualified_ident mname hd) (String.concat " " (print_indexes mname args)) | T_dep_pair t1 (x, t2) -> Printf.sprintf "(%s:%s & %s)" (print_ident x) (print_typ mname t1) (print_typ mname t2) | T_refine t e -> Printf.sprintf "(refine %s %s)" (print_typ mname t) (print_expr_lam mname e) | T_if_else e t1 t2 -> Printf.sprintf "(t_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname e) (print_typ mname t1) (print_typ mname t2) | T_pointer t -> Printf.sprintf "bpointer (%s)" (print_typ mname t) | T_with_action t _ | T_with_dep_action t _ | T_with_comment t _ -> print_typ mname t | T_with_probe t _ _ _ -> Printf.sprintf "bpointer (%s)" (print_typ mname t) and print_indexes (mname:string) (is:list index) : ML (list string) = //(decreases is) = match is with | [] -> [] | Inl t::is -> print_typ mname t::print_indexes mname is | Inr e::is -> print_expr mname e::print_indexes mname is let rec print_kind (mname:string) (k:parser_kind) : Tot string = match k.pk_kind with | PK_base hd -> Printf.sprintf "%skind_%s" (maybe_mname_prefix mname hd) (print_ident hd) | PK_list -> "kind_nlist" | PK_t_at_most -> "kind_t_at_most" | PK_t_exact -> "kind_t_exact" | PK_return -> "ret_kind" | PK_impos -> "impos_kind" | PK_and_then k1 k2 -> Printf.sprintf "(and_then_kind %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_glb k1 k2 -> Printf.sprintf "(glb %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_filter k -> Printf.sprintf "(filter_kind %s)" (print_kind mname k) | PK_string -> "parse_string_kind" let rec print_action (mname:string) (a:action) : ML string = let print_atomic_action (a:atomic_action) : ML string = match a with | Action_return e -> Printf.sprintf "(action_return %s)" (print_expr mname e) | Action_abort -> "(action_abort())" | Action_field_pos_64 -> "(action_field_pos_64())" | Action_field_pos_32 -> "(action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr -> "(action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr_after sz write_to -> Printf.sprintf "(action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)" (print_expr mname sz) (print_ident write_to) | Action_field_ptr_after_with_setter sz write_to_field write_to_obj -> Printf.sprintf "(action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))" (print_expr mname sz) (print_ident write_to_field) (print_expr mname write_to_obj) | Action_deref i -> Printf.sprintf "(action_deref %s)" (print_ident i) | Action_assignment lhs rhs -> Printf.sprintf "(action_assignment %s %s)" (print_ident lhs) (print_expr mname rhs) | Action_call f args -> Printf.sprintf "(mk_extern_action (%s %s))" (print_ident f) (String.concat " " (List.map (print_expr mname) args)) in match a with | Atomic_action a -> print_atomic_action a | Action_seq hd tl -> Printf.sprintf "(action_seq %s %s)" (print_atomic_action hd) (print_action mname tl) | Action_ite hd then_ else_ -> Printf.sprintf "(action_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname hd) (print_action mname then_) (print_action mname else_) | Action_let i a k -> Printf.sprintf "(action_bind \"%s\" %s (fun %s -> %s))" (print_ident i) (print_atomic_action a) (print_ident i) (print_action mname k) | Action_act a -> Printf.sprintf "(action_act %s)" (print_action mname a) let print_typedef_name (mname:string) (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> Printf.sprintf "(%s:%s)" (print_ident id) (print_typ mname t)) tdn.td_params)) let print_typedef_typ (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> (print_ident id)) tdn.td_params)) let print_typedef_body (mname:string) (b:typedef_body) : ML string = match b with | TD_abbrev t -> print_typ mname t | TD_struct fields -> let print_field (sf:field) : ML string = Printf.sprintf "%s : %s%s" (print_ident sf.sf_ident) (print_typ mname sf.sf_typ) (if sf.sf_dependence then " (*dep*)" else "") in let fields = String.concat ";\n" (List.map print_field fields) in Printf.sprintf "{\n%s\n}" fields let print_typedef_actions_inv_and_fp (td:type_decl) = //we need to add output loc to the modifies locs //if there is an output type type parameter let should_add_output_loc = List.Tot.existsb (fun (_, t) -> is_output_type t || is_extern_type t) td.decl_name.td_params in let pointers = //get only non output type pointers List.Tot.filter (fun (x, t) -> T_pointer? t && not (is_output_type t || is_extern_type t)) td.decl_name.td_params in let inv = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "((ptr_inv %s) `conj_inv` %s)" (print_ident x) out) pointers "true_inv" in let fp = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "(eloc_union (ptr_loc %s) %s)" (print_ident x) out) pointers (if should_add_output_loc then "output_loc" else "eloc_none") in inv, fp let print_comments (cs:list string) : string = match cs with | [] -> "" | _ -> let c = String.concat "\\n\\\n" cs in Printf.sprintf " (Comment \"%s\")" c let print_attributes (entrypoint:bool) (attrs:decl_attributes) : string = match attrs.comments with | [] -> if entrypoint || attrs.is_exported then "" else if attrs.should_inline then "inline_for_extraction noextract\n" else "[@ (CInline)]\n" | cs -> Printf.sprintf "[@ %s %s]\n%s" (print_comments cs) (if not entrypoint && not attrs.is_exported && not attrs.should_inline then "(CInline)" else "") (if attrs.should_inline then "inline_for_extraction\n" else "") /// Printing a decl for M.Types.fst /// /// Print all the definitions, and for a Type_decl, only the type definition let maybe_print_type_equality (mname:string) (td:type_decl) : ML string = if td.decl_name.td_entrypoint then let equate_types_list = Options.get_equate_types_list () in (match (List.tryFind (fun (_, m) -> m = mname) equate_types_list) with | Some (a, _) -> let typname = A.ident_name td.decl_name.td_name in Printf.sprintf "\n\nlet _ = assert (%s.Types.%s == %s) by (FStar.Tactics.trefl ())\n\n" a typname typname | None -> "") else "" let print_definition (mname:string) (d:decl { Definition? (fst d)} ) : ML string = match fst d with | Definition (x, [], T_app ({Ast.v={Ast.name="field_id"}}) _ _, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot field_id by (FStar.Tactics.trivial())\n\n" (print_comments (snd d).comments) (print_field_id_name x) (A.print_constant c) | Definition (x, [], t, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot %s\n\n" (print_comments (snd d).comments) (print_ident x) (A.print_constant c) (print_typ mname t) | Definition (x, params, typ, expr) -> let x_ps = { td_name = x; td_params = params; td_entrypoint = false } in Printf.sprintf "%slet %s : %s = %s\n\n" (print_attributes false (snd d)) (print_typedef_name mname x_ps) (print_typ mname typ) (print_expr mname expr) let print_assumption (mname:string) (d:decl { Assumption? (fst d) } ) : ML string = match fst d with | Assumption (x, t) -> Printf.sprintf "%sassume\nval %s : %s\n\n" (if (snd d).is_if_def then "[@@ CIfDef ]\n" else "") (print_ident x) (print_typ mname t) let print_decl_for_types (mname:string) (d:decl) : ML string = match fst d with | Assumption _ -> "" | Definition _ -> print_definition mname d | Type_decl td -> Printf.sprintf "noextract\ninline_for_extraction\ntype %s = %s\n\n" (print_typedef_name mname td.decl_name) (print_typedef_body mname td.decl_typ) `strcat` maybe_print_type_equality mname td | Output_type _ | Output_type_expr _ _ | Extern_type _ | Extern_fn _ _ _ | Extern_probe _ -> "" /// Print a decl for M.fst /// /// No need to print Definition(s), they are `include`d from M.Types.fst /// /// For a Type_decl, if it is an entry point, we need to emit a definition since /// there is a corresponding declaration in the .fsti /// We make the definition as simply the definition in M.Types.fst let is_type_abbreviation (td:type_decl) : bool = match td.decl_typ with | TD_abbrev _ -> true | TD_struct _ -> false let external_api_include (modul:string) (ds:list decl) : string = if has_external_api ds then Printf.sprintf "open %s.ExternalAPI\n\n" modul else "" #push-options "--z3rlimit_factor 4" let pascal_case name : ML string = let chars = String.list_of_string name in let has_underscore = List.mem '_' chars in let keep, up, low = 0, 1, 2 in if has_underscore then let what_next : ref int = alloc up in let rewrite_char c : ML (list FStar.Char.char) = match c with | '_' -> what_next := up; [] | c -> let c_next = let n = !what_next in if n = keep then c else if n = up then FStar.Char.uppercase c else FStar.Char.lowercase c in let _ = if Char.uppercase c = c then what_next := low else if Char.lowercase c = c then what_next := keep in [c_next] in let chars = List.collect rewrite_char (String.list_of_string name) in String.string_of_list chars else if String.length name = 0 then name else String.uppercase (String.sub name 0 1) ^ String.sub name 1 (String.length name - 1) let uppercase (name:string) : string = String.uppercase name let rec print_as_c_type (t:typ) : ML string = let open Ast in match t with | T_pointer t -> Printf.sprintf "%s*" (print_as_c_type t) | T_app {v={name="Bool"}} _ [] -> "BOOLEAN" | T_app {v={name="UINT8"}} _ [] -> "uint8_t" | T_app {v={name="UINT16"}} _ [] -> "uint16_t" | T_app {v={name="UINT32"}} _ [] -> "uint32_t" | T_app {v={name="UINT64"}} _ [] -> "uint64_t" | T_app {v={name="PUINT8"}} _ [] -> "uint8_t*" | T_app {v={name=x}} KindSpec [] -> x | T_app {v={name=x}} _ [] -> uppercase x | _ -> "__UNKNOWN__" let error_code_macros = //To be kept consistent with EverParse3d.ErrorCode.error_reason_of_result "#define EVERPARSE_ERROR_GENERIC 1uL\n\ #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL\n\ #define EVERPARSE_ERROR_IMPOSSIBLE 3uL\n\ #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL\n\ #define EVERPARSE_ERROR_ACTION_FAILED 5uL\n\ #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL\n\ #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL\n" let rec get_output_typ_dep (modul:string) (t:typ) : ML (option string) = match t with | T_app {v={modul_name=None}} _ _ -> None | T_app {v={modul_name=Some m}} _ _ -> if m = modul then None else Some m | T_pointer t -> get_output_typ_dep modul t | _ -> failwith "get_typ_deps: unexpected output type" let wrapper_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_check_%s" modul fn |> pascal_case let validator_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_validate_%s" modul fn |> pascal_case let print_c_entry (produce_everparse_error: opt_produce_everparse_error) (modul: string) (env: global_env) (ds:list decl) : ML (string & string) = let default_error_handler = "static\n\ void DefaultErrorHandler(\n\t\ const char *typename_s,\n\t\ const char *fieldname,\n\t\ const char *reason,\n\t\ uint64_t error_code,\n\t\ uint8_t *context,\n\t\ EVERPARSE_INPUT_BUFFER input,\n\t\ uint64_t start_pos)\n\ {\n\t\ EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context;\n\t\ EverParseDefaultErrorHandler(\n\t\t\ typename_s,\n\t\t\ fieldname,\n\t\t\ reason,\n\t\t\ error_code,\n\t\t\ frame,\n\t\t\ input,\n\t\t\ start_pos\n\t\ );\n\ }" in let input_stream_binding = Options.get_input_stream_binding () in let is_input_stream_buffer = HashingOptions.InputStreamBuffer? input_stream_binding in let wrapped_call_buffer name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame;\n\t\ frame.filled = FALSE;\n\t\ %s\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0);\n\t\ if (EverParseIsError(result))\n\t\ {\n\t\t\ if (frame.filled)\n\t\t\ {\n\t\t\t\ %sEverParseError(frame.typename_s, frame.fieldname, frame.reason);\n\t\t\ }\n\t\t\ return FALSE;\n\t\ }\n\t\ return TRUE;" (if is_input_stream_buffer then "" else "EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t") name params modul in let wrapped_call_stream name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame =\n\t\ { .filled = FALSE,\n\t\ .typename_s = \"UNKNOWN\",\n\t\ .fieldname = \"UNKNOWN\",\n\t\ .reason = \"UNKNOWN\",\n\t\ .error_code = 0uL\n\ };\n\ EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, input, 0);\n\t\ uint64_t parsedSize = EverParseGetValidatorErrorPos(result);\n\ if (EverParseIsError(result))\n\t\ {\n\t\t\ EverParseHandleError(_extra, parsedSize, frame.typename_s, frame.fieldname, frame.reason, frame.error_code);\n\t\t\ }\n\t\ EverParseRetreat(_extra, base, parsedSize);\n\ return parsedSize;" name params in let mk_param (name: string) (typ: string) : Tot param = (A.with_range (A.to_ident' name) A.dummy_range, T_app (A.with_range (A.to_ident' typ) A.dummy_range) A.KindSpec []) in let print_one_validator (d:type_decl) : ML (string & string) = let params = d.decl_name.td_params @ (if is_input_stream_buffer then [] else [mk_param "_extra" "EVERPARSE_EXTRA_T"]) in let print_params (ps:list param) : ML string = let params = String.concat ", " (List.map (fun (id, t) -> Printf.sprintf "%s %s" (print_as_c_type t) (print_ident id)) ps) in match ps with | [] -> params | _ -> params ^ ", " in let print_arguments (ps:list param) : Tot string = let params = String.concat ", " (List.Tot.map (fun (id, t) -> if is_output_type t //output type pointers are uint8_t* in the F* generated code then (print_ident id) else print_ident id) ps) in match ps with | [] -> params | _ -> params ^ ", " in let wrapper_name = wrapper_name modul d.decl_name.td_name.A.v.A.name in let signature = if is_input_stream_buffer then Printf.sprintf "BOOLEAN %s(%suint8_t *base, uint32_t len)" wrapper_name (print_params params) else Printf.sprintf "uint64_t %s(%sEVERPARSE_INPUT_STREAM_BASE base)" wrapper_name (print_params params) in let validator_name = validator_name modul d.decl_name.td_name.A.v.A.name in let impl = let body = if is_input_stream_buffer then wrapped_call_buffer validator_name (print_arguments params) else wrapped_call_stream validator_name (print_arguments params) in Printf.sprintf "%s {\n\t%s\n}" signature body in signature ^";", impl in let signatures_output_typ_deps = List.fold_left (fun deps (d, _) -> match d with | Type_decl d -> if d.decl_name.td_entrypoint then let params = d.decl_name.td_params in List.fold_left (fun deps (_, t) -> match get_output_typ_dep modul t with | Some dep -> if List.mem dep deps then deps else deps@[dep] | _ -> deps) deps params else deps | _ -> deps) [] ds in let signatures, impls = List.split (List.collect (fun d -> match fst d with | Type_decl d -> if d.decl_name.td_entrypoint then [print_one_validator d] else [] | _ -> []) ds) in let external_defs_includes = if not (Options.get_emit_output_types_defs ()) then "" else let deps = if List.length signatures_output_typ_deps = 0 then "" else String.concat "" (List.map (fun dep -> Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" dep) signatures_output_typ_deps) in let self = if has_output_types ds || has_extern_types ds then Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n" modul else "" in Printf.sprintf "%s\n%s\n\n" deps self in let header = Printf.sprintf "#include \"EverParseEndianness.h\"\n\ %s\n\ %s\ #ifdef __cplusplus\n\ extern \"C\" {\n\ #endif\n\ %s\n\ #ifdef __cplusplus\n\ }\n\ #endif\n" error_code_macros external_defs_includes (signatures |> String.concat "\n\n") in let input_stream_include = HashingOptions.input_stream_include input_stream_binding in let header = if input_stream_include = "" then header else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include header in let add_includes = Options.make_includes () in let header = Printf.sprintf "%s%s" add_includes header in let error_callback_proto = if HashingOptions.InputStreamBuffer? input_stream_binding then Printf.sprintf "void %sEverParseError(const char *StructName, const char *FieldName, const char *Reason)%s" modul (if produce_everparse_error = Some ProduceEverParseError then "{(void) StructName; (void) FieldName; (void) Reason;}" else ";") else "" in let impl = Printf.sprintf "#include \"%sWrapper.h\"\n\ #include \"EverParse.h\"\n\ #include \"%s.h\"\n\ %s\n\n\ %s\n\n\ %s\n" modul modul error_callback_proto default_error_handler (impls |> String.concat "\n\n") in let impl = if input_stream_include = "" then impl else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include impl in let impl = Printf.sprintf "%s%s" add_includes impl in header, impl /// Functions for printing setters and getters for output expressions let rec out_bt_name (t:typ) : ML string = match t with | T_app i _ _ -> A.ident_name i | T_pointer t -> out_bt_name t | _ -> failwith "Impossible, out_bt_name received a non output type!" let out_expr_bt_name (oe:output_expr) : ML string = out_bt_name oe.oe_bt (* * Walks over the output expressions AST and constructs a string *) let rec out_fn_name (oe:output_expr) : ML string = match oe.oe_expr with | T_OE_id _ -> out_expr_bt_name oe | T_OE_star oe -> Printf.sprintf "%s_star" (out_fn_name oe) | T_OE_addrof oe -> Printf.sprintf "%s_addrof" (out_fn_name oe) | T_OE_deref oe f -> Printf.sprintf "%s_deref_%s" (out_fn_name oe) (A.ident_name f) | T_OE_dot oe f -> Printf.sprintf "%s_dot_%s" (out_fn_name oe) (A.ident_name f) module H = Hashtable type set = H.t string unit (* * In the printing functions, a hashtable tracks that we print a defn. only once * * E.g. multiple output expressions may require a val decl. for types, * we need to print them only once each *) let rec base_output_type (t:typ) : ML A.ident = match t with | T_app id A.KindOutput [] -> id | T_pointer t -> base_output_type t | _ -> failwith "Target.base_output_type called with a non-output type" #push-options "--fuel 1" let rec print_output_type_val (tbl:set) (t:typ) : ML string = let open A in if is_output_type t then let s = print_output_type false t in if H.try_find tbl s <> None then "" else let _ = H.insert tbl s () in assert (is_output_type t); match t with | T_app id KindOutput [] -> Printf.sprintf "\n\nval %s : Type0\n\n" s | T_pointer bt -> let bs = print_output_type_val tbl bt in bs ^ (Printf.sprintf "\n\ninline_for_extraction noextract type %s = bpointer %s\n\n" s (print_output_type false bt)) else "" #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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": 4, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
oe: Target.output_expr' -> FStar.All.ML Prims.string
FStar.All.ML
[ "ml" ]
[]
[ "Target.output_expr'", "Ast.ident", "Ast.ident_to_string", "Prims.string", "Target.output_expr", "FStar.Printf.sprintf", "Target.print_out_expr'", "Target.__proj__Mkoutput_expr__item__oe_expr" ]
[ "recursion" ]
false
true
false
false
false
let rec print_out_expr' (oe: output_expr') : ML string =
match oe with | T_OE_id id -> A.ident_to_string id | T_OE_star o -> Printf.sprintf "*(%s)" (print_out_expr' o.oe_expr) | T_OE_addrof o -> Printf.sprintf "&(%s)" (print_out_expr' o.oe_expr) | T_OE_deref o i -> Printf.sprintf "(%s)->%s" (print_out_expr' o.oe_expr) (A.ident_to_string i) | T_OE_dot o i -> Printf.sprintf "(%s).%s" (print_out_expr' o.oe_expr) (A.ident_to_string i)
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.fadd
val fadd (#w: lanes) (x y: elem w) : elem w
val fadd (#w: lanes) (x y: elem w) : elem w
let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 38, "start_col": 0, "start_line": 37 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Hacl.Spec.Poly1305.Vec.elem w -> y: Hacl.Spec.Poly1305.Vec.elem w -> Hacl.Spec.Poly1305.Vec.elem w
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Hacl.Spec.Poly1305.Vec.elem", "Lib.Sequence.map2", "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.pfadd" ]
[]
false
false
false
false
false
let fadd (#w: lanes) (x y: elem w) : elem w =
map2 pfadd x y
false
Target.fst
Target.print_exprs
val print_exprs (mname: string) (es: list expr) : ML (list string)
val print_exprs (mname: string) (es: list expr) : ML (list string)
let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 28, "end_line": 353, "start_col": 0, "start_line": 307 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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 -> es: Prims.list Target.expr -> FStar.All.ML (Prims.list Prims.string)
FStar.All.ML
[ "ml" ]
[ "print_expr", "print_exprs", "print_fields" ]
[ "Prims.string", "Prims.list", "Target.expr", "Prims.Nil", "Prims.Cons", "Target.print_exprs", "Target.print_expr" ]
[ "mutual recursion" ]
false
true
false
false
false
let rec print_exprs (mname: string) (es: list expr) : ML (list string) =
match es with | [] -> [] | hd :: tl -> print_expr mname hd :: print_exprs mname tl
false
Target.fst
Target.out_fn_name
val out_fn_name (oe: output_expr) : ML string
val out_fn_name (oe: output_expr) : ML string
let rec out_fn_name (oe:output_expr) : ML string = match oe.oe_expr with | T_OE_id _ -> out_expr_bt_name oe | T_OE_star oe -> Printf.sprintf "%s_star" (out_fn_name oe) | T_OE_addrof oe -> Printf.sprintf "%s_addrof" (out_fn_name oe) | T_OE_deref oe f -> Printf.sprintf "%s_deref_%s" (out_fn_name oe) (A.ident_name f) | T_OE_dot oe f -> Printf.sprintf "%s_dot_%s" (out_fn_name oe) (A.ident_name f)
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 81, "end_line": 1050, "start_col": 0, "start_line": 1044 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl let print_lam (#a:Type) (f:a -> ML string) (x:lam a) : ML string = match x with | Some x, y -> Printf.sprintf ("(fun %s -> %s)") (print_ident x) (f y) | None, y -> f y let print_expr_lam (mname:string) (x:lam expr) : ML string = print_lam (print_expr mname) x let rec is_output_type (t:typ) : bool = match t with | T_app _ A.KindOutput [] -> true | T_pointer t -> is_output_type t | _ -> false let rec is_extern_type (t:typ) : bool = match t with | T_app _ A.KindExtern [] -> true | T_pointer t -> is_extern_type t | _ -> false (* * An output type is printed as the ident, or p_<ident> * * They are abstract types in the emitted F* code *) let print_output_type (qual:bool) (t:typ) : ML string = let rec aux (t:typ) : ML (option string & string) = match t with | T_app id _ _ -> id.v.modul_name, print_ident id | T_pointer t -> let m, i = aux t in m, Printf.sprintf "p_%s" i | _ -> failwith "Print: not an output type" in let mopt, i = aux t in if qual then match mopt with | None -> i | Some m -> Printf.sprintf "%s.ExternalTypes.%s" m i else i let rec print_typ (mname:string) (t:typ) : ML string = //(decreases t) = if is_output_type t then print_output_type true t else match t with | T_false -> "False" | T_app hd _ args -> //output types are already handled at the beginning of print_typ Printf.sprintf "(%s %s)" (print_maybe_qualified_ident mname hd) (String.concat " " (print_indexes mname args)) | T_dep_pair t1 (x, t2) -> Printf.sprintf "(%s:%s & %s)" (print_ident x) (print_typ mname t1) (print_typ mname t2) | T_refine t e -> Printf.sprintf "(refine %s %s)" (print_typ mname t) (print_expr_lam mname e) | T_if_else e t1 t2 -> Printf.sprintf "(t_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname e) (print_typ mname t1) (print_typ mname t2) | T_pointer t -> Printf.sprintf "bpointer (%s)" (print_typ mname t) | T_with_action t _ | T_with_dep_action t _ | T_with_comment t _ -> print_typ mname t | T_with_probe t _ _ _ -> Printf.sprintf "bpointer (%s)" (print_typ mname t) and print_indexes (mname:string) (is:list index) : ML (list string) = //(decreases is) = match is with | [] -> [] | Inl t::is -> print_typ mname t::print_indexes mname is | Inr e::is -> print_expr mname e::print_indexes mname is let rec print_kind (mname:string) (k:parser_kind) : Tot string = match k.pk_kind with | PK_base hd -> Printf.sprintf "%skind_%s" (maybe_mname_prefix mname hd) (print_ident hd) | PK_list -> "kind_nlist" | PK_t_at_most -> "kind_t_at_most" | PK_t_exact -> "kind_t_exact" | PK_return -> "ret_kind" | PK_impos -> "impos_kind" | PK_and_then k1 k2 -> Printf.sprintf "(and_then_kind %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_glb k1 k2 -> Printf.sprintf "(glb %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_filter k -> Printf.sprintf "(filter_kind %s)" (print_kind mname k) | PK_string -> "parse_string_kind" let rec print_action (mname:string) (a:action) : ML string = let print_atomic_action (a:atomic_action) : ML string = match a with | Action_return e -> Printf.sprintf "(action_return %s)" (print_expr mname e) | Action_abort -> "(action_abort())" | Action_field_pos_64 -> "(action_field_pos_64())" | Action_field_pos_32 -> "(action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr -> "(action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr_after sz write_to -> Printf.sprintf "(action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)" (print_expr mname sz) (print_ident write_to) | Action_field_ptr_after_with_setter sz write_to_field write_to_obj -> Printf.sprintf "(action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))" (print_expr mname sz) (print_ident write_to_field) (print_expr mname write_to_obj) | Action_deref i -> Printf.sprintf "(action_deref %s)" (print_ident i) | Action_assignment lhs rhs -> Printf.sprintf "(action_assignment %s %s)" (print_ident lhs) (print_expr mname rhs) | Action_call f args -> Printf.sprintf "(mk_extern_action (%s %s))" (print_ident f) (String.concat " " (List.map (print_expr mname) args)) in match a with | Atomic_action a -> print_atomic_action a | Action_seq hd tl -> Printf.sprintf "(action_seq %s %s)" (print_atomic_action hd) (print_action mname tl) | Action_ite hd then_ else_ -> Printf.sprintf "(action_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname hd) (print_action mname then_) (print_action mname else_) | Action_let i a k -> Printf.sprintf "(action_bind \"%s\" %s (fun %s -> %s))" (print_ident i) (print_atomic_action a) (print_ident i) (print_action mname k) | Action_act a -> Printf.sprintf "(action_act %s)" (print_action mname a) let print_typedef_name (mname:string) (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> Printf.sprintf "(%s:%s)" (print_ident id) (print_typ mname t)) tdn.td_params)) let print_typedef_typ (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> (print_ident id)) tdn.td_params)) let print_typedef_body (mname:string) (b:typedef_body) : ML string = match b with | TD_abbrev t -> print_typ mname t | TD_struct fields -> let print_field (sf:field) : ML string = Printf.sprintf "%s : %s%s" (print_ident sf.sf_ident) (print_typ mname sf.sf_typ) (if sf.sf_dependence then " (*dep*)" else "") in let fields = String.concat ";\n" (List.map print_field fields) in Printf.sprintf "{\n%s\n}" fields let print_typedef_actions_inv_and_fp (td:type_decl) = //we need to add output loc to the modifies locs //if there is an output type type parameter let should_add_output_loc = List.Tot.existsb (fun (_, t) -> is_output_type t || is_extern_type t) td.decl_name.td_params in let pointers = //get only non output type pointers List.Tot.filter (fun (x, t) -> T_pointer? t && not (is_output_type t || is_extern_type t)) td.decl_name.td_params in let inv = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "((ptr_inv %s) `conj_inv` %s)" (print_ident x) out) pointers "true_inv" in let fp = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "(eloc_union (ptr_loc %s) %s)" (print_ident x) out) pointers (if should_add_output_loc then "output_loc" else "eloc_none") in inv, fp let print_comments (cs:list string) : string = match cs with | [] -> "" | _ -> let c = String.concat "\\n\\\n" cs in Printf.sprintf " (Comment \"%s\")" c let print_attributes (entrypoint:bool) (attrs:decl_attributes) : string = match attrs.comments with | [] -> if entrypoint || attrs.is_exported then "" else if attrs.should_inline then "inline_for_extraction noextract\n" else "[@ (CInline)]\n" | cs -> Printf.sprintf "[@ %s %s]\n%s" (print_comments cs) (if not entrypoint && not attrs.is_exported && not attrs.should_inline then "(CInline)" else "") (if attrs.should_inline then "inline_for_extraction\n" else "") /// Printing a decl for M.Types.fst /// /// Print all the definitions, and for a Type_decl, only the type definition let maybe_print_type_equality (mname:string) (td:type_decl) : ML string = if td.decl_name.td_entrypoint then let equate_types_list = Options.get_equate_types_list () in (match (List.tryFind (fun (_, m) -> m = mname) equate_types_list) with | Some (a, _) -> let typname = A.ident_name td.decl_name.td_name in Printf.sprintf "\n\nlet _ = assert (%s.Types.%s == %s) by (FStar.Tactics.trefl ())\n\n" a typname typname | None -> "") else "" let print_definition (mname:string) (d:decl { Definition? (fst d)} ) : ML string = match fst d with | Definition (x, [], T_app ({Ast.v={Ast.name="field_id"}}) _ _, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot field_id by (FStar.Tactics.trivial())\n\n" (print_comments (snd d).comments) (print_field_id_name x) (A.print_constant c) | Definition (x, [], t, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot %s\n\n" (print_comments (snd d).comments) (print_ident x) (A.print_constant c) (print_typ mname t) | Definition (x, params, typ, expr) -> let x_ps = { td_name = x; td_params = params; td_entrypoint = false } in Printf.sprintf "%slet %s : %s = %s\n\n" (print_attributes false (snd d)) (print_typedef_name mname x_ps) (print_typ mname typ) (print_expr mname expr) let print_assumption (mname:string) (d:decl { Assumption? (fst d) } ) : ML string = match fst d with | Assumption (x, t) -> Printf.sprintf "%sassume\nval %s : %s\n\n" (if (snd d).is_if_def then "[@@ CIfDef ]\n" else "") (print_ident x) (print_typ mname t) let print_decl_for_types (mname:string) (d:decl) : ML string = match fst d with | Assumption _ -> "" | Definition _ -> print_definition mname d | Type_decl td -> Printf.sprintf "noextract\ninline_for_extraction\ntype %s = %s\n\n" (print_typedef_name mname td.decl_name) (print_typedef_body mname td.decl_typ) `strcat` maybe_print_type_equality mname td | Output_type _ | Output_type_expr _ _ | Extern_type _ | Extern_fn _ _ _ | Extern_probe _ -> "" /// Print a decl for M.fst /// /// No need to print Definition(s), they are `include`d from M.Types.fst /// /// For a Type_decl, if it is an entry point, we need to emit a definition since /// there is a corresponding declaration in the .fsti /// We make the definition as simply the definition in M.Types.fst let is_type_abbreviation (td:type_decl) : bool = match td.decl_typ with | TD_abbrev _ -> true | TD_struct _ -> false let external_api_include (modul:string) (ds:list decl) : string = if has_external_api ds then Printf.sprintf "open %s.ExternalAPI\n\n" modul else "" #push-options "--z3rlimit_factor 4" let pascal_case name : ML string = let chars = String.list_of_string name in let has_underscore = List.mem '_' chars in let keep, up, low = 0, 1, 2 in if has_underscore then let what_next : ref int = alloc up in let rewrite_char c : ML (list FStar.Char.char) = match c with | '_' -> what_next := up; [] | c -> let c_next = let n = !what_next in if n = keep then c else if n = up then FStar.Char.uppercase c else FStar.Char.lowercase c in let _ = if Char.uppercase c = c then what_next := low else if Char.lowercase c = c then what_next := keep in [c_next] in let chars = List.collect rewrite_char (String.list_of_string name) in String.string_of_list chars else if String.length name = 0 then name else String.uppercase (String.sub name 0 1) ^ String.sub name 1 (String.length name - 1) let uppercase (name:string) : string = String.uppercase name let rec print_as_c_type (t:typ) : ML string = let open Ast in match t with | T_pointer t -> Printf.sprintf "%s*" (print_as_c_type t) | T_app {v={name="Bool"}} _ [] -> "BOOLEAN" | T_app {v={name="UINT8"}} _ [] -> "uint8_t" | T_app {v={name="UINT16"}} _ [] -> "uint16_t" | T_app {v={name="UINT32"}} _ [] -> "uint32_t" | T_app {v={name="UINT64"}} _ [] -> "uint64_t" | T_app {v={name="PUINT8"}} _ [] -> "uint8_t*" | T_app {v={name=x}} KindSpec [] -> x | T_app {v={name=x}} _ [] -> uppercase x | _ -> "__UNKNOWN__" let error_code_macros = //To be kept consistent with EverParse3d.ErrorCode.error_reason_of_result "#define EVERPARSE_ERROR_GENERIC 1uL\n\ #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL\n\ #define EVERPARSE_ERROR_IMPOSSIBLE 3uL\n\ #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL\n\ #define EVERPARSE_ERROR_ACTION_FAILED 5uL\n\ #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL\n\ #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL\n" let rec get_output_typ_dep (modul:string) (t:typ) : ML (option string) = match t with | T_app {v={modul_name=None}} _ _ -> None | T_app {v={modul_name=Some m}} _ _ -> if m = modul then None else Some m | T_pointer t -> get_output_typ_dep modul t | _ -> failwith "get_typ_deps: unexpected output type" let wrapper_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_check_%s" modul fn |> pascal_case let validator_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_validate_%s" modul fn |> pascal_case let print_c_entry (produce_everparse_error: opt_produce_everparse_error) (modul: string) (env: global_env) (ds:list decl) : ML (string & string) = let default_error_handler = "static\n\ void DefaultErrorHandler(\n\t\ const char *typename_s,\n\t\ const char *fieldname,\n\t\ const char *reason,\n\t\ uint64_t error_code,\n\t\ uint8_t *context,\n\t\ EVERPARSE_INPUT_BUFFER input,\n\t\ uint64_t start_pos)\n\ {\n\t\ EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context;\n\t\ EverParseDefaultErrorHandler(\n\t\t\ typename_s,\n\t\t\ fieldname,\n\t\t\ reason,\n\t\t\ error_code,\n\t\t\ frame,\n\t\t\ input,\n\t\t\ start_pos\n\t\ );\n\ }" in let input_stream_binding = Options.get_input_stream_binding () in let is_input_stream_buffer = HashingOptions.InputStreamBuffer? input_stream_binding in let wrapped_call_buffer name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame;\n\t\ frame.filled = FALSE;\n\t\ %s\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0);\n\t\ if (EverParseIsError(result))\n\t\ {\n\t\t\ if (frame.filled)\n\t\t\ {\n\t\t\t\ %sEverParseError(frame.typename_s, frame.fieldname, frame.reason);\n\t\t\ }\n\t\t\ return FALSE;\n\t\ }\n\t\ return TRUE;" (if is_input_stream_buffer then "" else "EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t") name params modul in let wrapped_call_stream name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame =\n\t\ { .filled = FALSE,\n\t\ .typename_s = \"UNKNOWN\",\n\t\ .fieldname = \"UNKNOWN\",\n\t\ .reason = \"UNKNOWN\",\n\t\ .error_code = 0uL\n\ };\n\ EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, input, 0);\n\t\ uint64_t parsedSize = EverParseGetValidatorErrorPos(result);\n\ if (EverParseIsError(result))\n\t\ {\n\t\t\ EverParseHandleError(_extra, parsedSize, frame.typename_s, frame.fieldname, frame.reason, frame.error_code);\n\t\t\ }\n\t\ EverParseRetreat(_extra, base, parsedSize);\n\ return parsedSize;" name params in let mk_param (name: string) (typ: string) : Tot param = (A.with_range (A.to_ident' name) A.dummy_range, T_app (A.with_range (A.to_ident' typ) A.dummy_range) A.KindSpec []) in let print_one_validator (d:type_decl) : ML (string & string) = let params = d.decl_name.td_params @ (if is_input_stream_buffer then [] else [mk_param "_extra" "EVERPARSE_EXTRA_T"]) in let print_params (ps:list param) : ML string = let params = String.concat ", " (List.map (fun (id, t) -> Printf.sprintf "%s %s" (print_as_c_type t) (print_ident id)) ps) in match ps with | [] -> params | _ -> params ^ ", " in let print_arguments (ps:list param) : Tot string = let params = String.concat ", " (List.Tot.map (fun (id, t) -> if is_output_type t //output type pointers are uint8_t* in the F* generated code then (print_ident id) else print_ident id) ps) in match ps with | [] -> params | _ -> params ^ ", " in let wrapper_name = wrapper_name modul d.decl_name.td_name.A.v.A.name in let signature = if is_input_stream_buffer then Printf.sprintf "BOOLEAN %s(%suint8_t *base, uint32_t len)" wrapper_name (print_params params) else Printf.sprintf "uint64_t %s(%sEVERPARSE_INPUT_STREAM_BASE base)" wrapper_name (print_params params) in let validator_name = validator_name modul d.decl_name.td_name.A.v.A.name in let impl = let body = if is_input_stream_buffer then wrapped_call_buffer validator_name (print_arguments params) else wrapped_call_stream validator_name (print_arguments params) in Printf.sprintf "%s {\n\t%s\n}" signature body in signature ^";", impl in let signatures_output_typ_deps = List.fold_left (fun deps (d, _) -> match d with | Type_decl d -> if d.decl_name.td_entrypoint then let params = d.decl_name.td_params in List.fold_left (fun deps (_, t) -> match get_output_typ_dep modul t with | Some dep -> if List.mem dep deps then deps else deps@[dep] | _ -> deps) deps params else deps | _ -> deps) [] ds in let signatures, impls = List.split (List.collect (fun d -> match fst d with | Type_decl d -> if d.decl_name.td_entrypoint then [print_one_validator d] else [] | _ -> []) ds) in let external_defs_includes = if not (Options.get_emit_output_types_defs ()) then "" else let deps = if List.length signatures_output_typ_deps = 0 then "" else String.concat "" (List.map (fun dep -> Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" dep) signatures_output_typ_deps) in let self = if has_output_types ds || has_extern_types ds then Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n" modul else "" in Printf.sprintf "%s\n%s\n\n" deps self in let header = Printf.sprintf "#include \"EverParseEndianness.h\"\n\ %s\n\ %s\ #ifdef __cplusplus\n\ extern \"C\" {\n\ #endif\n\ %s\n\ #ifdef __cplusplus\n\ }\n\ #endif\n" error_code_macros external_defs_includes (signatures |> String.concat "\n\n") in let input_stream_include = HashingOptions.input_stream_include input_stream_binding in let header = if input_stream_include = "" then header else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include header in let add_includes = Options.make_includes () in let header = Printf.sprintf "%s%s" add_includes header in let error_callback_proto = if HashingOptions.InputStreamBuffer? input_stream_binding then Printf.sprintf "void %sEverParseError(const char *StructName, const char *FieldName, const char *Reason)%s" modul (if produce_everparse_error = Some ProduceEverParseError then "{(void) StructName; (void) FieldName; (void) Reason;}" else ";") else "" in let impl = Printf.sprintf "#include \"%sWrapper.h\"\n\ #include \"EverParse.h\"\n\ #include \"%s.h\"\n\ %s\n\n\ %s\n\n\ %s\n" modul modul error_callback_proto default_error_handler (impls |> String.concat "\n\n") in let impl = if input_stream_include = "" then impl else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include impl in let impl = Printf.sprintf "%s%s" add_includes impl in header, impl /// Functions for printing setters and getters for output expressions let rec out_bt_name (t:typ) : ML string = match t with | T_app i _ _ -> A.ident_name i | T_pointer t -> out_bt_name t | _ -> failwith "Impossible, out_bt_name received a non output type!" let out_expr_bt_name (oe:output_expr) : ML string = out_bt_name oe.oe_bt (* * Walks over the output expressions AST and constructs a string
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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": 4, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
oe: Target.output_expr -> FStar.All.ML Prims.string
FStar.All.ML
[ "ml" ]
[]
[ "Target.output_expr", "Target.__proj__Mkoutput_expr__item__oe_expr", "Ast.ident", "Target.out_expr_bt_name", "Prims.string", "FStar.Printf.sprintf", "Target.out_fn_name", "Ast.ident_name" ]
[ "recursion" ]
false
true
false
false
false
let rec out_fn_name (oe: output_expr) : ML string =
match oe.oe_expr with | T_OE_id _ -> out_expr_bt_name oe | T_OE_star oe -> Printf.sprintf "%s_star" (out_fn_name oe) | T_OE_addrof oe -> Printf.sprintf "%s_addrof" (out_fn_name oe) | T_OE_deref oe f -> Printf.sprintf "%s_deref_%s" (out_fn_name oe) (A.ident_name f) | T_OE_dot oe f -> Printf.sprintf "%s_dot_%s" (out_fn_name oe) (A.ident_name f)
false
Target.fst
Target.get_out_exprs_deps
val get_out_exprs_deps (modul: string) (ds: decls) : ML (list string)
val get_out_exprs_deps (modul: string) (ds: decls) : ML (list string)
let get_out_exprs_deps (modul:string) (ds:decls) : ML (list string) = let maybe_add_dep (deps:list string) (s:option string) : list string = match s with | None -> deps | Some s -> if List.mem s deps then deps else deps@[s] in List.fold_left (fun deps (d, _) -> match d with | Output_type_expr oe _ -> maybe_add_dep (maybe_add_dep deps (get_output_typ_dep modul oe.oe_bt)) (get_output_typ_dep modul oe.oe_t) | _ -> deps) [] ds
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 22, "end_line": 1279, "start_col": 0, "start_line": 1268 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl let print_lam (#a:Type) (f:a -> ML string) (x:lam a) : ML string = match x with | Some x, y -> Printf.sprintf ("(fun %s -> %s)") (print_ident x) (f y) | None, y -> f y let print_expr_lam (mname:string) (x:lam expr) : ML string = print_lam (print_expr mname) x let rec is_output_type (t:typ) : bool = match t with | T_app _ A.KindOutput [] -> true | T_pointer t -> is_output_type t | _ -> false let rec is_extern_type (t:typ) : bool = match t with | T_app _ A.KindExtern [] -> true | T_pointer t -> is_extern_type t | _ -> false (* * An output type is printed as the ident, or p_<ident> * * They are abstract types in the emitted F* code *) let print_output_type (qual:bool) (t:typ) : ML string = let rec aux (t:typ) : ML (option string & string) = match t with | T_app id _ _ -> id.v.modul_name, print_ident id | T_pointer t -> let m, i = aux t in m, Printf.sprintf "p_%s" i | _ -> failwith "Print: not an output type" in let mopt, i = aux t in if qual then match mopt with | None -> i | Some m -> Printf.sprintf "%s.ExternalTypes.%s" m i else i let rec print_typ (mname:string) (t:typ) : ML string = //(decreases t) = if is_output_type t then print_output_type true t else match t with | T_false -> "False" | T_app hd _ args -> //output types are already handled at the beginning of print_typ Printf.sprintf "(%s %s)" (print_maybe_qualified_ident mname hd) (String.concat " " (print_indexes mname args)) | T_dep_pair t1 (x, t2) -> Printf.sprintf "(%s:%s & %s)" (print_ident x) (print_typ mname t1) (print_typ mname t2) | T_refine t e -> Printf.sprintf "(refine %s %s)" (print_typ mname t) (print_expr_lam mname e) | T_if_else e t1 t2 -> Printf.sprintf "(t_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname e) (print_typ mname t1) (print_typ mname t2) | T_pointer t -> Printf.sprintf "bpointer (%s)" (print_typ mname t) | T_with_action t _ | T_with_dep_action t _ | T_with_comment t _ -> print_typ mname t | T_with_probe t _ _ _ -> Printf.sprintf "bpointer (%s)" (print_typ mname t) and print_indexes (mname:string) (is:list index) : ML (list string) = //(decreases is) = match is with | [] -> [] | Inl t::is -> print_typ mname t::print_indexes mname is | Inr e::is -> print_expr mname e::print_indexes mname is let rec print_kind (mname:string) (k:parser_kind) : Tot string = match k.pk_kind with | PK_base hd -> Printf.sprintf "%skind_%s" (maybe_mname_prefix mname hd) (print_ident hd) | PK_list -> "kind_nlist" | PK_t_at_most -> "kind_t_at_most" | PK_t_exact -> "kind_t_exact" | PK_return -> "ret_kind" | PK_impos -> "impos_kind" | PK_and_then k1 k2 -> Printf.sprintf "(and_then_kind %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_glb k1 k2 -> Printf.sprintf "(glb %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_filter k -> Printf.sprintf "(filter_kind %s)" (print_kind mname k) | PK_string -> "parse_string_kind" let rec print_action (mname:string) (a:action) : ML string = let print_atomic_action (a:atomic_action) : ML string = match a with | Action_return e -> Printf.sprintf "(action_return %s)" (print_expr mname e) | Action_abort -> "(action_abort())" | Action_field_pos_64 -> "(action_field_pos_64())" | Action_field_pos_32 -> "(action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr -> "(action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr_after sz write_to -> Printf.sprintf "(action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)" (print_expr mname sz) (print_ident write_to) | Action_field_ptr_after_with_setter sz write_to_field write_to_obj -> Printf.sprintf "(action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))" (print_expr mname sz) (print_ident write_to_field) (print_expr mname write_to_obj) | Action_deref i -> Printf.sprintf "(action_deref %s)" (print_ident i) | Action_assignment lhs rhs -> Printf.sprintf "(action_assignment %s %s)" (print_ident lhs) (print_expr mname rhs) | Action_call f args -> Printf.sprintf "(mk_extern_action (%s %s))" (print_ident f) (String.concat " " (List.map (print_expr mname) args)) in match a with | Atomic_action a -> print_atomic_action a | Action_seq hd tl -> Printf.sprintf "(action_seq %s %s)" (print_atomic_action hd) (print_action mname tl) | Action_ite hd then_ else_ -> Printf.sprintf "(action_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname hd) (print_action mname then_) (print_action mname else_) | Action_let i a k -> Printf.sprintf "(action_bind \"%s\" %s (fun %s -> %s))" (print_ident i) (print_atomic_action a) (print_ident i) (print_action mname k) | Action_act a -> Printf.sprintf "(action_act %s)" (print_action mname a) let print_typedef_name (mname:string) (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> Printf.sprintf "(%s:%s)" (print_ident id) (print_typ mname t)) tdn.td_params)) let print_typedef_typ (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> (print_ident id)) tdn.td_params)) let print_typedef_body (mname:string) (b:typedef_body) : ML string = match b with | TD_abbrev t -> print_typ mname t | TD_struct fields -> let print_field (sf:field) : ML string = Printf.sprintf "%s : %s%s" (print_ident sf.sf_ident) (print_typ mname sf.sf_typ) (if sf.sf_dependence then " (*dep*)" else "") in let fields = String.concat ";\n" (List.map print_field fields) in Printf.sprintf "{\n%s\n}" fields let print_typedef_actions_inv_and_fp (td:type_decl) = //we need to add output loc to the modifies locs //if there is an output type type parameter let should_add_output_loc = List.Tot.existsb (fun (_, t) -> is_output_type t || is_extern_type t) td.decl_name.td_params in let pointers = //get only non output type pointers List.Tot.filter (fun (x, t) -> T_pointer? t && not (is_output_type t || is_extern_type t)) td.decl_name.td_params in let inv = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "((ptr_inv %s) `conj_inv` %s)" (print_ident x) out) pointers "true_inv" in let fp = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "(eloc_union (ptr_loc %s) %s)" (print_ident x) out) pointers (if should_add_output_loc then "output_loc" else "eloc_none") in inv, fp let print_comments (cs:list string) : string = match cs with | [] -> "" | _ -> let c = String.concat "\\n\\\n" cs in Printf.sprintf " (Comment \"%s\")" c let print_attributes (entrypoint:bool) (attrs:decl_attributes) : string = match attrs.comments with | [] -> if entrypoint || attrs.is_exported then "" else if attrs.should_inline then "inline_for_extraction noextract\n" else "[@ (CInline)]\n" | cs -> Printf.sprintf "[@ %s %s]\n%s" (print_comments cs) (if not entrypoint && not attrs.is_exported && not attrs.should_inline then "(CInline)" else "") (if attrs.should_inline then "inline_for_extraction\n" else "") /// Printing a decl for M.Types.fst /// /// Print all the definitions, and for a Type_decl, only the type definition let maybe_print_type_equality (mname:string) (td:type_decl) : ML string = if td.decl_name.td_entrypoint then let equate_types_list = Options.get_equate_types_list () in (match (List.tryFind (fun (_, m) -> m = mname) equate_types_list) with | Some (a, _) -> let typname = A.ident_name td.decl_name.td_name in Printf.sprintf "\n\nlet _ = assert (%s.Types.%s == %s) by (FStar.Tactics.trefl ())\n\n" a typname typname | None -> "") else "" let print_definition (mname:string) (d:decl { Definition? (fst d)} ) : ML string = match fst d with | Definition (x, [], T_app ({Ast.v={Ast.name="field_id"}}) _ _, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot field_id by (FStar.Tactics.trivial())\n\n" (print_comments (snd d).comments) (print_field_id_name x) (A.print_constant c) | Definition (x, [], t, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot %s\n\n" (print_comments (snd d).comments) (print_ident x) (A.print_constant c) (print_typ mname t) | Definition (x, params, typ, expr) -> let x_ps = { td_name = x; td_params = params; td_entrypoint = false } in Printf.sprintf "%slet %s : %s = %s\n\n" (print_attributes false (snd d)) (print_typedef_name mname x_ps) (print_typ mname typ) (print_expr mname expr) let print_assumption (mname:string) (d:decl { Assumption? (fst d) } ) : ML string = match fst d with | Assumption (x, t) -> Printf.sprintf "%sassume\nval %s : %s\n\n" (if (snd d).is_if_def then "[@@ CIfDef ]\n" else "") (print_ident x) (print_typ mname t) let print_decl_for_types (mname:string) (d:decl) : ML string = match fst d with | Assumption _ -> "" | Definition _ -> print_definition mname d | Type_decl td -> Printf.sprintf "noextract\ninline_for_extraction\ntype %s = %s\n\n" (print_typedef_name mname td.decl_name) (print_typedef_body mname td.decl_typ) `strcat` maybe_print_type_equality mname td | Output_type _ | Output_type_expr _ _ | Extern_type _ | Extern_fn _ _ _ | Extern_probe _ -> "" /// Print a decl for M.fst /// /// No need to print Definition(s), they are `include`d from M.Types.fst /// /// For a Type_decl, if it is an entry point, we need to emit a definition since /// there is a corresponding declaration in the .fsti /// We make the definition as simply the definition in M.Types.fst let is_type_abbreviation (td:type_decl) : bool = match td.decl_typ with | TD_abbrev _ -> true | TD_struct _ -> false let external_api_include (modul:string) (ds:list decl) : string = if has_external_api ds then Printf.sprintf "open %s.ExternalAPI\n\n" modul else "" #push-options "--z3rlimit_factor 4" let pascal_case name : ML string = let chars = String.list_of_string name in let has_underscore = List.mem '_' chars in let keep, up, low = 0, 1, 2 in if has_underscore then let what_next : ref int = alloc up in let rewrite_char c : ML (list FStar.Char.char) = match c with | '_' -> what_next := up; [] | c -> let c_next = let n = !what_next in if n = keep then c else if n = up then FStar.Char.uppercase c else FStar.Char.lowercase c in let _ = if Char.uppercase c = c then what_next := low else if Char.lowercase c = c then what_next := keep in [c_next] in let chars = List.collect rewrite_char (String.list_of_string name) in String.string_of_list chars else if String.length name = 0 then name else String.uppercase (String.sub name 0 1) ^ String.sub name 1 (String.length name - 1) let uppercase (name:string) : string = String.uppercase name let rec print_as_c_type (t:typ) : ML string = let open Ast in match t with | T_pointer t -> Printf.sprintf "%s*" (print_as_c_type t) | T_app {v={name="Bool"}} _ [] -> "BOOLEAN" | T_app {v={name="UINT8"}} _ [] -> "uint8_t" | T_app {v={name="UINT16"}} _ [] -> "uint16_t" | T_app {v={name="UINT32"}} _ [] -> "uint32_t" | T_app {v={name="UINT64"}} _ [] -> "uint64_t" | T_app {v={name="PUINT8"}} _ [] -> "uint8_t*" | T_app {v={name=x}} KindSpec [] -> x | T_app {v={name=x}} _ [] -> uppercase x | _ -> "__UNKNOWN__" let error_code_macros = //To be kept consistent with EverParse3d.ErrorCode.error_reason_of_result "#define EVERPARSE_ERROR_GENERIC 1uL\n\ #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL\n\ #define EVERPARSE_ERROR_IMPOSSIBLE 3uL\n\ #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL\n\ #define EVERPARSE_ERROR_ACTION_FAILED 5uL\n\ #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL\n\ #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL\n" let rec get_output_typ_dep (modul:string) (t:typ) : ML (option string) = match t with | T_app {v={modul_name=None}} _ _ -> None | T_app {v={modul_name=Some m}} _ _ -> if m = modul then None else Some m | T_pointer t -> get_output_typ_dep modul t | _ -> failwith "get_typ_deps: unexpected output type" let wrapper_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_check_%s" modul fn |> pascal_case let validator_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_validate_%s" modul fn |> pascal_case let print_c_entry (produce_everparse_error: opt_produce_everparse_error) (modul: string) (env: global_env) (ds:list decl) : ML (string & string) = let default_error_handler = "static\n\ void DefaultErrorHandler(\n\t\ const char *typename_s,\n\t\ const char *fieldname,\n\t\ const char *reason,\n\t\ uint64_t error_code,\n\t\ uint8_t *context,\n\t\ EVERPARSE_INPUT_BUFFER input,\n\t\ uint64_t start_pos)\n\ {\n\t\ EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context;\n\t\ EverParseDefaultErrorHandler(\n\t\t\ typename_s,\n\t\t\ fieldname,\n\t\t\ reason,\n\t\t\ error_code,\n\t\t\ frame,\n\t\t\ input,\n\t\t\ start_pos\n\t\ );\n\ }" in let input_stream_binding = Options.get_input_stream_binding () in let is_input_stream_buffer = HashingOptions.InputStreamBuffer? input_stream_binding in let wrapped_call_buffer name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame;\n\t\ frame.filled = FALSE;\n\t\ %s\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0);\n\t\ if (EverParseIsError(result))\n\t\ {\n\t\t\ if (frame.filled)\n\t\t\ {\n\t\t\t\ %sEverParseError(frame.typename_s, frame.fieldname, frame.reason);\n\t\t\ }\n\t\t\ return FALSE;\n\t\ }\n\t\ return TRUE;" (if is_input_stream_buffer then "" else "EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t") name params modul in let wrapped_call_stream name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame =\n\t\ { .filled = FALSE,\n\t\ .typename_s = \"UNKNOWN\",\n\t\ .fieldname = \"UNKNOWN\",\n\t\ .reason = \"UNKNOWN\",\n\t\ .error_code = 0uL\n\ };\n\ EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, input, 0);\n\t\ uint64_t parsedSize = EverParseGetValidatorErrorPos(result);\n\ if (EverParseIsError(result))\n\t\ {\n\t\t\ EverParseHandleError(_extra, parsedSize, frame.typename_s, frame.fieldname, frame.reason, frame.error_code);\n\t\t\ }\n\t\ EverParseRetreat(_extra, base, parsedSize);\n\ return parsedSize;" name params in let mk_param (name: string) (typ: string) : Tot param = (A.with_range (A.to_ident' name) A.dummy_range, T_app (A.with_range (A.to_ident' typ) A.dummy_range) A.KindSpec []) in let print_one_validator (d:type_decl) : ML (string & string) = let params = d.decl_name.td_params @ (if is_input_stream_buffer then [] else [mk_param "_extra" "EVERPARSE_EXTRA_T"]) in let print_params (ps:list param) : ML string = let params = String.concat ", " (List.map (fun (id, t) -> Printf.sprintf "%s %s" (print_as_c_type t) (print_ident id)) ps) in match ps with | [] -> params | _ -> params ^ ", " in let print_arguments (ps:list param) : Tot string = let params = String.concat ", " (List.Tot.map (fun (id, t) -> if is_output_type t //output type pointers are uint8_t* in the F* generated code then (print_ident id) else print_ident id) ps) in match ps with | [] -> params | _ -> params ^ ", " in let wrapper_name = wrapper_name modul d.decl_name.td_name.A.v.A.name in let signature = if is_input_stream_buffer then Printf.sprintf "BOOLEAN %s(%suint8_t *base, uint32_t len)" wrapper_name (print_params params) else Printf.sprintf "uint64_t %s(%sEVERPARSE_INPUT_STREAM_BASE base)" wrapper_name (print_params params) in let validator_name = validator_name modul d.decl_name.td_name.A.v.A.name in let impl = let body = if is_input_stream_buffer then wrapped_call_buffer validator_name (print_arguments params) else wrapped_call_stream validator_name (print_arguments params) in Printf.sprintf "%s {\n\t%s\n}" signature body in signature ^";", impl in let signatures_output_typ_deps = List.fold_left (fun deps (d, _) -> match d with | Type_decl d -> if d.decl_name.td_entrypoint then let params = d.decl_name.td_params in List.fold_left (fun deps (_, t) -> match get_output_typ_dep modul t with | Some dep -> if List.mem dep deps then deps else deps@[dep] | _ -> deps) deps params else deps | _ -> deps) [] ds in let signatures, impls = List.split (List.collect (fun d -> match fst d with | Type_decl d -> if d.decl_name.td_entrypoint then [print_one_validator d] else [] | _ -> []) ds) in let external_defs_includes = if not (Options.get_emit_output_types_defs ()) then "" else let deps = if List.length signatures_output_typ_deps = 0 then "" else String.concat "" (List.map (fun dep -> Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" dep) signatures_output_typ_deps) in let self = if has_output_types ds || has_extern_types ds then Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n" modul else "" in Printf.sprintf "%s\n%s\n\n" deps self in let header = Printf.sprintf "#include \"EverParseEndianness.h\"\n\ %s\n\ %s\ #ifdef __cplusplus\n\ extern \"C\" {\n\ #endif\n\ %s\n\ #ifdef __cplusplus\n\ }\n\ #endif\n" error_code_macros external_defs_includes (signatures |> String.concat "\n\n") in let input_stream_include = HashingOptions.input_stream_include input_stream_binding in let header = if input_stream_include = "" then header else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include header in let add_includes = Options.make_includes () in let header = Printf.sprintf "%s%s" add_includes header in let error_callback_proto = if HashingOptions.InputStreamBuffer? input_stream_binding then Printf.sprintf "void %sEverParseError(const char *StructName, const char *FieldName, const char *Reason)%s" modul (if produce_everparse_error = Some ProduceEverParseError then "{(void) StructName; (void) FieldName; (void) Reason;}" else ";") else "" in let impl = Printf.sprintf "#include \"%sWrapper.h\"\n\ #include \"EverParse.h\"\n\ #include \"%s.h\"\n\ %s\n\n\ %s\n\n\ %s\n" modul modul error_callback_proto default_error_handler (impls |> String.concat "\n\n") in let impl = if input_stream_include = "" then impl else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include impl in let impl = Printf.sprintf "%s%s" add_includes impl in header, impl /// Functions for printing setters and getters for output expressions let rec out_bt_name (t:typ) : ML string = match t with | T_app i _ _ -> A.ident_name i | T_pointer t -> out_bt_name t | _ -> failwith "Impossible, out_bt_name received a non output type!" let out_expr_bt_name (oe:output_expr) : ML string = out_bt_name oe.oe_bt (* * Walks over the output expressions AST and constructs a string *) let rec out_fn_name (oe:output_expr) : ML string = match oe.oe_expr with | T_OE_id _ -> out_expr_bt_name oe | T_OE_star oe -> Printf.sprintf "%s_star" (out_fn_name oe) | T_OE_addrof oe -> Printf.sprintf "%s_addrof" (out_fn_name oe) | T_OE_deref oe f -> Printf.sprintf "%s_deref_%s" (out_fn_name oe) (A.ident_name f) | T_OE_dot oe f -> Printf.sprintf "%s_dot_%s" (out_fn_name oe) (A.ident_name f) module H = Hashtable type set = H.t string unit (* * In the printing functions, a hashtable tracks that we print a defn. only once * * E.g. multiple output expressions may require a val decl. for types, * we need to print them only once each *) let rec base_output_type (t:typ) : ML A.ident = match t with | T_app id A.KindOutput [] -> id | T_pointer t -> base_output_type t | _ -> failwith "Target.base_output_type called with a non-output type" #push-options "--fuel 1" let rec print_output_type_val (tbl:set) (t:typ) : ML string = let open A in if is_output_type t then let s = print_output_type false t in if H.try_find tbl s <> None then "" else let _ = H.insert tbl s () in assert (is_output_type t); match t with | T_app id KindOutput [] -> Printf.sprintf "\n\nval %s : Type0\n\n" s | T_pointer bt -> let bs = print_output_type_val tbl bt in bs ^ (Printf.sprintf "\n\ninline_for_extraction noextract type %s = bpointer %s\n\n" s (print_output_type false bt)) else "" #pop-options let rec print_out_expr' (oe:output_expr') : ML string = match oe with | T_OE_id id -> A.ident_to_string id | T_OE_star o -> Printf.sprintf "*(%s)" (print_out_expr' o.oe_expr) | T_OE_addrof o -> Printf.sprintf "&(%s)" (print_out_expr' o.oe_expr) | T_OE_deref o i -> Printf.sprintf "(%s)->%s" (print_out_expr' o.oe_expr) (A.ident_to_string i) | T_OE_dot o i -> Printf.sprintf "(%s).%s" (print_out_expr' o.oe_expr) (A.ident_to_string i) (* * F* val for the setter for the output expression *) let print_out_expr_set_fstar (tbl:set) (mname:string) (oe:output_expr) : ML string = let fn_name = Printf.sprintf "set_%s" (out_fn_name oe) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); //TODO: module name? let fn_arg1_t = print_typ mname oe.oe_bt in let fn_arg2_t = (* * If bitwidth is not None, * then output the size restriction in the refinement * Is there a better way to output it? *) if oe.oe_bitwidth = None then print_typ mname oe.oe_t else begin Printf.sprintf "(i:%s{FStar.UInt.size (FStar.Integers.v i) %d})" (print_typ mname oe.oe_t) (Some?.v oe.oe_bitwidth) end in Printf.sprintf "\n\nval %s (_:%s) (_:%s) : extern_action (NonTrivial output_loc)\n\n" fn_name fn_arg1_t fn_arg2_t let rec base_id_of_output_expr (oe:output_expr) : A.ident = match oe.oe_expr with | T_OE_id id -> id | T_OE_star oe | T_OE_addrof oe | T_OE_deref oe _ | T_OE_dot oe _ -> base_id_of_output_expr oe (* * C defn. for the setter for the output expression *) let print_out_expr_set (tbl:set) (oe:output_expr) : ML string = let fn_name = pascal_case (Printf.sprintf "set_%s" (out_fn_name oe)) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); let fn_arg1_t = print_as_c_type oe.oe_bt in let fn_arg1_name = base_id_of_output_expr oe in let fn_arg2_t = print_as_c_type oe.oe_t in let fn_arg2_name = "__v" in let fn_body = Printf.sprintf "%s = %s;" (print_out_expr' oe.oe_expr) fn_arg2_name in let fn = Printf.sprintf "void %s (%s %s, %s %s){\n %s;\n}\n" fn_name fn_arg1_t (A.ident_name fn_arg1_name) fn_arg2_t fn_arg2_name fn_body in Printf.sprintf "\n\n%s\n\n" fn (* * F* val for the getter for the output expression *) let print_out_expr_get_fstar (tbl:set) (mname:string) (oe:output_expr) : ML string = let fn_name = Printf.sprintf "get_%s" (out_fn_name oe) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); let fn_arg1_t = print_typ mname oe.oe_bt in let fn_res = print_typ mname oe.oe_t in //No bitfields, we could enforce? Printf.sprintf "\n\nval %s : %s -> %s\n\n" fn_name fn_arg1_t fn_res (* * C defn. for the getter for the output expression *) let print_out_expr_get(tbl:set) (oe:output_expr) : ML string = let fn_name = pascal_case (Printf.sprintf "get_%s" (out_fn_name oe)) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); let fn_arg1_t = print_as_c_type oe.oe_bt in let fn_arg1_name = base_id_of_output_expr oe in let fn_res = print_as_c_type oe.oe_t in let fn_body = Printf.sprintf "return %s;" (print_out_expr' oe.oe_expr) in let fn = Printf.sprintf "%s %s (%s %s){\n %s;\n}\n" fn_res fn_name fn_arg1_t (A.ident_name fn_arg1_name) fn_body in Printf.sprintf "\n\n%s\n\n" fn let output_setter_name lhs = Printf.sprintf "set_%s" (out_fn_name lhs) let output_getter_name lhs = Printf.sprintf "get_%s" (out_fn_name lhs) let output_base_var lhs = base_id_of_output_expr lhs let print_external_types_fstar_interpreter (modul:string) (ds:decls) : ML string = let tbl = H.create 10 in let s = String.concat "" (ds |> List.map (fun d -> match fst d with | Output_type ot -> let t = T_app ot.out_typ_names.typedef_abbrev A.KindOutput [] in Printf.sprintf "%s%s" (print_output_type_val tbl t) (print_output_type_val tbl (T_pointer t)) | Extern_type i -> Printf.sprintf "\n\nval %s : Type0\n\n" (print_ident i) | _ -> "")) in Printf.sprintf "module %s.ExternalTypes\n\n\ open EverParse3d.Prelude\n\ open EverParse3d.Actions.All\n\n%s" modul s let print_external_api_fstar_interpreter (modul:string) (ds:decls) : ML string = let tbl = H.create 10 in let s = String.concat "" (ds |> List.map (fun d -> match fst d with // | Output_type ot -> // let t = T_app ot.out_typ_names.typedef_name A.KindOutput [] in // Printf.sprintf "%s%s" // (print_output_type_val tbl t) // (print_output_type_val tbl (T_pointer t)) | Output_type_expr oe is_get -> Printf.sprintf "%s" // (print_output_type_val tbl oe.oe_bt) // (print_output_type_val tbl oe.oe_t) (if not is_get then print_out_expr_set_fstar tbl modul oe else print_out_expr_get_fstar tbl modul oe) | Extern_type i -> Printf.sprintf "\n\nval %s : Type0\n\n" (print_ident i) | Extern_fn f ret params -> Printf.sprintf "\n\nval %s %s : extern_action (NonTrivial output_loc)\n" (print_ident f) (String.concat " " (params |> List.map (fun (i, t) -> Printf.sprintf "(%s:%s)" (print_ident i) (print_typ modul t)))) | Extern_probe f -> Printf.sprintf "\n\nval %s : EverParse3d.CopyBuffer.probe_fn\n\n" (print_ident f) | _ -> "")) in let external_types_include = if has_output_types ds || has_extern_types ds then Printf.sprintf "include %s.ExternalTypes\n\n" modul else "" in Printf.sprintf "module %s.ExternalAPI\n\n\ open EverParse3d.Prelude\n\ open EverParse3d.Actions.All\n\ open EverParse3d.Interpreter\n\ %s\n\ noextract val output_loc : eloc\n\n%s" modul external_types_include s // // When printing output expressions in C, // the output types may be coming from some other module // This function gets all the dependencies from output expressions // so that they can be added in the M_OutputTypes.c file
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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": 4, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
modul: Prims.string -> ds: Target.decls -> FStar.All.ML (Prims.list Prims.string)
FStar.All.ML
[ "ml" ]
[]
[ "Prims.string", "Target.decls", "FStar.List.fold_left", "Prims.list", "FStar.Pervasives.Native.tuple2", "Target.decl'", "Target.decl_attributes", "Target.output_expr", "Prims.bool", "FStar.Pervasives.Native.option", "Target.get_output_typ_dep", "Target.__proj__Mkoutput_expr__item__oe_t", "Target.__proj__Mkoutput_expr__item__oe_bt", "Prims.Nil", "FStar.List.Tot.Base.mem", "FStar.List.Tot.Base.append", "Prims.Cons" ]
[]
false
true
false
false
false
let get_out_exprs_deps (modul: string) (ds: decls) : ML (list string) =
let maybe_add_dep (deps: list string) (s: option string) : list string = match s with | None -> deps | Some s -> if List.mem s deps then deps else deps @ [s] in List.fold_left (fun deps (d, _) -> match d with | Output_type_expr oe _ -> maybe_add_dep (maybe_add_dep deps (get_output_typ_dep modul oe.oe_bt)) (get_output_typ_dep modul oe.oe_t) | _ -> deps) [] ds
false
Target.fst
Target.print_output_types_fields
val print_output_types_fields (flds: list A.out_field) : ML string
val print_output_types_fields (flds: list A.out_field) : ML string
let rec print_output_types_fields (flds:list A.out_field) : ML string = List.fold_left (fun s fld -> let fld_s = match fld with | A.Out_field_named id t bopt -> Printf.sprintf "%s %s%s;\n" (print_as_c_type (atyp_to_ttyp t)) (A.ident_name id) (match bopt with | None -> "" | Some n -> ":" ^ (string_of_int n)) | A.Out_field_anon flds is_union -> Printf.sprintf "%s {\n %s };\n" (if is_union then "union" else "struct") (print_output_types_fields flds) in s ^ fld_s) "" flds
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 22, "end_line": 1343, "start_col": 0, "start_line": 1328 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl let print_lam (#a:Type) (f:a -> ML string) (x:lam a) : ML string = match x with | Some x, y -> Printf.sprintf ("(fun %s -> %s)") (print_ident x) (f y) | None, y -> f y let print_expr_lam (mname:string) (x:lam expr) : ML string = print_lam (print_expr mname) x let rec is_output_type (t:typ) : bool = match t with | T_app _ A.KindOutput [] -> true | T_pointer t -> is_output_type t | _ -> false let rec is_extern_type (t:typ) : bool = match t with | T_app _ A.KindExtern [] -> true | T_pointer t -> is_extern_type t | _ -> false (* * An output type is printed as the ident, or p_<ident> * * They are abstract types in the emitted F* code *) let print_output_type (qual:bool) (t:typ) : ML string = let rec aux (t:typ) : ML (option string & string) = match t with | T_app id _ _ -> id.v.modul_name, print_ident id | T_pointer t -> let m, i = aux t in m, Printf.sprintf "p_%s" i | _ -> failwith "Print: not an output type" in let mopt, i = aux t in if qual then match mopt with | None -> i | Some m -> Printf.sprintf "%s.ExternalTypes.%s" m i else i let rec print_typ (mname:string) (t:typ) : ML string = //(decreases t) = if is_output_type t then print_output_type true t else match t with | T_false -> "False" | T_app hd _ args -> //output types are already handled at the beginning of print_typ Printf.sprintf "(%s %s)" (print_maybe_qualified_ident mname hd) (String.concat " " (print_indexes mname args)) | T_dep_pair t1 (x, t2) -> Printf.sprintf "(%s:%s & %s)" (print_ident x) (print_typ mname t1) (print_typ mname t2) | T_refine t e -> Printf.sprintf "(refine %s %s)" (print_typ mname t) (print_expr_lam mname e) | T_if_else e t1 t2 -> Printf.sprintf "(t_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname e) (print_typ mname t1) (print_typ mname t2) | T_pointer t -> Printf.sprintf "bpointer (%s)" (print_typ mname t) | T_with_action t _ | T_with_dep_action t _ | T_with_comment t _ -> print_typ mname t | T_with_probe t _ _ _ -> Printf.sprintf "bpointer (%s)" (print_typ mname t) and print_indexes (mname:string) (is:list index) : ML (list string) = //(decreases is) = match is with | [] -> [] | Inl t::is -> print_typ mname t::print_indexes mname is | Inr e::is -> print_expr mname e::print_indexes mname is let rec print_kind (mname:string) (k:parser_kind) : Tot string = match k.pk_kind with | PK_base hd -> Printf.sprintf "%skind_%s" (maybe_mname_prefix mname hd) (print_ident hd) | PK_list -> "kind_nlist" | PK_t_at_most -> "kind_t_at_most" | PK_t_exact -> "kind_t_exact" | PK_return -> "ret_kind" | PK_impos -> "impos_kind" | PK_and_then k1 k2 -> Printf.sprintf "(and_then_kind %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_glb k1 k2 -> Printf.sprintf "(glb %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_filter k -> Printf.sprintf "(filter_kind %s)" (print_kind mname k) | PK_string -> "parse_string_kind" let rec print_action (mname:string) (a:action) : ML string = let print_atomic_action (a:atomic_action) : ML string = match a with | Action_return e -> Printf.sprintf "(action_return %s)" (print_expr mname e) | Action_abort -> "(action_abort())" | Action_field_pos_64 -> "(action_field_pos_64())" | Action_field_pos_32 -> "(action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr -> "(action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr_after sz write_to -> Printf.sprintf "(action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)" (print_expr mname sz) (print_ident write_to) | Action_field_ptr_after_with_setter sz write_to_field write_to_obj -> Printf.sprintf "(action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))" (print_expr mname sz) (print_ident write_to_field) (print_expr mname write_to_obj) | Action_deref i -> Printf.sprintf "(action_deref %s)" (print_ident i) | Action_assignment lhs rhs -> Printf.sprintf "(action_assignment %s %s)" (print_ident lhs) (print_expr mname rhs) | Action_call f args -> Printf.sprintf "(mk_extern_action (%s %s))" (print_ident f) (String.concat " " (List.map (print_expr mname) args)) in match a with | Atomic_action a -> print_atomic_action a | Action_seq hd tl -> Printf.sprintf "(action_seq %s %s)" (print_atomic_action hd) (print_action mname tl) | Action_ite hd then_ else_ -> Printf.sprintf "(action_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname hd) (print_action mname then_) (print_action mname else_) | Action_let i a k -> Printf.sprintf "(action_bind \"%s\" %s (fun %s -> %s))" (print_ident i) (print_atomic_action a) (print_ident i) (print_action mname k) | Action_act a -> Printf.sprintf "(action_act %s)" (print_action mname a) let print_typedef_name (mname:string) (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> Printf.sprintf "(%s:%s)" (print_ident id) (print_typ mname t)) tdn.td_params)) let print_typedef_typ (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> (print_ident id)) tdn.td_params)) let print_typedef_body (mname:string) (b:typedef_body) : ML string = match b with | TD_abbrev t -> print_typ mname t | TD_struct fields -> let print_field (sf:field) : ML string = Printf.sprintf "%s : %s%s" (print_ident sf.sf_ident) (print_typ mname sf.sf_typ) (if sf.sf_dependence then " (*dep*)" else "") in let fields = String.concat ";\n" (List.map print_field fields) in Printf.sprintf "{\n%s\n}" fields let print_typedef_actions_inv_and_fp (td:type_decl) = //we need to add output loc to the modifies locs //if there is an output type type parameter let should_add_output_loc = List.Tot.existsb (fun (_, t) -> is_output_type t || is_extern_type t) td.decl_name.td_params in let pointers = //get only non output type pointers List.Tot.filter (fun (x, t) -> T_pointer? t && not (is_output_type t || is_extern_type t)) td.decl_name.td_params in let inv = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "((ptr_inv %s) `conj_inv` %s)" (print_ident x) out) pointers "true_inv" in let fp = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "(eloc_union (ptr_loc %s) %s)" (print_ident x) out) pointers (if should_add_output_loc then "output_loc" else "eloc_none") in inv, fp let print_comments (cs:list string) : string = match cs with | [] -> "" | _ -> let c = String.concat "\\n\\\n" cs in Printf.sprintf " (Comment \"%s\")" c let print_attributes (entrypoint:bool) (attrs:decl_attributes) : string = match attrs.comments with | [] -> if entrypoint || attrs.is_exported then "" else if attrs.should_inline then "inline_for_extraction noextract\n" else "[@ (CInline)]\n" | cs -> Printf.sprintf "[@ %s %s]\n%s" (print_comments cs) (if not entrypoint && not attrs.is_exported && not attrs.should_inline then "(CInline)" else "") (if attrs.should_inline then "inline_for_extraction\n" else "") /// Printing a decl for M.Types.fst /// /// Print all the definitions, and for a Type_decl, only the type definition let maybe_print_type_equality (mname:string) (td:type_decl) : ML string = if td.decl_name.td_entrypoint then let equate_types_list = Options.get_equate_types_list () in (match (List.tryFind (fun (_, m) -> m = mname) equate_types_list) with | Some (a, _) -> let typname = A.ident_name td.decl_name.td_name in Printf.sprintf "\n\nlet _ = assert (%s.Types.%s == %s) by (FStar.Tactics.trefl ())\n\n" a typname typname | None -> "") else "" let print_definition (mname:string) (d:decl { Definition? (fst d)} ) : ML string = match fst d with | Definition (x, [], T_app ({Ast.v={Ast.name="field_id"}}) _ _, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot field_id by (FStar.Tactics.trivial())\n\n" (print_comments (snd d).comments) (print_field_id_name x) (A.print_constant c) | Definition (x, [], t, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot %s\n\n" (print_comments (snd d).comments) (print_ident x) (A.print_constant c) (print_typ mname t) | Definition (x, params, typ, expr) -> let x_ps = { td_name = x; td_params = params; td_entrypoint = false } in Printf.sprintf "%slet %s : %s = %s\n\n" (print_attributes false (snd d)) (print_typedef_name mname x_ps) (print_typ mname typ) (print_expr mname expr) let print_assumption (mname:string) (d:decl { Assumption? (fst d) } ) : ML string = match fst d with | Assumption (x, t) -> Printf.sprintf "%sassume\nval %s : %s\n\n" (if (snd d).is_if_def then "[@@ CIfDef ]\n" else "") (print_ident x) (print_typ mname t) let print_decl_for_types (mname:string) (d:decl) : ML string = match fst d with | Assumption _ -> "" | Definition _ -> print_definition mname d | Type_decl td -> Printf.sprintf "noextract\ninline_for_extraction\ntype %s = %s\n\n" (print_typedef_name mname td.decl_name) (print_typedef_body mname td.decl_typ) `strcat` maybe_print_type_equality mname td | Output_type _ | Output_type_expr _ _ | Extern_type _ | Extern_fn _ _ _ | Extern_probe _ -> "" /// Print a decl for M.fst /// /// No need to print Definition(s), they are `include`d from M.Types.fst /// /// For a Type_decl, if it is an entry point, we need to emit a definition since /// there is a corresponding declaration in the .fsti /// We make the definition as simply the definition in M.Types.fst let is_type_abbreviation (td:type_decl) : bool = match td.decl_typ with | TD_abbrev _ -> true | TD_struct _ -> false let external_api_include (modul:string) (ds:list decl) : string = if has_external_api ds then Printf.sprintf "open %s.ExternalAPI\n\n" modul else "" #push-options "--z3rlimit_factor 4" let pascal_case name : ML string = let chars = String.list_of_string name in let has_underscore = List.mem '_' chars in let keep, up, low = 0, 1, 2 in if has_underscore then let what_next : ref int = alloc up in let rewrite_char c : ML (list FStar.Char.char) = match c with | '_' -> what_next := up; [] | c -> let c_next = let n = !what_next in if n = keep then c else if n = up then FStar.Char.uppercase c else FStar.Char.lowercase c in let _ = if Char.uppercase c = c then what_next := low else if Char.lowercase c = c then what_next := keep in [c_next] in let chars = List.collect rewrite_char (String.list_of_string name) in String.string_of_list chars else if String.length name = 0 then name else String.uppercase (String.sub name 0 1) ^ String.sub name 1 (String.length name - 1) let uppercase (name:string) : string = String.uppercase name let rec print_as_c_type (t:typ) : ML string = let open Ast in match t with | T_pointer t -> Printf.sprintf "%s*" (print_as_c_type t) | T_app {v={name="Bool"}} _ [] -> "BOOLEAN" | T_app {v={name="UINT8"}} _ [] -> "uint8_t" | T_app {v={name="UINT16"}} _ [] -> "uint16_t" | T_app {v={name="UINT32"}} _ [] -> "uint32_t" | T_app {v={name="UINT64"}} _ [] -> "uint64_t" | T_app {v={name="PUINT8"}} _ [] -> "uint8_t*" | T_app {v={name=x}} KindSpec [] -> x | T_app {v={name=x}} _ [] -> uppercase x | _ -> "__UNKNOWN__" let error_code_macros = //To be kept consistent with EverParse3d.ErrorCode.error_reason_of_result "#define EVERPARSE_ERROR_GENERIC 1uL\n\ #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL\n\ #define EVERPARSE_ERROR_IMPOSSIBLE 3uL\n\ #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL\n\ #define EVERPARSE_ERROR_ACTION_FAILED 5uL\n\ #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL\n\ #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL\n" let rec get_output_typ_dep (modul:string) (t:typ) : ML (option string) = match t with | T_app {v={modul_name=None}} _ _ -> None | T_app {v={modul_name=Some m}} _ _ -> if m = modul then None else Some m | T_pointer t -> get_output_typ_dep modul t | _ -> failwith "get_typ_deps: unexpected output type" let wrapper_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_check_%s" modul fn |> pascal_case let validator_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_validate_%s" modul fn |> pascal_case let print_c_entry (produce_everparse_error: opt_produce_everparse_error) (modul: string) (env: global_env) (ds:list decl) : ML (string & string) = let default_error_handler = "static\n\ void DefaultErrorHandler(\n\t\ const char *typename_s,\n\t\ const char *fieldname,\n\t\ const char *reason,\n\t\ uint64_t error_code,\n\t\ uint8_t *context,\n\t\ EVERPARSE_INPUT_BUFFER input,\n\t\ uint64_t start_pos)\n\ {\n\t\ EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context;\n\t\ EverParseDefaultErrorHandler(\n\t\t\ typename_s,\n\t\t\ fieldname,\n\t\t\ reason,\n\t\t\ error_code,\n\t\t\ frame,\n\t\t\ input,\n\t\t\ start_pos\n\t\ );\n\ }" in let input_stream_binding = Options.get_input_stream_binding () in let is_input_stream_buffer = HashingOptions.InputStreamBuffer? input_stream_binding in let wrapped_call_buffer name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame;\n\t\ frame.filled = FALSE;\n\t\ %s\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0);\n\t\ if (EverParseIsError(result))\n\t\ {\n\t\t\ if (frame.filled)\n\t\t\ {\n\t\t\t\ %sEverParseError(frame.typename_s, frame.fieldname, frame.reason);\n\t\t\ }\n\t\t\ return FALSE;\n\t\ }\n\t\ return TRUE;" (if is_input_stream_buffer then "" else "EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t") name params modul in let wrapped_call_stream name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame =\n\t\ { .filled = FALSE,\n\t\ .typename_s = \"UNKNOWN\",\n\t\ .fieldname = \"UNKNOWN\",\n\t\ .reason = \"UNKNOWN\",\n\t\ .error_code = 0uL\n\ };\n\ EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, input, 0);\n\t\ uint64_t parsedSize = EverParseGetValidatorErrorPos(result);\n\ if (EverParseIsError(result))\n\t\ {\n\t\t\ EverParseHandleError(_extra, parsedSize, frame.typename_s, frame.fieldname, frame.reason, frame.error_code);\n\t\t\ }\n\t\ EverParseRetreat(_extra, base, parsedSize);\n\ return parsedSize;" name params in let mk_param (name: string) (typ: string) : Tot param = (A.with_range (A.to_ident' name) A.dummy_range, T_app (A.with_range (A.to_ident' typ) A.dummy_range) A.KindSpec []) in let print_one_validator (d:type_decl) : ML (string & string) = let params = d.decl_name.td_params @ (if is_input_stream_buffer then [] else [mk_param "_extra" "EVERPARSE_EXTRA_T"]) in let print_params (ps:list param) : ML string = let params = String.concat ", " (List.map (fun (id, t) -> Printf.sprintf "%s %s" (print_as_c_type t) (print_ident id)) ps) in match ps with | [] -> params | _ -> params ^ ", " in let print_arguments (ps:list param) : Tot string = let params = String.concat ", " (List.Tot.map (fun (id, t) -> if is_output_type t //output type pointers are uint8_t* in the F* generated code then (print_ident id) else print_ident id) ps) in match ps with | [] -> params | _ -> params ^ ", " in let wrapper_name = wrapper_name modul d.decl_name.td_name.A.v.A.name in let signature = if is_input_stream_buffer then Printf.sprintf "BOOLEAN %s(%suint8_t *base, uint32_t len)" wrapper_name (print_params params) else Printf.sprintf "uint64_t %s(%sEVERPARSE_INPUT_STREAM_BASE base)" wrapper_name (print_params params) in let validator_name = validator_name modul d.decl_name.td_name.A.v.A.name in let impl = let body = if is_input_stream_buffer then wrapped_call_buffer validator_name (print_arguments params) else wrapped_call_stream validator_name (print_arguments params) in Printf.sprintf "%s {\n\t%s\n}" signature body in signature ^";", impl in let signatures_output_typ_deps = List.fold_left (fun deps (d, _) -> match d with | Type_decl d -> if d.decl_name.td_entrypoint then let params = d.decl_name.td_params in List.fold_left (fun deps (_, t) -> match get_output_typ_dep modul t with | Some dep -> if List.mem dep deps then deps else deps@[dep] | _ -> deps) deps params else deps | _ -> deps) [] ds in let signatures, impls = List.split (List.collect (fun d -> match fst d with | Type_decl d -> if d.decl_name.td_entrypoint then [print_one_validator d] else [] | _ -> []) ds) in let external_defs_includes = if not (Options.get_emit_output_types_defs ()) then "" else let deps = if List.length signatures_output_typ_deps = 0 then "" else String.concat "" (List.map (fun dep -> Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" dep) signatures_output_typ_deps) in let self = if has_output_types ds || has_extern_types ds then Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n" modul else "" in Printf.sprintf "%s\n%s\n\n" deps self in let header = Printf.sprintf "#include \"EverParseEndianness.h\"\n\ %s\n\ %s\ #ifdef __cplusplus\n\ extern \"C\" {\n\ #endif\n\ %s\n\ #ifdef __cplusplus\n\ }\n\ #endif\n" error_code_macros external_defs_includes (signatures |> String.concat "\n\n") in let input_stream_include = HashingOptions.input_stream_include input_stream_binding in let header = if input_stream_include = "" then header else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include header in let add_includes = Options.make_includes () in let header = Printf.sprintf "%s%s" add_includes header in let error_callback_proto = if HashingOptions.InputStreamBuffer? input_stream_binding then Printf.sprintf "void %sEverParseError(const char *StructName, const char *FieldName, const char *Reason)%s" modul (if produce_everparse_error = Some ProduceEverParseError then "{(void) StructName; (void) FieldName; (void) Reason;}" else ";") else "" in let impl = Printf.sprintf "#include \"%sWrapper.h\"\n\ #include \"EverParse.h\"\n\ #include \"%s.h\"\n\ %s\n\n\ %s\n\n\ %s\n" modul modul error_callback_proto default_error_handler (impls |> String.concat "\n\n") in let impl = if input_stream_include = "" then impl else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include impl in let impl = Printf.sprintf "%s%s" add_includes impl in header, impl /// Functions for printing setters and getters for output expressions let rec out_bt_name (t:typ) : ML string = match t with | T_app i _ _ -> A.ident_name i | T_pointer t -> out_bt_name t | _ -> failwith "Impossible, out_bt_name received a non output type!" let out_expr_bt_name (oe:output_expr) : ML string = out_bt_name oe.oe_bt (* * Walks over the output expressions AST and constructs a string *) let rec out_fn_name (oe:output_expr) : ML string = match oe.oe_expr with | T_OE_id _ -> out_expr_bt_name oe | T_OE_star oe -> Printf.sprintf "%s_star" (out_fn_name oe) | T_OE_addrof oe -> Printf.sprintf "%s_addrof" (out_fn_name oe) | T_OE_deref oe f -> Printf.sprintf "%s_deref_%s" (out_fn_name oe) (A.ident_name f) | T_OE_dot oe f -> Printf.sprintf "%s_dot_%s" (out_fn_name oe) (A.ident_name f) module H = Hashtable type set = H.t string unit (* * In the printing functions, a hashtable tracks that we print a defn. only once * * E.g. multiple output expressions may require a val decl. for types, * we need to print them only once each *) let rec base_output_type (t:typ) : ML A.ident = match t with | T_app id A.KindOutput [] -> id | T_pointer t -> base_output_type t | _ -> failwith "Target.base_output_type called with a non-output type" #push-options "--fuel 1" let rec print_output_type_val (tbl:set) (t:typ) : ML string = let open A in if is_output_type t then let s = print_output_type false t in if H.try_find tbl s <> None then "" else let _ = H.insert tbl s () in assert (is_output_type t); match t with | T_app id KindOutput [] -> Printf.sprintf "\n\nval %s : Type0\n\n" s | T_pointer bt -> let bs = print_output_type_val tbl bt in bs ^ (Printf.sprintf "\n\ninline_for_extraction noextract type %s = bpointer %s\n\n" s (print_output_type false bt)) else "" #pop-options let rec print_out_expr' (oe:output_expr') : ML string = match oe with | T_OE_id id -> A.ident_to_string id | T_OE_star o -> Printf.sprintf "*(%s)" (print_out_expr' o.oe_expr) | T_OE_addrof o -> Printf.sprintf "&(%s)" (print_out_expr' o.oe_expr) | T_OE_deref o i -> Printf.sprintf "(%s)->%s" (print_out_expr' o.oe_expr) (A.ident_to_string i) | T_OE_dot o i -> Printf.sprintf "(%s).%s" (print_out_expr' o.oe_expr) (A.ident_to_string i) (* * F* val for the setter for the output expression *) let print_out_expr_set_fstar (tbl:set) (mname:string) (oe:output_expr) : ML string = let fn_name = Printf.sprintf "set_%s" (out_fn_name oe) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); //TODO: module name? let fn_arg1_t = print_typ mname oe.oe_bt in let fn_arg2_t = (* * If bitwidth is not None, * then output the size restriction in the refinement * Is there a better way to output it? *) if oe.oe_bitwidth = None then print_typ mname oe.oe_t else begin Printf.sprintf "(i:%s{FStar.UInt.size (FStar.Integers.v i) %d})" (print_typ mname oe.oe_t) (Some?.v oe.oe_bitwidth) end in Printf.sprintf "\n\nval %s (_:%s) (_:%s) : extern_action (NonTrivial output_loc)\n\n" fn_name fn_arg1_t fn_arg2_t let rec base_id_of_output_expr (oe:output_expr) : A.ident = match oe.oe_expr with | T_OE_id id -> id | T_OE_star oe | T_OE_addrof oe | T_OE_deref oe _ | T_OE_dot oe _ -> base_id_of_output_expr oe (* * C defn. for the setter for the output expression *) let print_out_expr_set (tbl:set) (oe:output_expr) : ML string = let fn_name = pascal_case (Printf.sprintf "set_%s" (out_fn_name oe)) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); let fn_arg1_t = print_as_c_type oe.oe_bt in let fn_arg1_name = base_id_of_output_expr oe in let fn_arg2_t = print_as_c_type oe.oe_t in let fn_arg2_name = "__v" in let fn_body = Printf.sprintf "%s = %s;" (print_out_expr' oe.oe_expr) fn_arg2_name in let fn = Printf.sprintf "void %s (%s %s, %s %s){\n %s;\n}\n" fn_name fn_arg1_t (A.ident_name fn_arg1_name) fn_arg2_t fn_arg2_name fn_body in Printf.sprintf "\n\n%s\n\n" fn (* * F* val for the getter for the output expression *) let print_out_expr_get_fstar (tbl:set) (mname:string) (oe:output_expr) : ML string = let fn_name = Printf.sprintf "get_%s" (out_fn_name oe) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); let fn_arg1_t = print_typ mname oe.oe_bt in let fn_res = print_typ mname oe.oe_t in //No bitfields, we could enforce? Printf.sprintf "\n\nval %s : %s -> %s\n\n" fn_name fn_arg1_t fn_res (* * C defn. for the getter for the output expression *) let print_out_expr_get(tbl:set) (oe:output_expr) : ML string = let fn_name = pascal_case (Printf.sprintf "get_%s" (out_fn_name oe)) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); let fn_arg1_t = print_as_c_type oe.oe_bt in let fn_arg1_name = base_id_of_output_expr oe in let fn_res = print_as_c_type oe.oe_t in let fn_body = Printf.sprintf "return %s;" (print_out_expr' oe.oe_expr) in let fn = Printf.sprintf "%s %s (%s %s){\n %s;\n}\n" fn_res fn_name fn_arg1_t (A.ident_name fn_arg1_name) fn_body in Printf.sprintf "\n\n%s\n\n" fn let output_setter_name lhs = Printf.sprintf "set_%s" (out_fn_name lhs) let output_getter_name lhs = Printf.sprintf "get_%s" (out_fn_name lhs) let output_base_var lhs = base_id_of_output_expr lhs let print_external_types_fstar_interpreter (modul:string) (ds:decls) : ML string = let tbl = H.create 10 in let s = String.concat "" (ds |> List.map (fun d -> match fst d with | Output_type ot -> let t = T_app ot.out_typ_names.typedef_abbrev A.KindOutput [] in Printf.sprintf "%s%s" (print_output_type_val tbl t) (print_output_type_val tbl (T_pointer t)) | Extern_type i -> Printf.sprintf "\n\nval %s : Type0\n\n" (print_ident i) | _ -> "")) in Printf.sprintf "module %s.ExternalTypes\n\n\ open EverParse3d.Prelude\n\ open EverParse3d.Actions.All\n\n%s" modul s let print_external_api_fstar_interpreter (modul:string) (ds:decls) : ML string = let tbl = H.create 10 in let s = String.concat "" (ds |> List.map (fun d -> match fst d with // | Output_type ot -> // let t = T_app ot.out_typ_names.typedef_name A.KindOutput [] in // Printf.sprintf "%s%s" // (print_output_type_val tbl t) // (print_output_type_val tbl (T_pointer t)) | Output_type_expr oe is_get -> Printf.sprintf "%s" // (print_output_type_val tbl oe.oe_bt) // (print_output_type_val tbl oe.oe_t) (if not is_get then print_out_expr_set_fstar tbl modul oe else print_out_expr_get_fstar tbl modul oe) | Extern_type i -> Printf.sprintf "\n\nval %s : Type0\n\n" (print_ident i) | Extern_fn f ret params -> Printf.sprintf "\n\nval %s %s : extern_action (NonTrivial output_loc)\n" (print_ident f) (String.concat " " (params |> List.map (fun (i, t) -> Printf.sprintf "(%s:%s)" (print_ident i) (print_typ modul t)))) | Extern_probe f -> Printf.sprintf "\n\nval %s : EverParse3d.CopyBuffer.probe_fn\n\n" (print_ident f) | _ -> "")) in let external_types_include = if has_output_types ds || has_extern_types ds then Printf.sprintf "include %s.ExternalTypes\n\n" modul else "" in Printf.sprintf "module %s.ExternalAPI\n\n\ open EverParse3d.Prelude\n\ open EverParse3d.Actions.All\n\ open EverParse3d.Interpreter\n\ %s\n\ noextract val output_loc : eloc\n\n%s" modul external_types_include s // // When printing output expressions in C, // the output types may be coming from some other module // This function gets all the dependencies from output expressions // so that they can be added in the M_OutputTypes.c file // let get_out_exprs_deps (modul:string) (ds:decls) : ML (list string) = let maybe_add_dep (deps:list string) (s:option string) : list string = match s with | None -> deps | Some s -> if List.mem s deps then deps else deps@[s] in List.fold_left (fun deps (d, _) -> match d with | Output_type_expr oe _ -> maybe_add_dep (maybe_add_dep deps (get_output_typ_dep modul oe.oe_bt)) (get_output_typ_dep modul oe.oe_t) | _ -> deps) [] ds let print_out_exprs_c modul (ds:decls) : ML string = let tbl = H.create 10 in let deps = get_out_exprs_deps modul ds in let emit_output_types_defs = Options.get_emit_output_types_defs () in let dep_includes = if List.length deps = 0 || not emit_output_types_defs then "" else String.concat "" (List.map (fun s -> FStar.Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" s) deps) in let self_external_typedef_include = if has_output_types ds && emit_output_types_defs then Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" modul else "" in (Printf.sprintf "%s#include<stdint.h>\n\n\ %s\ %s\ #if defined(__cplusplus)\n\ extern \"C\" {\n\ #endif\n\n" (Options.make_includes ()) dep_includes self_external_typedef_include) ^ (String.concat "" (ds |> List.map (fun d -> match fst d with | Output_type_expr oe is_get -> if not is_get then print_out_expr_set tbl oe else print_out_expr_get tbl oe | _ -> ""))) ^ ("#if defined(__cplusplus)\n\ }\n\ #endif\n\n") let rec atyp_to_ttyp (t:A.typ) : ML typ = match t.v with | A.Pointer t -> let t = atyp_to_ttyp t in T_pointer t | A.Type_app hd _b _args -> T_app hd _b []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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": 4, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
flds: Prims.list Ast.out_field -> FStar.All.ML Prims.string
FStar.All.ML
[ "ml" ]
[]
[ "Prims.list", "Ast.out_field", "FStar.List.fold_left", "Prims.string", "Prims.op_Hat", "Ast.ident", "Ast.typ", "FStar.Pervasives.Native.option", "Prims.int", "Prims.string_of_int", "Ast.ident_name", "FStar.Printf.sprintf", "Target.print_as_c_type", "Target.typ", "Target.atyp_to_ttyp", "Prims.bool", "Target.print_output_types_fields" ]
[ "recursion" ]
false
true
false
false
false
let rec print_output_types_fields (flds: list A.out_field) : ML string =
List.fold_left (fun s fld -> let fld_s = match fld with | A.Out_field_named id t bopt -> Printf.sprintf "%s %s%s;\n" (print_as_c_type (atyp_to_ttyp t)) (A.ident_name id) (match bopt with | None -> "" | Some n -> ":" ^ (string_of_int n)) | A.Out_field_anon flds is_union -> Printf.sprintf "%s {\n %s };\n" (if is_union then "union" else "struct") (print_output_types_fields flds) in s ^ fld_s) "" flds
false
FStar.OrdSetProps.fst
FStar.OrdSetProps.union_lemma
val union_lemma: #a:eqtype -> #f:cmp a -> s1:ordset a f -> s2:ordset a f -> Lemma (requires (True)) (ensures (forall x. mem x (union s1 s2) = mem x (union' s1 s2))) (decreases (size s1))
val union_lemma: #a:eqtype -> #f:cmp a -> s1:ordset a f -> s2:ordset a f -> Lemma (requires (True)) (ensures (forall x. mem x (union s1 s2) = mem x (union' s1 s2))) (decreases (size s1))
let rec union_lemma (#a:eqtype) #f s1 s2 = if s1 = empty then () else union_lemma (remove (Some?.v (choose s1)) s1) s2
{ "file_name": "ulib/FStar.OrdSetProps.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 43, "start_col": 0, "start_line": 40 }
(* Copyright 2008-2018 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 FStar.OrdSetProps open FStar.OrdSet val fold: #a:eqtype -> #b:Type -> #f:cmp a -> (a -> b -> Tot b) -> s:ordset a f -> b -> Tot b (decreases (size s)) let rec fold (#a:eqtype) (#b:Type) #f g s x = if s = empty then x else let Some e = choose s in let a_rest = fold g (remove e s) x in g e a_rest (**********) let insert (#a:eqtype) (#f:cmp a) (x:a) (s:ordset a f) = union #a #f (singleton #a #f x) s val union':#a:eqtype -> #f:cmp a -> ordset a f -> ordset a f -> Tot (ordset a f) let union' (#a:eqtype) #f s1 s2 = fold (fun e (s:ordset a f) -> insert e s) s1 s2 val union_lemma: #a:eqtype -> #f:cmp a -> s1:ordset a f -> s2:ordset a f -> Lemma (requires (True)) (ensures (forall x. mem x (union s1 s2) = mem x (union' s1 s2)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.OrdSet.fsti.checked" ], "interface_file": false, "source_file": "FStar.OrdSetProps.fst" }
[ { "abbrev": false, "full_module": "FStar.OrdSet", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "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
s1: FStar.OrdSet.ordset a f -> s2: FStar.OrdSet.ordset a f -> FStar.Pervasives.Lemma (ensures forall (x: a). FStar.OrdSet.mem x (FStar.OrdSet.union s1 s2) = FStar.OrdSet.mem x (FStar.OrdSetProps.union' s1 s2)) (decreases FStar.OrdSet.size s1)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.eqtype", "FStar.OrdSet.cmp", "FStar.OrdSet.ordset", "Prims.op_Equality", "FStar.OrdSet.empty", "Prims.bool", "FStar.OrdSetProps.union_lemma", "FStar.OrdSet.remove", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.OrdSet.choose", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec union_lemma (#a: eqtype) #f s1 s2 =
if s1 = empty then () else union_lemma (remove (Some?.v (choose s1)) s1) s2
false
FStar.OrdSetProps.fst
FStar.OrdSetProps.fold
val fold: #a:eqtype -> #b:Type -> #f:cmp a -> (a -> b -> Tot b) -> s:ordset a f -> b -> Tot b (decreases (size s))
val fold: #a:eqtype -> #b:Type -> #f:cmp a -> (a -> b -> Tot b) -> s:ordset a f -> b -> Tot b (decreases (size s))
let rec fold (#a:eqtype) (#b:Type) #f g s x = if s = empty then x else let Some e = choose s in let a_rest = fold g (remove e s) x in g e a_rest
{ "file_name": "ulib/FStar.OrdSetProps.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 14, "end_line": 27, "start_col": 0, "start_line": 22 }
(* Copyright 2008-2018 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 FStar.OrdSetProps open FStar.OrdSet val fold: #a:eqtype -> #b:Type -> #f:cmp a -> (a -> b -> Tot b) -> s:ordset a f -> b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.OrdSet.fsti.checked" ], "interface_file": false, "source_file": "FStar.OrdSetProps.fst" }
[ { "abbrev": false, "full_module": "FStar.OrdSet", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "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
g: (_: a -> _: b -> b) -> s: FStar.OrdSet.ordset a f -> x: b -> Prims.Tot b
Prims.Tot
[ "total", "" ]
[]
[ "Prims.eqtype", "FStar.OrdSet.cmp", "FStar.OrdSet.ordset", "Prims.op_Equality", "FStar.OrdSet.empty", "Prims.bool", "FStar.OrdSetProps.fold", "FStar.OrdSet.remove", "FStar.Pervasives.Native.option", "FStar.OrdSet.choose" ]
[ "recursion" ]
false
false
false
false
false
let rec fold (#a: eqtype) (#b: Type) #f g s x =
if s = empty then x else let Some e = choose s in let a_rest = fold g (remove e s) x in g e a_rest
false
FStar.OrdSetProps.fst
FStar.OrdSetProps.union_lemma'
val union_lemma': #a:eqtype -> #f:cmp a -> s1:ordset a f -> s2:ordset a f -> Lemma (requires (True)) (ensures (union s1 s2 = union' s1 s2))
val union_lemma': #a:eqtype -> #f:cmp a -> s1:ordset a f -> s2:ordset a f -> Lemma (requires (True)) (ensures (union s1 s2 = union' s1 s2))
let union_lemma' (#a:eqtype) #f s1 s2 = union_lemma s1 s2; eq_lemma (union s1 s2) (union' s1 s2)
{ "file_name": "ulib/FStar.OrdSetProps.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 39, "end_line": 50, "start_col": 0, "start_line": 48 }
(* Copyright 2008-2018 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 FStar.OrdSetProps open FStar.OrdSet val fold: #a:eqtype -> #b:Type -> #f:cmp a -> (a -> b -> Tot b) -> s:ordset a f -> b -> Tot b (decreases (size s)) let rec fold (#a:eqtype) (#b:Type) #f g s x = if s = empty then x else let Some e = choose s in let a_rest = fold g (remove e s) x in g e a_rest (**********) let insert (#a:eqtype) (#f:cmp a) (x:a) (s:ordset a f) = union #a #f (singleton #a #f x) s val union':#a:eqtype -> #f:cmp a -> ordset a f -> ordset a f -> Tot (ordset a f) let union' (#a:eqtype) #f s1 s2 = fold (fun e (s:ordset a f) -> insert e s) s1 s2 val union_lemma: #a:eqtype -> #f:cmp a -> s1:ordset a f -> s2:ordset a f -> Lemma (requires (True)) (ensures (forall x. mem x (union s1 s2) = mem x (union' s1 s2))) (decreases (size s1)) let rec union_lemma (#a:eqtype) #f s1 s2 = if s1 = empty then () else union_lemma (remove (Some?.v (choose s1)) s1) s2 val union_lemma': #a:eqtype -> #f:cmp a -> s1:ordset a f -> s2:ordset a f -> Lemma (requires (True))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.OrdSet.fsti.checked" ], "interface_file": false, "source_file": "FStar.OrdSetProps.fst" }
[ { "abbrev": false, "full_module": "FStar.OrdSet", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "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
s1: FStar.OrdSet.ordset a f -> s2: FStar.OrdSet.ordset a f -> FStar.Pervasives.Lemma (ensures FStar.OrdSet.union s1 s2 = FStar.OrdSetProps.union' s1 s2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "FStar.OrdSet.cmp", "FStar.OrdSet.ordset", "FStar.OrdSet.eq_lemma", "FStar.OrdSet.union", "FStar.OrdSetProps.union'", "Prims.unit", "FStar.OrdSetProps.union_lemma" ]
[]
true
false
true
false
false
let union_lemma' (#a: eqtype) #f s1 s2 =
union_lemma s1 s2; eq_lemma (union s1 s2) (union' s1 s2)
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.poly1305_mac
val poly1305_mac (#w: lanes) (msg: bytes) (k: Scalar.key) : Scalar.tag
val poly1305_mac (#w: lanes) (msg: bytes) (k: Scalar.key) : Scalar.tag
let poly1305_mac (#w:lanes) (msg:bytes) (k:Scalar.key) : Scalar.tag = let acc, r = Scalar.poly1305_init k in let acc = poly1305_update #w msg acc r in Scalar.poly1305_finish k acc
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 158, "start_col": 0, "start_line": 155 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r let normalize_2 (r:pfelem) (acc:elem 2) : pfelem = let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[0] a.[1] let normalize_4 (r:pfelem) (acc:elem 4) : pfelem = let r2 = pfmul r r in let r3 = pfmul r2 r in let r4 = pfmul r2 r2 in let r4321 = create4 r4 r3 r2 r in let a = fmul acc r4321 in pfadd (pfadd (pfadd a.[0] a.[1]) a.[2]) a.[3] let normalize_n (#w:lanes) (r:pfelem) (acc:elem w) : pfelem = match w with | 1 -> normalize_1 r acc | 2 -> normalize_2 r acc | 4 -> normalize_4 r acc let compute_r1 (r:pfelem) : elem 1 = to_elem 1 r let compute_r2 (r:pfelem) : elem 2 = to_elem 2 (pfmul r r) let compute_r4 (r:pfelem) : elem 4 = to_elem 4 (pfmul (pfmul r r) (pfmul r r)) let compute_rw (#w:lanes) (r:pfelem) : elem w = match w with | 1 -> compute_r1 r | 2 -> compute_r2 r | 4 -> compute_r4 r let poly1305_update_nblocks (#w:lanes) (r_w:elem w) (b:lbytes (w * size_block)) (acc:elem w) : elem w = let e = load_blocks b in let acc = fadd (fmul acc r_w) e in acc let poly1305_update_multi (#w:lanes) (text:bytes{0 < length text /\ length text % (w * size_block) = 0}) (acc:pfelem) (r:pfelem) : pfelem = let rw = compute_rw r in let acc = load_acc (Seq.slice text 0 (w * size_block)) acc in let text = Seq.slice text (w * size_block) (length text) in let acc = repeat_blocks_multi #uint8 #(elem w) (w * size_block) text (poly1305_update_nblocks rw) acc in let acc = normalize_n r acc in acc let poly1305_update_vec (#w:lanes) (text:bytes) (acc:pfelem) (r:pfelem) : pfelem = let len = length text in let sz_block = w * size_block in let len0 = len / sz_block * sz_block in let t0 = Seq.slice text 0 len0 in let acc = if len0 > 0 then poly1305_update_multi #w t0 acc r else acc in let t1 = Seq.slice text len0 len in Scalar.poly1305_update t1 acc r let poly1305_update (#w:lanes) (text:bytes) (acc:pfelem) (r:pfelem) : pfelem = match w with | 1 -> Scalar.poly1305_update text acc r | 2 -> poly1305_update_vec #2 text acc r | 4 -> poly1305_update_vec #4 text acc r
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
msg: Lib.ByteSequence.bytes -> k: Spec.Poly1305.key -> Spec.Poly1305.tag
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Lib.ByteSequence.bytes", "Spec.Poly1305.key", "Spec.Poly1305.felem", "Spec.Poly1305.poly1305_finish", "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.poly1305_update", "Spec.Poly1305.tag", "FStar.Pervasives.Native.tuple2", "Spec.Poly1305.poly1305_init" ]
[]
false
false
false
true
false
let poly1305_mac (#w: lanes) (msg: bytes) (k: Scalar.key) : Scalar.tag =
let acc, r = Scalar.poly1305_init k in let acc = poly1305_update #w msg acc r in Scalar.poly1305_finish k acc
false
Target.fst
Target.atyp_to_ttyp
val atyp_to_ttyp (t: A.typ) : ML typ
val atyp_to_ttyp (t: A.typ) : ML typ
let rec atyp_to_ttyp (t:A.typ) : ML typ = match t.v with | A.Pointer t -> let t = atyp_to_ttyp t in T_pointer t | A.Type_app hd _b _args -> T_app hd _b []
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 18, "end_line": 1326, "start_col": 0, "start_line": 1320 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl let print_lam (#a:Type) (f:a -> ML string) (x:lam a) : ML string = match x with | Some x, y -> Printf.sprintf ("(fun %s -> %s)") (print_ident x) (f y) | None, y -> f y let print_expr_lam (mname:string) (x:lam expr) : ML string = print_lam (print_expr mname) x let rec is_output_type (t:typ) : bool = match t with | T_app _ A.KindOutput [] -> true | T_pointer t -> is_output_type t | _ -> false let rec is_extern_type (t:typ) : bool = match t with | T_app _ A.KindExtern [] -> true | T_pointer t -> is_extern_type t | _ -> false (* * An output type is printed as the ident, or p_<ident> * * They are abstract types in the emitted F* code *) let print_output_type (qual:bool) (t:typ) : ML string = let rec aux (t:typ) : ML (option string & string) = match t with | T_app id _ _ -> id.v.modul_name, print_ident id | T_pointer t -> let m, i = aux t in m, Printf.sprintf "p_%s" i | _ -> failwith "Print: not an output type" in let mopt, i = aux t in if qual then match mopt with | None -> i | Some m -> Printf.sprintf "%s.ExternalTypes.%s" m i else i let rec print_typ (mname:string) (t:typ) : ML string = //(decreases t) = if is_output_type t then print_output_type true t else match t with | T_false -> "False" | T_app hd _ args -> //output types are already handled at the beginning of print_typ Printf.sprintf "(%s %s)" (print_maybe_qualified_ident mname hd) (String.concat " " (print_indexes mname args)) | T_dep_pair t1 (x, t2) -> Printf.sprintf "(%s:%s & %s)" (print_ident x) (print_typ mname t1) (print_typ mname t2) | T_refine t e -> Printf.sprintf "(refine %s %s)" (print_typ mname t) (print_expr_lam mname e) | T_if_else e t1 t2 -> Printf.sprintf "(t_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname e) (print_typ mname t1) (print_typ mname t2) | T_pointer t -> Printf.sprintf "bpointer (%s)" (print_typ mname t) | T_with_action t _ | T_with_dep_action t _ | T_with_comment t _ -> print_typ mname t | T_with_probe t _ _ _ -> Printf.sprintf "bpointer (%s)" (print_typ mname t) and print_indexes (mname:string) (is:list index) : ML (list string) = //(decreases is) = match is with | [] -> [] | Inl t::is -> print_typ mname t::print_indexes mname is | Inr e::is -> print_expr mname e::print_indexes mname is let rec print_kind (mname:string) (k:parser_kind) : Tot string = match k.pk_kind with | PK_base hd -> Printf.sprintf "%skind_%s" (maybe_mname_prefix mname hd) (print_ident hd) | PK_list -> "kind_nlist" | PK_t_at_most -> "kind_t_at_most" | PK_t_exact -> "kind_t_exact" | PK_return -> "ret_kind" | PK_impos -> "impos_kind" | PK_and_then k1 k2 -> Printf.sprintf "(and_then_kind %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_glb k1 k2 -> Printf.sprintf "(glb %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_filter k -> Printf.sprintf "(filter_kind %s)" (print_kind mname k) | PK_string -> "parse_string_kind" let rec print_action (mname:string) (a:action) : ML string = let print_atomic_action (a:atomic_action) : ML string = match a with | Action_return e -> Printf.sprintf "(action_return %s)" (print_expr mname e) | Action_abort -> "(action_abort())" | Action_field_pos_64 -> "(action_field_pos_64())" | Action_field_pos_32 -> "(action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr -> "(action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr_after sz write_to -> Printf.sprintf "(action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)" (print_expr mname sz) (print_ident write_to) | Action_field_ptr_after_with_setter sz write_to_field write_to_obj -> Printf.sprintf "(action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))" (print_expr mname sz) (print_ident write_to_field) (print_expr mname write_to_obj) | Action_deref i -> Printf.sprintf "(action_deref %s)" (print_ident i) | Action_assignment lhs rhs -> Printf.sprintf "(action_assignment %s %s)" (print_ident lhs) (print_expr mname rhs) | Action_call f args -> Printf.sprintf "(mk_extern_action (%s %s))" (print_ident f) (String.concat " " (List.map (print_expr mname) args)) in match a with | Atomic_action a -> print_atomic_action a | Action_seq hd tl -> Printf.sprintf "(action_seq %s %s)" (print_atomic_action hd) (print_action mname tl) | Action_ite hd then_ else_ -> Printf.sprintf "(action_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname hd) (print_action mname then_) (print_action mname else_) | Action_let i a k -> Printf.sprintf "(action_bind \"%s\" %s (fun %s -> %s))" (print_ident i) (print_atomic_action a) (print_ident i) (print_action mname k) | Action_act a -> Printf.sprintf "(action_act %s)" (print_action mname a) let print_typedef_name (mname:string) (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> Printf.sprintf "(%s:%s)" (print_ident id) (print_typ mname t)) tdn.td_params)) let print_typedef_typ (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> (print_ident id)) tdn.td_params)) let print_typedef_body (mname:string) (b:typedef_body) : ML string = match b with | TD_abbrev t -> print_typ mname t | TD_struct fields -> let print_field (sf:field) : ML string = Printf.sprintf "%s : %s%s" (print_ident sf.sf_ident) (print_typ mname sf.sf_typ) (if sf.sf_dependence then " (*dep*)" else "") in let fields = String.concat ";\n" (List.map print_field fields) in Printf.sprintf "{\n%s\n}" fields let print_typedef_actions_inv_and_fp (td:type_decl) = //we need to add output loc to the modifies locs //if there is an output type type parameter let should_add_output_loc = List.Tot.existsb (fun (_, t) -> is_output_type t || is_extern_type t) td.decl_name.td_params in let pointers = //get only non output type pointers List.Tot.filter (fun (x, t) -> T_pointer? t && not (is_output_type t || is_extern_type t)) td.decl_name.td_params in let inv = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "((ptr_inv %s) `conj_inv` %s)" (print_ident x) out) pointers "true_inv" in let fp = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "(eloc_union (ptr_loc %s) %s)" (print_ident x) out) pointers (if should_add_output_loc then "output_loc" else "eloc_none") in inv, fp let print_comments (cs:list string) : string = match cs with | [] -> "" | _ -> let c = String.concat "\\n\\\n" cs in Printf.sprintf " (Comment \"%s\")" c let print_attributes (entrypoint:bool) (attrs:decl_attributes) : string = match attrs.comments with | [] -> if entrypoint || attrs.is_exported then "" else if attrs.should_inline then "inline_for_extraction noextract\n" else "[@ (CInline)]\n" | cs -> Printf.sprintf "[@ %s %s]\n%s" (print_comments cs) (if not entrypoint && not attrs.is_exported && not attrs.should_inline then "(CInline)" else "") (if attrs.should_inline then "inline_for_extraction\n" else "") /// Printing a decl for M.Types.fst /// /// Print all the definitions, and for a Type_decl, only the type definition let maybe_print_type_equality (mname:string) (td:type_decl) : ML string = if td.decl_name.td_entrypoint then let equate_types_list = Options.get_equate_types_list () in (match (List.tryFind (fun (_, m) -> m = mname) equate_types_list) with | Some (a, _) -> let typname = A.ident_name td.decl_name.td_name in Printf.sprintf "\n\nlet _ = assert (%s.Types.%s == %s) by (FStar.Tactics.trefl ())\n\n" a typname typname | None -> "") else "" let print_definition (mname:string) (d:decl { Definition? (fst d)} ) : ML string = match fst d with | Definition (x, [], T_app ({Ast.v={Ast.name="field_id"}}) _ _, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot field_id by (FStar.Tactics.trivial())\n\n" (print_comments (snd d).comments) (print_field_id_name x) (A.print_constant c) | Definition (x, [], t, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot %s\n\n" (print_comments (snd d).comments) (print_ident x) (A.print_constant c) (print_typ mname t) | Definition (x, params, typ, expr) -> let x_ps = { td_name = x; td_params = params; td_entrypoint = false } in Printf.sprintf "%slet %s : %s = %s\n\n" (print_attributes false (snd d)) (print_typedef_name mname x_ps) (print_typ mname typ) (print_expr mname expr) let print_assumption (mname:string) (d:decl { Assumption? (fst d) } ) : ML string = match fst d with | Assumption (x, t) -> Printf.sprintf "%sassume\nval %s : %s\n\n" (if (snd d).is_if_def then "[@@ CIfDef ]\n" else "") (print_ident x) (print_typ mname t) let print_decl_for_types (mname:string) (d:decl) : ML string = match fst d with | Assumption _ -> "" | Definition _ -> print_definition mname d | Type_decl td -> Printf.sprintf "noextract\ninline_for_extraction\ntype %s = %s\n\n" (print_typedef_name mname td.decl_name) (print_typedef_body mname td.decl_typ) `strcat` maybe_print_type_equality mname td | Output_type _ | Output_type_expr _ _ | Extern_type _ | Extern_fn _ _ _ | Extern_probe _ -> "" /// Print a decl for M.fst /// /// No need to print Definition(s), they are `include`d from M.Types.fst /// /// For a Type_decl, if it is an entry point, we need to emit a definition since /// there is a corresponding declaration in the .fsti /// We make the definition as simply the definition in M.Types.fst let is_type_abbreviation (td:type_decl) : bool = match td.decl_typ with | TD_abbrev _ -> true | TD_struct _ -> false let external_api_include (modul:string) (ds:list decl) : string = if has_external_api ds then Printf.sprintf "open %s.ExternalAPI\n\n" modul else "" #push-options "--z3rlimit_factor 4" let pascal_case name : ML string = let chars = String.list_of_string name in let has_underscore = List.mem '_' chars in let keep, up, low = 0, 1, 2 in if has_underscore then let what_next : ref int = alloc up in let rewrite_char c : ML (list FStar.Char.char) = match c with | '_' -> what_next := up; [] | c -> let c_next = let n = !what_next in if n = keep then c else if n = up then FStar.Char.uppercase c else FStar.Char.lowercase c in let _ = if Char.uppercase c = c then what_next := low else if Char.lowercase c = c then what_next := keep in [c_next] in let chars = List.collect rewrite_char (String.list_of_string name) in String.string_of_list chars else if String.length name = 0 then name else String.uppercase (String.sub name 0 1) ^ String.sub name 1 (String.length name - 1) let uppercase (name:string) : string = String.uppercase name let rec print_as_c_type (t:typ) : ML string = let open Ast in match t with | T_pointer t -> Printf.sprintf "%s*" (print_as_c_type t) | T_app {v={name="Bool"}} _ [] -> "BOOLEAN" | T_app {v={name="UINT8"}} _ [] -> "uint8_t" | T_app {v={name="UINT16"}} _ [] -> "uint16_t" | T_app {v={name="UINT32"}} _ [] -> "uint32_t" | T_app {v={name="UINT64"}} _ [] -> "uint64_t" | T_app {v={name="PUINT8"}} _ [] -> "uint8_t*" | T_app {v={name=x}} KindSpec [] -> x | T_app {v={name=x}} _ [] -> uppercase x | _ -> "__UNKNOWN__" let error_code_macros = //To be kept consistent with EverParse3d.ErrorCode.error_reason_of_result "#define EVERPARSE_ERROR_GENERIC 1uL\n\ #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL\n\ #define EVERPARSE_ERROR_IMPOSSIBLE 3uL\n\ #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL\n\ #define EVERPARSE_ERROR_ACTION_FAILED 5uL\n\ #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL\n\ #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL\n" let rec get_output_typ_dep (modul:string) (t:typ) : ML (option string) = match t with | T_app {v={modul_name=None}} _ _ -> None | T_app {v={modul_name=Some m}} _ _ -> if m = modul then None else Some m | T_pointer t -> get_output_typ_dep modul t | _ -> failwith "get_typ_deps: unexpected output type" let wrapper_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_check_%s" modul fn |> pascal_case let validator_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_validate_%s" modul fn |> pascal_case let print_c_entry (produce_everparse_error: opt_produce_everparse_error) (modul: string) (env: global_env) (ds:list decl) : ML (string & string) = let default_error_handler = "static\n\ void DefaultErrorHandler(\n\t\ const char *typename_s,\n\t\ const char *fieldname,\n\t\ const char *reason,\n\t\ uint64_t error_code,\n\t\ uint8_t *context,\n\t\ EVERPARSE_INPUT_BUFFER input,\n\t\ uint64_t start_pos)\n\ {\n\t\ EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context;\n\t\ EverParseDefaultErrorHandler(\n\t\t\ typename_s,\n\t\t\ fieldname,\n\t\t\ reason,\n\t\t\ error_code,\n\t\t\ frame,\n\t\t\ input,\n\t\t\ start_pos\n\t\ );\n\ }" in let input_stream_binding = Options.get_input_stream_binding () in let is_input_stream_buffer = HashingOptions.InputStreamBuffer? input_stream_binding in let wrapped_call_buffer name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame;\n\t\ frame.filled = FALSE;\n\t\ %s\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0);\n\t\ if (EverParseIsError(result))\n\t\ {\n\t\t\ if (frame.filled)\n\t\t\ {\n\t\t\t\ %sEverParseError(frame.typename_s, frame.fieldname, frame.reason);\n\t\t\ }\n\t\t\ return FALSE;\n\t\ }\n\t\ return TRUE;" (if is_input_stream_buffer then "" else "EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t") name params modul in let wrapped_call_stream name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame =\n\t\ { .filled = FALSE,\n\t\ .typename_s = \"UNKNOWN\",\n\t\ .fieldname = \"UNKNOWN\",\n\t\ .reason = \"UNKNOWN\",\n\t\ .error_code = 0uL\n\ };\n\ EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, input, 0);\n\t\ uint64_t parsedSize = EverParseGetValidatorErrorPos(result);\n\ if (EverParseIsError(result))\n\t\ {\n\t\t\ EverParseHandleError(_extra, parsedSize, frame.typename_s, frame.fieldname, frame.reason, frame.error_code);\n\t\t\ }\n\t\ EverParseRetreat(_extra, base, parsedSize);\n\ return parsedSize;" name params in let mk_param (name: string) (typ: string) : Tot param = (A.with_range (A.to_ident' name) A.dummy_range, T_app (A.with_range (A.to_ident' typ) A.dummy_range) A.KindSpec []) in let print_one_validator (d:type_decl) : ML (string & string) = let params = d.decl_name.td_params @ (if is_input_stream_buffer then [] else [mk_param "_extra" "EVERPARSE_EXTRA_T"]) in let print_params (ps:list param) : ML string = let params = String.concat ", " (List.map (fun (id, t) -> Printf.sprintf "%s %s" (print_as_c_type t) (print_ident id)) ps) in match ps with | [] -> params | _ -> params ^ ", " in let print_arguments (ps:list param) : Tot string = let params = String.concat ", " (List.Tot.map (fun (id, t) -> if is_output_type t //output type pointers are uint8_t* in the F* generated code then (print_ident id) else print_ident id) ps) in match ps with | [] -> params | _ -> params ^ ", " in let wrapper_name = wrapper_name modul d.decl_name.td_name.A.v.A.name in let signature = if is_input_stream_buffer then Printf.sprintf "BOOLEAN %s(%suint8_t *base, uint32_t len)" wrapper_name (print_params params) else Printf.sprintf "uint64_t %s(%sEVERPARSE_INPUT_STREAM_BASE base)" wrapper_name (print_params params) in let validator_name = validator_name modul d.decl_name.td_name.A.v.A.name in let impl = let body = if is_input_stream_buffer then wrapped_call_buffer validator_name (print_arguments params) else wrapped_call_stream validator_name (print_arguments params) in Printf.sprintf "%s {\n\t%s\n}" signature body in signature ^";", impl in let signatures_output_typ_deps = List.fold_left (fun deps (d, _) -> match d with | Type_decl d -> if d.decl_name.td_entrypoint then let params = d.decl_name.td_params in List.fold_left (fun deps (_, t) -> match get_output_typ_dep modul t with | Some dep -> if List.mem dep deps then deps else deps@[dep] | _ -> deps) deps params else deps | _ -> deps) [] ds in let signatures, impls = List.split (List.collect (fun d -> match fst d with | Type_decl d -> if d.decl_name.td_entrypoint then [print_one_validator d] else [] | _ -> []) ds) in let external_defs_includes = if not (Options.get_emit_output_types_defs ()) then "" else let deps = if List.length signatures_output_typ_deps = 0 then "" else String.concat "" (List.map (fun dep -> Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" dep) signatures_output_typ_deps) in let self = if has_output_types ds || has_extern_types ds then Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n" modul else "" in Printf.sprintf "%s\n%s\n\n" deps self in let header = Printf.sprintf "#include \"EverParseEndianness.h\"\n\ %s\n\ %s\ #ifdef __cplusplus\n\ extern \"C\" {\n\ #endif\n\ %s\n\ #ifdef __cplusplus\n\ }\n\ #endif\n" error_code_macros external_defs_includes (signatures |> String.concat "\n\n") in let input_stream_include = HashingOptions.input_stream_include input_stream_binding in let header = if input_stream_include = "" then header else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include header in let add_includes = Options.make_includes () in let header = Printf.sprintf "%s%s" add_includes header in let error_callback_proto = if HashingOptions.InputStreamBuffer? input_stream_binding then Printf.sprintf "void %sEverParseError(const char *StructName, const char *FieldName, const char *Reason)%s" modul (if produce_everparse_error = Some ProduceEverParseError then "{(void) StructName; (void) FieldName; (void) Reason;}" else ";") else "" in let impl = Printf.sprintf "#include \"%sWrapper.h\"\n\ #include \"EverParse.h\"\n\ #include \"%s.h\"\n\ %s\n\n\ %s\n\n\ %s\n" modul modul error_callback_proto default_error_handler (impls |> String.concat "\n\n") in let impl = if input_stream_include = "" then impl else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include impl in let impl = Printf.sprintf "%s%s" add_includes impl in header, impl /// Functions for printing setters and getters for output expressions let rec out_bt_name (t:typ) : ML string = match t with | T_app i _ _ -> A.ident_name i | T_pointer t -> out_bt_name t | _ -> failwith "Impossible, out_bt_name received a non output type!" let out_expr_bt_name (oe:output_expr) : ML string = out_bt_name oe.oe_bt (* * Walks over the output expressions AST and constructs a string *) let rec out_fn_name (oe:output_expr) : ML string = match oe.oe_expr with | T_OE_id _ -> out_expr_bt_name oe | T_OE_star oe -> Printf.sprintf "%s_star" (out_fn_name oe) | T_OE_addrof oe -> Printf.sprintf "%s_addrof" (out_fn_name oe) | T_OE_deref oe f -> Printf.sprintf "%s_deref_%s" (out_fn_name oe) (A.ident_name f) | T_OE_dot oe f -> Printf.sprintf "%s_dot_%s" (out_fn_name oe) (A.ident_name f) module H = Hashtable type set = H.t string unit (* * In the printing functions, a hashtable tracks that we print a defn. only once * * E.g. multiple output expressions may require a val decl. for types, * we need to print them only once each *) let rec base_output_type (t:typ) : ML A.ident = match t with | T_app id A.KindOutput [] -> id | T_pointer t -> base_output_type t | _ -> failwith "Target.base_output_type called with a non-output type" #push-options "--fuel 1" let rec print_output_type_val (tbl:set) (t:typ) : ML string = let open A in if is_output_type t then let s = print_output_type false t in if H.try_find tbl s <> None then "" else let _ = H.insert tbl s () in assert (is_output_type t); match t with | T_app id KindOutput [] -> Printf.sprintf "\n\nval %s : Type0\n\n" s | T_pointer bt -> let bs = print_output_type_val tbl bt in bs ^ (Printf.sprintf "\n\ninline_for_extraction noextract type %s = bpointer %s\n\n" s (print_output_type false bt)) else "" #pop-options let rec print_out_expr' (oe:output_expr') : ML string = match oe with | T_OE_id id -> A.ident_to_string id | T_OE_star o -> Printf.sprintf "*(%s)" (print_out_expr' o.oe_expr) | T_OE_addrof o -> Printf.sprintf "&(%s)" (print_out_expr' o.oe_expr) | T_OE_deref o i -> Printf.sprintf "(%s)->%s" (print_out_expr' o.oe_expr) (A.ident_to_string i) | T_OE_dot o i -> Printf.sprintf "(%s).%s" (print_out_expr' o.oe_expr) (A.ident_to_string i) (* * F* val for the setter for the output expression *) let print_out_expr_set_fstar (tbl:set) (mname:string) (oe:output_expr) : ML string = let fn_name = Printf.sprintf "set_%s" (out_fn_name oe) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); //TODO: module name? let fn_arg1_t = print_typ mname oe.oe_bt in let fn_arg2_t = (* * If bitwidth is not None, * then output the size restriction in the refinement * Is there a better way to output it? *) if oe.oe_bitwidth = None then print_typ mname oe.oe_t else begin Printf.sprintf "(i:%s{FStar.UInt.size (FStar.Integers.v i) %d})" (print_typ mname oe.oe_t) (Some?.v oe.oe_bitwidth) end in Printf.sprintf "\n\nval %s (_:%s) (_:%s) : extern_action (NonTrivial output_loc)\n\n" fn_name fn_arg1_t fn_arg2_t let rec base_id_of_output_expr (oe:output_expr) : A.ident = match oe.oe_expr with | T_OE_id id -> id | T_OE_star oe | T_OE_addrof oe | T_OE_deref oe _ | T_OE_dot oe _ -> base_id_of_output_expr oe (* * C defn. for the setter for the output expression *) let print_out_expr_set (tbl:set) (oe:output_expr) : ML string = let fn_name = pascal_case (Printf.sprintf "set_%s" (out_fn_name oe)) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); let fn_arg1_t = print_as_c_type oe.oe_bt in let fn_arg1_name = base_id_of_output_expr oe in let fn_arg2_t = print_as_c_type oe.oe_t in let fn_arg2_name = "__v" in let fn_body = Printf.sprintf "%s = %s;" (print_out_expr' oe.oe_expr) fn_arg2_name in let fn = Printf.sprintf "void %s (%s %s, %s %s){\n %s;\n}\n" fn_name fn_arg1_t (A.ident_name fn_arg1_name) fn_arg2_t fn_arg2_name fn_body in Printf.sprintf "\n\n%s\n\n" fn (* * F* val for the getter for the output expression *) let print_out_expr_get_fstar (tbl:set) (mname:string) (oe:output_expr) : ML string = let fn_name = Printf.sprintf "get_%s" (out_fn_name oe) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); let fn_arg1_t = print_typ mname oe.oe_bt in let fn_res = print_typ mname oe.oe_t in //No bitfields, we could enforce? Printf.sprintf "\n\nval %s : %s -> %s\n\n" fn_name fn_arg1_t fn_res (* * C defn. for the getter for the output expression *) let print_out_expr_get(tbl:set) (oe:output_expr) : ML string = let fn_name = pascal_case (Printf.sprintf "get_%s" (out_fn_name oe)) in match H.try_find tbl fn_name with | Some _ -> "" | _ -> H.insert tbl fn_name (); let fn_arg1_t = print_as_c_type oe.oe_bt in let fn_arg1_name = base_id_of_output_expr oe in let fn_res = print_as_c_type oe.oe_t in let fn_body = Printf.sprintf "return %s;" (print_out_expr' oe.oe_expr) in let fn = Printf.sprintf "%s %s (%s %s){\n %s;\n}\n" fn_res fn_name fn_arg1_t (A.ident_name fn_arg1_name) fn_body in Printf.sprintf "\n\n%s\n\n" fn let output_setter_name lhs = Printf.sprintf "set_%s" (out_fn_name lhs) let output_getter_name lhs = Printf.sprintf "get_%s" (out_fn_name lhs) let output_base_var lhs = base_id_of_output_expr lhs let print_external_types_fstar_interpreter (modul:string) (ds:decls) : ML string = let tbl = H.create 10 in let s = String.concat "" (ds |> List.map (fun d -> match fst d with | Output_type ot -> let t = T_app ot.out_typ_names.typedef_abbrev A.KindOutput [] in Printf.sprintf "%s%s" (print_output_type_val tbl t) (print_output_type_val tbl (T_pointer t)) | Extern_type i -> Printf.sprintf "\n\nval %s : Type0\n\n" (print_ident i) | _ -> "")) in Printf.sprintf "module %s.ExternalTypes\n\n\ open EverParse3d.Prelude\n\ open EverParse3d.Actions.All\n\n%s" modul s let print_external_api_fstar_interpreter (modul:string) (ds:decls) : ML string = let tbl = H.create 10 in let s = String.concat "" (ds |> List.map (fun d -> match fst d with // | Output_type ot -> // let t = T_app ot.out_typ_names.typedef_name A.KindOutput [] in // Printf.sprintf "%s%s" // (print_output_type_val tbl t) // (print_output_type_val tbl (T_pointer t)) | Output_type_expr oe is_get -> Printf.sprintf "%s" // (print_output_type_val tbl oe.oe_bt) // (print_output_type_val tbl oe.oe_t) (if not is_get then print_out_expr_set_fstar tbl modul oe else print_out_expr_get_fstar tbl modul oe) | Extern_type i -> Printf.sprintf "\n\nval %s : Type0\n\n" (print_ident i) | Extern_fn f ret params -> Printf.sprintf "\n\nval %s %s : extern_action (NonTrivial output_loc)\n" (print_ident f) (String.concat " " (params |> List.map (fun (i, t) -> Printf.sprintf "(%s:%s)" (print_ident i) (print_typ modul t)))) | Extern_probe f -> Printf.sprintf "\n\nval %s : EverParse3d.CopyBuffer.probe_fn\n\n" (print_ident f) | _ -> "")) in let external_types_include = if has_output_types ds || has_extern_types ds then Printf.sprintf "include %s.ExternalTypes\n\n" modul else "" in Printf.sprintf "module %s.ExternalAPI\n\n\ open EverParse3d.Prelude\n\ open EverParse3d.Actions.All\n\ open EverParse3d.Interpreter\n\ %s\n\ noextract val output_loc : eloc\n\n%s" modul external_types_include s // // When printing output expressions in C, // the output types may be coming from some other module // This function gets all the dependencies from output expressions // so that they can be added in the M_OutputTypes.c file // let get_out_exprs_deps (modul:string) (ds:decls) : ML (list string) = let maybe_add_dep (deps:list string) (s:option string) : list string = match s with | None -> deps | Some s -> if List.mem s deps then deps else deps@[s] in List.fold_left (fun deps (d, _) -> match d with | Output_type_expr oe _ -> maybe_add_dep (maybe_add_dep deps (get_output_typ_dep modul oe.oe_bt)) (get_output_typ_dep modul oe.oe_t) | _ -> deps) [] ds let print_out_exprs_c modul (ds:decls) : ML string = let tbl = H.create 10 in let deps = get_out_exprs_deps modul ds in let emit_output_types_defs = Options.get_emit_output_types_defs () in let dep_includes = if List.length deps = 0 || not emit_output_types_defs then "" else String.concat "" (List.map (fun s -> FStar.Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" s) deps) in let self_external_typedef_include = if has_output_types ds && emit_output_types_defs then Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" modul else "" in (Printf.sprintf "%s#include<stdint.h>\n\n\ %s\ %s\ #if defined(__cplusplus)\n\ extern \"C\" {\n\ #endif\n\n" (Options.make_includes ()) dep_includes self_external_typedef_include) ^ (String.concat "" (ds |> List.map (fun d -> match fst d with | Output_type_expr oe is_get -> if not is_get then print_out_expr_set tbl oe else print_out_expr_get tbl oe | _ -> ""))) ^ ("#if defined(__cplusplus)\n\ }\n\ #endif\n\n")
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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": 4, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Ast.typ -> FStar.All.ML Target.typ
FStar.All.ML
[ "ml" ]
[]
[ "Ast.typ", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.typ'", "Ast.with_meta_t", "Target.T_pointer", "Target.typ", "Target.atyp_to_ttyp", "Ast.ident", "Ast.t_kind", "Prims.list", "Ast.either", "Ast.expr", "Ast.out_expr", "Target.T_app", "Prims.Nil", "FStar.Pervasives.either", "Target.expr" ]
[ "recursion" ]
false
true
false
false
false
let rec atyp_to_ttyp (t: A.typ) : ML typ =
match t.v with | A.Pointer t -> let t = atyp_to_ttyp t in T_pointer t | A.Type_app hd _b _args -> T_app hd _b []
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.lemma_pow2_128
val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)]
val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)]
let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime)
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 22, "start_col": 0, "start_line": 19 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime)
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 128) (ensures Prims.pow2 n < Spec.Poly1305.prime) [SMTPat (Prims.pow2 n)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Spec.Poly1305.prime", "Prims.unit", "Prims._assert", "Prims.op_LessThanOrEqual", "FStar.Math.Lemmas.pow2_le_compat" ]
[]
true
false
true
false
false
let lemma_pow2_128 n =
Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime)
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.zero
val zero (w: lanes) : elem w
val zero (w: lanes) : elem w
let zero (w:lanes) : elem w = to_elem w 0
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 35, "start_col": 0, "start_line": 35 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
w: Hacl.Spec.Poly1305.Vec.lanes -> Hacl.Spec.Poly1305.Vec.elem w
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Hacl.Spec.Poly1305.Vec.to_elem", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let zero (w: lanes) : elem w =
to_elem w 0
false
Pulse.Lib.Forall.fst
Pulse.Lib.Forall.uquant
val uquant (#a: Type u#a) (p: (a -> vprop)) : vprop
val uquant (#a: Type u#a) (p: (a -> vprop)) : vprop
let uquant (#a:Type u#a) (p: a -> vprop) : vprop = exists* (v:vprop). pure (is_forall v p) ** token v
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.Forall.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 11, "end_line": 18, "start_col": 0, "start_line": 14 }
module Pulse.Lib.Forall open Pulse.Main open Pulse.Lib.Core module F = FStar.FunctionalExtensionality let token (v:vprop) = v let universal_quantifier #a (v:vprop) (p: a -> vprop) = x:a -> stt_ghost unit v (fun _ -> p x) let is_forall #a (v:vprop) (p:a -> vprop) = squash (universal_quantifier #a v p)
{ "checked_file": "/", "dependencies": [ "Pulse.Main.fsti.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.Forall.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "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
p: (_: a -> Pulse.Lib.Core.vprop) -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Core.vprop", "Pulse.Lib.Core.op_exists_Star", "Pulse.Lib.Core.op_Star_Star", "Pulse.Lib.Core.pure", "Pulse.Lib.Forall.is_forall", "Pulse.Lib.Forall.token" ]
[]
false
false
false
true
false
let uquant (#a: Type u#a) (p: (a -> vprop)) : vprop =
exists* (v: vprop). pure (is_forall v p) ** token v
false
Pulse.Lib.Forall.fst
Pulse.Lib.Forall.elim_forall
val elim_forall (#a:Type) (#p:a->vprop) (x:a) : stt_ghost unit (forall* x. p x) (fun _ -> p x)
val elim_forall (#a:Type) (#p:a->vprop) (x:a) : stt_ghost unit (forall* x. p x) (fun _ -> p x)
let elim_forall (#a:Type u#a) (#p:a->vprop) (x:a) : stt_ghost unit (forall* (x:a). p x) (fun _ -> p x) = let m1 = elim_exists #vprop (fun (v:vprop) -> pure (is_forall v p) ** token v) in let m2 (v:Ghost.erased vprop) : stt_ghost unit (pure (is_forall v p) ** token v) (fun _ -> p x) = bind_ghost (frame_ghost (token v) (elim_pure_explicit (is_forall v p))) (fun (pf:squash (is_forall v p)) -> let f = extract_q v p pf in sub_ghost (emp ** Ghost.reveal v) (fun _ -> p x) (vprop_equiv_sym _ _ (vprop_equiv_unit _)) (intro_vprop_post_equiv (fun _ -> p x) (fun _ -> p x) (fun _ -> vprop_equiv_refl (p x))) (f x)) in bind_ghost m1 m2
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.Forall.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 18, "end_line": 99, "start_col": 0, "start_line": 72 }
module Pulse.Lib.Forall open Pulse.Main open Pulse.Lib.Core module F = FStar.FunctionalExtensionality let token (v:vprop) = v let universal_quantifier #a (v:vprop) (p: a -> vprop) = x:a -> stt_ghost unit v (fun _ -> p x) let is_forall #a (v:vprop) (p:a -> vprop) = squash (universal_quantifier #a v p) let uquant (#a:Type u#a) (p: a -> vprop) : vprop = exists* (v:vprop). pure (is_forall v p) ** token v let ( forall* ) (#a:Type u#a) (p:a -> vprop) = uquant #a (F.on_dom a p) let extract_q #a (v:vprop) (p:a -> vprop) (pf:squash (is_forall v p)) : universal_quantifier #a v p = let f : squash (universal_quantifier #a v p) = FStar.Squash.join_squash pf in let f : squash (exists (x:universal_quantifier #a v p). True) = FStar.Squash.bind_squash f (fun x -> (introduce exists (x:universal_quantifier #a v p). True with x and ())) in let x:Ghost.erased (universal_quantifier #a v p) = FStar.IndefiniteDescription.indefinite_description_tot (universal_quantifier #a v p) (fun x -> True) in Ghost.reveal x ```pulse ghost fn return (#a:Type u#2) (x:a) requires emp returns v:a ensures pure (v == x) { x } ``` ```pulse ghost fn elim_forall' (#a:Type u#0) (#p:a->vprop) (x:a) requires forall* (x:a). p x ensures p x { unfold (forall* x. p x); unfold (uquant #a (F.on_dom a (fun x -> p x))); with v. assert (token v); unfold token; let f = return (extract_q (Ghost.reveal v) (F.on_dom a (fun x -> p x)) ()); f x; rewrite ((F.on_dom a (fun x -> p x)) x) as (p x); } ```
{ "checked_file": "/", "dependencies": [ "Pulse.Main.fsti.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.Forall.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "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: a -> Pulse.Lib.Core.stt_ghost Prims.unit (forall* (x: a). p x) (fun _ -> p x)
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Core.vprop", "Pulse.Lib.Core.bind_ghost", "FStar.Ghost.erased", "Prims.unit", "Pulse.Lib.Core.op_exists_Star", "Pulse.Lib.Core.op_Star_Star", "Pulse.Lib.Core.pure", "Pulse.Lib.Forall.is_forall", "Pulse.Lib.Forall.token", "FStar.Ghost.reveal", "Pulse.Lib.Core.stt_ghost", "Prims.squash", "Pulse.Lib.Core.emp", "Pulse.Lib.Core.frame_ghost", "Pulse.Lib.Core.elim_pure_explicit", "Pulse.Lib.Core.sub_ghost", "Pulse.Lib.Core.vprop_equiv_sym", "Pulse.Lib.Core.vprop_equiv_unit", "Pulse.Lib.Core.intro_vprop_post_equiv", "Pulse.Lib.Core.vprop_equiv_refl", "Pulse.Lib.Core.vprop_equiv", "Pulse.Lib.Forall.universal_quantifier", "Pulse.Lib.Forall.extract_q", "Pulse.Lib.Core.elim_exists", "Pulse.Lib.Forall.op_forall_Star" ]
[]
false
false
false
false
false
let elim_forall (#a: Type u#a) (#p: (a -> vprop)) (x: a) : stt_ghost unit (forall* (x: a). p x) (fun _ -> p x) =
let m1 = elim_exists #vprop (fun (v: vprop) -> pure (is_forall v p) ** token v) in let m2 (v: Ghost.erased vprop) : stt_ghost unit (pure (is_forall v p) ** token v) (fun _ -> p x) = bind_ghost (frame_ghost (token v) (elim_pure_explicit (is_forall v p))) (fun (pf: squash (is_forall v p)) -> let f = extract_q v p pf in sub_ghost (emp ** Ghost.reveal v) (fun _ -> p x) (vprop_equiv_sym _ _ (vprop_equiv_unit _)) (intro_vprop_post_equiv (fun _ -> p x) (fun _ -> p x) (fun _ -> vprop_equiv_refl (p x))) (f x)) in bind_ghost m1 m2
false
IntroGhost.fst
IntroGhost.my_inv
val my_inv (b: bool) (r: R.ref int) : vprop
val my_inv (b: bool) (r: R.ref int) : vprop
let my_inv (b:bool) (r:R.ref int) : vprop = exists* v. R.pts_to r v ** pure ( b == (v = 0) )
{ "file_name": "share/steel/examples/pulse/bug-reports/IntroGhost.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 27, "end_line": 30, "start_col": 0, "start_line": 27 }
(* 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 IntroGhost open Pulse.Lib.Pervasives module R = Pulse.Lib.Reference (* invariant pattern makes the condition var b a ghost var, making it impossible to infer the entry condition to the loop because the condition var outside the loop is not ghost
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Reference.fsti.checked", "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "IntroGhost.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "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
b: Prims.bool -> r: Pulse.Lib.Reference.ref Prims.int -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Pulse.Lib.Reference.ref", "Prims.int", "Pulse.Lib.Core.op_exists_Star", "Pulse.Lib.Core.op_Star_Star", "Pulse.Lib.Reference.pts_to", "PulseCore.FractionalPermission.full_perm", "Pulse.Lib.Core.pure", "Prims.eq2", "Prims.op_Equality", "Pulse.Lib.Core.vprop" ]
[]
false
false
false
true
false
let my_inv (b: bool) (r: R.ref int) : vprop =
exists* v. R.pts_to r v ** pure (b == (v = 0))
false
Pulse.Lib.Forall.fst
Pulse.Lib.Forall.vprop_equiv_forall
val vprop_equiv_forall (#a:Type) (p q: a -> vprop) (_:squash (forall x. p x == q x)) : vprop_equiv (op_forall_Star p) (op_forall_Star q)
val vprop_equiv_forall (#a:Type) (p q: a -> vprop) (_:squash (forall x. p x == q x)) : vprop_equiv (op_forall_Star p) (op_forall_Star q)
let vprop_equiv_forall (#a:Type) (p q: a -> vprop) (_:squash (forall x. p x == q x)) : vprop_equiv (op_forall_Star p) (op_forall_Star q) = FStar.FunctionalExtensionality.extensionality _ _ p q; vprop_equiv_refl (op_forall_Star p)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.Forall.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 131, "start_col": 0, "start_line": 125 }
module Pulse.Lib.Forall open Pulse.Main open Pulse.Lib.Core module F = FStar.FunctionalExtensionality let token (v:vprop) = v let universal_quantifier #a (v:vprop) (p: a -> vprop) = x:a -> stt_ghost unit v (fun _ -> p x) let is_forall #a (v:vprop) (p:a -> vprop) = squash (universal_quantifier #a v p) let uquant (#a:Type u#a) (p: a -> vprop) : vprop = exists* (v:vprop). pure (is_forall v p) ** token v let ( forall* ) (#a:Type u#a) (p:a -> vprop) = uquant #a (F.on_dom a p) let extract_q #a (v:vprop) (p:a -> vprop) (pf:squash (is_forall v p)) : universal_quantifier #a v p = let f : squash (universal_quantifier #a v p) = FStar.Squash.join_squash pf in let f : squash (exists (x:universal_quantifier #a v p). True) = FStar.Squash.bind_squash f (fun x -> (introduce exists (x:universal_quantifier #a v p). True with x and ())) in let x:Ghost.erased (universal_quantifier #a v p) = FStar.IndefiniteDescription.indefinite_description_tot (universal_quantifier #a v p) (fun x -> True) in Ghost.reveal x ```pulse ghost fn return (#a:Type u#2) (x:a) requires emp returns v:a ensures pure (v == x) { x } ``` ```pulse ghost fn elim_forall' (#a:Type u#0) (#p:a->vprop) (x:a) requires forall* (x:a). p x ensures p x { unfold (forall* x. p x); unfold (uquant #a (F.on_dom a (fun x -> p x))); with v. assert (token v); unfold token; let f = return (extract_q (Ghost.reveal v) (F.on_dom a (fun x -> p x)) ()); f x; rewrite ((F.on_dom a (fun x -> p x)) x) as (p x); } ``` let elim_forall (#a:Type u#a) (#p:a->vprop) (x:a) : stt_ghost unit (forall* (x:a). p x) (fun _ -> p x) = let m1 = elim_exists #vprop (fun (v:vprop) -> pure (is_forall v p) ** token v) in let m2 (v:Ghost.erased vprop) : stt_ghost unit (pure (is_forall v p) ** token v) (fun _ -> p x) = bind_ghost (frame_ghost (token v) (elim_pure_explicit (is_forall v p))) (fun (pf:squash (is_forall v p)) -> let f = extract_q v p pf in sub_ghost (emp ** Ghost.reveal v) (fun _ -> p x) (vprop_equiv_sym _ _ (vprop_equiv_unit _)) (intro_vprop_post_equiv (fun _ -> p x) (fun _ -> p x) (fun _ -> vprop_equiv_refl (p x))) (f x)) in bind_ghost m1 m2 let intro_forall (#a:Type) (#p:a->vprop) (v:vprop) (f_elim : (x:a -> stt_ghost unit v (fun _ -> p x))) : stt_ghost unit v (fun _ -> forall* x. p x) = let _ : squash (universal_quantifier v p) = FStar.Squash.return_squash f_elim in let m1 : stt_ghost unit (emp ** v) (fun _ -> pure (is_forall v p) ** v) = frame_ghost v (intro_pure (is_forall v p) ()) in let m2 () : stt_ghost unit (pure (is_forall v p) ** token v) (fun _ -> forall* x. p x) = intro_exists (fun (v:vprop) -> pure (is_forall v p) ** token v) v in let m = bind_ghost m1 m2 in sub_ghost v _ (vprop_equiv_unit _) (intro_vprop_post_equiv _ _ (fun _ -> vprop_equiv_refl _)) m
{ "checked_file": "/", "dependencies": [ "Pulse.Main.fsti.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.Forall.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "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
p: (_: a -> Pulse.Lib.Core.vprop) -> q: (_: a -> Pulse.Lib.Core.vprop) -> _: Prims.squash (forall (x: a). p x == q x) -> Pulse.Lib.Core.vprop_equiv (exists . p) (exists . q)
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Core.vprop", "Prims.squash", "Prims.l_Forall", "Prims.eq2", "Pulse.Lib.Core.vprop_equiv_refl", "Pulse.Lib.Forall.op_forall_Star", "Prims.unit", "FStar.FunctionalExtensionality.extensionality", "Pulse.Lib.Core.vprop_equiv" ]
[]
false
false
false
false
false
let vprop_equiv_forall (#a: Type) (p: (a -> vprop)) (q: (a -> vprop)) (_: squash (forall x. p x == q x)) : vprop_equiv (op_forall_Star p) (op_forall_Star q) =
FStar.FunctionalExtensionality.extensionality _ _ p q; vprop_equiv_refl (op_forall_Star p)
false
Pulse.Lib.Forall.fst
Pulse.Lib.Forall.extract_q
val extract_q (#a: _) (v: vprop) (p: (a -> vprop)) (pf: squash (is_forall v p)) : universal_quantifier #a v p
val extract_q (#a: _) (v: vprop) (p: (a -> vprop)) (pf: squash (is_forall v p)) : universal_quantifier #a v p
let extract_q #a (v:vprop) (p:a -> vprop) (pf:squash (is_forall v p)) : universal_quantifier #a v p = let f : squash (universal_quantifier #a v p) = FStar.Squash.join_squash pf in let f : squash (exists (x:universal_quantifier #a v p). True) = FStar.Squash.bind_squash f (fun x -> (introduce exists (x:universal_quantifier #a v p). True with x and ())) in let x:Ghost.erased (universal_quantifier #a v p) = FStar.IndefiniteDescription.indefinite_description_tot (universal_quantifier #a v p) (fun x -> True) in Ghost.reveal x
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.Forall.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 16, "end_line": 39, "start_col": 0, "start_line": 21 }
module Pulse.Lib.Forall open Pulse.Main open Pulse.Lib.Core module F = FStar.FunctionalExtensionality let token (v:vprop) = v let universal_quantifier #a (v:vprop) (p: a -> vprop) = x:a -> stt_ghost unit v (fun _ -> p x) let is_forall #a (v:vprop) (p:a -> vprop) = squash (universal_quantifier #a v p) let uquant (#a:Type u#a) (p: a -> vprop) : vprop = exists* (v:vprop). pure (is_forall v p) ** token v let ( forall* ) (#a:Type u#a) (p:a -> vprop) = uquant #a (F.on_dom a p)
{ "checked_file": "/", "dependencies": [ "Pulse.Main.fsti.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.Forall.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "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
v: Pulse.Lib.Core.vprop -> p: (_: a -> Pulse.Lib.Core.vprop) -> pf: Prims.squash (Pulse.Lib.Forall.is_forall v p) -> Pulse.Lib.Forall.universal_quantifier v p
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Core.vprop", "Prims.squash", "Pulse.Lib.Forall.is_forall", "FStar.Ghost.reveal", "Pulse.Lib.Forall.universal_quantifier", "FStar.Ghost.erased", "FStar.IndefiniteDescription.indefinite_description_tot", "Prims.l_True", "Prims.prop", "Prims.l_Exists", "FStar.Squash.bind_squash", "FStar.Classical.Sugar.exists_intro", "Prims.unit", "FStar.Squash.join_squash" ]
[]
false
false
false
false
false
let extract_q #a (v: vprop) (p: (a -> vprop)) (pf: squash (is_forall v p)) : universal_quantifier #a v p =
let f:squash (universal_quantifier #a v p) = FStar.Squash.join_squash pf in let f:squash (exists (x: universal_quantifier #a v p). True) = FStar.Squash.bind_squash f (fun x -> (introduce exists (x: universal_quantifier #a v p).True with x and ())) in let x:Ghost.erased (universal_quantifier #a v p) = FStar.IndefiniteDescription.indefinite_description_tot (universal_quantifier #a v p) (fun x -> True) in Ghost.reveal x
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.normalize_n
val normalize_n (#w: lanes) (r: pfelem) (acc: elem w) : pfelem
val normalize_n (#w: lanes) (r: pfelem) (acc: elem w) : pfelem
let normalize_n (#w:lanes) (r:pfelem) (acc:elem w) : pfelem = match w with | 1 -> normalize_1 r acc | 2 -> normalize_2 r acc | 4 -> normalize_4 r acc
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 110, "start_col": 0, "start_line": 106 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r let normalize_2 (r:pfelem) (acc:elem 2) : pfelem = let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[0] a.[1] let normalize_4 (r:pfelem) (acc:elem 4) : pfelem = let r2 = pfmul r r in let r3 = pfmul r2 r in let r4 = pfmul r2 r2 in let r4321 = create4 r4 r3 r2 r in let a = fmul acc r4321 in pfadd (pfadd (pfadd a.[0] a.[1]) a.[2]) a.[3]
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Hacl.Spec.Poly1305.Vec.pfelem -> acc: Hacl.Spec.Poly1305.Vec.elem w -> Hacl.Spec.Poly1305.Vec.pfelem
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.elem", "Hacl.Spec.Poly1305.Vec.normalize_1", "Hacl.Spec.Poly1305.Vec.normalize_2", "Hacl.Spec.Poly1305.Vec.normalize_4" ]
[]
false
false
false
false
false
let normalize_n (#w: lanes) (r: pfelem) (acc: elem w) : pfelem =
match w with | 1 -> normalize_1 r acc | 2 -> normalize_2 r acc | 4 -> normalize_4 r acc
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.load_elem1
val load_elem1 (b: Scalar.block) : elem 1
val load_elem1 (b: Scalar.block) : elem 1
let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b)
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 46, "start_col": 0, "start_line": 45 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Spec.Poly1305.block -> Hacl.Spec.Poly1305.Vec.elem 1
Prims.Tot
[ "total" ]
[]
[ "Spec.Poly1305.block", "Hacl.Spec.Poly1305.Vec.to_elem", "Lib.ByteSequence.nat_from_bytes_le", "Lib.IntTypes.SEC", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let load_elem1 (b: Scalar.block) : elem 1 =
to_elem 1 (nat_from_bytes_le b)
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.from_elem
val from_elem (#w: lanes) (x: elem w) : pfelem
val from_elem (#w: lanes) (x: elem w) : pfelem
let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0]
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 34, "start_col": 0, "start_line": 34 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Hacl.Spec.Poly1305.Vec.elem w -> Hacl.Spec.Poly1305.Vec.pfelem
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Hacl.Spec.Poly1305.Vec.elem", "Lib.Sequence.op_String_Access", "Hacl.Spec.Poly1305.Vec.pfelem" ]
[]
false
false
false
false
false
let from_elem (#w: lanes) (x: elem w) : pfelem =
x.[ 0 ]
false
Pulse.Lib.Forall.fst
Pulse.Lib.Forall.intro_forall
val intro_forall (#a:Type) (#p:a->vprop) (v:vprop) (f_elim : (x:a -> stt_ghost unit v (fun _ -> p x))) : stt_ghost unit v (fun _ -> forall* x. p x)
val intro_forall (#a:Type) (#p:a->vprop) (v:vprop) (f_elim : (x:a -> stt_ghost unit v (fun _ -> p x))) : stt_ghost unit v (fun _ -> forall* x. p x)
let intro_forall (#a:Type) (#p:a->vprop) (v:vprop) (f_elim : (x:a -> stt_ghost unit v (fun _ -> p x))) : stt_ghost unit v (fun _ -> forall* x. p x) = let _ : squash (universal_quantifier v p) = FStar.Squash.return_squash f_elim in let m1 : stt_ghost unit (emp ** v) (fun _ -> pure (is_forall v p) ** v) = frame_ghost v (intro_pure (is_forall v p) ()) in let m2 () : stt_ghost unit (pure (is_forall v p) ** token v) (fun _ -> forall* x. p x) = intro_exists (fun (v:vprop) -> pure (is_forall v p) ** token v) v in let m = bind_ghost m1 m2 in sub_ghost v _ (vprop_equiv_unit _) (intro_vprop_post_equiv _ _ (fun _ -> vprop_equiv_refl _)) m
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.Forall.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 123, "start_col": 0, "start_line": 101 }
module Pulse.Lib.Forall open Pulse.Main open Pulse.Lib.Core module F = FStar.FunctionalExtensionality let token (v:vprop) = v let universal_quantifier #a (v:vprop) (p: a -> vprop) = x:a -> stt_ghost unit v (fun _ -> p x) let is_forall #a (v:vprop) (p:a -> vprop) = squash (universal_quantifier #a v p) let uquant (#a:Type u#a) (p: a -> vprop) : vprop = exists* (v:vprop). pure (is_forall v p) ** token v let ( forall* ) (#a:Type u#a) (p:a -> vprop) = uquant #a (F.on_dom a p) let extract_q #a (v:vprop) (p:a -> vprop) (pf:squash (is_forall v p)) : universal_quantifier #a v p = let f : squash (universal_quantifier #a v p) = FStar.Squash.join_squash pf in let f : squash (exists (x:universal_quantifier #a v p). True) = FStar.Squash.bind_squash f (fun x -> (introduce exists (x:universal_quantifier #a v p). True with x and ())) in let x:Ghost.erased (universal_quantifier #a v p) = FStar.IndefiniteDescription.indefinite_description_tot (universal_quantifier #a v p) (fun x -> True) in Ghost.reveal x ```pulse ghost fn return (#a:Type u#2) (x:a) requires emp returns v:a ensures pure (v == x) { x } ``` ```pulse ghost fn elim_forall' (#a:Type u#0) (#p:a->vprop) (x:a) requires forall* (x:a). p x ensures p x { unfold (forall* x. p x); unfold (uquant #a (F.on_dom a (fun x -> p x))); with v. assert (token v); unfold token; let f = return (extract_q (Ghost.reveal v) (F.on_dom a (fun x -> p x)) ()); f x; rewrite ((F.on_dom a (fun x -> p x)) x) as (p x); } ``` let elim_forall (#a:Type u#a) (#p:a->vprop) (x:a) : stt_ghost unit (forall* (x:a). p x) (fun _ -> p x) = let m1 = elim_exists #vprop (fun (v:vprop) -> pure (is_forall v p) ** token v) in let m2 (v:Ghost.erased vprop) : stt_ghost unit (pure (is_forall v p) ** token v) (fun _ -> p x) = bind_ghost (frame_ghost (token v) (elim_pure_explicit (is_forall v p))) (fun (pf:squash (is_forall v p)) -> let f = extract_q v p pf in sub_ghost (emp ** Ghost.reveal v) (fun _ -> p x) (vprop_equiv_sym _ _ (vprop_equiv_unit _)) (intro_vprop_post_equiv (fun _ -> p x) (fun _ -> p x) (fun _ -> vprop_equiv_refl (p x))) (f x)) in bind_ghost m1 m2
{ "checked_file": "/", "dependencies": [ "Pulse.Main.fsti.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.Forall.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "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
v: Pulse.Lib.Core.vprop -> f_elim: (x: a -> Pulse.Lib.Core.stt_ghost Prims.unit v (fun _ -> p x)) -> Pulse.Lib.Core.stt_ghost Prims.unit v (fun _ -> forall* (x: a). p x)
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Core.vprop", "Pulse.Lib.Core.stt_ghost", "Prims.unit", "Pulse.Lib.Core.sub_ghost", "Pulse.Lib.Core.op_Star_Star", "Pulse.Lib.Core.emp", "Pulse.Lib.Forall.op_forall_Star", "Pulse.Lib.Core.vprop_equiv_unit", "Pulse.Lib.Core.intro_vprop_post_equiv", "Pulse.Lib.Core.vprop_equiv_refl", "Pulse.Lib.Core.vprop_equiv", "Pulse.Lib.Core.bind_ghost", "Pulse.Lib.Core.pure", "Pulse.Lib.Forall.is_forall", "Pulse.Lib.Forall.token", "Pulse.Lib.Core.intro_exists", "Pulse.Lib.Core.frame_ghost", "Pulse.Lib.Core.intro_pure", "Prims.squash", "Pulse.Lib.Forall.universal_quantifier", "FStar.Squash.return_squash" ]
[]
false
false
false
false
false
let intro_forall (#a: Type) (#p: (a -> vprop)) (v: vprop) (f_elim: (x: a -> stt_ghost unit v (fun _ -> p x))) : stt_ghost unit v (fun _ -> forall* x. p x) =
let _:squash (universal_quantifier v p) = FStar.Squash.return_squash f_elim in let m1:stt_ghost unit (emp ** v) (fun _ -> pure (is_forall v p) ** v) = frame_ghost v (intro_pure (is_forall v p) ()) in let m2 () : stt_ghost unit (pure (is_forall v p) ** token v) (fun _ -> forall* x. p x) = intro_exists (fun (v: vprop) -> pure (is_forall v p) ** token v) v in let m = bind_ghost m1 m2 in sub_ghost v _ (vprop_equiv_unit _) (intro_vprop_post_equiv _ _ (fun _ -> vprop_equiv_refl _)) m
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.compute_rw
val compute_rw (#w: lanes) (r: pfelem) : elem w
val compute_rw (#w: lanes) (r: pfelem) : elem w
let compute_rw (#w:lanes) (r:pfelem) : elem w = match w with | 1 -> compute_r1 r | 2 -> compute_r2 r | 4 -> compute_r4 r
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 119, "start_col": 0, "start_line": 115 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r let normalize_2 (r:pfelem) (acc:elem 2) : pfelem = let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[0] a.[1] let normalize_4 (r:pfelem) (acc:elem 4) : pfelem = let r2 = pfmul r r in let r3 = pfmul r2 r in let r4 = pfmul r2 r2 in let r4321 = create4 r4 r3 r2 r in let a = fmul acc r4321 in pfadd (pfadd (pfadd a.[0] a.[1]) a.[2]) a.[3] let normalize_n (#w:lanes) (r:pfelem) (acc:elem w) : pfelem = match w with | 1 -> normalize_1 r acc | 2 -> normalize_2 r acc | 4 -> normalize_4 r acc let compute_r1 (r:pfelem) : elem 1 = to_elem 1 r let compute_r2 (r:pfelem) : elem 2 = to_elem 2 (pfmul r r)
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.elem w
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.compute_r1", "Hacl.Spec.Poly1305.Vec.compute_r2", "Hacl.Spec.Poly1305.Vec.compute_r4", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let compute_rw (#w: lanes) (r: pfelem) : elem w =
match w with | 1 -> compute_r1 r | 2 -> compute_r2 r | 4 -> compute_r4 r
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.load_acc1
val load_acc1 (text: lbytes size_block) (acc: pfelem) : elem 1
val load_acc1 (text: lbytes size_block) (acc: pfelem) : elem 1
let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text)
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 73, "start_col": 0, "start_line": 71 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
text: Lib.ByteSequence.lbytes Hacl.Spec.Poly1305.Vec.size_block -> acc: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.elem 1
Prims.Tot
[ "total" ]
[]
[ "Lib.ByteSequence.lbytes", "Hacl.Spec.Poly1305.Vec.size_block", "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.fadd", "Hacl.Spec.Poly1305.Vec.load_blocks", "Lib.Sequence.lseq", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.create", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "Lib.Sequence.index", "Lib.Sequence.create", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let load_acc1 (text: lbytes size_block) (acc: pfelem) : elem 1 =
let acc = create 1 acc in fadd acc (load_blocks #1 text)
false
CQueue.Cell.fst
CQueue.Cell.elim_ccell_ghost
val elim_ccell_ghost (#opened: _) (#a: Type0) (c: ccell_ptrvalue a) : SteelGhost (Ghost.erased (ccell_lvalue a)) opened (ccell c) (fun c' -> vptr (ccell_data c') `star` vptr (ccell_next c')) (fun _ -> True) (fun h c' h' -> ccell_ptrvalue_is_null c == false /\ (c' <: ccell_ptrvalue a) == c /\ h (ccell c) == { vcell_data = h' (vptr (ccell_data c')); vcell_next = h' (vptr (ccell_next c')) } )
val elim_ccell_ghost (#opened: _) (#a: Type0) (c: ccell_ptrvalue a) : SteelGhost (Ghost.erased (ccell_lvalue a)) opened (ccell c) (fun c' -> vptr (ccell_data c') `star` vptr (ccell_next c')) (fun _ -> True) (fun h c' h' -> ccell_ptrvalue_is_null c == false /\ (c' <: ccell_ptrvalue a) == c /\ h (ccell c) == { vcell_data = h' (vptr (ccell_data c')); vcell_next = h' (vptr (ccell_next c')) } )
let elim_ccell_ghost #opened #a c = change_slprop_rel (ccell c) (ccell1 c) (fun x y -> x == y) (fun m -> assert_norm (hp_of (ccell1 c) == ccell_hp c); assert_norm (sel_of (ccell1 c) m === sel_of (ccell c) m) ); elim_vrewrite (ccell_is_lvalue c `vdep` ccell0 a) (ccell_rewrite c); let c' : Ghost.erased (ccell_lvalue a) = elim_vdep (ccell_is_lvalue c) (ccell0 a) in elim_ccell_is_lvalue c; change_equal_slprop (ccell0 a c') (vptr (ccell_data (Ghost.reveal c')) `star` vptr (ccell_next (Ghost.reveal c'))); reveal_star (vptr (ccell_data (Ghost.reveal c'))) (vptr (ccell_next (Ghost.reveal c'))); c'
{ "file_name": "share/steel/examples/steel/CQueue.Cell.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 4, "end_line": 164, "start_col": 0, "start_line": 141 }
module CQueue.Cell (* A Steel model of C cell structs *) #push-options "--__no_positivity" noeq type mcell (a: Type0) = { data: ref a; next: ref (mcell a); all_or_none_null: squash (is_null data == is_null next); // TODO: /\ freeable data /\ freeable next, if freeable is implemented as a pure space proposition rather than as stateful permissions (i.e. "freeable if you have the whole permission") } #pop-options let ccell_ptrvalue a = mcell a let ccell_ptrvalue_null a = {data = null; next = null; all_or_none_null = ()} let ccell_ptrvalue_is_null #a x = is_null x.data let ccell_data #a c = c.data let ccell_next #a c = c.next let ccell_is_lvalue_refine (#a: Type) (c: ccell_ptrvalue a) (_: t_of emp) : Tot prop = ccell_ptrvalue_is_null c == false let ccell_is_lvalue_rewrite (#a: Type) (c: ccell_ptrvalue a) (_: normal (t_of (emp `vrefine` ccell_is_lvalue_refine c))) : GTot (ccell_lvalue a) = c [@@ __steel_reduce__; __reduce__ ] let ccell_is_lvalue0 (#a: Type) (c: ccell_ptrvalue a) : Tot vprop = emp `vrefine` ccell_is_lvalue_refine c `vrewrite` ccell_is_lvalue_rewrite c let ccell_is_lvalue_hp (#a: Type) (c: ccell_ptrvalue a) : Tot (slprop u#1) = hp_of (ccell_is_lvalue0 c) let ccell_is_lvalue_sel (#a: Type) (c: ccell_ptrvalue a) : GTot (selector (ccell_lvalue a) (ccell_is_lvalue_hp c)) = sel_of (ccell_is_lvalue0 c) let intro_ccell_is_lvalue #_ #a c = intro_vrefine emp (ccell_is_lvalue_refine c); intro_vrewrite (emp `vrefine` ccell_is_lvalue_refine c) (ccell_is_lvalue_rewrite c); change_slprop_rel (ccell_is_lvalue0 c) (ccell_is_lvalue c) (fun x y -> x == y) (fun m -> assert_norm (hp_of (ccell_is_lvalue c) == hp_of (ccell_is_lvalue0 c)); assert_norm (sel_of (ccell_is_lvalue c) m === sel_of (ccell_is_lvalue0 c) m) ) let elim_ccell_is_lvalue #_ #a c = change_slprop_rel (ccell_is_lvalue c) (ccell_is_lvalue0 c) (fun x y -> x == y) (fun m -> assert_norm (hp_of (ccell_is_lvalue c) == hp_of (ccell_is_lvalue0 c)); assert_norm (sel_of (ccell_is_lvalue c) m === sel_of (ccell_is_lvalue0 c) m) ); elim_vrewrite (emp `vrefine` ccell_is_lvalue_refine c) (ccell_is_lvalue_rewrite c); elim_vrefine emp (ccell_is_lvalue_refine c) [@@ __steel_reduce__] let ccell0 (a: Type0) (c: ccell_lvalue a) : Tot vprop = (vptr (ccell_data c) `star` vptr (ccell_next c)) // unfold let ccell_rewrite (#a: Type0) (c: ccell_ptrvalue a) (x: dtuple2 (ccell_lvalue a) (vdep_payload (ccell_is_lvalue c) (ccell0 a))) : GTot (vcell a) = let p = dsnd #(ccell_lvalue a) #(vdep_payload (ccell_is_lvalue c) (ccell0 a)) x in { vcell_data = fst p; vcell_next = snd p; } [@@ __steel_reduce__ ; __reduce__] // to avoid manual unfoldings through change_slprop let ccell1 (#a: Type0) (c: ccell_ptrvalue a) : Tot vprop = ccell_is_lvalue c `vdep` ccell0 a `vrewrite` ccell_rewrite c let ccell_hp #a c = hp_of (ccell1 c) let ccell_sel #a c = sel_of (ccell1 c) let intro_ccell #opened #a c = intro_ccell_is_lvalue c; reveal_star (vptr (ccell_data c)) (vptr (ccell_next c)); intro_vdep (ccell_is_lvalue c) (vptr (ccell_data c) `star` vptr (ccell_next c)) (ccell0 a); intro_vrewrite (ccell_is_lvalue c `vdep` ccell0 a) (ccell_rewrite c); change_slprop_rel (ccell1 c) (ccell c) (fun x y -> x == y) (fun m -> assert_norm (hp_of (ccell1 c) == ccell_hp c); assert_norm (sel_of (ccell1 c) m === sel_of (ccell c) m) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "CQueue.Cell.fst" }
[ { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "CQueue", "short_module": null }, { "abbrev": false, "full_module": "CQueue", "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
c: CQueue.Cell.ccell_ptrvalue a -> Steel.Effect.Atomic.SteelGhost (FStar.Ghost.erased (CQueue.Cell.ccell_lvalue a))
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.Memory.inames", "CQueue.Cell.ccell_ptrvalue", "FStar.Ghost.erased", "CQueue.Cell.ccell_lvalue", "Prims.unit", "Steel.Effect.Atomic.reveal_star", "Steel.Reference.vptr", "CQueue.Cell.ccell_data", "FStar.Ghost.reveal", "CQueue.Cell.ccell_next", "Steel.Effect.Atomic.change_equal_slprop", "CQueue.Cell.ccell0", "Steel.Effect.Common.star", "CQueue.Cell.elim_ccell_is_lvalue", "Steel.Effect.Atomic.elim_vdep", "CQueue.Cell.ccell_is_lvalue", "Steel.Effect.Common.t_of", "Steel.Effect.Atomic.elim_vrewrite", "Steel.Effect.Common.vdep", "CQueue.Cell.vcell", "CQueue.Cell.ccell_rewrite", "Steel.Effect.Atomic.change_slprop_rel", "CQueue.Cell.ccell", "CQueue.Cell.ccell1", "Steel.Effect.Common.normal", "Prims.eq2", "Prims.prop", "Steel.Memory.mem", "FStar.Pervasives.assert_norm", "Prims.op_Equals_Equals_Equals", "Steel.Effect.Common.sel_of", "Steel.Memory.slprop", "Steel.Effect.Common.hp_of", "CQueue.Cell.ccell_hp" ]
[]
false
true
false
false
false
let elim_ccell_ghost #opened #a c =
change_slprop_rel (ccell c) (ccell1 c) (fun x y -> x == y) (fun m -> assert_norm (hp_of (ccell1 c) == ccell_hp c); assert_norm (sel_of (ccell1 c) m === sel_of (ccell c) m)); elim_vrewrite ((ccell_is_lvalue c) `vdep` (ccell0 a)) (ccell_rewrite c); let c':Ghost.erased (ccell_lvalue a) = elim_vdep (ccell_is_lvalue c) (ccell0 a) in elim_ccell_is_lvalue c; change_equal_slprop (ccell0 a c') ((vptr (ccell_data (Ghost.reveal c'))) `star` (vptr (ccell_next (Ghost.reveal c')))); reveal_star (vptr (ccell_data (Ghost.reveal c'))) (vptr (ccell_next (Ghost.reveal c'))); c'
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.poly1305_update
val poly1305_update (#w: lanes) (text: bytes) (acc r: pfelem) : pfelem
val poly1305_update (#w: lanes) (text: bytes) (acc r: pfelem) : pfelem
let poly1305_update (#w:lanes) (text:bytes) (acc:pfelem) (r:pfelem) : pfelem = match w with | 1 -> Scalar.poly1305_update text acc r | 2 -> poly1305_update_vec #2 text acc r | 4 -> poly1305_update_vec #4 text acc r
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 152, "start_col": 0, "start_line": 148 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r let normalize_2 (r:pfelem) (acc:elem 2) : pfelem = let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[0] a.[1] let normalize_4 (r:pfelem) (acc:elem 4) : pfelem = let r2 = pfmul r r in let r3 = pfmul r2 r in let r4 = pfmul r2 r2 in let r4321 = create4 r4 r3 r2 r in let a = fmul acc r4321 in pfadd (pfadd (pfadd a.[0] a.[1]) a.[2]) a.[3] let normalize_n (#w:lanes) (r:pfelem) (acc:elem w) : pfelem = match w with | 1 -> normalize_1 r acc | 2 -> normalize_2 r acc | 4 -> normalize_4 r acc let compute_r1 (r:pfelem) : elem 1 = to_elem 1 r let compute_r2 (r:pfelem) : elem 2 = to_elem 2 (pfmul r r) let compute_r4 (r:pfelem) : elem 4 = to_elem 4 (pfmul (pfmul r r) (pfmul r r)) let compute_rw (#w:lanes) (r:pfelem) : elem w = match w with | 1 -> compute_r1 r | 2 -> compute_r2 r | 4 -> compute_r4 r let poly1305_update_nblocks (#w:lanes) (r_w:elem w) (b:lbytes (w * size_block)) (acc:elem w) : elem w = let e = load_blocks b in let acc = fadd (fmul acc r_w) e in acc let poly1305_update_multi (#w:lanes) (text:bytes{0 < length text /\ length text % (w * size_block) = 0}) (acc:pfelem) (r:pfelem) : pfelem = let rw = compute_rw r in let acc = load_acc (Seq.slice text 0 (w * size_block)) acc in let text = Seq.slice text (w * size_block) (length text) in let acc = repeat_blocks_multi #uint8 #(elem w) (w * size_block) text (poly1305_update_nblocks rw) acc in let acc = normalize_n r acc in acc let poly1305_update_vec (#w:lanes) (text:bytes) (acc:pfelem) (r:pfelem) : pfelem = let len = length text in let sz_block = w * size_block in let len0 = len / sz_block * sz_block in let t0 = Seq.slice text 0 len0 in let acc = if len0 > 0 then poly1305_update_multi #w t0 acc r else acc in let t1 = Seq.slice text len0 len in Scalar.poly1305_update t1 acc r
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
text: Lib.ByteSequence.bytes -> acc: Hacl.Spec.Poly1305.Vec.pfelem -> r: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.pfelem
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Lib.ByteSequence.bytes", "Hacl.Spec.Poly1305.Vec.pfelem", "Spec.Poly1305.poly1305_update", "Hacl.Spec.Poly1305.Vec.poly1305_update_vec" ]
[]
false
false
false
true
false
let poly1305_update (#w: lanes) (text: bytes) (acc r: pfelem) : pfelem =
match w with | 1 -> Scalar.poly1305_update text acc r | 2 -> poly1305_update_vec #2 text acc r | 4 -> poly1305_update_vec #4 text acc r
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.normalize_2
val normalize_2 (r: pfelem) (acc: elem 2) : pfelem
val normalize_2 (r: pfelem) (acc: elem 2) : pfelem
let normalize_2 (r:pfelem) (acc:elem 2) : pfelem = let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[0] a.[1]
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 96, "start_col": 0, "start_line": 92 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Hacl.Spec.Poly1305.Vec.pfelem -> acc: Hacl.Spec.Poly1305.Vec.elem 2 -> Hacl.Spec.Poly1305.Vec.pfelem
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.elem", "Hacl.Spec.Poly1305.Vec.pfadd", "Lib.Sequence.op_String_Access", "Hacl.Spec.Poly1305.Vec.fmul", "Lib.Sequence.lseq", "Lib.Sequence.create2", "Hacl.Spec.Poly1305.Vec.pfmul" ]
[]
false
false
false
false
false
let normalize_2 (r: pfelem) (acc: elem 2) : pfelem =
let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[ 0 ] a.[ 1 ]
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.load_elem2
val load_elem2 (b: lbytes (2 * size_block)) : elem 2
val load_elem2 (b: lbytes (2 * size_block)) : elem 2
let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 15, "end_line": 51, "start_col": 0, "start_line": 48 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b)
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.ByteSequence.lbytes (2 * Hacl.Spec.Poly1305.Vec.size_block) -> Hacl.Spec.Poly1305.Vec.elem 2
Prims.Tot
[ "total" ]
[]
[ "Lib.ByteSequence.lbytes", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Vec.size_block", "Lib.Sequence.create2", "Hacl.Spec.Poly1305.Vec.pfelem", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Multiply", "Lib.Sequence.length", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Sequence.sub", "Lib.ByteSequence.nat_from_bytes_le", "Lib.IntTypes.uint_t", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let load_elem2 (b: lbytes (2 * size_block)) : elem 2 =
let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.compute_r2
val compute_r2 (r: pfelem) : elem 2
val compute_r2 (r: pfelem) : elem 2
let compute_r2 (r:pfelem) : elem 2 = to_elem 2 (pfmul r r)
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 113, "start_col": 0, "start_line": 113 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r let normalize_2 (r:pfelem) (acc:elem 2) : pfelem = let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[0] a.[1] let normalize_4 (r:pfelem) (acc:elem 4) : pfelem = let r2 = pfmul r r in let r3 = pfmul r2 r in let r4 = pfmul r2 r2 in let r4321 = create4 r4 r3 r2 r in let a = fmul acc r4321 in pfadd (pfadd (pfadd a.[0] a.[1]) a.[2]) a.[3] let normalize_n (#w:lanes) (r:pfelem) (acc:elem w) : pfelem = match w with | 1 -> normalize_1 r acc | 2 -> normalize_2 r acc | 4 -> normalize_4 r acc
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.elem 2
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.to_elem", "Hacl.Spec.Poly1305.Vec.pfmul", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let compute_r2 (r: pfelem) : elem 2 =
to_elem 2 (pfmul r r)
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.normalize_4
val normalize_4 (r: pfelem) (acc: elem 4) : pfelem
val normalize_4 (r: pfelem) (acc: elem 4) : pfelem
let normalize_4 (r:pfelem) (acc:elem 4) : pfelem = let r2 = pfmul r r in let r3 = pfmul r2 r in let r4 = pfmul r2 r2 in let r4321 = create4 r4 r3 r2 r in let a = fmul acc r4321 in pfadd (pfadd (pfadd a.[0] a.[1]) a.[2]) a.[3]
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 104, "start_col": 0, "start_line": 98 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r let normalize_2 (r:pfelem) (acc:elem 2) : pfelem = let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[0] a.[1]
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Hacl.Spec.Poly1305.Vec.pfelem -> acc: Hacl.Spec.Poly1305.Vec.elem 4 -> Hacl.Spec.Poly1305.Vec.pfelem
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.elem", "Hacl.Spec.Poly1305.Vec.pfadd", "Lib.Sequence.op_String_Access", "Hacl.Spec.Poly1305.Vec.fmul", "Lib.Sequence.lseq", "Lib.Sequence.create4", "Hacl.Spec.Poly1305.Vec.pfmul" ]
[]
false
false
false
false
false
let normalize_4 (r: pfelem) (acc: elem 4) : pfelem =
let r2 = pfmul r r in let r3 = pfmul r2 r in let r4 = pfmul r2 r2 in let r4321 = create4 r4 r3 r2 r in let a = fmul acc r4321 in pfadd (pfadd (pfadd a.[ 0 ] a.[ 1 ]) a.[ 2 ]) a.[ 3 ]
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.normalize_1
val normalize_1 (r: pfelem) (acc: elem 1) : pfelem
val normalize_1 (r: pfelem) (acc: elem 1) : pfelem
let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 90, "start_col": 0, "start_line": 89 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Hacl.Spec.Poly1305.Vec.pfelem -> acc: Hacl.Spec.Poly1305.Vec.elem 1 -> Hacl.Spec.Poly1305.Vec.pfelem
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.elem", "Hacl.Spec.Poly1305.Vec.pfmul", "Lib.Sequence.op_String_Access" ]
[]
false
false
false
false
false
let normalize_1 (r: pfelem) (acc: elem 1) : pfelem =
pfmul acc.[ 0 ] r
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.load_acc2
val load_acc2 (text: lbytes (2 * size_block)) (acc: pfelem) : elem 2
val load_acc2 (text: lbytes (2 * size_block)) (acc: pfelem) : elem 2
let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text)
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 77, "start_col": 0, "start_line": 75 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text)
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
text: Lib.ByteSequence.lbytes (2 * Hacl.Spec.Poly1305.Vec.size_block) -> acc: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.elem 2
Prims.Tot
[ "total" ]
[]
[ "Lib.ByteSequence.lbytes", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Vec.size_block", "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.fadd", "Hacl.Spec.Poly1305.Vec.load_blocks", "Lib.Sequence.lseq", "Lib.Sequence.create2", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let load_acc2 (text: lbytes (2 * size_block)) (acc: pfelem) : elem 2 =
let acc = create2 acc 0 in fadd acc (load_blocks #2 text)
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.compute_r4
val compute_r4 (r: pfelem) : elem 4
val compute_r4 (r: pfelem) : elem 4
let compute_r4 (r:pfelem) : elem 4 = to_elem 4 (pfmul (pfmul r r) (pfmul r r))
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 78, "end_line": 114, "start_col": 0, "start_line": 114 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r let normalize_2 (r:pfelem) (acc:elem 2) : pfelem = let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[0] a.[1] let normalize_4 (r:pfelem) (acc:elem 4) : pfelem = let r2 = pfmul r r in let r3 = pfmul r2 r in let r4 = pfmul r2 r2 in let r4321 = create4 r4 r3 r2 r in let a = fmul acc r4321 in pfadd (pfadd (pfadd a.[0] a.[1]) a.[2]) a.[3] let normalize_n (#w:lanes) (r:pfelem) (acc:elem w) : pfelem = match w with | 1 -> normalize_1 r acc | 2 -> normalize_2 r acc | 4 -> normalize_4 r acc let compute_r1 (r:pfelem) : elem 1 = to_elem 1 r
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.elem 4
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.to_elem", "Hacl.Spec.Poly1305.Vec.pfmul", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let compute_r4 (r: pfelem) : elem 4 =
to_elem 4 (pfmul (pfmul r r) (pfmul r r))
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.compute_r1
val compute_r1 (r: pfelem) : elem 1
val compute_r1 (r: pfelem) : elem 1
let compute_r1 (r:pfelem) : elem 1 = to_elem 1 r
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 112, "start_col": 0, "start_line": 112 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r let normalize_2 (r:pfelem) (acc:elem 2) : pfelem = let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[0] a.[1] let normalize_4 (r:pfelem) (acc:elem 4) : pfelem = let r2 = pfmul r r in let r3 = pfmul r2 r in let r4 = pfmul r2 r2 in let r4321 = create4 r4 r3 r2 r in let a = fmul acc r4321 in pfadd (pfadd (pfadd a.[0] a.[1]) a.[2]) a.[3] let normalize_n (#w:lanes) (r:pfelem) (acc:elem w) : pfelem = match w with | 1 -> normalize_1 r acc | 2 -> normalize_2 r acc | 4 -> normalize_4 r acc
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.elem 1
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.to_elem", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let compute_r1 (r: pfelem) : elem 1 =
to_elem 1 r
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.load_elem
val load_elem (#w: lanes) (b: lbytes (w * size_block)) : elem w
val load_elem (#w: lanes) (b: lbytes (w * size_block)) : elem w
let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 64, "start_col": 0, "start_line": 60 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.ByteSequence.lbytes (w * Hacl.Spec.Poly1305.Vec.size_block) -> Hacl.Spec.Poly1305.Vec.elem w
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Lib.ByteSequence.lbytes", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Vec.size_block", "Hacl.Spec.Poly1305.Vec.load_elem1", "Hacl.Spec.Poly1305.Vec.load_elem2", "Hacl.Spec.Poly1305.Vec.load_elem4", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let load_elem (#w: lanes) (b: lbytes (w * size_block)) : elem w =
match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.load_acc4
val load_acc4 (text: lbytes (4 * size_block)) (acc: pfelem) : elem 4
val load_acc4 (text: lbytes (4 * size_block)) (acc: pfelem) : elem 4
let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text)
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 81, "start_col": 0, "start_line": 79 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text)
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
text: Lib.ByteSequence.lbytes (4 * Hacl.Spec.Poly1305.Vec.size_block) -> acc: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.elem 4
Prims.Tot
[ "total" ]
[]
[ "Lib.ByteSequence.lbytes", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Vec.size_block", "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.fadd", "Hacl.Spec.Poly1305.Vec.load_blocks", "Lib.Sequence.lseq", "Lib.Sequence.create4", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let load_acc4 (text: lbytes (4 * size_block)) (acc: pfelem) : elem 4 =
let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text)
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.load_acc
val load_acc (#w: lanes) (text: lbytes (w * size_block)) (acc: pfelem) : elem w
val load_acc (#w: lanes) (text: lbytes (w * size_block)) (acc: pfelem) : elem w
let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 87, "start_col": 0, "start_line": 83 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text)
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
text: Lib.ByteSequence.lbytes (w * Hacl.Spec.Poly1305.Vec.size_block) -> acc: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.elem w
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Lib.ByteSequence.lbytes", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Vec.size_block", "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.load_acc1", "Hacl.Spec.Poly1305.Vec.load_acc2", "Hacl.Spec.Poly1305.Vec.load_acc4", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let load_acc (#w: lanes) (text: lbytes (w * size_block)) (acc: pfelem) : elem w =
match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.poly1305_update_vec
val poly1305_update_vec (#w: lanes) (text: bytes) (acc r: pfelem) : pfelem
val poly1305_update_vec (#w: lanes) (text: bytes) (acc r: pfelem) : pfelem
let poly1305_update_vec (#w:lanes) (text:bytes) (acc:pfelem) (r:pfelem) : pfelem = let len = length text in let sz_block = w * size_block in let len0 = len / sz_block * sz_block in let t0 = Seq.slice text 0 len0 in let acc = if len0 > 0 then poly1305_update_multi #w t0 acc r else acc in let t1 = Seq.slice text len0 len in Scalar.poly1305_update t1 acc r
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 145, "start_col": 0, "start_line": 137 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r let normalize_2 (r:pfelem) (acc:elem 2) : pfelem = let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[0] a.[1] let normalize_4 (r:pfelem) (acc:elem 4) : pfelem = let r2 = pfmul r r in let r3 = pfmul r2 r in let r4 = pfmul r2 r2 in let r4321 = create4 r4 r3 r2 r in let a = fmul acc r4321 in pfadd (pfadd (pfadd a.[0] a.[1]) a.[2]) a.[3] let normalize_n (#w:lanes) (r:pfelem) (acc:elem w) : pfelem = match w with | 1 -> normalize_1 r acc | 2 -> normalize_2 r acc | 4 -> normalize_4 r acc let compute_r1 (r:pfelem) : elem 1 = to_elem 1 r let compute_r2 (r:pfelem) : elem 2 = to_elem 2 (pfmul r r) let compute_r4 (r:pfelem) : elem 4 = to_elem 4 (pfmul (pfmul r r) (pfmul r r)) let compute_rw (#w:lanes) (r:pfelem) : elem w = match w with | 1 -> compute_r1 r | 2 -> compute_r2 r | 4 -> compute_r4 r let poly1305_update_nblocks (#w:lanes) (r_w:elem w) (b:lbytes (w * size_block)) (acc:elem w) : elem w = let e = load_blocks b in let acc = fadd (fmul acc r_w) e in acc let poly1305_update_multi (#w:lanes) (text:bytes{0 < length text /\ length text % (w * size_block) = 0}) (acc:pfelem) (r:pfelem) : pfelem = let rw = compute_rw r in let acc = load_acc (Seq.slice text 0 (w * size_block)) acc in let text = Seq.slice text (w * size_block) (length text) in let acc = repeat_blocks_multi #uint8 #(elem w) (w * size_block) text (poly1305_update_nblocks rw) acc in let acc = normalize_n r acc in acc
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
text: Lib.ByteSequence.bytes -> acc: Hacl.Spec.Poly1305.Vec.pfelem -> r: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.pfelem
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Lib.ByteSequence.bytes", "Hacl.Spec.Poly1305.Vec.pfelem", "Spec.Poly1305.poly1305_update", "FStar.Seq.Base.seq", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.Seq.Base.slice", "Lib.IntTypes.uint_t", "Spec.Poly1305.felem", "Prims.op_GreaterThan", "Hacl.Spec.Poly1305.Vec.poly1305_update_multi", "Prims.bool", "Prims.int", "FStar.Mul.op_Star", "Prims.op_Division", "Hacl.Spec.Poly1305.Vec.size_block", "Prims.nat", "Lib.Sequence.length" ]
[]
false
false
false
true
false
let poly1305_update_vec (#w: lanes) (text: bytes) (acc r: pfelem) : pfelem =
let len = length text in let sz_block = w * size_block in let len0 = (len / sz_block) * sz_block in let t0 = Seq.slice text 0 len0 in let acc = if len0 > 0 then poly1305_update_multi #w t0 acc r else acc in let t1 = Seq.slice text len0 len in Scalar.poly1305_update t1 acc r
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.load_blocks
val load_blocks (#w: lanes) (b: lbytes (w * size_block)) : elem w
val load_blocks (#w: lanes) (b: lbytes (w * size_block)) : elem w
let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 69, "start_col": 0, "start_line": 66 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.ByteSequence.lbytes (w * Hacl.Spec.Poly1305.Vec.size_block) -> Hacl.Spec.Poly1305.Vec.elem w
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Lib.ByteSequence.lbytes", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Vec.size_block", "Lib.Sequence.lseq", "Hacl.Spec.Poly1305.Vec.pfelem", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "Lib.Sequence.index", "Hacl.Spec.Poly1305.Vec.pfadd", "Prims.pow2", "Lib.Sequence.map", "Hacl.Spec.Poly1305.Vec.elem", "Hacl.Spec.Poly1305.Vec.load_elem" ]
[]
false
false
false
false
false
let load_blocks (#w: lanes) (b: lbytes (w * size_block)) : elem w =
let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.poly1305_update_nblocks
val poly1305_update_nblocks (#w: lanes) (r_w: elem w) (b: lbytes (w * size_block)) (acc: elem w) : elem w
val poly1305_update_nblocks (#w: lanes) (r_w: elem w) (b: lbytes (w * size_block)) (acc: elem w) : elem w
let poly1305_update_nblocks (#w:lanes) (r_w:elem w) (b:lbytes (w * size_block)) (acc:elem w) : elem w = let e = load_blocks b in let acc = fadd (fmul acc r_w) e in acc
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 125, "start_col": 0, "start_line": 122 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r let normalize_2 (r:pfelem) (acc:elem 2) : pfelem = let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[0] a.[1] let normalize_4 (r:pfelem) (acc:elem 4) : pfelem = let r2 = pfmul r r in let r3 = pfmul r2 r in let r4 = pfmul r2 r2 in let r4321 = create4 r4 r3 r2 r in let a = fmul acc r4321 in pfadd (pfadd (pfadd a.[0] a.[1]) a.[2]) a.[3] let normalize_n (#w:lanes) (r:pfelem) (acc:elem w) : pfelem = match w with | 1 -> normalize_1 r acc | 2 -> normalize_2 r acc | 4 -> normalize_4 r acc let compute_r1 (r:pfelem) : elem 1 = to_elem 1 r let compute_r2 (r:pfelem) : elem 2 = to_elem 2 (pfmul r r) let compute_r4 (r:pfelem) : elem 4 = to_elem 4 (pfmul (pfmul r r) (pfmul r r)) let compute_rw (#w:lanes) (r:pfelem) : elem w = match w with | 1 -> compute_r1 r | 2 -> compute_r2 r | 4 -> compute_r4 r
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r_w: Hacl.Spec.Poly1305.Vec.elem w -> b: Lib.ByteSequence.lbytes (w * Hacl.Spec.Poly1305.Vec.size_block) -> acc: Hacl.Spec.Poly1305.Vec.elem w -> Hacl.Spec.Poly1305.Vec.elem w
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Hacl.Spec.Poly1305.Vec.elem", "Lib.ByteSequence.lbytes", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Vec.size_block", "Hacl.Spec.Poly1305.Vec.fadd", "Hacl.Spec.Poly1305.Vec.fmul", "Hacl.Spec.Poly1305.Vec.load_blocks" ]
[]
false
false
false
false
false
let poly1305_update_nblocks (#w: lanes) (r_w: elem w) (b: lbytes (w * size_block)) (acc: elem w) : elem w =
let e = load_blocks b in let acc = fadd (fmul acc r_w) e in acc
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.poly1305_update_multi
val poly1305_update_multi (#w: lanes) (text: bytes{0 < length text /\ length text % (w * size_block) = 0}) (acc r: pfelem) : pfelem
val poly1305_update_multi (#w: lanes) (text: bytes{0 < length text /\ length text % (w * size_block) = 0}) (acc r: pfelem) : pfelem
let poly1305_update_multi (#w:lanes) (text:bytes{0 < length text /\ length text % (w * size_block) = 0}) (acc:pfelem) (r:pfelem) : pfelem = let rw = compute_rw r in let acc = load_acc (Seq.slice text 0 (w * size_block)) acc in let text = Seq.slice text (w * size_block) (length text) in let acc = repeat_blocks_multi #uint8 #(elem w) (w * size_block) text (poly1305_update_nblocks rw) acc in let acc = normalize_n r acc in acc
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 134, "start_col": 0, "start_line": 128 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2 let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4 let load_elem (#w:lanes) (b:lbytes (w * size_block)) : elem w = match w with | 1 -> load_elem1 b | 2 -> load_elem2 b | 4 -> load_elem4 b let load_blocks (#w:lanes) (b:lbytes (w * size_block)) : elem w = let e = load_elem #w b in let e = map (pfadd (pow2 128)) e in e let load_acc1 (text:lbytes size_block) (acc:pfelem) : elem 1 = let acc = create 1 acc in fadd acc (load_blocks #1 text) let load_acc2 (text:lbytes (2 * size_block)) (acc:pfelem) : elem 2 = let acc = create2 acc 0 in fadd acc (load_blocks #2 text) let load_acc4 (text:lbytes (4 * size_block)) (acc:pfelem) : elem 4 = let acc = create4 acc 0 0 0 in fadd acc (load_blocks #4 text) let load_acc (#w:lanes) (text:lbytes (w * size_block)) (acc:pfelem) : elem w = match w with | 1 -> load_acc1 text acc | 2 -> load_acc2 text acc | 4 -> load_acc4 text acc let normalize_1 (r:pfelem) (acc:elem 1) : pfelem = pfmul acc.[0] r let normalize_2 (r:pfelem) (acc:elem 2) : pfelem = let r2 = pfmul r r in let r21 = create2 r2 r in let a = fmul acc r21 in pfadd a.[0] a.[1] let normalize_4 (r:pfelem) (acc:elem 4) : pfelem = let r2 = pfmul r r in let r3 = pfmul r2 r in let r4 = pfmul r2 r2 in let r4321 = create4 r4 r3 r2 r in let a = fmul acc r4321 in pfadd (pfadd (pfadd a.[0] a.[1]) a.[2]) a.[3] let normalize_n (#w:lanes) (r:pfelem) (acc:elem w) : pfelem = match w with | 1 -> normalize_1 r acc | 2 -> normalize_2 r acc | 4 -> normalize_4 r acc let compute_r1 (r:pfelem) : elem 1 = to_elem 1 r let compute_r2 (r:pfelem) : elem 2 = to_elem 2 (pfmul r r) let compute_r4 (r:pfelem) : elem 4 = to_elem 4 (pfmul (pfmul r r) (pfmul r r)) let compute_rw (#w:lanes) (r:pfelem) : elem w = match w with | 1 -> compute_r1 r | 2 -> compute_r2 r | 4 -> compute_r4 r let poly1305_update_nblocks (#w:lanes) (r_w:elem w) (b:lbytes (w * size_block)) (acc:elem w) : elem w = let e = load_blocks b in let acc = fadd (fmul acc r_w) e in acc
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
text: Lib.ByteSequence.bytes { 0 < Lib.Sequence.length text /\ Lib.Sequence.length text % (w * Hacl.Spec.Poly1305.Vec.size_block) = 0 } -> acc: Hacl.Spec.Poly1305.Vec.pfelem -> r: Hacl.Spec.Poly1305.Vec.pfelem -> Hacl.Spec.Poly1305.Vec.pfelem
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Poly1305.Vec.lanes", "Lib.ByteSequence.bytes", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Vec.size_block", "Hacl.Spec.Poly1305.Vec.pfelem", "Hacl.Spec.Poly1305.Vec.normalize_n", "Hacl.Spec.Poly1305.Vec.elem", "Lib.Sequence.repeat_blocks_multi", "Lib.IntTypes.uint8", "Hacl.Spec.Poly1305.Vec.poly1305_update_nblocks", "FStar.Seq.Base.seq", "Lib.IntTypes.int_t", "FStar.Seq.Base.slice", "Hacl.Spec.Poly1305.Vec.load_acc", "Hacl.Spec.Poly1305.Vec.compute_rw" ]
[]
false
false
false
false
false
let poly1305_update_multi (#w: lanes) (text: bytes{0 < length text /\ length text % (w * size_block) = 0}) (acc r: pfelem) : pfelem =
let rw = compute_rw r in let acc = load_acc (Seq.slice text 0 (w * size_block)) acc in let text = Seq.slice text (w * size_block) (length text) in let acc = repeat_blocks_multi #uint8 #(elem w) (w * size_block) text (poly1305_update_nblocks rw) acc in let acc = normalize_n r acc in acc
false
Steel.ST.C.Types.Base.fsti
Steel.ST.C.Types.Base.ptr
val ptr (#t: Type) (td: typedef t) : Tot Type0
val ptr (#t: Type) (td: typedef t) : Tot Type0
let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 58, "end_line": 96, "start_col": 0, "start_line": 96 }
module Steel.ST.C.Types.Base open Steel.ST.Util module P = Steel.FractionalPermission /// Helper to compose two permissions into one val prod_perm (p1 p2: P.perm) : Pure P.perm (requires True) (ensures (fun p -> ((p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm) ==> p `P.lesser_equal_perm` P.full_perm) /\ p.v == (let open FStar.Real in p1.v *. p2.v) )) [@@noextract_to "krml"] // proof-only val typedef (t: Type0) : Type0 inline_for_extraction [@@noextract_to "krml"] let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: P.perm) : Ghost t (requires (fractionable td x)) (ensures (fun y -> p `P.lesser_equal_perm` P.full_perm ==> fractionable td y)) val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma (requires (fractionable td x)) (ensures (mk_fraction td x P.full_perm == x)) [SMTPat (mk_fraction td x P.full_perm)] val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: P.perm) : Lemma (requires (fractionable td x /\ p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm)) (ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2))) val full (#t: Type0) (td: typedef t) (v: t) : GTot prop val uninitialized (#t: Type0) (td: typedef t) : Ghost t (requires True) (ensures (fun y -> full td y /\ fractionable td y)) val unknown (#t: Type0) (td: typedef t) : Ghost t (requires True) (ensures (fun y -> fractionable td y)) val full_not_unknown (#t: Type) (td: typedef t) (v: t) : Lemma (requires (full td v)) (ensures (~ (v == unknown td))) [SMTPat (full td v)] val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: P.perm) : Lemma (ensures (mk_fraction td (unknown td) p == unknown td)) val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: P.perm) : Lemma (requires (fractionable td v /\ mk_fraction td v p == unknown td)) (ensures (v == unknown td)) // To be extracted as: void* [@@noextract_to "krml"] // primitive val void_ptr : Type0 // To be extracted as: NULL [@@noextract_to "krml"] // primitive val void_null: void_ptr // To be extracted as: *t [@@noextract_to "krml"] // primitive val ptr_gen ([@@@unused] t: Type) : Type0 [@@noextract_to "krml"] // primitive val null_gen (t: Type) : Tot (ptr_gen t) val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t) val ghost_void_ptr_of_ptr_gen_of_void_ptr (x: void_ptr) (t: Type) : Lemma (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x) [SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))] val ghost_ptr_gen_of_void_ptr_of_ptr_gen (#t: Type) (x: ptr_gen t) : Lemma (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x) [SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)]
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Base.fsti" }
[ { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "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
td: Steel.ST.C.Types.Base.typedef t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.C.Types.Base.typedef", "Steel.ST.C.Types.Base.ptr_gen" ]
[]
false
false
false
true
true
let ptr (#t: Type) (td: typedef t) : Tot Type0 =
ptr_gen t
false
Hacl.Spec.Poly1305.Vec.fst
Hacl.Spec.Poly1305.Vec.load_elem4
val load_elem4 (b: lbytes (4 * size_block)) : elem 4
val load_elem4 (b: lbytes (4 * size_block)) : elem 4
let load_elem4 (b:lbytes (4 * size_block)) : elem 4 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4
{ "file_name": "code/poly1305/Hacl.Spec.Poly1305.Vec.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 58, "start_col": 0, "start_line": 53 }
module Hacl.Spec.Poly1305.Vec #reset-options "--z3rlimit 60 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Poly1305 (* Field types and parameters *) val lemma_pow2_128: n:nat -> Lemma (requires n <= 128) (ensures pow2 n < Scalar.prime) [SMTPat (pow2 n)] let lemma_pow2_128 n = Math.Lemmas.pow2_le_compat 128 n; assert (pow2 n <= pow2 128); assert_norm (pow2 128 < Scalar.prime) let prime = Scalar.prime let pfelem = Scalar.felem let pfadd (x:pfelem) (y:pfelem) : pfelem = Scalar.fadd x y let pfmul (x:pfelem) (y:pfelem) : pfelem = Scalar.fmul x y let lanes = w:width{w == 1 \/ w == 2 \/ w == 4} type elem (w:lanes) = lseq pfelem w let to_elem (w:lanes) (x:pfelem) : elem w = create w x let from_elem (#w:lanes) (x:elem w) : pfelem = x.[0] let zero (w:lanes) : elem w = to_elem w 0 let fadd (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfadd x y let fmul (#w:lanes) (x:elem w) (y:elem w) : elem w = map2 pfmul x y (* Specification *) let size_block : size_nat = Scalar.size_block let load_elem1 (b:Scalar.block) : elem 1 = to_elem 1 (nat_from_bytes_le b) let load_elem2 (b:lbytes (2 * size_block)) : elem 2 = let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in create2 b1 b2
{ "checked_file": "/", "dependencies": [ "Spec.Poly1305.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Poly1305.Vec.fst" }
[ { "abbrev": true, "full_module": "Spec.Poly1305", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305", "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": 0, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.ByteSequence.lbytes (4 * Hacl.Spec.Poly1305.Vec.size_block) -> Hacl.Spec.Poly1305.Vec.elem 4
Prims.Tot
[ "total" ]
[]
[ "Lib.ByteSequence.lbytes", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Vec.size_block", "Lib.Sequence.create4", "Hacl.Spec.Poly1305.Vec.pfelem", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Multiply", "Lib.Sequence.length", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Sequence.sub", "Lib.ByteSequence.nat_from_bytes_le", "Lib.IntTypes.uint_t", "Hacl.Spec.Poly1305.Vec.elem" ]
[]
false
false
false
false
false
let load_elem4 (b: lbytes (4 * size_block)) : elem 4 =
let b1 = nat_from_bytes_le (sub b 0 size_block) in let b2 = nat_from_bytes_le (sub b size_block size_block) in let b3 = nat_from_bytes_le (sub b (2 * size_block) size_block) in let b4 = nat_from_bytes_le (sub b (3 * size_block) size_block) in create4 b1 b2 b3 b4
false
Steel.ST.C.Types.Base.fsti
Steel.ST.C.Types.Base.typeof
val typeof (#t: Type0) (td: typedef t) : Tot Type0
val typeof (#t: Type0) (td: typedef t) : Tot Type0
let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 54, "end_line": 19, "start_col": 0, "start_line": 19 }
module Steel.ST.C.Types.Base open Steel.ST.Util module P = Steel.FractionalPermission /// Helper to compose two permissions into one val prod_perm (p1 p2: P.perm) : Pure P.perm (requires True) (ensures (fun p -> ((p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm) ==> p `P.lesser_equal_perm` P.full_perm) /\ p.v == (let open FStar.Real in p1.v *. p2.v) )) [@@noextract_to "krml"] // proof-only val typedef (t: Type0) : Type0
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Base.fsti" }
[ { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "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
td: Steel.ST.C.Types.Base.typedef t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.C.Types.Base.typedef" ]
[]
false
false
false
true
true
let typeof (#t: Type0) (td: typedef t) : Tot Type0 =
t
false
Steel.ST.C.Types.Base.fsti
Steel.ST.C.Types.Base.ref
val ref (#t: Type) (td: typedef t) : Tot Type0
val ref (#t: Type) (td: typedef t) : Tot Type0
let ref (#t: Type) (td: typedef t) : Tot Type0 = (p: ptr td { ~ (p == null td) })
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 81, "end_line": 101, "start_col": 0, "start_line": 101 }
module Steel.ST.C.Types.Base open Steel.ST.Util module P = Steel.FractionalPermission /// Helper to compose two permissions into one val prod_perm (p1 p2: P.perm) : Pure P.perm (requires True) (ensures (fun p -> ((p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm) ==> p `P.lesser_equal_perm` P.full_perm) /\ p.v == (let open FStar.Real in p1.v *. p2.v) )) [@@noextract_to "krml"] // proof-only val typedef (t: Type0) : Type0 inline_for_extraction [@@noextract_to "krml"] let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: P.perm) : Ghost t (requires (fractionable td x)) (ensures (fun y -> p `P.lesser_equal_perm` P.full_perm ==> fractionable td y)) val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma (requires (fractionable td x)) (ensures (mk_fraction td x P.full_perm == x)) [SMTPat (mk_fraction td x P.full_perm)] val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: P.perm) : Lemma (requires (fractionable td x /\ p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm)) (ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2))) val full (#t: Type0) (td: typedef t) (v: t) : GTot prop val uninitialized (#t: Type0) (td: typedef t) : Ghost t (requires True) (ensures (fun y -> full td y /\ fractionable td y)) val unknown (#t: Type0) (td: typedef t) : Ghost t (requires True) (ensures (fun y -> fractionable td y)) val full_not_unknown (#t: Type) (td: typedef t) (v: t) : Lemma (requires (full td v)) (ensures (~ (v == unknown td))) [SMTPat (full td v)] val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: P.perm) : Lemma (ensures (mk_fraction td (unknown td) p == unknown td)) val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: P.perm) : Lemma (requires (fractionable td v /\ mk_fraction td v p == unknown td)) (ensures (v == unknown td)) // To be extracted as: void* [@@noextract_to "krml"] // primitive val void_ptr : Type0 // To be extracted as: NULL [@@noextract_to "krml"] // primitive val void_null: void_ptr // To be extracted as: *t [@@noextract_to "krml"] // primitive val ptr_gen ([@@@unused] t: Type) : Type0 [@@noextract_to "krml"] // primitive val null_gen (t: Type) : Tot (ptr_gen t) val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t) val ghost_void_ptr_of_ptr_gen_of_void_ptr (x: void_ptr) (t: Type) : Lemma (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x) [SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))] val ghost_ptr_gen_of_void_ptr_of_ptr_gen (#t: Type) (x: ptr_gen t) : Lemma (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x) [SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)] inline_for_extraction [@@noextract_to "krml"] // primitive let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t inline_for_extraction [@@noextract_to "krml"] // primitive let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Base.fsti" }
[ { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "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
td: Steel.ST.C.Types.Base.typedef t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.C.Types.Base.typedef", "Steel.ST.C.Types.Base.ptr", "Prims.l_not", "Prims.eq2", "Steel.ST.C.Types.Base.null" ]
[]
false
false
false
true
true
let ref (#t: Type) (td: typedef t) : Tot Type0 =
(p: ptr td {~(p == null td)})
false
Steel.ST.C.Types.Base.fsti
Steel.ST.C.Types.Base.null
val null (#t: Type) (td: typedef t) : Tot (ptr td)
val null (#t: Type) (td: typedef t) : Tot (ptr td)
let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 63, "end_line": 98, "start_col": 0, "start_line": 98 }
module Steel.ST.C.Types.Base open Steel.ST.Util module P = Steel.FractionalPermission /// Helper to compose two permissions into one val prod_perm (p1 p2: P.perm) : Pure P.perm (requires True) (ensures (fun p -> ((p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm) ==> p `P.lesser_equal_perm` P.full_perm) /\ p.v == (let open FStar.Real in p1.v *. p2.v) )) [@@noextract_to "krml"] // proof-only val typedef (t: Type0) : Type0 inline_for_extraction [@@noextract_to "krml"] let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: P.perm) : Ghost t (requires (fractionable td x)) (ensures (fun y -> p `P.lesser_equal_perm` P.full_perm ==> fractionable td y)) val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma (requires (fractionable td x)) (ensures (mk_fraction td x P.full_perm == x)) [SMTPat (mk_fraction td x P.full_perm)] val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: P.perm) : Lemma (requires (fractionable td x /\ p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm)) (ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2))) val full (#t: Type0) (td: typedef t) (v: t) : GTot prop val uninitialized (#t: Type0) (td: typedef t) : Ghost t (requires True) (ensures (fun y -> full td y /\ fractionable td y)) val unknown (#t: Type0) (td: typedef t) : Ghost t (requires True) (ensures (fun y -> fractionable td y)) val full_not_unknown (#t: Type) (td: typedef t) (v: t) : Lemma (requires (full td v)) (ensures (~ (v == unknown td))) [SMTPat (full td v)] val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: P.perm) : Lemma (ensures (mk_fraction td (unknown td) p == unknown td)) val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: P.perm) : Lemma (requires (fractionable td v /\ mk_fraction td v p == unknown td)) (ensures (v == unknown td)) // To be extracted as: void* [@@noextract_to "krml"] // primitive val void_ptr : Type0 // To be extracted as: NULL [@@noextract_to "krml"] // primitive val void_null: void_ptr // To be extracted as: *t [@@noextract_to "krml"] // primitive val ptr_gen ([@@@unused] t: Type) : Type0 [@@noextract_to "krml"] // primitive val null_gen (t: Type) : Tot (ptr_gen t) val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t) val ghost_void_ptr_of_ptr_gen_of_void_ptr (x: void_ptr) (t: Type) : Lemma (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x) [SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))] val ghost_ptr_gen_of_void_ptr_of_ptr_gen (#t: Type) (x: ptr_gen t) : Lemma (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x) [SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)] inline_for_extraction [@@noextract_to "krml"] // primitive let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Base.fsti" }
[ { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "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
td: Steel.ST.C.Types.Base.typedef t -> Steel.ST.C.Types.Base.ptr td
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.C.Types.Base.typedef", "Steel.ST.C.Types.Base.null_gen", "Steel.ST.C.Types.Base.ptr" ]
[]
false
false
false
false
false
let null (#t: Type) (td: typedef t) : Tot (ptr td) =
null_gen t
false
Vale.AES.PPC64LE.GF128_Mul.fsti
Vale.AES.PPC64LE.GF128_Mul.va_wp_ShiftLeft128_1
val va_wp_ShiftLeft128_1 (a: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
val va_wp_ShiftLeft128_1 (a: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
let va_wp_ShiftLeft128_1 (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_v1:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 va_s0) in va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) ==> va_k va_sM (())))
{ "file_name": "obj/Vale.AES.PPC64LE.GF128_Mul.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 88, "end_line": 41, "start_col": 0, "start_line": 37 }
module Vale.AES.PPC64LE.GF128_Mul open Vale.Def.Types_s open Vale.Arch.Types open Vale.Arch.TypesNative open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.Math.Poly2.Lemmas open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.PPC64LE.Machine_s open Vale.PPC64LE.State open Vale.PPC64LE.Decls open Vale.PPC64LE.InsBasic open Vale.PPC64LE.InsMem open Vale.PPC64LE.InsVector open Vale.PPC64LE.QuickCode open Vale.PPC64LE.QuickCodes open Vale.AES.PPC64LE.PolyOps open Vale.AES.Types_helpers open Vale.AES.GHash_BE //-- ShiftLeft128_1 val va_code_ShiftLeft128_1 : va_dummy:unit -> Tot va_code val va_codegen_success_ShiftLeft128_1 : va_dummy:unit -> Tot va_pbool val va_lemma_ShiftLeft128_1 : va_b0:va_code -> va_s0:va_state -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_ShiftLeft128_1 ()) va_s0 /\ va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) /\ va_state_eq va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_ok va_sM va_s0)))))
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.QuickCodes.fsti.checked", "Vale.PPC64LE.QuickCode.fst.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.InsVector.fsti.checked", "Vale.PPC64LE.InsMem.fsti.checked", "Vale.PPC64LE.InsBasic.fsti.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.PPC64LE.PolyOps.fsti.checked", "Vale.AES.GHash_BE.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.PPC64LE.GF128_Mul.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.GHash_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "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.Math.Poly2_s.poly -> va_s0: Vale.PPC64LE.Decls.va_state -> va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0) -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.poly", "Vale.PPC64LE.Decls.va_state", "Prims.unit", "Prims.l_and", "Prims.b2t", "Vale.PPC64LE.Decls.va_get_ok", "Prims.op_LessThan", "Vale.Math.Poly2_s.degree", "Prims.eq2", "Vale.Def.Types_s.quad32", "Vale.PPC64LE.Decls.va_get_vec", "Vale.Math.Poly2.Bits_s.to_quad32", "Prims.l_Forall", "Vale.PPC64LE.Machine_s.quad32", "Prims.l_imp", "Vale.Math.Poly2_s.shift", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Decls.va_upd_vec" ]
[]
false
false
false
true
true
let va_wp_ShiftLeft128_1 (a: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_v1: quad32) (va_x_v2: quad32). let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 va_s0) in va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) ==> va_k va_sM (())))
false
Steel.ST.C.Types.Base.fsti
Steel.ST.C.Types.Base.norm_field_steps
val norm_field_steps : Prims.list FStar.Pervasives.norm_step
let norm_field_steps = [ delta_attr [`%norm_field_attr]; iota; zeta; primops; ]
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 1, "end_line": 330, "start_col": 0, "start_line": 327 }
module Steel.ST.C.Types.Base open Steel.ST.Util module P = Steel.FractionalPermission /// Helper to compose two permissions into one val prod_perm (p1 p2: P.perm) : Pure P.perm (requires True) (ensures (fun p -> ((p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm) ==> p `P.lesser_equal_perm` P.full_perm) /\ p.v == (let open FStar.Real in p1.v *. p2.v) )) [@@noextract_to "krml"] // proof-only val typedef (t: Type0) : Type0 inline_for_extraction [@@noextract_to "krml"] let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: P.perm) : Ghost t (requires (fractionable td x)) (ensures (fun y -> p `P.lesser_equal_perm` P.full_perm ==> fractionable td y)) val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma (requires (fractionable td x)) (ensures (mk_fraction td x P.full_perm == x)) [SMTPat (mk_fraction td x P.full_perm)] val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: P.perm) : Lemma (requires (fractionable td x /\ p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm)) (ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2))) val full (#t: Type0) (td: typedef t) (v: t) : GTot prop val uninitialized (#t: Type0) (td: typedef t) : Ghost t (requires True) (ensures (fun y -> full td y /\ fractionable td y)) val unknown (#t: Type0) (td: typedef t) : Ghost t (requires True) (ensures (fun y -> fractionable td y)) val full_not_unknown (#t: Type) (td: typedef t) (v: t) : Lemma (requires (full td v)) (ensures (~ (v == unknown td))) [SMTPat (full td v)] val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: P.perm) : Lemma (ensures (mk_fraction td (unknown td) p == unknown td)) val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: P.perm) : Lemma (requires (fractionable td v /\ mk_fraction td v p == unknown td)) (ensures (v == unknown td)) // To be extracted as: void* [@@noextract_to "krml"] // primitive val void_ptr : Type0 // To be extracted as: NULL [@@noextract_to "krml"] // primitive val void_null: void_ptr // To be extracted as: *t [@@noextract_to "krml"] // primitive val ptr_gen ([@@@unused] t: Type) : Type0 [@@noextract_to "krml"] // primitive val null_gen (t: Type) : Tot (ptr_gen t) val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t) val ghost_void_ptr_of_ptr_gen_of_void_ptr (x: void_ptr) (t: Type) : Lemma (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x) [SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))] val ghost_ptr_gen_of_void_ptr_of_ptr_gen (#t: Type) (x: ptr_gen t) : Lemma (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x) [SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)] inline_for_extraction [@@noextract_to "krml"] // primitive let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t inline_for_extraction [@@noextract_to "krml"] // primitive let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t inline_for_extraction [@@noextract_to "krml"] let ref (#t: Type) (td: typedef t) : Tot Type0 = (p: ptr td { ~ (p == null td) }) val pts_to (#t: Type) (#td: typedef t) (r: ref td) ([@@@smt_fallback] v: Ghost.erased t) : vprop let pts_to_or_null (#t: Type) (#td: typedef t) (p: ptr td) (v: Ghost.erased t) : vprop = if FStar.StrongExcludedMiddle.strong_excluded_middle (p == null _) then emp else pts_to p v [@@noextract_to "krml"] // primitive val is_null (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (p: ptr td) : STAtomicBase bool false opened Unobservable (pts_to_or_null p v) (fun _ -> pts_to_or_null p v) (True) (fun res -> res == true <==> p == null _) let assert_null (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (p: ptr td) : STGhost unit opened (pts_to_or_null p v) (fun _ -> emp) (p == null _) (fun _ -> True) = rewrite (pts_to_or_null p v) emp let assert_not_null (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (p: ptr td) : STGhost (squash (~ (p == null _))) opened (pts_to_or_null p v) (fun _ -> pts_to p v) (~ (p == null _)) (fun _ -> True) = rewrite (pts_to_or_null p v) (pts_to p v) [@@noextract_to "krml"] // primitive val void_ptr_of_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ptr td) : STAtomicBase void_ptr false opened Unobservable (pts_to_or_null x v) (fun _ -> pts_to_or_null x v) True (fun y -> y == ghost_void_ptr_of_ptr_gen x) [@@noextract_to "krml"] inline_for_extraction let void_ptr_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ref td) : STAtomicBase void_ptr false opened Unobservable (pts_to x v) (fun _ -> pts_to x v) True (fun y -> y == ghost_void_ptr_of_ptr_gen x) = rewrite (pts_to x v) (pts_to_or_null x v); let res = void_ptr_of_ptr x in rewrite (pts_to_or_null x v) (pts_to x v); return res [@@noextract_to "krml"] // primitive val ptr_of_void_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) : STAtomicBase (ptr td) false opened Unobservable (pts_to_or_null (ghost_ptr_gen_of_void_ptr x t <: ptr td) v) (fun y -> pts_to_or_null y v) True (fun y -> y == ghost_ptr_gen_of_void_ptr x t) [@@noextract_to "krml"] inline_for_extraction let ref_of_void_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) (y': Ghost.erased (ref td)) : STAtomicBase (ref td) false opened Unobservable (pts_to y' v) (fun y -> pts_to y v) (Ghost.reveal y' == ghost_ptr_gen_of_void_ptr x t) (fun y -> y == Ghost.reveal y') = rewrite (pts_to y' v) (pts_to_or_null (ghost_ptr_gen_of_void_ptr x t <: ptr td) v); let y = ptr_of_void_ptr x in rewrite (pts_to_or_null y v) (pts_to y v); return y val ref_equiv (#t: Type) (#td: typedef t) (r1 r2: ref td) : Tot vprop val pts_to_equiv (#opened: _) (#t: Type) (#td: typedef t) (r1 r2: ref td) (v: Ghost.erased t) : STGhostT unit opened (ref_equiv r1 r2 `star` pts_to r1 v) (fun _ -> ref_equiv r1 r2 `star` pts_to r2 v) val freeable (#t: Type) (#td: typedef t) (r: ref td) : Tot vprop val freeable_dup (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) : STGhostT unit opened (freeable r) (fun _ -> freeable r `star` freeable r) val freeable_equiv (#opened: _) (#t: Type) (#td: typedef t) (r1 r2: ref td) : STGhostT unit opened (ref_equiv r1 r2 `star` freeable r1) (fun _ -> ref_equiv r1 r2 `star` freeable r2) let freeable_or_null (#t: Type) (#td: typedef t) (r: ptr td) : Tot vprop = if FStar.StrongExcludedMiddle.strong_excluded_middle (r == null _) then emp else freeable r (* let freeable_or_null_dup (#opened: _) (#t: Type) (#td: typedef t) (r: ptr td) : SteelGhostT vprop opened (freeable_or_null r) (fun _ -> freeable_or_null r `star` freeable_or_null r) = if FStar.StrongExcludedMiddle.strong_excluded_middle (r == null _) then () else freeable r *) [@@noextract_to "krml"] // primitive val alloc (#t: Type) (td: typedef t) : STT (ptr td) emp (fun p -> pts_to_or_null p (uninitialized td) `star` freeable_or_null p) [@@noextract_to "krml"] // primitive val free (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : ST unit (pts_to r v `star` freeable r) (fun _ -> emp) ( full td v ) (fun _ -> True) val mk_fraction_split_gen (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (v: t { fractionable td v }) (p p1 p2: P.perm) : STGhost unit opened (pts_to r (mk_fraction td v p)) (fun _ -> pts_to r (mk_fraction td v p1) `star` pts_to r (mk_fraction td v p2)) (p == p1 `P.sum_perm` p2 /\ p `P.lesser_equal_perm` P.full_perm) (fun _ -> True) let mk_fraction_split (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (v: Ghost.erased t { fractionable td v }) (p1 p2: P.perm) : STGhost unit opened (pts_to r v) (fun _ -> pts_to r (mk_fraction td v p1) `star` pts_to r (mk_fraction td v p2)) (P.full_perm == p1 `P.sum_perm` p2) (fun _ -> True) = mk_fraction_full td v; rewrite (pts_to _ _) (pts_to _ _); mk_fraction_split_gen r v P.full_perm p1 p2 val mk_fraction_join (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (v: t { fractionable td v }) (p1 p2: P.perm) : STGhostT unit opened (pts_to r (mk_fraction td v p1) `star` pts_to r (mk_fraction td v p2)) (fun _ -> pts_to r (mk_fraction td v (p1 `P.sum_perm` p2))) val fractional_permissions_theorem (#opened: _) (#t: Type) (#td: typedef t) (v1: t { fractionable td v1 }) (v2: t { fractionable td v2 }) (p1 p2: P.perm) (r: ref td) : STGhost unit opened (pts_to r (mk_fraction td v1 p1) `star` pts_to r (mk_fraction td v2 p2)) (fun _ -> pts_to r (mk_fraction td v1 p1) `star` pts_to r (mk_fraction td v2 p2)) (full td v1 /\ full td v2) (fun _ -> v1 == v2 /\ (p1 `P.sum_perm` p2) `P.lesser_equal_perm` P.full_perm) [@@noextract_to "krml"] // primitive val copy (#t: Type) (#td: typedef t) (#v_src: Ghost.erased t { full td v_src /\ fractionable td v_src }) (#p_src: P.perm) (#v_dst: Ghost.erased t { full td v_dst }) (src: ref td) (dst: ref td) : STT unit (pts_to src (mk_fraction td v_src p_src) `star` pts_to dst v_dst) (fun _ -> pts_to src (mk_fraction td v_src p_src) `star` pts_to dst v_src) val norm_field_attr : unit
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Base.fsti" }
[ { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "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.list FStar.Pervasives.norm_step
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_attr", "Prims.string", "Prims.Nil", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "FStar.Pervasives.primops" ]
[]
false
false
false
true
false
let norm_field_steps =
[delta_attr [`%norm_field_attr]; iota; zeta; primops]
false
Target.fst
Target.print_c_entry
val print_c_entry (_: opt_produce_everparse_error) (modul: string) (env: global_env) (ds:list decl) : ML (string & string)
val print_c_entry (_: opt_produce_everparse_error) (modul: string) (env: global_env) (ds:list decl) : ML (string & string)
let print_c_entry (produce_everparse_error: opt_produce_everparse_error) (modul: string) (env: global_env) (ds:list decl) : ML (string & string) = let default_error_handler = "static\n\ void DefaultErrorHandler(\n\t\ const char *typename_s,\n\t\ const char *fieldname,\n\t\ const char *reason,\n\t\ uint64_t error_code,\n\t\ uint8_t *context,\n\t\ EVERPARSE_INPUT_BUFFER input,\n\t\ uint64_t start_pos)\n\ {\n\t\ EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context;\n\t\ EverParseDefaultErrorHandler(\n\t\t\ typename_s,\n\t\t\ fieldname,\n\t\t\ reason,\n\t\t\ error_code,\n\t\t\ frame,\n\t\t\ input,\n\t\t\ start_pos\n\t\ );\n\ }" in let input_stream_binding = Options.get_input_stream_binding () in let is_input_stream_buffer = HashingOptions.InputStreamBuffer? input_stream_binding in let wrapped_call_buffer name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame;\n\t\ frame.filled = FALSE;\n\t\ %s\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0);\n\t\ if (EverParseIsError(result))\n\t\ {\n\t\t\ if (frame.filled)\n\t\t\ {\n\t\t\t\ %sEverParseError(frame.typename_s, frame.fieldname, frame.reason);\n\t\t\ }\n\t\t\ return FALSE;\n\t\ }\n\t\ return TRUE;" (if is_input_stream_buffer then "" else "EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t") name params modul in let wrapped_call_stream name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame =\n\t\ { .filled = FALSE,\n\t\ .typename_s = \"UNKNOWN\",\n\t\ .fieldname = \"UNKNOWN\",\n\t\ .reason = \"UNKNOWN\",\n\t\ .error_code = 0uL\n\ };\n\ EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t\ uint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, input, 0);\n\t\ uint64_t parsedSize = EverParseGetValidatorErrorPos(result);\n\ if (EverParseIsError(result))\n\t\ {\n\t\t\ EverParseHandleError(_extra, parsedSize, frame.typename_s, frame.fieldname, frame.reason, frame.error_code);\n\t\t\ }\n\t\ EverParseRetreat(_extra, base, parsedSize);\n\ return parsedSize;" name params in let mk_param (name: string) (typ: string) : Tot param = (A.with_range (A.to_ident' name) A.dummy_range, T_app (A.with_range (A.to_ident' typ) A.dummy_range) A.KindSpec []) in let print_one_validator (d:type_decl) : ML (string & string) = let params = d.decl_name.td_params @ (if is_input_stream_buffer then [] else [mk_param "_extra" "EVERPARSE_EXTRA_T"]) in let print_params (ps:list param) : ML string = let params = String.concat ", " (List.map (fun (id, t) -> Printf.sprintf "%s %s" (print_as_c_type t) (print_ident id)) ps) in match ps with | [] -> params | _ -> params ^ ", " in let print_arguments (ps:list param) : Tot string = let params = String.concat ", " (List.Tot.map (fun (id, t) -> if is_output_type t //output type pointers are uint8_t* in the F* generated code then (print_ident id) else print_ident id) ps) in match ps with | [] -> params | _ -> params ^ ", " in let wrapper_name = wrapper_name modul d.decl_name.td_name.A.v.A.name in let signature = if is_input_stream_buffer then Printf.sprintf "BOOLEAN %s(%suint8_t *base, uint32_t len)" wrapper_name (print_params params) else Printf.sprintf "uint64_t %s(%sEVERPARSE_INPUT_STREAM_BASE base)" wrapper_name (print_params params) in let validator_name = validator_name modul d.decl_name.td_name.A.v.A.name in let impl = let body = if is_input_stream_buffer then wrapped_call_buffer validator_name (print_arguments params) else wrapped_call_stream validator_name (print_arguments params) in Printf.sprintf "%s {\n\t%s\n}" signature body in signature ^";", impl in let signatures_output_typ_deps = List.fold_left (fun deps (d, _) -> match d with | Type_decl d -> if d.decl_name.td_entrypoint then let params = d.decl_name.td_params in List.fold_left (fun deps (_, t) -> match get_output_typ_dep modul t with | Some dep -> if List.mem dep deps then deps else deps@[dep] | _ -> deps) deps params else deps | _ -> deps) [] ds in let signatures, impls = List.split (List.collect (fun d -> match fst d with | Type_decl d -> if d.decl_name.td_entrypoint then [print_one_validator d] else [] | _ -> []) ds) in let external_defs_includes = if not (Options.get_emit_output_types_defs ()) then "" else let deps = if List.length signatures_output_typ_deps = 0 then "" else String.concat "" (List.map (fun dep -> Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" dep) signatures_output_typ_deps) in let self = if has_output_types ds || has_extern_types ds then Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n" modul else "" in Printf.sprintf "%s\n%s\n\n" deps self in let header = Printf.sprintf "#include \"EverParseEndianness.h\"\n\ %s\n\ %s\ #ifdef __cplusplus\n\ extern \"C\" {\n\ #endif\n\ %s\n\ #ifdef __cplusplus\n\ }\n\ #endif\n" error_code_macros external_defs_includes (signatures |> String.concat "\n\n") in let input_stream_include = HashingOptions.input_stream_include input_stream_binding in let header = if input_stream_include = "" then header else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include header in let add_includes = Options.make_includes () in let header = Printf.sprintf "%s%s" add_includes header in let error_callback_proto = if HashingOptions.InputStreamBuffer? input_stream_binding then Printf.sprintf "void %sEverParseError(const char *StructName, const char *FieldName, const char *Reason)%s" modul (if produce_everparse_error = Some ProduceEverParseError then "{(void) StructName; (void) FieldName; (void) Reason;}" else ";") else "" in let impl = Printf.sprintf "#include \"%sWrapper.h\"\n\ #include \"EverParse.h\"\n\ #include \"%s.h\"\n\ %s\n\n\ %s\n\n\ %s\n" modul modul error_callback_proto default_error_handler (impls |> String.concat "\n\n") in let impl = if input_stream_include = "" then impl else Printf.sprintf "#include \"%s\"\n\ %s" input_stream_include impl in let impl = Printf.sprintf "%s%s" add_includes impl in header, impl
{ "file_name": "src/3d/Target.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 1028, "start_col": 0, "start_line": 787 }
(* Copyright 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 Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding let lookup (s:subst) (i:A.ident) : option expr = List.Tot.assoc i.v s let rec subst_expr (s:subst) (e:expr) : expr = match fst e with | Constant _ -> e | Identifier i -> ( match lookup s i with | Some e' -> e' | None -> e ) | App hd args -> ( App hd (subst_exprs s args), snd e ) | Record tn fields -> ( Record tn (subst_fields s fields), snd e ) and subst_exprs s es = match es with | [] -> [] | e::es -> subst_expr s e :: subst_exprs s es and subst_fields s fs = match fs with | [] -> [] | (i, e)::fs -> (i, subst_expr s e)::subst_fields s fs let rec expr_eq e1 e2 = match fst e1, fst e2 with | Constant c1, Constant c2 -> c1=c2 | Identifier i1, Identifier i2 -> A.(i1.v = i2.v) | App hd1 args1, App hd2 args2 -> hd1 = hd2 && exprs_eq args1 args2 | Record t1 fields1, Record t2 fields2 -> A.(t1.v = t2.v) && fields_eq fields1 fields2 | _ -> false and exprs_eq es1 es2 = match es1, es2 with | [], [] -> true | e1::es1, e2::es2 -> expr_eq e1 e2 && exprs_eq es1 es2 | _ -> false and fields_eq fs1 fs2 = match fs1, fs2 with | [], [] -> true | (i1, e1)::fs1, (i2, e2)::fs2 -> A.(i1.v = i2.v) && fields_eq fs1 fs2 | _ -> false let rec parser_kind_eq k k' = match k.pk_kind, k'.pk_kind with | PK_return, PK_return -> true | PK_impos, PK_impos -> true | PK_list, PK_list -> true | PK_t_at_most, PK_t_at_most -> true | PK_t_exact, PK_t_exact -> true | PK_base hd1, PK_base hd2 -> A.(hd1.v = hd2.v) | PK_filter k, PK_filter k' -> parser_kind_eq k k' | PK_and_then k1 k2, PK_and_then k1' k2' | PK_glb k1 k2, PK_glb k1' k2' -> parser_kind_eq k1 k1' && parser_kind_eq k2 k2' | _ -> false let has_output_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type? d) ds let has_output_type_exprs (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Output_type_expr? d) ds let has_extern_types (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_type? d) ds let has_extern_functions (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_fn? d) ds let has_extern_probes (ds:list decl) : bool = List.Tot.existsb (fun (d, _) -> Extern_probe? d) ds let has_external_api (ds:list decl) : bool = has_output_type_exprs ds || has_extern_types ds || has_extern_functions ds || has_extern_probes ds // Some constants let default_attrs = { is_hoisted = false; is_if_def = false; is_exported = false; should_inline = false; comments = [] } let error_handler_name = let open A in let id' = { modul_name = None; name = "handle_error"; } in let id = with_range id' dummy_range in id let error_handler_decl = let open A in let error_handler_id' = { modul_name = Some "EverParse3d.Actions.Base"; name = "error_handler" } in let error_handler_id = with_range error_handler_id' dummy_range in let typ = T_app error_handler_id KindSpec [] in let a = Assumption (error_handler_name, typ) in a, default_attrs //////////////////////////////////////////////////////////////////////////////// // Printing the target AST in F* concrete syntax //////////////////////////////////////////////////////////////////////////////// let maybe_mname_prefix (mname:string) (i:A.ident) = let open A in match i.v.modul_name with | None -> "" | Some s -> if s = mname then "" else Printf.sprintf "%s." s let print_ident (i:A.ident) = let open A in match String.list_of_string i.v.name with | [] -> i.v.name | c0::_ -> if FStar.Char.lowercase c0 = c0 then i.v.name else Ast.reserved_prefix^i.v.name let print_maybe_qualified_ident (mname:string) (i:A.ident) = Printf.sprintf "%s%s" (maybe_mname_prefix mname i) (print_ident i) let print_field_id_name (i:A.ident) = let open A in match i.v.modul_name with | None -> failwith "Unexpected: module name missing from the field id" | Some m -> Printf.sprintf "%s_%s" (String.lowercase m) i.v.name let print_integer_type = let open A in function | UInt8 -> "uint8" | UInt16 -> "uint16" | UInt32 -> "uint32" | UInt64 -> "uint64" let namespace_of_integer_type = let open A in function | UInt8 -> "UInt8" | UInt16 -> "UInt16" | UInt32 -> "UInt32" | UInt64 -> "UInt64" let print_range (r:A.range) : string = let open A in Printf.sprintf "(FStar.Range.mk_range \"%s\" %d %d %d %d)" (fst r).filename (fst r).line (fst r).col (snd r).line (snd r).col let arith_op (o:op) = match o with | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> true | _ -> false let integer_type_of_arith_op (o:op{arith_op o}) = match o with | Plus t | Minus t | Mul t | Division t | Remainder t | ShiftLeft t | ShiftRight t | BitwiseAnd t | BitwiseOr t | BitwiseXor t | BitwiseNot t -> t let print_arith_op_range () : ML bool = List.length (Options.get_equate_types_list ()) = 0 let print_arith_op (o:op{arith_op o}) (r:option A.range) : ML string = let fn = match o with | Plus _ -> "add" | Minus _ -> "sub" | Mul _ -> "mul" | Division _ -> "div" | Remainder _ -> "rem" | ShiftLeft _ -> "shift_left" | ShiftRight _ -> "shift_right" | BitwiseAnd _ -> "logand" | BitwiseOr _ -> "logor" | BitwiseXor _ -> "logxor" | BitwiseNot _ -> "lognot" in if print_arith_op_range () then let t = match integer_type_of_arith_op o with | A.UInt8 -> "u8" | A.UInt16 -> "u16" | A.UInt32 -> "u32" | A.UInt64 -> "u64" in let r = match r with | Some r -> r | None -> A.dummy_range in Printf.sprintf "EverParse3d.Prelude.%s_%s %s" t fn (print_range r) else let m = match integer_type_of_arith_op o with | A.UInt8 -> "FStar.UInt8" | A.UInt16 -> "FStar.UInt16" | A.UInt32 -> "FStar.UInt32" | A.UInt64 -> "FStar.UInt64" in Printf.sprintf "%s.%s" m fn let is_infix = function | Eq | Neq | And | Or -> true | _ -> false // Bitfield operators from EverParse3d.Prelude.StaticHeader are least // significant bit first by default, following MSVC // (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields) let print_bitfield_bit_order = function | A.LSBFirst -> "" | A.MSBFirst -> "_msb_first" let print_op_with_range ropt o = match o with | Eq -> "=" | Neq -> "<>" | And -> "&&" | Or -> "||" | Not -> "not" | Plus _ | Minus _ | Mul _ | Division _ | Remainder _ | ShiftLeft _ | ShiftRight _ | BitwiseAnd _ | BitwiseOr _ | BitwiseXor _ | BitwiseNot _ -> print_arith_op o ropt | LT t -> Printf.sprintf "FStar.%s.lt" (namespace_of_integer_type t) | GT t -> Printf.sprintf "FStar.%s.gt" (namespace_of_integer_type t) | LE t -> Printf.sprintf "FStar.%s.lte" (namespace_of_integer_type t) | GE t -> Printf.sprintf "FStar.%s.gte" (namespace_of_integer_type t) | IfThenElse -> "ite" | BitFieldOf i order -> Printf.sprintf "get_bitfield%d%s" i (print_bitfield_bit_order order) | Cast from to -> let tfrom = print_integer_type from in let tto = print_integer_type to in if tfrom = tto then "EverParse3d.Prelude.id" else Printf.sprintf "EverParse3d.Prelude.%s_to_%s" tfrom tto | Ext s -> s let print_op = print_op_with_range None let rec print_expr (mname:string) (e:expr) : ML string = match fst e with | Constant c -> A.print_constant c | Identifier i -> print_maybe_qualified_ident mname i | Record nm fields -> Printf.sprintf "{ %s }" (String.concat "; " (print_fields mname fields)) | App op [e1;e2] -> if is_infix op then Printf.sprintf "(%s %s %s)" (print_expr mname e1) (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e2) else Printf.sprintf "(%s %s %s)" (print_op_with_range (Some (snd e)) (App?.hd (fst e))) (print_expr mname e1) (print_expr mname e2) | App Not [e1] | App (BitwiseNot _) [e1] -> Printf.sprintf "(%s %s)" (print_op (App?.hd (fst e))) (print_expr mname e1) | App IfThenElse [e1;e2;e3] -> Printf.sprintf "(if %s then %s else %s)" (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App (BitFieldOf i order) [e1;e2;e3] -> Printf.sprintf "(%s %s %s %s)" (print_op (BitFieldOf i order)) (print_expr mname e1) (print_expr mname e2) (print_expr mname e3) | App op [] -> print_op op | App op es -> Printf.sprintf "(%s %s)" (print_op op) (String.concat " " (print_exprs mname es)) and print_exprs (mname:string) (es:list expr) : ML (list string) = match es with | [] -> [] | hd::tl -> print_expr mname hd :: print_exprs mname tl and print_fields (mname:string) (fs:_) : ML (list string) = match fs with | [] -> [] | (x, e)::tl -> Printf.sprintf "%s = %s" (print_ident x) (print_expr mname e) :: print_fields mname tl let print_lam (#a:Type) (f:a -> ML string) (x:lam a) : ML string = match x with | Some x, y -> Printf.sprintf ("(fun %s -> %s)") (print_ident x) (f y) | None, y -> f y let print_expr_lam (mname:string) (x:lam expr) : ML string = print_lam (print_expr mname) x let rec is_output_type (t:typ) : bool = match t with | T_app _ A.KindOutput [] -> true | T_pointer t -> is_output_type t | _ -> false let rec is_extern_type (t:typ) : bool = match t with | T_app _ A.KindExtern [] -> true | T_pointer t -> is_extern_type t | _ -> false (* * An output type is printed as the ident, or p_<ident> * * They are abstract types in the emitted F* code *) let print_output_type (qual:bool) (t:typ) : ML string = let rec aux (t:typ) : ML (option string & string) = match t with | T_app id _ _ -> id.v.modul_name, print_ident id | T_pointer t -> let m, i = aux t in m, Printf.sprintf "p_%s" i | _ -> failwith "Print: not an output type" in let mopt, i = aux t in if qual then match mopt with | None -> i | Some m -> Printf.sprintf "%s.ExternalTypes.%s" m i else i let rec print_typ (mname:string) (t:typ) : ML string = //(decreases t) = if is_output_type t then print_output_type true t else match t with | T_false -> "False" | T_app hd _ args -> //output types are already handled at the beginning of print_typ Printf.sprintf "(%s %s)" (print_maybe_qualified_ident mname hd) (String.concat " " (print_indexes mname args)) | T_dep_pair t1 (x, t2) -> Printf.sprintf "(%s:%s & %s)" (print_ident x) (print_typ mname t1) (print_typ mname t2) | T_refine t e -> Printf.sprintf "(refine %s %s)" (print_typ mname t) (print_expr_lam mname e) | T_if_else e t1 t2 -> Printf.sprintf "(t_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname e) (print_typ mname t1) (print_typ mname t2) | T_pointer t -> Printf.sprintf "bpointer (%s)" (print_typ mname t) | T_with_action t _ | T_with_dep_action t _ | T_with_comment t _ -> print_typ mname t | T_with_probe t _ _ _ -> Printf.sprintf "bpointer (%s)" (print_typ mname t) and print_indexes (mname:string) (is:list index) : ML (list string) = //(decreases is) = match is with | [] -> [] | Inl t::is -> print_typ mname t::print_indexes mname is | Inr e::is -> print_expr mname e::print_indexes mname is let rec print_kind (mname:string) (k:parser_kind) : Tot string = match k.pk_kind with | PK_base hd -> Printf.sprintf "%skind_%s" (maybe_mname_prefix mname hd) (print_ident hd) | PK_list -> "kind_nlist" | PK_t_at_most -> "kind_t_at_most" | PK_t_exact -> "kind_t_exact" | PK_return -> "ret_kind" | PK_impos -> "impos_kind" | PK_and_then k1 k2 -> Printf.sprintf "(and_then_kind %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_glb k1 k2 -> Printf.sprintf "(glb %s %s)" (print_kind mname k1) (print_kind mname k2) | PK_filter k -> Printf.sprintf "(filter_kind %s)" (print_kind mname k) | PK_string -> "parse_string_kind" let rec print_action (mname:string) (a:action) : ML string = let print_atomic_action (a:atomic_action) : ML string = match a with | Action_return e -> Printf.sprintf "(action_return %s)" (print_expr mname e) | Action_abort -> "(action_abort())" | Action_field_pos_64 -> "(action_field_pos_64())" | Action_field_pos_32 -> "(action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr -> "(action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)" | Action_field_ptr_after sz write_to -> Printf.sprintf "(action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)" (print_expr mname sz) (print_ident write_to) | Action_field_ptr_after_with_setter sz write_to_field write_to_obj -> Printf.sprintf "(action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))" (print_expr mname sz) (print_ident write_to_field) (print_expr mname write_to_obj) | Action_deref i -> Printf.sprintf "(action_deref %s)" (print_ident i) | Action_assignment lhs rhs -> Printf.sprintf "(action_assignment %s %s)" (print_ident lhs) (print_expr mname rhs) | Action_call f args -> Printf.sprintf "(mk_extern_action (%s %s))" (print_ident f) (String.concat " " (List.map (print_expr mname) args)) in match a with | Atomic_action a -> print_atomic_action a | Action_seq hd tl -> Printf.sprintf "(action_seq %s %s)" (print_atomic_action hd) (print_action mname tl) | Action_ite hd then_ else_ -> Printf.sprintf "(action_ite %s (fun _ -> %s) (fun _ -> %s))" (print_expr mname hd) (print_action mname then_) (print_action mname else_) | Action_let i a k -> Printf.sprintf "(action_bind \"%s\" %s (fun %s -> %s))" (print_ident i) (print_atomic_action a) (print_ident i) (print_action mname k) | Action_act a -> Printf.sprintf "(action_act %s)" (print_action mname a) let print_typedef_name (mname:string) (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> Printf.sprintf "(%s:%s)" (print_ident id) (print_typ mname t)) tdn.td_params)) let print_typedef_typ (tdn:typedef_name) : ML string = Printf.sprintf "%s %s" (print_ident tdn.td_name) (String.concat " " (List.map (fun (id, t) -> (print_ident id)) tdn.td_params)) let print_typedef_body (mname:string) (b:typedef_body) : ML string = match b with | TD_abbrev t -> print_typ mname t | TD_struct fields -> let print_field (sf:field) : ML string = Printf.sprintf "%s : %s%s" (print_ident sf.sf_ident) (print_typ mname sf.sf_typ) (if sf.sf_dependence then " (*dep*)" else "") in let fields = String.concat ";\n" (List.map print_field fields) in Printf.sprintf "{\n%s\n}" fields let print_typedef_actions_inv_and_fp (td:type_decl) = //we need to add output loc to the modifies locs //if there is an output type type parameter let should_add_output_loc = List.Tot.existsb (fun (_, t) -> is_output_type t || is_extern_type t) td.decl_name.td_params in let pointers = //get only non output type pointers List.Tot.filter (fun (x, t) -> T_pointer? t && not (is_output_type t || is_extern_type t)) td.decl_name.td_params in let inv = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "((ptr_inv %s) `conj_inv` %s)" (print_ident x) out) pointers "true_inv" in let fp = List.Tot.fold_right (fun (x, t) out -> Printf.sprintf "(eloc_union (ptr_loc %s) %s)" (print_ident x) out) pointers (if should_add_output_loc then "output_loc" else "eloc_none") in inv, fp let print_comments (cs:list string) : string = match cs with | [] -> "" | _ -> let c = String.concat "\\n\\\n" cs in Printf.sprintf " (Comment \"%s\")" c let print_attributes (entrypoint:bool) (attrs:decl_attributes) : string = match attrs.comments with | [] -> if entrypoint || attrs.is_exported then "" else if attrs.should_inline then "inline_for_extraction noextract\n" else "[@ (CInline)]\n" | cs -> Printf.sprintf "[@ %s %s]\n%s" (print_comments cs) (if not entrypoint && not attrs.is_exported && not attrs.should_inline then "(CInline)" else "") (if attrs.should_inline then "inline_for_extraction\n" else "") /// Printing a decl for M.Types.fst /// /// Print all the definitions, and for a Type_decl, only the type definition let maybe_print_type_equality (mname:string) (td:type_decl) : ML string = if td.decl_name.td_entrypoint then let equate_types_list = Options.get_equate_types_list () in (match (List.tryFind (fun (_, m) -> m = mname) equate_types_list) with | Some (a, _) -> let typname = A.ident_name td.decl_name.td_name in Printf.sprintf "\n\nlet _ = assert (%s.Types.%s == %s) by (FStar.Tactics.trefl ())\n\n" a typname typname | None -> "") else "" let print_definition (mname:string) (d:decl { Definition? (fst d)} ) : ML string = match fst d with | Definition (x, [], T_app ({Ast.v={Ast.name="field_id"}}) _ _, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot field_id by (FStar.Tactics.trivial())\n\n" (print_comments (snd d).comments) (print_field_id_name x) (A.print_constant c) | Definition (x, [], t, (Constant c, _)) -> Printf.sprintf "[@(CMacro)%s]\nlet %s = %s <: Tot %s\n\n" (print_comments (snd d).comments) (print_ident x) (A.print_constant c) (print_typ mname t) | Definition (x, params, typ, expr) -> let x_ps = { td_name = x; td_params = params; td_entrypoint = false } in Printf.sprintf "%slet %s : %s = %s\n\n" (print_attributes false (snd d)) (print_typedef_name mname x_ps) (print_typ mname typ) (print_expr mname expr) let print_assumption (mname:string) (d:decl { Assumption? (fst d) } ) : ML string = match fst d with | Assumption (x, t) -> Printf.sprintf "%sassume\nval %s : %s\n\n" (if (snd d).is_if_def then "[@@ CIfDef ]\n" else "") (print_ident x) (print_typ mname t) let print_decl_for_types (mname:string) (d:decl) : ML string = match fst d with | Assumption _ -> "" | Definition _ -> print_definition mname d | Type_decl td -> Printf.sprintf "noextract\ninline_for_extraction\ntype %s = %s\n\n" (print_typedef_name mname td.decl_name) (print_typedef_body mname td.decl_typ) `strcat` maybe_print_type_equality mname td | Output_type _ | Output_type_expr _ _ | Extern_type _ | Extern_fn _ _ _ | Extern_probe _ -> "" /// Print a decl for M.fst /// /// No need to print Definition(s), they are `include`d from M.Types.fst /// /// For a Type_decl, if it is an entry point, we need to emit a definition since /// there is a corresponding declaration in the .fsti /// We make the definition as simply the definition in M.Types.fst let is_type_abbreviation (td:type_decl) : bool = match td.decl_typ with | TD_abbrev _ -> true | TD_struct _ -> false let external_api_include (modul:string) (ds:list decl) : string = if has_external_api ds then Printf.sprintf "open %s.ExternalAPI\n\n" modul else "" #push-options "--z3rlimit_factor 4" let pascal_case name : ML string = let chars = String.list_of_string name in let has_underscore = List.mem '_' chars in let keep, up, low = 0, 1, 2 in if has_underscore then let what_next : ref int = alloc up in let rewrite_char c : ML (list FStar.Char.char) = match c with | '_' -> what_next := up; [] | c -> let c_next = let n = !what_next in if n = keep then c else if n = up then FStar.Char.uppercase c else FStar.Char.lowercase c in let _ = if Char.uppercase c = c then what_next := low else if Char.lowercase c = c then what_next := keep in [c_next] in let chars = List.collect rewrite_char (String.list_of_string name) in String.string_of_list chars else if String.length name = 0 then name else String.uppercase (String.sub name 0 1) ^ String.sub name 1 (String.length name - 1) let uppercase (name:string) : string = String.uppercase name let rec print_as_c_type (t:typ) : ML string = let open Ast in match t with | T_pointer t -> Printf.sprintf "%s*" (print_as_c_type t) | T_app {v={name="Bool"}} _ [] -> "BOOLEAN" | T_app {v={name="UINT8"}} _ [] -> "uint8_t" | T_app {v={name="UINT16"}} _ [] -> "uint16_t" | T_app {v={name="UINT32"}} _ [] -> "uint32_t" | T_app {v={name="UINT64"}} _ [] -> "uint64_t" | T_app {v={name="PUINT8"}} _ [] -> "uint8_t*" | T_app {v={name=x}} KindSpec [] -> x | T_app {v={name=x}} _ [] -> uppercase x | _ -> "__UNKNOWN__" let error_code_macros = //To be kept consistent with EverParse3d.ErrorCode.error_reason_of_result "#define EVERPARSE_ERROR_GENERIC 1uL\n\ #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL\n\ #define EVERPARSE_ERROR_IMPOSSIBLE 3uL\n\ #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL\n\ #define EVERPARSE_ERROR_ACTION_FAILED 5uL\n\ #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL\n\ #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL\n" let rec get_output_typ_dep (modul:string) (t:typ) : ML (option string) = match t with | T_app {v={modul_name=None}} _ _ -> None | T_app {v={modul_name=Some m}} _ _ -> if m = modul then None else Some m | T_pointer t -> get_output_typ_dep modul t | _ -> failwith "get_typ_deps: unexpected output type" let wrapper_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_check_%s" modul fn |> pascal_case let validator_name (modul: string) (fn: string) : ML string = Printf.sprintf "%s_validate_%s" modul fn |> pascal_case
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Target.fst" }
[ { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "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": 4, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
produce_everparse_error: Target.opt_produce_everparse_error -> modul: Prims.string -> env: GlobalEnv.global_env -> ds: Prims.list Target.decl -> FStar.All.ML (Prims.string * Prims.string)
FStar.All.ML
[ "ml" ]
[]
[ "Target.opt_produce_everparse_error", "Prims.string", "GlobalEnv.global_env", "Prims.list", "Target.decl", "FStar.Pervasives.Native.Mktuple2", "FStar.Printf.sprintf", "Prims.op_Equality", "Prims.bool", "FStar.String.concat", "HashingOptions.uu___is_InputStreamBuffer", "FStar.Pervasives.Native.option", "Target.produce_everparse_error", "FStar.Pervasives.Native.Some", "Target.ProduceEverParseError", "FStar.Pervasives.Native.tuple2", "Options.make_includes", "HashingOptions.input_stream_include", "Target.error_code_macros", "Prims.op_BarBar", "Target.has_output_types", "Target.has_extern_types", "Prims.int", "FStar.List.Tot.Base.length", "FStar.List.map", "Prims.op_Negation", "Options.get_emit_output_types_defs", "FStar.List.Tot.Base.split", "FStar.List.collect", "Target.decl'", "Target.decl_attributes", "FStar.Pervasives.Native.fst", "Target.type_decl", "Target.__proj__Mktypedef_name__item__td_entrypoint", "Target.__proj__Mktype_decl__item__decl_name", "Prims.Cons", "Prims.Nil", "FStar.List.fold_left", "Ast.ident", "Target.typ", "FStar.List.Tot.Base.mem", "FStar.List.Tot.Base.append", "Target.get_output_typ_dep", "Target.param", "Target.__proj__Mktypedef_name__item__td_params", "Prims.op_Hat", "Target.validator_name", "Ast.__proj__Mkident'__item__name", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.ident'", "Target.__proj__Mktypedef_name__item__td_name", "Target.wrapper_name", "FStar.List.Tot.Base.map", "Target.is_output_type", "Target.print_ident", "Target.print_as_c_type", "Ast.with_range", "Ast.to_ident'", "Ast.dummy_range", "Target.T_app", "Ast.KindSpec", "FStar.Pervasives.either", "Target.expr", "HashingOptions.input_stream_binding_t", "Options.get_input_stream_binding" ]
[]
false
true
false
false
false
let print_c_entry (produce_everparse_error: opt_produce_everparse_error) (modul: string) (env: global_env) (ds: list decl) : ML (string & string) =
let default_error_handler = "static\nvoid DefaultErrorHandler(\n\tconst char *typename_s,\n\tconst char *fieldname,\n\tconst char *reason,\n\tuint64_t error_code,\n\tuint8_t *context,\n\tEVERPARSE_INPUT_BUFFER input,\n\tuint64_t start_pos)\n{\n\tEVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context;\n\tEverParseDefaultErrorHandler(\n\t\ttypename_s,\n\t\tfieldname,\n\t\treason,\n\t\terror_code,\n\t\tframe,\n\t\tinput,\n\t\tstart_pos\n\t);\n}" in let input_stream_binding = Options.get_input_stream_binding () in let is_input_stream_buffer = HashingOptions.InputStreamBuffer? input_stream_binding in let wrapped_call_buffer name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame;\n\tframe.filled = FALSE;\n\t%suint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0);\n\tif (EverParseIsError(result))\n\t{\n\t\tif (frame.filled)\n\t\t{\n\t\t\t%sEverParseError(frame.typename_s, frame.fieldname, frame.reason);\n\t\t}\n\t\treturn FALSE;\n\t}\n\treturn TRUE;" (if is_input_stream_buffer then "" else "EVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\t") name params modul in let wrapped_call_stream name params = Printf.sprintf "EVERPARSE_ERROR_FRAME frame =\n\t{ .filled = FALSE,\n\t.typename_s = \"UNKNOWN\",\n\t.fieldname = \"UNKNOWN\",\n\t.reason = \"UNKNOWN\",\n\t.error_code = 0uL\n};\nEVERPARSE_INPUT_BUFFER input = EverParseMakeInputBuffer(base);\n\tuint64_t result = %s(%s (uint8_t*)&frame, &DefaultErrorHandler, input, 0);\n\tuint64_t parsedSize = EverParseGetValidatorErrorPos(result);\nif (EverParseIsError(result))\n\t{\n\t\tEverParseHandleError(_extra, parsedSize, frame.typename_s, frame.fieldname, frame.reason, frame.error_code);\n\t\t}\n\tEverParseRetreat(_extra, base, parsedSize);\nreturn parsedSize;" name params in let mk_param (name typ: string) : Tot param = (A.with_range (A.to_ident' name) A.dummy_range, T_app (A.with_range (A.to_ident' typ) A.dummy_range) A.KindSpec []) in let print_one_validator (d: type_decl) : ML (string & string) = let params = d.decl_name.td_params @ (if is_input_stream_buffer then [] else [mk_param "_extra" "EVERPARSE_EXTRA_T"]) in let print_params (ps: list param) : ML string = let params = String.concat ", " (List.map (fun (id, t) -> Printf.sprintf "%s %s" (print_as_c_type t) (print_ident id)) ps) in match ps with | [] -> params | _ -> params ^ ", " in let print_arguments (ps: list param) : Tot string = let params = String.concat ", " (List.Tot.map (fun (id, t) -> if is_output_type t then (print_ident id) else print_ident id) ps) in match ps with | [] -> params | _ -> params ^ ", " in let wrapper_name = wrapper_name modul d.decl_name.td_name.A.v.A.name in let signature = if is_input_stream_buffer then Printf.sprintf "BOOLEAN %s(%suint8_t *base, uint32_t len)" wrapper_name (print_params params) else Printf.sprintf "uint64_t %s(%sEVERPARSE_INPUT_STREAM_BASE base)" wrapper_name (print_params params) in let validator_name = validator_name modul d.decl_name.td_name.A.v.A.name in let impl = let body = if is_input_stream_buffer then wrapped_call_buffer validator_name (print_arguments params) else wrapped_call_stream validator_name (print_arguments params) in Printf.sprintf "%s {\n\t%s\n}" signature body in signature ^ ";", impl in let signatures_output_typ_deps = List.fold_left (fun deps (d, _) -> match d with | Type_decl d -> if d.decl_name.td_entrypoint then let params = d.decl_name.td_params in List.fold_left (fun deps (_, t) -> match get_output_typ_dep modul t with | Some dep -> if List.mem dep deps then deps else deps @ [dep] | _ -> deps) deps params else deps | _ -> deps) [] ds in let signatures, impls = List.split (List.collect (fun d -> match fst d with | Type_decl d -> if d.decl_name.td_entrypoint then [print_one_validator d] else [] | _ -> []) ds) in let external_defs_includes = if not (Options.get_emit_output_types_defs ()) then "" else let deps = if List.length signatures_output_typ_deps = 0 then "" else String.concat "" (List.map (fun dep -> Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n\n" dep) signatures_output_typ_deps) in let self = if has_output_types ds || has_extern_types ds then Printf.sprintf "#include \"%s_ExternalTypedefs.h\"\n" modul else "" in Printf.sprintf "%s\n%s\n\n" deps self in let header = Printf.sprintf "#include \"EverParseEndianness.h\"\n%s\n%s#ifdef __cplusplus\nextern \"C\" {\n#endif\n%s\n#ifdef __cplusplus\n}\n#endif\n" error_code_macros external_defs_includes (signatures |> String.concat "\n\n") in let input_stream_include = HashingOptions.input_stream_include input_stream_binding in let header = if input_stream_include = "" then header else Printf.sprintf "#include \"%s\"\n%s" input_stream_include header in let add_includes = Options.make_includes () in let header = Printf.sprintf "%s%s" add_includes header in let error_callback_proto = if HashingOptions.InputStreamBuffer? input_stream_binding then Printf.sprintf "void %sEverParseError(const char *StructName, const char *FieldName, const char *Reason)%s" modul (if produce_everparse_error = Some ProduceEverParseError then "{(void) StructName; (void) FieldName; (void) Reason;}" else ";") else "" in let impl = Printf.sprintf "#include \"%sWrapper.h\"\n#include \"EverParse.h\"\n#include \"%s.h\"\n%s\n\n%s\n\n%s\n" modul modul error_callback_proto default_error_handler (impls |> String.concat "\n\n") in let impl = if input_stream_include = "" then impl else Printf.sprintf "#include \"%s\"\n%s" input_stream_include impl in let impl = Printf.sprintf "%s%s" add_includes impl in header, impl
false
Vale.AES.PPC64LE.GF128_Mul.fsti
Vale.AES.PPC64LE.GF128_Mul.va_wp_Low64ToHigh
val va_wp_Low64ToHigh (dst src: va_operand_vec_opr) (a: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
val va_wp_Low64ToHigh (dst src: va_operand_vec_opr) (a: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
let va_wp_Low64ToHigh (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_dst:va_value_vec_opr) . let va_sM = va_upd_operand_vec_opr dst va_x_dst va_s0 in va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.mod a (Vale.Math.Poly2_s.monomial 64)) (Vale.Math.Poly2_s.monomial 64)) ==> va_k va_sM (())))
{ "file_name": "obj/Vale.AES.PPC64LE.GF128_Mul.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 120, "start_col": 0, "start_line": 112 }
module Vale.AES.PPC64LE.GF128_Mul open Vale.Def.Types_s open Vale.Arch.Types open Vale.Arch.TypesNative open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.Math.Poly2.Lemmas open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.PPC64LE.Machine_s open Vale.PPC64LE.State open Vale.PPC64LE.Decls open Vale.PPC64LE.InsBasic open Vale.PPC64LE.InsMem open Vale.PPC64LE.InsVector open Vale.PPC64LE.QuickCode open Vale.PPC64LE.QuickCodes open Vale.AES.PPC64LE.PolyOps open Vale.AES.Types_helpers open Vale.AES.GHash_BE //-- ShiftLeft128_1 val va_code_ShiftLeft128_1 : va_dummy:unit -> Tot va_code val va_codegen_success_ShiftLeft128_1 : va_dummy:unit -> Tot va_pbool val va_lemma_ShiftLeft128_1 : va_b0:va_code -> va_s0:va_state -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_ShiftLeft128_1 ()) va_s0 /\ va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) /\ va_state_eq va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_ok va_sM va_s0))))) [@ va_qattr] let va_wp_ShiftLeft128_1 (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_v1:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 va_s0) in va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) ==> va_k va_sM (()))) val va_wpProof_ShiftLeft128_1 : a:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_ShiftLeft128_1 a va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftLeft128_1 ()) ([va_Mod_vec 2; va_Mod_vec 1]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_ShiftLeft128_1 (a:poly) : (va_quickCode unit (va_code_ShiftLeft128_1 ())) = (va_QProc (va_code_ShiftLeft128_1 ()) ([va_Mod_vec 2; va_Mod_vec 1]) (va_wp_ShiftLeft128_1 a) (va_wpProof_ShiftLeft128_1 a)) //-- //-- High64ToLow val va_code_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_code val va_codegen_success_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_pbool val va_lemma_High64ToLow : va_b0:va_code -> va_s0:va_state -> dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_High64ToLow dst src) va_s0 /\ va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.div a (Vale.Math.Poly2_s.monomial 64)) /\ va_state_eq va_sM (va_update_ok va_sM (va_update_operand_vec_opr dst va_sM va_s0)))) [@ va_qattr] let va_wp_High64ToLow (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_dst:va_value_vec_opr) . let va_sM = va_upd_operand_vec_opr dst va_x_dst va_s0 in va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.div a (Vale.Math.Poly2_s.monomial 64)) ==> va_k va_sM (()))) val va_wpProof_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_High64ToLow dst src a va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_High64ToLow dst src) ([va_mod_vec_opr dst]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_High64ToLow (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) : (va_quickCode unit (va_code_High64ToLow dst src)) = (va_QProc (va_code_High64ToLow dst src) ([va_mod_vec_opr dst]) (va_wp_High64ToLow dst src a) (va_wpProof_High64ToLow dst src a)) //-- //-- Low64ToHigh val va_code_Low64ToHigh : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_code val va_codegen_success_Low64ToHigh : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_pbool val va_lemma_Low64ToHigh : va_b0:va_code -> va_s0:va_state -> dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Low64ToHigh dst src) va_s0 /\ va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.mod a (Vale.Math.Poly2_s.monomial 64)) (Vale.Math.Poly2_s.monomial 64)) /\ va_state_eq va_sM (va_update_ok va_sM (va_update_operand_vec_opr dst va_sM va_s0))))
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.QuickCodes.fsti.checked", "Vale.PPC64LE.QuickCode.fst.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.InsVector.fsti.checked", "Vale.PPC64LE.InsMem.fsti.checked", "Vale.PPC64LE.InsBasic.fsti.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.PPC64LE.PolyOps.fsti.checked", "Vale.AES.GHash_BE.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.PPC64LE.GF128_Mul.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.GHash_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "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
dst: Vale.PPC64LE.Decls.va_operand_vec_opr -> src: Vale.PPC64LE.Decls.va_operand_vec_opr -> a: Vale.Math.Poly2_s.poly -> va_s0: Vale.PPC64LE.Decls.va_state -> va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0) -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Decls.va_operand_vec_opr", "Vale.Math.Poly2_s.poly", "Vale.PPC64LE.Decls.va_state", "Prims.unit", "Prims.l_and", "Vale.PPC64LE.Decls.va_is_dst_vec_opr", "Vale.PPC64LE.Decls.va_is_src_vec_opr", "Prims.b2t", "Vale.PPC64LE.Decls.va_get_ok", "Prims.eq2", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat32", "Vale.PPC64LE.Decls.va_get_vec", "Vale.Def.Words_s.Mkfour", "Prims.op_LessThanOrEqual", "Vale.Math.Poly2_s.degree", "Vale.Def.Types_s.quad32", "Vale.PPC64LE.Decls.va_eval_vec_opr", "Vale.Math.Poly2.Bits_s.to_quad32", "Prims.l_Forall", "Vale.PPC64LE.Decls.va_value_vec_opr", "Prims.l_imp", "Vale.Math.Poly2_s.mul", "Vale.Math.Poly2_s.mod", "Vale.Math.Poly2_s.monomial", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Decls.va_upd_operand_vec_opr" ]
[]
false
false
false
true
true
let va_wp_Low64ToHigh (dst src: va_operand_vec_opr) (a: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 =
(va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_dst: va_value_vec_opr). let va_sM = va_upd_operand_vec_opr dst va_x_dst va_s0 in va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.mod a (Vale.Math.Poly2_s.monomial 64)) (Vale.Math.Poly2_s.monomial 64)) ==> va_k va_sM (())))
false
Vale.AES.PPC64LE.GF128_Mul.fsti
Vale.AES.PPC64LE.GF128_Mul.va_wp_ReduceMulRev128
val va_wp_ReduceMulRev128 (a b: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
val va_wp_ReduceMulRev128 (a b: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
let va_wp_ReduceMulRev128 (a:poly) (b:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ Vale.Math.Poly2_s.degree b <= 127 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse a 127) /\ va_get_vec 2 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse b 127) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) . let va_sM = va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))) in va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse (Vale.AES.GF128_s.gf128_mul a b) 127) ==> va_k va_sM (())))
{ "file_name": "obj/Vale.AES.PPC64LE.GF128_Mul.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 63, "end_line": 163, "start_col": 0, "start_line": 153 }
module Vale.AES.PPC64LE.GF128_Mul open Vale.Def.Types_s open Vale.Arch.Types open Vale.Arch.TypesNative open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.Math.Poly2.Lemmas open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.PPC64LE.Machine_s open Vale.PPC64LE.State open Vale.PPC64LE.Decls open Vale.PPC64LE.InsBasic open Vale.PPC64LE.InsMem open Vale.PPC64LE.InsVector open Vale.PPC64LE.QuickCode open Vale.PPC64LE.QuickCodes open Vale.AES.PPC64LE.PolyOps open Vale.AES.Types_helpers open Vale.AES.GHash_BE //-- ShiftLeft128_1 val va_code_ShiftLeft128_1 : va_dummy:unit -> Tot va_code val va_codegen_success_ShiftLeft128_1 : va_dummy:unit -> Tot va_pbool val va_lemma_ShiftLeft128_1 : va_b0:va_code -> va_s0:va_state -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_ShiftLeft128_1 ()) va_s0 /\ va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) /\ va_state_eq va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_ok va_sM va_s0))))) [@ va_qattr] let va_wp_ShiftLeft128_1 (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_v1:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 va_s0) in va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) ==> va_k va_sM (()))) val va_wpProof_ShiftLeft128_1 : a:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_ShiftLeft128_1 a va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftLeft128_1 ()) ([va_Mod_vec 2; va_Mod_vec 1]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_ShiftLeft128_1 (a:poly) : (va_quickCode unit (va_code_ShiftLeft128_1 ())) = (va_QProc (va_code_ShiftLeft128_1 ()) ([va_Mod_vec 2; va_Mod_vec 1]) (va_wp_ShiftLeft128_1 a) (va_wpProof_ShiftLeft128_1 a)) //-- //-- High64ToLow val va_code_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_code val va_codegen_success_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_pbool val va_lemma_High64ToLow : va_b0:va_code -> va_s0:va_state -> dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_High64ToLow dst src) va_s0 /\ va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.div a (Vale.Math.Poly2_s.monomial 64)) /\ va_state_eq va_sM (va_update_ok va_sM (va_update_operand_vec_opr dst va_sM va_s0)))) [@ va_qattr] let va_wp_High64ToLow (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_dst:va_value_vec_opr) . let va_sM = va_upd_operand_vec_opr dst va_x_dst va_s0 in va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.div a (Vale.Math.Poly2_s.monomial 64)) ==> va_k va_sM (()))) val va_wpProof_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_High64ToLow dst src a va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_High64ToLow dst src) ([va_mod_vec_opr dst]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_High64ToLow (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) : (va_quickCode unit (va_code_High64ToLow dst src)) = (va_QProc (va_code_High64ToLow dst src) ([va_mod_vec_opr dst]) (va_wp_High64ToLow dst src a) (va_wpProof_High64ToLow dst src a)) //-- //-- Low64ToHigh val va_code_Low64ToHigh : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_code val va_codegen_success_Low64ToHigh : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_pbool val va_lemma_Low64ToHigh : va_b0:va_code -> va_s0:va_state -> dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Low64ToHigh dst src) va_s0 /\ va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.mod a (Vale.Math.Poly2_s.monomial 64)) (Vale.Math.Poly2_s.monomial 64)) /\ va_state_eq va_sM (va_update_ok va_sM (va_update_operand_vec_opr dst va_sM va_s0)))) [@ va_qattr] let va_wp_Low64ToHigh (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_dst:va_value_vec_opr) . let va_sM = va_upd_operand_vec_opr dst va_x_dst va_s0 in va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.mod a (Vale.Math.Poly2_s.monomial 64)) (Vale.Math.Poly2_s.monomial 64)) ==> va_k va_sM (()))) val va_wpProof_Low64ToHigh : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_Low64ToHigh dst src a va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Low64ToHigh dst src) ([va_mod_vec_opr dst]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_Low64ToHigh (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) : (va_quickCode unit (va_code_Low64ToHigh dst src)) = (va_QProc (va_code_Low64ToHigh dst src) ([va_mod_vec_opr dst]) (va_wp_Low64ToHigh dst src a) (va_wpProof_Low64ToHigh dst src a)) //-- //-- ReduceMulRev128 val va_code_ReduceMulRev128 : va_dummy:unit -> Tot va_code val va_codegen_success_ReduceMulRev128 : va_dummy:unit -> Tot va_pbool val va_lemma_ReduceMulRev128 : va_b0:va_code -> va_s0:va_state -> a:poly -> b:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_ReduceMulRev128 ()) va_s0 /\ va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ Vale.Math.Poly2_s.degree b <= 127 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse a 127) /\ va_get_vec 2 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse b 127))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse (Vale.AES.GF128_s.gf128_mul a b) 127) /\ va_state_eq va_sM (va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))))))))
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.QuickCodes.fsti.checked", "Vale.PPC64LE.QuickCode.fst.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.InsVector.fsti.checked", "Vale.PPC64LE.InsMem.fsti.checked", "Vale.PPC64LE.InsBasic.fsti.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.PPC64LE.PolyOps.fsti.checked", "Vale.AES.GHash_BE.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.PPC64LE.GF128_Mul.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.GHash_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "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.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> va_s0: Vale.PPC64LE.Decls.va_state -> va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0) -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.poly", "Vale.PPC64LE.Decls.va_state", "Prims.unit", "Prims.l_and", "Prims.b2t", "Vale.PPC64LE.Decls.va_get_ok", "Prims.op_LessThanOrEqual", "Vale.Math.Poly2_s.degree", "Prims.eq2", "Vale.Def.Types_s.quad32", "Vale.PPC64LE.Decls.va_get_vec", "Vale.Math.Poly2.Bits_s.to_quad32", "Vale.Math.Poly2_s.reverse", "Prims.l_Forall", "Vale.PPC64LE.Machine_s.nat64", "Vale.PPC64LE.Machine_s.quad32", "Prims.l_imp", "Vale.AES.GF128_s.gf128_mul", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Decls.va_upd_vec", "Vale.PPC64LE.Decls.va_upd_reg" ]
[]
false
false
false
true
true
let va_wp_ReduceMulRev128 (a b: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ Vale.Math.Poly2_s.degree b <= 127 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse a 127) /\ va_get_vec 2 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse b 127) /\ (forall (va_x_r10: nat64) (va_x_v0: quad32) (va_x_v1: quad32) (va_x_v2: quad32) (va_x_v3: quad32) (va_x_v4: quad32) (va_x_v5: quad32) (va_x_v6: quad32). let va_sM = va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))) in va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse (Vale.AES.GF128_s.gf128_mul a b) 127) ==> va_k va_sM (())))
false
Vale.AES.PPC64LE.GF128_Mul.fsti
Vale.AES.PPC64LE.GF128_Mul.va_wp_High64ToLow
val va_wp_High64ToLow (dst src: va_operand_vec_opr) (a: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
val va_wp_High64ToLow (dst src: va_operand_vec_opr) (a: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
let va_wp_High64ToLow (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_dst:va_value_vec_opr) . let va_sM = va_upd_operand_vec_opr dst va_x_dst va_s0 in va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.div a (Vale.Math.Poly2_s.monomial 64)) ==> va_k va_sM (())))
{ "file_name": "obj/Vale.AES.PPC64LE.GF128_Mul.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 83, "end_line": 79, "start_col": 0, "start_line": 72 }
module Vale.AES.PPC64LE.GF128_Mul open Vale.Def.Types_s open Vale.Arch.Types open Vale.Arch.TypesNative open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.Math.Poly2.Lemmas open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.PPC64LE.Machine_s open Vale.PPC64LE.State open Vale.PPC64LE.Decls open Vale.PPC64LE.InsBasic open Vale.PPC64LE.InsMem open Vale.PPC64LE.InsVector open Vale.PPC64LE.QuickCode open Vale.PPC64LE.QuickCodes open Vale.AES.PPC64LE.PolyOps open Vale.AES.Types_helpers open Vale.AES.GHash_BE //-- ShiftLeft128_1 val va_code_ShiftLeft128_1 : va_dummy:unit -> Tot va_code val va_codegen_success_ShiftLeft128_1 : va_dummy:unit -> Tot va_pbool val va_lemma_ShiftLeft128_1 : va_b0:va_code -> va_s0:va_state -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_ShiftLeft128_1 ()) va_s0 /\ va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) /\ va_state_eq va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_ok va_sM va_s0))))) [@ va_qattr] let va_wp_ShiftLeft128_1 (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_v1:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 va_s0) in va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) ==> va_k va_sM (()))) val va_wpProof_ShiftLeft128_1 : a:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_ShiftLeft128_1 a va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftLeft128_1 ()) ([va_Mod_vec 2; va_Mod_vec 1]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_ShiftLeft128_1 (a:poly) : (va_quickCode unit (va_code_ShiftLeft128_1 ())) = (va_QProc (va_code_ShiftLeft128_1 ()) ([va_Mod_vec 2; va_Mod_vec 1]) (va_wp_ShiftLeft128_1 a) (va_wpProof_ShiftLeft128_1 a)) //-- //-- High64ToLow val va_code_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_code val va_codegen_success_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_pbool val va_lemma_High64ToLow : va_b0:va_code -> va_s0:va_state -> dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_High64ToLow dst src) va_s0 /\ va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.div a (Vale.Math.Poly2_s.monomial 64)) /\ va_state_eq va_sM (va_update_ok va_sM (va_update_operand_vec_opr dst va_sM va_s0))))
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.QuickCodes.fsti.checked", "Vale.PPC64LE.QuickCode.fst.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.InsVector.fsti.checked", "Vale.PPC64LE.InsMem.fsti.checked", "Vale.PPC64LE.InsBasic.fsti.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.PPC64LE.PolyOps.fsti.checked", "Vale.AES.GHash_BE.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.PPC64LE.GF128_Mul.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.GHash_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "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
dst: Vale.PPC64LE.Decls.va_operand_vec_opr -> src: Vale.PPC64LE.Decls.va_operand_vec_opr -> a: Vale.Math.Poly2_s.poly -> va_s0: Vale.PPC64LE.Decls.va_state -> va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0) -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Decls.va_operand_vec_opr", "Vale.Math.Poly2_s.poly", "Vale.PPC64LE.Decls.va_state", "Prims.unit", "Prims.l_and", "Vale.PPC64LE.Decls.va_is_dst_vec_opr", "Vale.PPC64LE.Decls.va_is_src_vec_opr", "Prims.b2t", "Vale.PPC64LE.Decls.va_get_ok", "Prims.eq2", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat32", "Vale.PPC64LE.Decls.va_get_vec", "Vale.Def.Words_s.Mkfour", "Prims.op_LessThanOrEqual", "Vale.Math.Poly2_s.degree", "Vale.Def.Types_s.quad32", "Vale.PPC64LE.Decls.va_eval_vec_opr", "Vale.Math.Poly2.Bits_s.to_quad32", "Prims.l_Forall", "Vale.PPC64LE.Decls.va_value_vec_opr", "Prims.l_imp", "Vale.Math.Poly2_s.div", "Vale.Math.Poly2_s.monomial", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Decls.va_upd_operand_vec_opr" ]
[]
false
false
false
true
true
let va_wp_High64ToLow (dst src: va_operand_vec_opr) (a: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 =
(va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_dst: va_value_vec_opr). let va_sM = va_upd_operand_vec_opr dst va_x_dst va_s0 in va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.div a (Vale.Math.Poly2_s.monomial 64)) ==> va_k va_sM (())))
false
Vale.AES.PPC64LE.GF128_Mul.fsti
Vale.AES.PPC64LE.GF128_Mul.va_wp_Gf128MulRev128
val va_wp_Gf128MulRev128 (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
val va_wp_Gf128MulRev128 (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
let va_wp_Gf128MulRev128 (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) . let va_sM = va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))) in va_get_ok va_sM /\ (let (a:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) in let (b:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) == Vale.AES.GF128.gf128_mul_rev a b) ==> va_k va_sM (())))
{ "file_name": "obj/Vale.AES.PPC64LE.GF128_Mul.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 203, "start_col": 0, "start_line": 195 }
module Vale.AES.PPC64LE.GF128_Mul open Vale.Def.Types_s open Vale.Arch.Types open Vale.Arch.TypesNative open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.Math.Poly2.Lemmas open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.PPC64LE.Machine_s open Vale.PPC64LE.State open Vale.PPC64LE.Decls open Vale.PPC64LE.InsBasic open Vale.PPC64LE.InsMem open Vale.PPC64LE.InsVector open Vale.PPC64LE.QuickCode open Vale.PPC64LE.QuickCodes open Vale.AES.PPC64LE.PolyOps open Vale.AES.Types_helpers open Vale.AES.GHash_BE //-- ShiftLeft128_1 val va_code_ShiftLeft128_1 : va_dummy:unit -> Tot va_code val va_codegen_success_ShiftLeft128_1 : va_dummy:unit -> Tot va_pbool val va_lemma_ShiftLeft128_1 : va_b0:va_code -> va_s0:va_state -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_ShiftLeft128_1 ()) va_s0 /\ va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) /\ va_state_eq va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_ok va_sM va_s0))))) [@ va_qattr] let va_wp_ShiftLeft128_1 (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_v1:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 va_s0) in va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) ==> va_k va_sM (()))) val va_wpProof_ShiftLeft128_1 : a:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_ShiftLeft128_1 a va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftLeft128_1 ()) ([va_Mod_vec 2; va_Mod_vec 1]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_ShiftLeft128_1 (a:poly) : (va_quickCode unit (va_code_ShiftLeft128_1 ())) = (va_QProc (va_code_ShiftLeft128_1 ()) ([va_Mod_vec 2; va_Mod_vec 1]) (va_wp_ShiftLeft128_1 a) (va_wpProof_ShiftLeft128_1 a)) //-- //-- High64ToLow val va_code_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_code val va_codegen_success_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_pbool val va_lemma_High64ToLow : va_b0:va_code -> va_s0:va_state -> dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_High64ToLow dst src) va_s0 /\ va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.div a (Vale.Math.Poly2_s.monomial 64)) /\ va_state_eq va_sM (va_update_ok va_sM (va_update_operand_vec_opr dst va_sM va_s0)))) [@ va_qattr] let va_wp_High64ToLow (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_dst:va_value_vec_opr) . let va_sM = va_upd_operand_vec_opr dst va_x_dst va_s0 in va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.div a (Vale.Math.Poly2_s.monomial 64)) ==> va_k va_sM (()))) val va_wpProof_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_High64ToLow dst src a va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_High64ToLow dst src) ([va_mod_vec_opr dst]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_High64ToLow (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) : (va_quickCode unit (va_code_High64ToLow dst src)) = (va_QProc (va_code_High64ToLow dst src) ([va_mod_vec_opr dst]) (va_wp_High64ToLow dst src a) (va_wpProof_High64ToLow dst src a)) //-- //-- Low64ToHigh val va_code_Low64ToHigh : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_code val va_codegen_success_Low64ToHigh : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_pbool val va_lemma_Low64ToHigh : va_b0:va_code -> va_s0:va_state -> dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Low64ToHigh dst src) va_s0 /\ va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.mod a (Vale.Math.Poly2_s.monomial 64)) (Vale.Math.Poly2_s.monomial 64)) /\ va_state_eq va_sM (va_update_ok va_sM (va_update_operand_vec_opr dst va_sM va_s0)))) [@ va_qattr] let va_wp_Low64ToHigh (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_dst:va_value_vec_opr) . let va_sM = va_upd_operand_vec_opr dst va_x_dst va_s0 in va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.mod a (Vale.Math.Poly2_s.monomial 64)) (Vale.Math.Poly2_s.monomial 64)) ==> va_k va_sM (()))) val va_wpProof_Low64ToHigh : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_Low64ToHigh dst src a va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Low64ToHigh dst src) ([va_mod_vec_opr dst]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_Low64ToHigh (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) : (va_quickCode unit (va_code_Low64ToHigh dst src)) = (va_QProc (va_code_Low64ToHigh dst src) ([va_mod_vec_opr dst]) (va_wp_Low64ToHigh dst src a) (va_wpProof_Low64ToHigh dst src a)) //-- //-- ReduceMulRev128 val va_code_ReduceMulRev128 : va_dummy:unit -> Tot va_code val va_codegen_success_ReduceMulRev128 : va_dummy:unit -> Tot va_pbool val va_lemma_ReduceMulRev128 : va_b0:va_code -> va_s0:va_state -> a:poly -> b:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_ReduceMulRev128 ()) va_s0 /\ va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ Vale.Math.Poly2_s.degree b <= 127 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse a 127) /\ va_get_vec 2 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse b 127))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse (Vale.AES.GF128_s.gf128_mul a b) 127) /\ va_state_eq va_sM (va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0))))))))))) [@ va_qattr] let va_wp_ReduceMulRev128 (a:poly) (b:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ Vale.Math.Poly2_s.degree b <= 127 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse a 127) /\ va_get_vec 2 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse b 127) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) . let va_sM = va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))) in va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.reverse (Vale.AES.GF128_s.gf128_mul a b) 127) ==> va_k va_sM (()))) val va_wpProof_ReduceMulRev128 : a:poly -> b:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_ReduceMulRev128 a b va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ReduceMulRev128 ()) ([va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_ReduceMulRev128 (a:poly) (b:poly) : (va_quickCode unit (va_code_ReduceMulRev128 ())) = (va_QProc (va_code_ReduceMulRev128 ()) ([va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10]) (va_wp_ReduceMulRev128 a b) (va_wpProof_ReduceMulRev128 a b)) //-- //-- Gf128MulRev128 val va_code_Gf128MulRev128 : va_dummy:unit -> Tot va_code val va_codegen_success_Gf128MulRev128 : va_dummy:unit -> Tot va_pbool val va_lemma_Gf128MulRev128 : va_b0:va_code -> va_s0:va_state -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Gf128MulRev128 ()) va_s0 /\ va_get_ok va_s0)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (a:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) in let (b:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) == Vale.AES.GF128.gf128_mul_rev a b) /\ va_state_eq va_sM (va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))))))))
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.QuickCodes.fsti.checked", "Vale.PPC64LE.QuickCode.fst.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.InsVector.fsti.checked", "Vale.PPC64LE.InsMem.fsti.checked", "Vale.PPC64LE.InsBasic.fsti.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.PPC64LE.PolyOps.fsti.checked", "Vale.AES.GHash_BE.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.PPC64LE.GF128_Mul.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.GHash_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "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
va_s0: Vale.PPC64LE.Decls.va_state -> va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0) -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Decls.va_state", "Prims.unit", "Prims.l_and", "Prims.b2t", "Vale.PPC64LE.Decls.va_get_ok", "Prims.l_Forall", "Vale.PPC64LE.Machine_s.nat64", "Vale.PPC64LE.Machine_s.quad32", "Prims.l_imp", "Prims.eq2", "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.Bits_s.of_quad32", "Vale.PPC64LE.Decls.va_get_vec", "Vale.AES.GF128.gf128_mul_rev", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Decls.va_upd_vec", "Vale.PPC64LE.Decls.va_upd_reg" ]
[]
false
false
false
true
true
let va_wp_Gf128MulRev128 (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (forall (va_x_r10: nat64) (va_x_v0: quad32) (va_x_v1: quad32) (va_x_v2: quad32) (va_x_v3: quad32) (va_x_v4: quad32) (va_x_v5: quad32) (va_x_v6: quad32). let va_sM = va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))) in va_get_ok va_sM /\ (let a:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) in let b:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) == Vale.AES.GF128.gf128_mul_rev a b) ==> va_k va_sM (())))
false
Steel.ST.C.Types.Base.fsti
Steel.ST.C.Types.Base.pts_to_or_null
val pts_to_or_null (#t: Type) (#td: typedef t) (p: ptr td) (v: Ghost.erased t) : vprop
val pts_to_or_null (#t: Type) (#td: typedef t) (p: ptr td) (v: Ghost.erased t) : vprop
let pts_to_or_null (#t: Type) (#td: typedef t) (p: ptr td) (v: Ghost.erased t) : vprop = if FStar.StrongExcludedMiddle.strong_excluded_middle (p == null _) then emp else pts_to p v
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 17, "end_line": 109, "start_col": 0, "start_line": 105 }
module Steel.ST.C.Types.Base open Steel.ST.Util module P = Steel.FractionalPermission /// Helper to compose two permissions into one val prod_perm (p1 p2: P.perm) : Pure P.perm (requires True) (ensures (fun p -> ((p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm) ==> p `P.lesser_equal_perm` P.full_perm) /\ p.v == (let open FStar.Real in p1.v *. p2.v) )) [@@noextract_to "krml"] // proof-only val typedef (t: Type0) : Type0 inline_for_extraction [@@noextract_to "krml"] let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: P.perm) : Ghost t (requires (fractionable td x)) (ensures (fun y -> p `P.lesser_equal_perm` P.full_perm ==> fractionable td y)) val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma (requires (fractionable td x)) (ensures (mk_fraction td x P.full_perm == x)) [SMTPat (mk_fraction td x P.full_perm)] val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: P.perm) : Lemma (requires (fractionable td x /\ p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm)) (ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2))) val full (#t: Type0) (td: typedef t) (v: t) : GTot prop val uninitialized (#t: Type0) (td: typedef t) : Ghost t (requires True) (ensures (fun y -> full td y /\ fractionable td y)) val unknown (#t: Type0) (td: typedef t) : Ghost t (requires True) (ensures (fun y -> fractionable td y)) val full_not_unknown (#t: Type) (td: typedef t) (v: t) : Lemma (requires (full td v)) (ensures (~ (v == unknown td))) [SMTPat (full td v)] val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: P.perm) : Lemma (ensures (mk_fraction td (unknown td) p == unknown td)) val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: P.perm) : Lemma (requires (fractionable td v /\ mk_fraction td v p == unknown td)) (ensures (v == unknown td)) // To be extracted as: void* [@@noextract_to "krml"] // primitive val void_ptr : Type0 // To be extracted as: NULL [@@noextract_to "krml"] // primitive val void_null: void_ptr // To be extracted as: *t [@@noextract_to "krml"] // primitive val ptr_gen ([@@@unused] t: Type) : Type0 [@@noextract_to "krml"] // primitive val null_gen (t: Type) : Tot (ptr_gen t) val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t) val ghost_void_ptr_of_ptr_gen_of_void_ptr (x: void_ptr) (t: Type) : Lemma (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x) [SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))] val ghost_ptr_gen_of_void_ptr_of_ptr_gen (#t: Type) (x: ptr_gen t) : Lemma (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x) [SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)] inline_for_extraction [@@noextract_to "krml"] // primitive let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t inline_for_extraction [@@noextract_to "krml"] // primitive let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t inline_for_extraction [@@noextract_to "krml"] let ref (#t: Type) (td: typedef t) : Tot Type0 = (p: ptr td { ~ (p == null td) }) val pts_to (#t: Type) (#td: typedef t) (r: ref td) ([@@@smt_fallback] v: Ghost.erased t) : vprop
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Base.fsti" }
[ { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "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
p: Steel.ST.C.Types.Base.ptr td -> v: FStar.Ghost.erased t -> Steel.Effect.Common.vprop
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.C.Types.Base.typedef", "Steel.ST.C.Types.Base.ptr", "FStar.Ghost.erased", "FStar.StrongExcludedMiddle.strong_excluded_middle", "Prims.eq2", "Steel.ST.C.Types.Base.null", "Steel.Effect.Common.emp", "Prims.bool", "Steel.ST.C.Types.Base.pts_to", "Steel.Effect.Common.vprop" ]
[]
false
false
false
false
false
let pts_to_or_null (#t: Type) (#td: typedef t) (p: ptr td) (v: Ghost.erased t) : vprop =
if FStar.StrongExcludedMiddle.strong_excluded_middle (p == null _) then emp else pts_to p v
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.flavor
val flavor : b: LowStar.Monotonic.Buffer.mbuffer a p q -> Type0
let flavor #a #p #q (b:B.mbuffer a p q) = f:flav{ f == Pointer ==> B.length b == 1 /\ ok_for_ptr q }
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 64, "start_col": 0, "start_line": 59 }
(* 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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a /// pointer. let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1 /// `flavor`: A buffer `b` is described as Pointer-flavor if /// -- its length is 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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
b: LowStar.Monotonic.Buffer.mbuffer a p q -> Type0
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Lens.Buffer.flav", "Prims.l_imp", "Prims.eq2", "LowStar.Lens.Buffer.Pointer", "Prims.l_and", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Lens.Buffer.ok_for_ptr" ]
[]
false
false
false
false
true
let flavor #a #p #q (b: B.mbuffer a p q) =
f: flav{f == Pointer ==> B.length b == 1 /\ ok_for_ptr q}
false
Steel.ST.C.Types.Base.fsti
Steel.ST.C.Types.Base.freeable_or_null
val freeable_or_null (#t: Type) (#td: typedef t) (r: ptr td) : Tot vprop
val freeable_or_null (#t: Type) (#td: typedef t) (r: ptr td) : Tot vprop
let freeable_or_null (#t: Type) (#td: typedef t) (r: ptr td) : Tot vprop = if FStar.StrongExcludedMiddle.strong_excluded_middle (r == null _) then emp else freeable r
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 17, "end_line": 233, "start_col": 0, "start_line": 226 }
module Steel.ST.C.Types.Base open Steel.ST.Util module P = Steel.FractionalPermission /// Helper to compose two permissions into one val prod_perm (p1 p2: P.perm) : Pure P.perm (requires True) (ensures (fun p -> ((p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm) ==> p `P.lesser_equal_perm` P.full_perm) /\ p.v == (let open FStar.Real in p1.v *. p2.v) )) [@@noextract_to "krml"] // proof-only val typedef (t: Type0) : Type0 inline_for_extraction [@@noextract_to "krml"] let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: P.perm) : Ghost t (requires (fractionable td x)) (ensures (fun y -> p `P.lesser_equal_perm` P.full_perm ==> fractionable td y)) val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma (requires (fractionable td x)) (ensures (mk_fraction td x P.full_perm == x)) [SMTPat (mk_fraction td x P.full_perm)] val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: P.perm) : Lemma (requires (fractionable td x /\ p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm)) (ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2))) val full (#t: Type0) (td: typedef t) (v: t) : GTot prop val uninitialized (#t: Type0) (td: typedef t) : Ghost t (requires True) (ensures (fun y -> full td y /\ fractionable td y)) val unknown (#t: Type0) (td: typedef t) : Ghost t (requires True) (ensures (fun y -> fractionable td y)) val full_not_unknown (#t: Type) (td: typedef t) (v: t) : Lemma (requires (full td v)) (ensures (~ (v == unknown td))) [SMTPat (full td v)] val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: P.perm) : Lemma (ensures (mk_fraction td (unknown td) p == unknown td)) val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: P.perm) : Lemma (requires (fractionable td v /\ mk_fraction td v p == unknown td)) (ensures (v == unknown td)) // To be extracted as: void* [@@noextract_to "krml"] // primitive val void_ptr : Type0 // To be extracted as: NULL [@@noextract_to "krml"] // primitive val void_null: void_ptr // To be extracted as: *t [@@noextract_to "krml"] // primitive val ptr_gen ([@@@unused] t: Type) : Type0 [@@noextract_to "krml"] // primitive val null_gen (t: Type) : Tot (ptr_gen t) val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t) val ghost_void_ptr_of_ptr_gen_of_void_ptr (x: void_ptr) (t: Type) : Lemma (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x) [SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))] val ghost_ptr_gen_of_void_ptr_of_ptr_gen (#t: Type) (x: ptr_gen t) : Lemma (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x) [SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)] inline_for_extraction [@@noextract_to "krml"] // primitive let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t inline_for_extraction [@@noextract_to "krml"] // primitive let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t inline_for_extraction [@@noextract_to "krml"] let ref (#t: Type) (td: typedef t) : Tot Type0 = (p: ptr td { ~ (p == null td) }) val pts_to (#t: Type) (#td: typedef t) (r: ref td) ([@@@smt_fallback] v: Ghost.erased t) : vprop let pts_to_or_null (#t: Type) (#td: typedef t) (p: ptr td) (v: Ghost.erased t) : vprop = if FStar.StrongExcludedMiddle.strong_excluded_middle (p == null _) then emp else pts_to p v [@@noextract_to "krml"] // primitive val is_null (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (p: ptr td) : STAtomicBase bool false opened Unobservable (pts_to_or_null p v) (fun _ -> pts_to_or_null p v) (True) (fun res -> res == true <==> p == null _) let assert_null (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (p: ptr td) : STGhost unit opened (pts_to_or_null p v) (fun _ -> emp) (p == null _) (fun _ -> True) = rewrite (pts_to_or_null p v) emp let assert_not_null (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (p: ptr td) : STGhost (squash (~ (p == null _))) opened (pts_to_or_null p v) (fun _ -> pts_to p v) (~ (p == null _)) (fun _ -> True) = rewrite (pts_to_or_null p v) (pts_to p v) [@@noextract_to "krml"] // primitive val void_ptr_of_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ptr td) : STAtomicBase void_ptr false opened Unobservable (pts_to_or_null x v) (fun _ -> pts_to_or_null x v) True (fun y -> y == ghost_void_ptr_of_ptr_gen x) [@@noextract_to "krml"] inline_for_extraction let void_ptr_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ref td) : STAtomicBase void_ptr false opened Unobservable (pts_to x v) (fun _ -> pts_to x v) True (fun y -> y == ghost_void_ptr_of_ptr_gen x) = rewrite (pts_to x v) (pts_to_or_null x v); let res = void_ptr_of_ptr x in rewrite (pts_to_or_null x v) (pts_to x v); return res [@@noextract_to "krml"] // primitive val ptr_of_void_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) : STAtomicBase (ptr td) false opened Unobservable (pts_to_or_null (ghost_ptr_gen_of_void_ptr x t <: ptr td) v) (fun y -> pts_to_or_null y v) True (fun y -> y == ghost_ptr_gen_of_void_ptr x t) [@@noextract_to "krml"] inline_for_extraction let ref_of_void_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) (y': Ghost.erased (ref td)) : STAtomicBase (ref td) false opened Unobservable (pts_to y' v) (fun y -> pts_to y v) (Ghost.reveal y' == ghost_ptr_gen_of_void_ptr x t) (fun y -> y == Ghost.reveal y') = rewrite (pts_to y' v) (pts_to_or_null (ghost_ptr_gen_of_void_ptr x t <: ptr td) v); let y = ptr_of_void_ptr x in rewrite (pts_to_or_null y v) (pts_to y v); return y val ref_equiv (#t: Type) (#td: typedef t) (r1 r2: ref td) : Tot vprop val pts_to_equiv (#opened: _) (#t: Type) (#td: typedef t) (r1 r2: ref td) (v: Ghost.erased t) : STGhostT unit opened (ref_equiv r1 r2 `star` pts_to r1 v) (fun _ -> ref_equiv r1 r2 `star` pts_to r2 v) val freeable (#t: Type) (#td: typedef t) (r: ref td) : Tot vprop val freeable_dup (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) : STGhostT unit opened (freeable r) (fun _ -> freeable r `star` freeable r) val freeable_equiv (#opened: _) (#t: Type) (#td: typedef t) (r1 r2: ref td) : STGhostT unit opened (ref_equiv r1 r2 `star` freeable r1) (fun _ -> ref_equiv r1 r2 `star` freeable r2)
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Base.fsti" }
[ { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "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
r: Steel.ST.C.Types.Base.ptr td -> Steel.Effect.Common.vprop
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.C.Types.Base.typedef", "Steel.ST.C.Types.Base.ptr", "FStar.StrongExcludedMiddle.strong_excluded_middle", "Prims.eq2", "Steel.ST.C.Types.Base.null", "Steel.Effect.Common.emp", "Prims.bool", "Steel.ST.C.Types.Base.freeable", "Steel.Effect.Common.vprop" ]
[]
false
false
false
false
false
let freeable_or_null (#t: Type) (#td: typedef t) (r: ptr td) : Tot vprop =
if FStar.StrongExcludedMiddle.strong_excluded_middle (r == null _) then emp else freeable r
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.lseq_of
val lseq_of : b: LowStar.Monotonic.Buffer.mbuffer a p q -> Type0
let lseq_of #a #p #q (b:B.mbuffer a p q) = Seq.lseq a (B.length b)
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 25, "end_line": 77, "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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a /// pointer. let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1 /// `flavor`: A buffer `b` is described as Pointer-flavor if /// -- its length is 1 /// -- its preorder is ok for pointers let flavor #a #p #q (b:B.mbuffer a p q) = f:flav{ f == Pointer ==> B.length b == 1 /\ ok_for_ptr q } /// A couple of convenient flavor abbreviations unfold let ptr (b:B.pointer 'a) : flavor b = Pointer unfold let buf (b:B.mbuffer 'a 'b 'c) : flavor b = Buffer
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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
b: LowStar.Monotonic.Buffer.mbuffer a p q -> Type0
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "FStar.Seq.Properties.lseq", "LowStar.Monotonic.Buffer.length" ]
[]
false
false
false
false
true
let lseq_of #a #p #q (b: B.mbuffer a p q) =
Seq.lseq a (B.length b)
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.with_state
val with_state : lens: LowStar.Lens.hs_lens from to -> $t: (_: LowStar.Lens.hs_lens from to -> Type) -> Type
let with_state #from #to (lens:hs_lens from to) ($t:hs_lens from to -> Type) = s:imem (lens.invariant lens.x) -> t (snap lens s)
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 138, "start_col": 0, "start_line": 134 }
(* 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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a /// pointer. let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1 /// `flavor`: A buffer `b` is described as Pointer-flavor if /// -- its length is 1 /// -- its preorder is ok for pointers let flavor #a #p #q (b:B.mbuffer a p q) = f:flav{ f == Pointer ==> B.length b == 1 /\ ok_for_ptr q } /// A couple of convenient flavor abbreviations unfold let ptr (b:B.pointer 'a) : flavor b = Pointer unfold let buf (b:B.mbuffer 'a 'b 'c) : flavor b = Buffer /// `lseq_of`: A sequence whose length matches the buffer's length let lseq_of #a #p #q (b:B.mbuffer a p q) = Seq.lseq a (B.length b) /// `view_type_of b f`: Provides an f-flavored voew on the buffer `b` let view_type_of #a #p #q (#b:B.mbuffer a p q) (f:flavor b) = match f with | Buffer -> lseq_of b | Pointer -> a /// `buffer_hs_lens`: /// hs_lens between a buffer `b` and `lseq_of b` /// of flavor `f` let buffer_hs_lens #a #p #q (b:B.mbuffer a p q) (f:flavor b) = l:hs_lens (B.mbuffer a p q) (view_type_of f){ Ghost.reveal l.footprint == B.loc_buffer b /\ l.x == b } /// `get_value_at` and `put_value_at`: provide a uniform sequence- or /// element-based view on top of both flavors of buffers unfold let get_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v:view_type_of f) (i:uint_32{ i < B.len b }) : a = match f with | Pointer -> v | Buffer -> Seq.index v (UInt32.v i) unfold let put_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v0:view_type_of f) (i:uint_32{ i < B.len b }) (x:a) : view_type_of f = match f with | Pointer -> x | Buffer -> Seq.upd v0 (UInt32.v i) x /// `as_seq` views both flavors as a sequence unfold let as_seq #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v0:view_type_of f) : lseq_of b = match f with | Pointer -> Seq.create 1 v0 | Buffer -> v0 /// `with_state t`: /// /// 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.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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 from to -> $t: (_: LowStar.Lens.hs_lens from to -> Type) -> 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_state #from #to (lens: hs_lens from to) ($t: (hs_lens from to -> Type)) =
s: imem (lens.invariant lens.x) -> t (snap lens s)
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.buffer_hs_lens
val buffer_hs_lens : b: LowStar.Monotonic.Buffer.mbuffer a p q -> f: LowStar.Lens.Buffer.flavor b -> Type
let buffer_hs_lens #a #p #q (b:B.mbuffer a p q) (f:flavor b) = l:hs_lens (B.mbuffer a p q) (view_type_of f){ Ghost.reveal l.footprint == B.loc_buffer b /\ l.x == b }
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 92, "start_col": 0, "start_line": 88 }
(* 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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a /// pointer. let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1 /// `flavor`: A buffer `b` is described as Pointer-flavor if /// -- its length is 1 /// -- its preorder is ok for pointers let flavor #a #p #q (b:B.mbuffer a p q) = f:flav{ f == Pointer ==> B.length b == 1 /\ ok_for_ptr q } /// A couple of convenient flavor abbreviations unfold let ptr (b:B.pointer 'a) : flavor b = Pointer unfold let buf (b:B.mbuffer 'a 'b 'c) : flavor b = Buffer /// `lseq_of`: A sequence whose length matches the buffer's length let lseq_of #a #p #q (b:B.mbuffer a p q) = Seq.lseq a (B.length b) /// `view_type_of b f`: Provides an f-flavored voew on the buffer `b` let view_type_of #a #p #q (#b:B.mbuffer a p q) (f:flavor b) = match f with | Buffer -> lseq_of b | Pointer -> a /// `buffer_hs_lens`: /// hs_lens between a buffer `b` and `lseq_of b`
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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
b: LowStar.Monotonic.Buffer.mbuffer a p q -> f: LowStar.Lens.Buffer.flavor b -> Type
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Lens.Buffer.flavor", "LowStar.Lens.hs_lens", "LowStar.Lens.Buffer.view_type_of", "Prims.l_and", "Prims.eq2", "LowStar.Monotonic.Buffer.loc", "FStar.Ghost.reveal", "LowStar.Lens.__proj__Mkhs_lens__item__footprint", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Lens.__proj__Mkhs_lens__item__x" ]
[]
false
false
false
false
true
let buffer_hs_lens #a #p #q (b: B.mbuffer a p q) (f: flavor b) =
l: hs_lens (B.mbuffer a p q) (view_type_of f) {Ghost.reveal l.footprint == B.loc_buffer b /\ l.x == b}
false
FStar.Int.Cast.fst
FStar.Int.Cast.op_At_Percent
val op_At_Percent : v: Prims.int -> p: Prims.int{p > 0 /\ p % 2 = 0} -> Prims.int
let op_At_Percent = FStar.Int.op_At_Percent
{ "file_name": "ulib/FStar.Int.Cast.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 43, "end_line": 27, "start_col": 0, "start_line": 27 }
(* Copyright 2008-2018 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 FStar.Int.Cast module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module I8 = FStar.Int8 module I16 = FStar.Int16 module I32 = FStar.Int32 module I64 = FStar.Int64
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Int.Cast.fst" }
[ { "abbrev": true, "full_module": "FStar.Int64", "short_module": "I64" }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "I32" }, { "abbrev": true, "full_module": "FStar.Int16", "short_module": "I16" }, { "abbrev": true, "full_module": "FStar.Int8", "short_module": "I8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Int", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int", "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
v: Prims.int -> p: Prims.int{p > 0 /\ p % 2 = 0} -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "FStar.Int.op_At_Percent" ]
[]
false
false
false
false
false
let op_At_Percent =
FStar.Int.op_At_Percent
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.reader_t
val reader_t : f: LowStar.Lens.Buffer.flavor b -> layer: LowStar.Lens.lens to (LowStar.Lens.Buffer.view_type_of f) -> l: LowStar.Lens.hs_lens from to -> Type0
let reader_t #a #p #q (#b:B.mbuffer a p q) (f:flavor b) #from #to (layer: lens to (view_type_of f)) (l:hs_lens from to) = i:ix b -> LensST a l (requires fun _ -> True) (ensures fun s0 v s1 -> s0 == s1 /\ v == get_value_at (LL.get layer s1) i)
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 152, "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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a /// pointer. let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1 /// `flavor`: A buffer `b` is described as Pointer-flavor if /// -- its length is 1 /// -- its preorder is ok for pointers let flavor #a #p #q (b:B.mbuffer a p q) = f:flav{ f == Pointer ==> B.length b == 1 /\ ok_for_ptr q } /// A couple of convenient flavor abbreviations unfold let ptr (b:B.pointer 'a) : flavor b = Pointer unfold let buf (b:B.mbuffer 'a 'b 'c) : flavor b = Buffer /// `lseq_of`: A sequence whose length matches the buffer's length let lseq_of #a #p #q (b:B.mbuffer a p q) = Seq.lseq a (B.length b) /// `view_type_of b f`: Provides an f-flavored voew on the buffer `b` let view_type_of #a #p #q (#b:B.mbuffer a p q) (f:flavor b) = match f with | Buffer -> lseq_of b | Pointer -> a /// `buffer_hs_lens`: /// hs_lens between a buffer `b` and `lseq_of b` /// of flavor `f` let buffer_hs_lens #a #p #q (b:B.mbuffer a p q) (f:flavor b) = l:hs_lens (B.mbuffer a p q) (view_type_of f){ Ghost.reveal l.footprint == B.loc_buffer b /\ l.x == b } /// `get_value_at` and `put_value_at`: provide a uniform sequence- or /// element-based view on top of both flavors of buffers unfold let get_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v:view_type_of f) (i:uint_32{ i < B.len b }) : a = match f with | Pointer -> v | Buffer -> Seq.index v (UInt32.v i) unfold let put_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v0:view_type_of f) (i:uint_32{ i < B.len b }) (x:a) : view_type_of f = match f with | Pointer -> x | Buffer -> Seq.upd v0 (UInt32.v i) x /// `as_seq` views both flavors as a sequence unfold let as_seq #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v0:view_type_of f) : lseq_of b = match f with | Pointer -> Seq.create 1 v0 | Buffer -> v0 /// `with_state t`: /// /// 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_state #from #to (lens:hs_lens from to) ($t:hs_lens from to -> Type) = s:imem (lens.invariant lens.x) -> t (snap lens s) let ix #a #p #q (b:B.mbuffer a p q) = i:uint_32{i < B.len b} module LL = LowStar.Lens
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Lens", "short_module": "LL" }, { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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: LowStar.Lens.Buffer.flavor b -> layer: LowStar.Lens.lens to (LowStar.Lens.Buffer.view_type_of f) -> l: LowStar.Lens.hs_lens from to -> Type0
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Lens.Buffer.flavor", "LowStar.Lens.lens", "LowStar.Lens.Buffer.view_type_of", "LowStar.Lens.hs_lens", "LowStar.Lens.Buffer.ix", "Prims.l_True", "Prims.l_and", "Prims.eq2", "LowStar.Lens.Buffer.get_value_at", "LowStar.Lens.get" ]
[]
false
false
false
false
true
let reader_t #a #p #q (#b: B.mbuffer a p q) (f: flavor b) #from #to (layer: lens to (view_type_of f)) (l: hs_lens from to) =
i: ix b -> LensST a l (requires fun _ -> True) (ensures fun s0 v s1 -> s0 == s1 /\ v == get_value_at (LL.get layer s1) i)
false
PointStructDirectDef.fst
PointStructDirectDef.point
val point:typedef point_t
val point:typedef point_t
let point : typedef point_t = struct0 _ _ _
{ "file_name": "share/steel/examples/steelc/PointStructDirectDef.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 28, "start_col": 0, "start_line": 28 }
module PointStructDirectDef open Steel.ST.Util open Steel.ST.C.Types module U32 = FStar.UInt32 // module C = C // for _zero_for_deref let swap (#v1 #v2: Ghost.erased U32.t) (r1 r2: ref (scalar U32.t)) : STT unit ((r1 `pts_to` mk_scalar (Ghost.reveal v1)) `star` (r2 `pts_to` mk_scalar (Ghost.reveal v2))) (fun _ -> (r1 `pts_to` mk_scalar (Ghost.reveal v2)) `star` (r2 `pts_to` mk_scalar (Ghost.reveal v1))) = let x1 = read r1 in let x2 = read r2 in write r1 x2; write r2 x1; return () // necessary to enable smt_fallback noextract inline_for_extraction [@@ norm_field_attr] let point_fields = field_description_cons "x" (scalar U32.t) ( field_description_cons "y" (scalar U32.t) ( field_description_nil)) let point_t = struct_t "PointStructDirectDef.point_t" point_fields
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.C.Types.fst.checked", "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PointStructDirectDef.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "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
Steel.ST.C.Types.Base.typedef PointStructDirectDef.point_t
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.C.Types.Struct.struct0", "Steel.C.Typestring.string_cons", "Steel.C.Typestring.cP", "Steel.C.Typestring.co", "Steel.C.Typestring.ci", "Steel.C.Typestring.cn", "Steel.C.Typestring.ct", "Steel.C.Typestring.cS", "Steel.C.Typestring.cr", "Steel.C.Typestring.cu", "Steel.C.Typestring.cc", "Steel.C.Typestring.cD", "Steel.C.Typestring.ce", "Steel.C.Typestring.cf", "Steel.C.Typestring.cdot", "Steel.C.Typestring.cp", "Steel.C.Typestring.c_", "Steel.C.Typestring.string_nil", "Steel.ST.C.Types.Fields.field_t_cons", "Steel.C.Typestring.cx", "Steel.ST.C.Types.Scalar.scalar_t", "FStar.UInt32.t", "Steel.C.Typestring.cy", "Steel.ST.C.Types.Fields.field_t_nil", "PointStructDirectDef.point_fields" ]
[]
false
false
false
true
false
let point:typedef point_t =
struct0 _ _ _
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.ix
val ix : b: LowStar.Monotonic.Buffer.mbuffer a p q -> Type0
let ix #a #p #q (b:B.mbuffer a p q) = i:uint_32{i < B.len b}
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 60, "end_line": 140, "start_col": 0, "start_line": 140 }
(* 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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a /// pointer. let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1 /// `flavor`: A buffer `b` is described as Pointer-flavor if /// -- its length is 1 /// -- its preorder is ok for pointers let flavor #a #p #q (b:B.mbuffer a p q) = f:flav{ f == Pointer ==> B.length b == 1 /\ ok_for_ptr q } /// A couple of convenient flavor abbreviations unfold let ptr (b:B.pointer 'a) : flavor b = Pointer unfold let buf (b:B.mbuffer 'a 'b 'c) : flavor b = Buffer /// `lseq_of`: A sequence whose length matches the buffer's length let lseq_of #a #p #q (b:B.mbuffer a p q) = Seq.lseq a (B.length b) /// `view_type_of b f`: Provides an f-flavored voew on the buffer `b` let view_type_of #a #p #q (#b:B.mbuffer a p q) (f:flavor b) = match f with | Buffer -> lseq_of b | Pointer -> a /// `buffer_hs_lens`: /// hs_lens between a buffer `b` and `lseq_of b` /// of flavor `f` let buffer_hs_lens #a #p #q (b:B.mbuffer a p q) (f:flavor b) = l:hs_lens (B.mbuffer a p q) (view_type_of f){ Ghost.reveal l.footprint == B.loc_buffer b /\ l.x == b } /// `get_value_at` and `put_value_at`: provide a uniform sequence- or /// element-based view on top of both flavors of buffers unfold let get_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v:view_type_of f) (i:uint_32{ i < B.len b }) : a = match f with | Pointer -> v | Buffer -> Seq.index v (UInt32.v i) unfold let put_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v0:view_type_of f) (i:uint_32{ i < B.len b }) (x:a) : view_type_of f = match f with | Pointer -> x | Buffer -> Seq.upd v0 (UInt32.v i) x /// `as_seq` views both flavors as a sequence unfold let as_seq #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v0:view_type_of f) : lseq_of b = match f with | Pointer -> Seq.create 1 v0 | Buffer -> v0 /// `with_state t`: /// /// 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_state #from #to (lens:hs_lens from to) ($t:hs_lens from to -> Type) = s:imem (lens.invariant lens.x) -> t (snap lens s)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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
b: LowStar.Monotonic.Buffer.mbuffer a p q -> Type0
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "FStar.Integers.uint_32", "Prims.b2t", "FStar.Integers.op_Less", "FStar.Integers.Unsigned", "FStar.Integers.W32", "LowStar.Monotonic.Buffer.len" ]
[]
false
false
false
false
true
let ix #a #p #q (b: B.mbuffer a p q) =
i: uint_32{i < B.len b}
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.lens_of
val lens_of (#a #p #q: _) (#b: B.mbuffer a p q) (#f: flavor b) (prw: buffer_lens b f) : buffer_hs_lens b f
val lens_of (#a #p #q: _) (#b: B.mbuffer a p q) (#f: flavor b) (prw: buffer_lens b f) : buffer_hs_lens b f
let lens_of #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (prw:buffer_lens b f) : buffer_hs_lens b f = prw.hs_lens
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 185, "start_col": 0, "start_line": 183 }
(* 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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a /// pointer. let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1 /// `flavor`: A buffer `b` is described as Pointer-flavor if /// -- its length is 1 /// -- its preorder is ok for pointers let flavor #a #p #q (b:B.mbuffer a p q) = f:flav{ f == Pointer ==> B.length b == 1 /\ ok_for_ptr q } /// A couple of convenient flavor abbreviations unfold let ptr (b:B.pointer 'a) : flavor b = Pointer unfold let buf (b:B.mbuffer 'a 'b 'c) : flavor b = Buffer /// `lseq_of`: A sequence whose length matches the buffer's length let lseq_of #a #p #q (b:B.mbuffer a p q) = Seq.lseq a (B.length b) /// `view_type_of b f`: Provides an f-flavored voew on the buffer `b` let view_type_of #a #p #q (#b:B.mbuffer a p q) (f:flavor b) = match f with | Buffer -> lseq_of b | Pointer -> a /// `buffer_hs_lens`: /// hs_lens between a buffer `b` and `lseq_of b` /// of flavor `f` let buffer_hs_lens #a #p #q (b:B.mbuffer a p q) (f:flavor b) = l:hs_lens (B.mbuffer a p q) (view_type_of f){ Ghost.reveal l.footprint == B.loc_buffer b /\ l.x == b } /// `get_value_at` and `put_value_at`: provide a uniform sequence- or /// element-based view on top of both flavors of buffers unfold let get_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v:view_type_of f) (i:uint_32{ i < B.len b }) : a = match f with | Pointer -> v | Buffer -> Seq.index v (UInt32.v i) unfold let put_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v0:view_type_of f) (i:uint_32{ i < B.len b }) (x:a) : view_type_of f = match f with | Pointer -> x | Buffer -> Seq.upd v0 (UInt32.v i) x /// `as_seq` views both flavors as a sequence unfold let as_seq #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v0:view_type_of f) : lseq_of b = match f with | Pointer -> Seq.create 1 v0 | Buffer -> v0 /// `with_state t`: /// /// 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_state #from #to (lens:hs_lens from to) ($t:hs_lens from to -> Type) = s:imem (lens.invariant lens.x) -> t (snap lens s) let ix #a #p #q (b:B.mbuffer a p q) = i:uint_32{i < B.len b} module LL = LowStar.Lens /// `writer_t l`: writes a single element to a buffer let reader_t #a #p #q (#b:B.mbuffer a p q) (f:flavor b) #from #to (layer: lens to (view_type_of f)) (l:hs_lens from to) = i:ix b -> LensST a l (requires fun _ -> True) (ensures fun s0 v s1 -> s0 == s1 /\ v == get_value_at (LL.get layer s1) i) /// `writer_t l`: writes a single element to a buffer let writer_t #a #p #q (#b:B.mbuffer a p q) (f:flavor b) #from #to (layer: lens to (view_type_of f)) (l:hs_lens from to) = i:ix b -> v:a -> LensST unit l (requires fun s0 -> as_seq (LL.get layer s0) `q` as_seq (put_value_at (LL.get layer s0) i v)) (ensures fun s0 _ s1 -> s1 == LL.put layer s0 (put_value_at (LL.get layer s0) i v)) unfold let id_lens #a : lens a a = { get= (fun x -> x); put= (fun x s -> x); lens_laws = () } /// `buffer_lens`: A triple of a lens for a buffer and its /// corresponding element readers and writers noeq type buffer_lens #a #p #q (b:B.mbuffer a p q) (f:flavor b) = | Mk : hs_lens:buffer_hs_lens b f -> reader:with_state hs_lens (reader_t f id_lens) -> writer:with_state hs_lens (writer_t f id_lens) -> buffer_lens b f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Lens", "short_module": "LL" }, { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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
prw: LowStar.Lens.Buffer.buffer_lens b f -> LowStar.Lens.Buffer.buffer_hs_lens b f
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Lens.Buffer.flavor", "LowStar.Lens.Buffer.buffer_lens", "LowStar.Lens.Buffer.__proj__Mk__item__hs_lens", "LowStar.Lens.Buffer.buffer_hs_lens" ]
[]
false
false
false
false
false
let lens_of #a #p #q (#b: B.mbuffer a p q) (#f: flavor b) (prw: buffer_lens b f) : buffer_hs_lens b f =
prw.hs_lens
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.writer_t
val writer_t : f: LowStar.Lens.Buffer.flavor b -> layer: LowStar.Lens.lens to (LowStar.Lens.Buffer.view_type_of f) -> l: LowStar.Lens.hs_lens from to -> Type0
let writer_t #a #p #q (#b:B.mbuffer a p q) (f:flavor b) #from #to (layer: lens to (view_type_of f)) (l:hs_lens from to) = i:ix b -> v:a -> LensST unit l (requires fun s0 -> as_seq (LL.get layer s0) `q` as_seq (put_value_at (LL.get layer s0) i v)) (ensures fun s0 _ s1 -> s1 == LL.put layer s0 (put_value_at (LL.get layer s0) i v))
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 67, "end_line": 164, "start_col": 0, "start_line": 155 }
(* 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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a /// pointer. let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1 /// `flavor`: A buffer `b` is described as Pointer-flavor if /// -- its length is 1 /// -- its preorder is ok for pointers let flavor #a #p #q (b:B.mbuffer a p q) = f:flav{ f == Pointer ==> B.length b == 1 /\ ok_for_ptr q } /// A couple of convenient flavor abbreviations unfold let ptr (b:B.pointer 'a) : flavor b = Pointer unfold let buf (b:B.mbuffer 'a 'b 'c) : flavor b = Buffer /// `lseq_of`: A sequence whose length matches the buffer's length let lseq_of #a #p #q (b:B.mbuffer a p q) = Seq.lseq a (B.length b) /// `view_type_of b f`: Provides an f-flavored voew on the buffer `b` let view_type_of #a #p #q (#b:B.mbuffer a p q) (f:flavor b) = match f with | Buffer -> lseq_of b | Pointer -> a /// `buffer_hs_lens`: /// hs_lens between a buffer `b` and `lseq_of b` /// of flavor `f` let buffer_hs_lens #a #p #q (b:B.mbuffer a p q) (f:flavor b) = l:hs_lens (B.mbuffer a p q) (view_type_of f){ Ghost.reveal l.footprint == B.loc_buffer b /\ l.x == b } /// `get_value_at` and `put_value_at`: provide a uniform sequence- or /// element-based view on top of both flavors of buffers unfold let get_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v:view_type_of f) (i:uint_32{ i < B.len b }) : a = match f with | Pointer -> v | Buffer -> Seq.index v (UInt32.v i) unfold let put_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v0:view_type_of f) (i:uint_32{ i < B.len b }) (x:a) : view_type_of f = match f with | Pointer -> x | Buffer -> Seq.upd v0 (UInt32.v i) x /// `as_seq` views both flavors as a sequence unfold let as_seq #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v0:view_type_of f) : lseq_of b = match f with | Pointer -> Seq.create 1 v0 | Buffer -> v0 /// `with_state t`: /// /// 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_state #from #to (lens:hs_lens from to) ($t:hs_lens from to -> Type) = s:imem (lens.invariant lens.x) -> t (snap lens s) let ix #a #p #q (b:B.mbuffer a p q) = i:uint_32{i < B.len b} module LL = LowStar.Lens /// `writer_t l`: writes a single element to a buffer let reader_t #a #p #q (#b:B.mbuffer a p q) (f:flavor b) #from #to (layer: lens to (view_type_of f)) (l:hs_lens from to) = i:ix b -> LensST a l (requires fun _ -> True) (ensures fun s0 v s1 -> s0 == s1 /\ v == get_value_at (LL.get layer s1) i)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Lens", "short_module": "LL" }, { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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: LowStar.Lens.Buffer.flavor b -> layer: LowStar.Lens.lens to (LowStar.Lens.Buffer.view_type_of f) -> l: LowStar.Lens.hs_lens from to -> Type0
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Lens.Buffer.flavor", "LowStar.Lens.lens", "LowStar.Lens.Buffer.view_type_of", "LowStar.Lens.hs_lens", "LowStar.Lens.Buffer.ix", "Prims.unit", "LowStar.Lens.Buffer.as_seq", "LowStar.Lens.get", "LowStar.Lens.Buffer.put_value_at", "Prims.eq2", "LowStar.Lens.put" ]
[]
false
false
false
false
true
let writer_t #a #p #q (#b: B.mbuffer a p q) (f: flavor b) #from #to (layer: lens to (view_type_of f)) (l: hs_lens from to) =
i: ix b -> v: a -> LensST unit l (requires fun s0 -> (as_seq (LL.get layer s0)) `q` (as_seq (put_value_at (LL.get layer s0) i v))) (ensures fun s0 _ s1 -> s1 == LL.put layer s0 (put_value_at (LL.get layer s0) i v))
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.ok_for_ptr
val ok_for_ptr : q: LowStar.Monotonic.Buffer.srel 'a -> Prims.logical
let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 54, "start_col": 0, "start_line": 49 }
(* 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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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: LowStar.Monotonic.Buffer.srel 'a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "Prims.l_Forall", "FStar.Seq.Base.seq", "Prims.l_imp", "Prims.l_and", "Prims.eq2", "Prims.nat", "FStar.Seq.Base.length", "Prims.int", "FStar.Seq.Base.create", "FStar.Seq.Base.index", "Prims.logical" ]
[]
false
false
false
true
true
let ok_for_ptr (q: B.srel 'a) =
forall (s0: Seq.seq 'a) (s1: Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.ptr
val ptr (b: B.pointer 'a) : flavor b
val ptr (b: B.pointer 'a) : flavor b
let ptr (b:B.pointer 'a) : flavor b = Pointer
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 45, "end_line": 69, "start_col": 0, "start_line": 69 }
(* 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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a /// pointer. let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1 /// `flavor`: A buffer `b` is described as Pointer-flavor if /// -- its length is 1 /// -- its preorder is ok for pointers let flavor #a #p #q (b:B.mbuffer a p q) = f:flav{ f == Pointer ==> B.length b == 1 /\ ok_for_ptr q } /// A couple of convenient flavor abbreviations
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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
b: LowStar.Buffer.pointer 'a -> LowStar.Lens.Buffer.flavor b
Prims.Tot
[ "total" ]
[]
[ "LowStar.Buffer.pointer", "LowStar.Lens.Buffer.Pointer", "LowStar.Lens.Buffer.flavor", "LowStar.Buffer.trivial_preorder" ]
[]
false
false
false
false
false
let ptr (b: B.pointer 'a) : flavor b =
Pointer
false
FStar.Int.Cast.fst
FStar.Int.Cast.uint8_to_uint16
val uint8_to_uint16: a:U8.t -> Tot (b:U16.t{U16.v b = U8.v a})
val uint8_to_uint16: a:U8.t -> Tot (b:U16.t{U16.v b = U8.v a})
let uint8_to_uint16 x = U16.uint_to_t (U8.v x)
{ "file_name": "ulib/FStar.Int.Cast.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 38, "start_col": 0, "start_line": 38 }
(* Copyright 2008-2018 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 FStar.Int.Cast module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module I8 = FStar.Int8 module I16 = FStar.Int16 module I32 = FStar.Int32 module I64 = FStar.Int64 let op_At_Percent = FStar.Int.op_At_Percent /// Unsigned to unsigned val uint8_to_uint64: a:U8.t -> Tot (b:U64.t{U64.v b = U8.v a}) let uint8_to_uint64 a = U64.uint_to_t (U8.v a) val uint8_to_uint32: a:U8.t -> Tot (b:U32.t{U32.v b = U8.v a}) let uint8_to_uint32 x = U32.uint_to_t (U8.v x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Int.Cast.fst" }
[ { "abbrev": true, "full_module": "FStar.Int64", "short_module": "I64" }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "I32" }, { "abbrev": true, "full_module": "FStar.Int16", "short_module": "I16" }, { "abbrev": true, "full_module": "FStar.Int8", "short_module": "I8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Int", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int", "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: FStar.UInt8.t -> b: FStar.UInt16.t{FStar.UInt16.v b = FStar.UInt8.v a}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.t", "FStar.UInt16.uint_to_t", "FStar.UInt8.v", "FStar.UInt16.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt16.n", "FStar.UInt8.n", "FStar.UInt16.v" ]
[]
false
false
false
false
false
let uint8_to_uint16 x =
U16.uint_to_t (U8.v x)
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.view_type_of
val view_type_of : f: LowStar.Lens.Buffer.flavor b -> Type0
let view_type_of #a #p #q (#b:B.mbuffer a p q) (f:flavor b) = match f with | Buffer -> lseq_of b | Pointer -> a
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 83, "start_col": 0, "start_line": 80 }
(* 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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a /// pointer. let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1 /// `flavor`: A buffer `b` is described as Pointer-flavor if /// -- its length is 1 /// -- its preorder is ok for pointers let flavor #a #p #q (b:B.mbuffer a p q) = f:flav{ f == Pointer ==> B.length b == 1 /\ ok_for_ptr q } /// A couple of convenient flavor abbreviations unfold let ptr (b:B.pointer 'a) : flavor b = Pointer unfold let buf (b:B.mbuffer 'a 'b 'c) : flavor b = Buffer /// `lseq_of`: A sequence whose length matches the buffer's length let lseq_of #a #p #q (b:B.mbuffer a p q) = Seq.lseq a (B.length b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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: LowStar.Lens.Buffer.flavor b -> Type0
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Lens.Buffer.flavor", "LowStar.Lens.Buffer.lseq_of" ]
[]
false
false
false
false
true
let view_type_of #a #p #q (#b: B.mbuffer a p q) (f: flavor b) =
match f with | Buffer -> lseq_of b | Pointer -> a
false
FStar.Int.Cast.fst
FStar.Int.Cast.uint8_to_uint32
val uint8_to_uint32: a:U8.t -> Tot (b:U32.t{U32.v b = U8.v a})
val uint8_to_uint32: a:U8.t -> Tot (b:U32.t{U32.v b = U8.v a})
let uint8_to_uint32 x = U32.uint_to_t (U8.v x)
{ "file_name": "ulib/FStar.Int.Cast.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 35, "start_col": 0, "start_line": 35 }
(* Copyright 2008-2018 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 FStar.Int.Cast module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module I8 = FStar.Int8 module I16 = FStar.Int16 module I32 = FStar.Int32 module I64 = FStar.Int64 let op_At_Percent = FStar.Int.op_At_Percent /// Unsigned to unsigned val uint8_to_uint64: a:U8.t -> Tot (b:U64.t{U64.v b = U8.v a}) let uint8_to_uint64 a = U64.uint_to_t (U8.v a)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Int.Cast.fst" }
[ { "abbrev": true, "full_module": "FStar.Int64", "short_module": "I64" }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "I32" }, { "abbrev": true, "full_module": "FStar.Int16", "short_module": "I16" }, { "abbrev": true, "full_module": "FStar.Int8", "short_module": "I8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Int", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int", "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: FStar.UInt8.t -> b: FStar.UInt32.t{FStar.UInt32.v b = FStar.UInt8.v a}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.t", "FStar.UInt32.uint_to_t", "FStar.UInt8.v", "FStar.UInt32.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "FStar.UInt8.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let uint8_to_uint32 x =
U32.uint_to_t (U8.v x)
false
FStar.Int.Cast.fst
FStar.Int.Cast.uint8_to_uint64
val uint8_to_uint64: a:U8.t -> Tot (b:U64.t{U64.v b = U8.v a})
val uint8_to_uint64: a:U8.t -> Tot (b:U64.t{U64.v b = U8.v a})
let uint8_to_uint64 a = U64.uint_to_t (U8.v a)
{ "file_name": "ulib/FStar.Int.Cast.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 32, "start_col": 0, "start_line": 32 }
(* Copyright 2008-2018 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 FStar.Int.Cast module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module I8 = FStar.Int8 module I16 = FStar.Int16 module I32 = FStar.Int32 module I64 = FStar.Int64 let op_At_Percent = FStar.Int.op_At_Percent /// Unsigned to unsigned
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Int.Cast.fst" }
[ { "abbrev": true, "full_module": "FStar.Int64", "short_module": "I64" }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "I32" }, { "abbrev": true, "full_module": "FStar.Int16", "short_module": "I16" }, { "abbrev": true, "full_module": "FStar.Int8", "short_module": "I8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Int", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int", "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: FStar.UInt8.t -> b: FStar.UInt64.t{FStar.UInt64.v b = FStar.UInt8.v a}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.t", "FStar.UInt64.uint_to_t", "FStar.UInt8.v", "FStar.UInt64.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt8.n", "FStar.UInt64.v" ]
[]
false
false
false
false
false
let uint8_to_uint64 a =
U64.uint_to_t (U8.v a)
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.get_value_at
val get_value_at (#a #p #q: _) (#b: B.mbuffer a p q) (#f: flavor b) (v: view_type_of f) (i: uint_32{i < B.len b}) : a
val get_value_at (#a #p #q: _) (#b: B.mbuffer a p q) (#f: flavor b) (v: view_type_of f) (i: uint_32{i < B.len b}) : a
let get_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v:view_type_of f) (i:uint_32{ i < B.len b }) : a = match f with | Pointer -> v | Buffer -> Seq.index v (UInt32.v i)
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 103, "start_col": 0, "start_line": 97 }
(* 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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a /// pointer. let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1 /// `flavor`: A buffer `b` is described as Pointer-flavor if /// -- its length is 1 /// -- its preorder is ok for pointers let flavor #a #p #q (b:B.mbuffer a p q) = f:flav{ f == Pointer ==> B.length b == 1 /\ ok_for_ptr q } /// A couple of convenient flavor abbreviations unfold let ptr (b:B.pointer 'a) : flavor b = Pointer unfold let buf (b:B.mbuffer 'a 'b 'c) : flavor b = Buffer /// `lseq_of`: A sequence whose length matches the buffer's length let lseq_of #a #p #q (b:B.mbuffer a p q) = Seq.lseq a (B.length b) /// `view_type_of b f`: Provides an f-flavored voew on the buffer `b` let view_type_of #a #p #q (#b:B.mbuffer a p q) (f:flavor b) = match f with | Buffer -> lseq_of b | Pointer -> a /// `buffer_hs_lens`: /// hs_lens between a buffer `b` and `lseq_of b` /// of flavor `f` let buffer_hs_lens #a #p #q (b:B.mbuffer a p q) (f:flavor b) = l:hs_lens (B.mbuffer a p q) (view_type_of f){ Ghost.reveal l.footprint == B.loc_buffer b /\ l.x == b } /// `get_value_at` and `put_value_at`: provide a uniform sequence- or /// element-based view on top of both flavors of buffers
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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
v: LowStar.Lens.Buffer.view_type_of f -> i: FStar.Integers.uint_32{i < LowStar.Monotonic.Buffer.len b} -> a
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Lens.Buffer.flavor", "LowStar.Lens.Buffer.view_type_of", "FStar.Integers.uint_32", "Prims.b2t", "FStar.Integers.op_Less", "FStar.Integers.Unsigned", "FStar.Integers.W32", "LowStar.Monotonic.Buffer.len", "FStar.Seq.Base.index", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let get_value_at #a #p #q (#b: B.mbuffer a p q) (#f: flavor b) (v: view_type_of f) (i: uint_32{i < B.len b}) : a =
match f with | Pointer -> v | Buffer -> Seq.index v (UInt32.v i)
false
FStar.Int.Cast.fst
FStar.Int.Cast.uint16_to_uint8
val uint16_to_uint8 : a:U16.t -> Tot (b:U8.t{U8.v b = U16.v a % pow2 8})
val uint16_to_uint8 : a:U16.t -> Tot (b:U8.t{U8.v b = U16.v a % pow2 8})
let uint16_to_uint8 x = U8.uint_to_t (U16.v x % pow2 8)
{ "file_name": "ulib/FStar.Int.Cast.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 47, "start_col": 0, "start_line": 47 }
(* Copyright 2008-2018 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 FStar.Int.Cast module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module I8 = FStar.Int8 module I16 = FStar.Int16 module I32 = FStar.Int32 module I64 = FStar.Int64 let op_At_Percent = FStar.Int.op_At_Percent /// Unsigned to unsigned val uint8_to_uint64: a:U8.t -> Tot (b:U64.t{U64.v b = U8.v a}) let uint8_to_uint64 a = U64.uint_to_t (U8.v a) val uint8_to_uint32: a:U8.t -> Tot (b:U32.t{U32.v b = U8.v a}) let uint8_to_uint32 x = U32.uint_to_t (U8.v x) val uint8_to_uint16: a:U8.t -> Tot (b:U16.t{U16.v b = U8.v a}) let uint8_to_uint16 x = U16.uint_to_t (U8.v x) val uint16_to_uint64: a:U16.t -> Tot (b:U64.t{U64.v b = U16.v a}) let uint16_to_uint64 x = U64.uint_to_t (U16.v x) val uint16_to_uint32: a:U16.t -> Tot (b:U32.t{U32.v b = U16.v a}) let uint16_to_uint32 x = U32.uint_to_t (U16.v x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Int.Cast.fst" }
[ { "abbrev": true, "full_module": "FStar.Int64", "short_module": "I64" }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "I32" }, { "abbrev": true, "full_module": "FStar.Int16", "short_module": "I16" }, { "abbrev": true, "full_module": "FStar.Int8", "short_module": "I8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Int", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int", "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: FStar.UInt16.t -> b: FStar.UInt8.t{FStar.UInt8.v b = FStar.UInt16.v a % Prims.pow2 8}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt16.t", "FStar.UInt8.uint_to_t", "Prims.op_Modulus", "FStar.UInt16.v", "Prims.pow2", "FStar.UInt8.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.UInt8.v" ]
[]
false
false
false
false
false
let uint16_to_uint8 x =
U8.uint_to_t (U16.v x % pow2 8)
false
FStar.Int.Cast.fst
FStar.Int.Cast.uint16_to_uint64
val uint16_to_uint64: a:U16.t -> Tot (b:U64.t{U64.v b = U16.v a})
val uint16_to_uint64: a:U16.t -> Tot (b:U64.t{U64.v b = U16.v a})
let uint16_to_uint64 x = U64.uint_to_t (U16.v x)
{ "file_name": "ulib/FStar.Int.Cast.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 41, "start_col": 0, "start_line": 41 }
(* Copyright 2008-2018 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 FStar.Int.Cast module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module I8 = FStar.Int8 module I16 = FStar.Int16 module I32 = FStar.Int32 module I64 = FStar.Int64 let op_At_Percent = FStar.Int.op_At_Percent /// Unsigned to unsigned val uint8_to_uint64: a:U8.t -> Tot (b:U64.t{U64.v b = U8.v a}) let uint8_to_uint64 a = U64.uint_to_t (U8.v a) val uint8_to_uint32: a:U8.t -> Tot (b:U32.t{U32.v b = U8.v a}) let uint8_to_uint32 x = U32.uint_to_t (U8.v x) val uint8_to_uint16: a:U8.t -> Tot (b:U16.t{U16.v b = U8.v a}) let uint8_to_uint16 x = U16.uint_to_t (U8.v x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Int.Cast.fst" }
[ { "abbrev": true, "full_module": "FStar.Int64", "short_module": "I64" }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "I32" }, { "abbrev": true, "full_module": "FStar.Int16", "short_module": "I16" }, { "abbrev": true, "full_module": "FStar.Int8", "short_module": "I8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Int", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int", "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: FStar.UInt16.t -> b: FStar.UInt64.t{FStar.UInt64.v b = FStar.UInt16.v a}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt16.t", "FStar.UInt64.uint_to_t", "FStar.UInt16.v", "FStar.UInt64.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt16.n", "FStar.UInt64.v" ]
[]
false
false
false
false
false
let uint16_to_uint64 x =
U64.uint_to_t (U16.v x)
false
LowStar.Lens.Buffer.fsti
LowStar.Lens.Buffer.put_value_at
val put_value_at (#a #p #q: _) (#b: B.mbuffer a p q) (#f: flavor b) (v0: view_type_of f) (i: uint_32{i < B.len b}) (x: a) : view_type_of f
val put_value_at (#a #p #q: _) (#b: B.mbuffer a p q) (#f: flavor b) (v0: view_type_of f) (i: uint_32{i < B.len b}) (x: a) : view_type_of f
let put_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v0:view_type_of f) (i:uint_32{ i < B.len b }) (x:a) : view_type_of f = match f with | Pointer -> x | Buffer -> Seq.upd v0 (UInt32.v i) x
{ "file_name": "examples/data_structures/LowStar.Lens.Buffer.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 113, "start_col": 0, "start_line": 106 }
(* 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.Buffer open LowStar.Lens open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST open FStar.Integers (* This module provides an instance of an `hs_lens` for monotonic buffers, allowing viewing a hyperstack containing a buffer as just a sequence of the buffer's contents. This is the main "leaf" instance of an `hs_lens`, since (almost) all mutable types in LowStar are expressed via monotonic buffers (referring to a sequence) or pointers (referring to a single element). This module multiplexes between the buffer and pointer views as "two flavors". Note, Low* also supports `ref` types, which are essentially equivalent to pointers. For uniformity, we recommend using `pointer` instead of `ref`. *) /// `flav`: Two varieties of references type flav = | Buffer | Pointer /// `ok_for_ptr q`: Pointers, unfortunately, are indexed by preorders on /// sequences, rather than preorders on elements. So, we need some /// conditions to ensure that a sequence preorder is appropriate for a /// pointer. let ok_for_ptr (q:B.srel 'a) = forall (s0 s1 : Seq.seq 'a). {:pattern (s0 `q` s1)} (Seq.length s0 == Seq.length s1 /\ Seq.length s0 == 1 /\ (Seq.create 1 (Seq.index s0 0)) `q` (Seq.create 1 (Seq.index s1 0))) ==> s0 `q` s1 /// `flavor`: A buffer `b` is described as Pointer-flavor if /// -- its length is 1 /// -- its preorder is ok for pointers let flavor #a #p #q (b:B.mbuffer a p q) = f:flav{ f == Pointer ==> B.length b == 1 /\ ok_for_ptr q } /// A couple of convenient flavor abbreviations unfold let ptr (b:B.pointer 'a) : flavor b = Pointer unfold let buf (b:B.mbuffer 'a 'b 'c) : flavor b = Buffer /// `lseq_of`: A sequence whose length matches the buffer's length let lseq_of #a #p #q (b:B.mbuffer a p q) = Seq.lseq a (B.length b) /// `view_type_of b f`: Provides an f-flavored voew on the buffer `b` let view_type_of #a #p #q (#b:B.mbuffer a p q) (f:flavor b) = match f with | Buffer -> lseq_of b | Pointer -> a /// `buffer_hs_lens`: /// hs_lens between a buffer `b` and `lseq_of b` /// of flavor `f` let buffer_hs_lens #a #p #q (b:B.mbuffer a p q) (f:flavor b) = l:hs_lens (B.mbuffer a p q) (view_type_of f){ Ghost.reveal l.footprint == B.loc_buffer b /\ l.x == b } /// `get_value_at` and `put_value_at`: provide a uniform sequence- or /// element-based view on top of both flavors of buffers unfold let get_value_at #a #p #q (#b:B.mbuffer a p q) (#f:flavor b) (v:view_type_of f) (i:uint_32{ i < B.len b }) : a = match f with | Pointer -> v | Buffer -> Seq.index v (UInt32.v i)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Lens.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lens.Buffer.fsti" }
[ { "abbrev": false, "full_module": "FStar.Integers", "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.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lens", "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
v0: LowStar.Lens.Buffer.view_type_of f -> i: FStar.Integers.uint_32{i < LowStar.Monotonic.Buffer.len b} -> x: a -> LowStar.Lens.Buffer.view_type_of f
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Lens.Buffer.flavor", "LowStar.Lens.Buffer.view_type_of", "FStar.Integers.uint_32", "Prims.b2t", "FStar.Integers.op_Less", "FStar.Integers.Unsigned", "FStar.Integers.W32", "LowStar.Monotonic.Buffer.len", "FStar.Seq.Base.upd", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let put_value_at #a #p #q (#b: B.mbuffer a p q) (#f: flavor b) (v0: view_type_of f) (i: uint_32{i < B.len b}) (x: a) : view_type_of f =
match f with | Pointer -> x | Buffer -> Seq.upd v0 (UInt32.v i) x
false
FStar.Int.Cast.fst
FStar.Int.Cast.uint16_to_uint32
val uint16_to_uint32: a:U16.t -> Tot (b:U32.t{U32.v b = U16.v a})
val uint16_to_uint32: a:U16.t -> Tot (b:U32.t{U32.v b = U16.v a})
let uint16_to_uint32 x = U32.uint_to_t (U16.v x)
{ "file_name": "ulib/FStar.Int.Cast.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 44, "start_col": 0, "start_line": 44 }
(* Copyright 2008-2018 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 FStar.Int.Cast module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module I8 = FStar.Int8 module I16 = FStar.Int16 module I32 = FStar.Int32 module I64 = FStar.Int64 let op_At_Percent = FStar.Int.op_At_Percent /// Unsigned to unsigned val uint8_to_uint64: a:U8.t -> Tot (b:U64.t{U64.v b = U8.v a}) let uint8_to_uint64 a = U64.uint_to_t (U8.v a) val uint8_to_uint32: a:U8.t -> Tot (b:U32.t{U32.v b = U8.v a}) let uint8_to_uint32 x = U32.uint_to_t (U8.v x) val uint8_to_uint16: a:U8.t -> Tot (b:U16.t{U16.v b = U8.v a}) let uint8_to_uint16 x = U16.uint_to_t (U8.v x) val uint16_to_uint64: a:U16.t -> Tot (b:U64.t{U64.v b = U16.v a}) let uint16_to_uint64 x = U64.uint_to_t (U16.v x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Int.Cast.fst" }
[ { "abbrev": true, "full_module": "FStar.Int64", "short_module": "I64" }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "I32" }, { "abbrev": true, "full_module": "FStar.Int16", "short_module": "I16" }, { "abbrev": true, "full_module": "FStar.Int8", "short_module": "I8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Int", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int", "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: FStar.UInt16.t -> b: FStar.UInt32.t{FStar.UInt32.v b = FStar.UInt16.v a}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt16.t", "FStar.UInt32.uint_to_t", "FStar.UInt16.v", "FStar.UInt32.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "FStar.UInt16.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let uint16_to_uint32 x =
U32.uint_to_t (U16.v x)
false
Vale.AES.PPC64LE.GF128_Mul.fsti
Vale.AES.PPC64LE.GF128_Mul.va_quick_Low64ToHigh
val va_quick_Low64ToHigh (dst src: va_operand_vec_opr) (a: poly) : (va_quickCode unit (va_code_Low64ToHigh dst src))
val va_quick_Low64ToHigh (dst src: va_operand_vec_opr) (a: poly) : (va_quickCode unit (va_code_Low64ToHigh dst src))
let va_quick_Low64ToHigh (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) : (va_quickCode unit (va_code_Low64ToHigh dst src)) = (va_QProc (va_code_Low64ToHigh dst src) ([va_mod_vec_opr dst]) (va_wp_Low64ToHigh dst src a) (va_wpProof_Low64ToHigh dst src a))
{ "file_name": "obj/Vale.AES.PPC64LE.GF128_Mul.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 132, "start_col": 0, "start_line": 129 }
module Vale.AES.PPC64LE.GF128_Mul open Vale.Def.Types_s open Vale.Arch.Types open Vale.Arch.TypesNative open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.Math.Poly2.Lemmas open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.PPC64LE.Machine_s open Vale.PPC64LE.State open Vale.PPC64LE.Decls open Vale.PPC64LE.InsBasic open Vale.PPC64LE.InsMem open Vale.PPC64LE.InsVector open Vale.PPC64LE.QuickCode open Vale.PPC64LE.QuickCodes open Vale.AES.PPC64LE.PolyOps open Vale.AES.Types_helpers open Vale.AES.GHash_BE //-- ShiftLeft128_1 val va_code_ShiftLeft128_1 : va_dummy:unit -> Tot va_code val va_codegen_success_ShiftLeft128_1 : va_dummy:unit -> Tot va_pbool val va_lemma_ShiftLeft128_1 : va_b0:va_code -> va_s0:va_state -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_ShiftLeft128_1 ()) va_s0 /\ va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) /\ va_state_eq va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_ok va_sM va_s0))))) [@ va_qattr] let va_wp_ShiftLeft128_1 (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ Vale.Math.Poly2_s.degree a < 128 /\ va_get_vec 1 va_s0 == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_v1:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 va_s0) in va_get_ok va_sM /\ va_get_vec 1 va_sM == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.shift a 1) ==> va_k va_sM (()))) val va_wpProof_ShiftLeft128_1 : a:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_ShiftLeft128_1 a va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftLeft128_1 ()) ([va_Mod_vec 2; va_Mod_vec 1]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_ShiftLeft128_1 (a:poly) : (va_quickCode unit (va_code_ShiftLeft128_1 ())) = (va_QProc (va_code_ShiftLeft128_1 ()) ([va_Mod_vec 2; va_Mod_vec 1]) (va_wp_ShiftLeft128_1 a) (va_wpProof_ShiftLeft128_1 a)) //-- //-- High64ToLow val va_code_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_code val va_codegen_success_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_pbool val va_lemma_High64ToLow : va_b0:va_code -> va_s0:va_state -> dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_High64ToLow dst src) va_s0 /\ va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.div a (Vale.Math.Poly2_s.monomial 64)) /\ va_state_eq va_sM (va_update_ok va_sM (va_update_operand_vec_opr dst va_sM va_s0)))) [@ va_qattr] let va_wp_High64ToLow (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_dst:va_value_vec_opr) . let va_sM = va_upd_operand_vec_opr dst va_x_dst va_s0 in va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.div a (Vale.Math.Poly2_s.monomial 64)) ==> va_k va_sM (()))) val va_wpProof_High64ToLow : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_High64ToLow dst src a va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_High64ToLow dst src) ([va_mod_vec_opr dst]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_High64ToLow (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) : (va_quickCode unit (va_code_High64ToLow dst src)) = (va_QProc (va_code_High64ToLow dst src) ([va_mod_vec_opr dst]) (va_wp_High64ToLow dst src a) (va_wpProof_High64ToLow dst src a)) //-- //-- Low64ToHigh val va_code_Low64ToHigh : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_code val va_codegen_success_Low64ToHigh : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> Tot va_pbool val va_lemma_Low64ToHigh : va_b0:va_code -> va_s0:va_state -> dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Low64ToHigh dst src) va_s0 /\ va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.mod a (Vale.Math.Poly2_s.monomial 64)) (Vale.Math.Poly2_s.monomial 64)) /\ va_state_eq va_sM (va_update_ok va_sM (va_update_operand_vec_opr dst va_sM va_s0)))) [@ va_qattr] let va_wp_Low64ToHigh (dst:va_operand_vec_opr) (src:va_operand_vec_opr) (a:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_is_dst_vec_opr dst va_s0 /\ va_is_src_vec_opr src va_s0 /\ va_get_ok va_s0 /\ va_get_vec 0 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0 /\ Vale.Math.Poly2_s.degree a <= 127 /\ va_eval_vec_opr va_s0 src == Vale.Math.Poly2.Bits_s.to_quad32 a /\ (forall (va_x_dst:va_value_vec_opr) . let va_sM = va_upd_operand_vec_opr dst va_x_dst va_s0 in va_get_ok va_sM /\ va_eval_vec_opr va_sM dst == Vale.Math.Poly2.Bits_s.to_quad32 (Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.mod a (Vale.Math.Poly2_s.monomial 64)) (Vale.Math.Poly2_s.monomial 64)) ==> va_k va_sM (()))) val va_wpProof_Low64ToHigh : dst:va_operand_vec_opr -> src:va_operand_vec_opr -> a:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_Low64ToHigh dst src a va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Low64ToHigh dst src) ([va_mod_vec_opr dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.State.fsti.checked", "Vale.PPC64LE.QuickCodes.fsti.checked", "Vale.PPC64LE.QuickCode.fst.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.PPC64LE.InsVector.fsti.checked", "Vale.PPC64LE.InsMem.fsti.checked", "Vale.PPC64LE.InsBasic.fsti.checked", "Vale.PPC64LE.Decls.fsti.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.PPC64LE.PolyOps.fsti.checked", "Vale.AES.GHash_BE.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.PPC64LE.GF128_Mul.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.GHash_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.PPC64LE", "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
dst: Vale.PPC64LE.Decls.va_operand_vec_opr -> src: Vale.PPC64LE.Decls.va_operand_vec_opr -> a: Vale.Math.Poly2_s.poly -> Vale.PPC64LE.QuickCode.va_quickCode Prims.unit (Vale.AES.PPC64LE.GF128_Mul.va_code_Low64ToHigh dst src)
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Decls.va_operand_vec_opr", "Vale.Math.Poly2_s.poly", "Vale.PPC64LE.QuickCode.va_QProc", "Prims.unit", "Vale.AES.PPC64LE.GF128_Mul.va_code_Low64ToHigh", "Prims.Cons", "Vale.PPC64LE.QuickCode.mod_t", "Vale.PPC64LE.QuickCode.va_mod_vec_opr", "Prims.Nil", "Vale.AES.PPC64LE.GF128_Mul.va_wp_Low64ToHigh", "Vale.AES.PPC64LE.GF128_Mul.va_wpProof_Low64ToHigh", "Vale.PPC64LE.QuickCode.va_quickCode" ]
[]
false
false
false
false
false
let va_quick_Low64ToHigh (dst src: va_operand_vec_opr) (a: poly) : (va_quickCode unit (va_code_Low64ToHigh dst src)) =
(va_QProc (va_code_Low64ToHigh dst src) ([va_mod_vec_opr dst]) (va_wp_Low64ToHigh dst src a) (va_wpProof_Low64ToHigh dst src a))
false
FStar.Int.Cast.fst
FStar.Int.Cast.uint32_to_uint64
val uint32_to_uint64: a:U32.t -> Tot (b:U64.t{U64.v b = U32.v a})
val uint32_to_uint64: a:U32.t -> Tot (b:U64.t{U64.v b = U32.v a})
let uint32_to_uint64 x = U64.uint_to_t (U32.v x)
{ "file_name": "ulib/FStar.Int.Cast.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 50, "start_col": 0, "start_line": 50 }
(* Copyright 2008-2018 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 FStar.Int.Cast module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module I8 = FStar.Int8 module I16 = FStar.Int16 module I32 = FStar.Int32 module I64 = FStar.Int64 let op_At_Percent = FStar.Int.op_At_Percent /// Unsigned to unsigned val uint8_to_uint64: a:U8.t -> Tot (b:U64.t{U64.v b = U8.v a}) let uint8_to_uint64 a = U64.uint_to_t (U8.v a) val uint8_to_uint32: a:U8.t -> Tot (b:U32.t{U32.v b = U8.v a}) let uint8_to_uint32 x = U32.uint_to_t (U8.v x) val uint8_to_uint16: a:U8.t -> Tot (b:U16.t{U16.v b = U8.v a}) let uint8_to_uint16 x = U16.uint_to_t (U8.v x) val uint16_to_uint64: a:U16.t -> Tot (b:U64.t{U64.v b = U16.v a}) let uint16_to_uint64 x = U64.uint_to_t (U16.v x) val uint16_to_uint32: a:U16.t -> Tot (b:U32.t{U32.v b = U16.v a}) let uint16_to_uint32 x = U32.uint_to_t (U16.v x) val uint16_to_uint8 : a:U16.t -> Tot (b:U8.t{U8.v b = U16.v a % pow2 8}) let uint16_to_uint8 x = U8.uint_to_t (U16.v x % pow2 8)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Int.Cast.fst" }
[ { "abbrev": true, "full_module": "FStar.Int64", "short_module": "I64" }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "I32" }, { "abbrev": true, "full_module": "FStar.Int16", "short_module": "I16" }, { "abbrev": true, "full_module": "FStar.Int8", "short_module": "I8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Int", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int", "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: FStar.UInt32.t -> b: FStar.UInt64.t{FStar.UInt64.v b = FStar.UInt32.v a}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "FStar.UInt64.uint_to_t", "FStar.UInt32.v", "FStar.UInt64.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt32.n", "FStar.UInt64.v" ]
[]
false
false
false
false
false
let uint32_to_uint64 x =
U64.uint_to_t (U32.v x)
false
FStar.Int.Cast.fst
FStar.Int.Cast.uint64_to_uint32
val uint64_to_uint32: a:U64.t -> Tot (b:U32.t{U32.v b = U64.v a % pow2 32})
val uint64_to_uint32: a:U64.t -> Tot (b:U32.t{U32.v b = U64.v a % pow2 32})
let uint64_to_uint32 x = U32.uint_to_t (U64.v x % pow2 32)
{ "file_name": "ulib/FStar.Int.Cast.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 59, "start_col": 0, "start_line": 59 }
(* Copyright 2008-2018 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 FStar.Int.Cast module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module I8 = FStar.Int8 module I16 = FStar.Int16 module I32 = FStar.Int32 module I64 = FStar.Int64 let op_At_Percent = FStar.Int.op_At_Percent /// Unsigned to unsigned val uint8_to_uint64: a:U8.t -> Tot (b:U64.t{U64.v b = U8.v a}) let uint8_to_uint64 a = U64.uint_to_t (U8.v a) val uint8_to_uint32: a:U8.t -> Tot (b:U32.t{U32.v b = U8.v a}) let uint8_to_uint32 x = U32.uint_to_t (U8.v x) val uint8_to_uint16: a:U8.t -> Tot (b:U16.t{U16.v b = U8.v a}) let uint8_to_uint16 x = U16.uint_to_t (U8.v x) val uint16_to_uint64: a:U16.t -> Tot (b:U64.t{U64.v b = U16.v a}) let uint16_to_uint64 x = U64.uint_to_t (U16.v x) val uint16_to_uint32: a:U16.t -> Tot (b:U32.t{U32.v b = U16.v a}) let uint16_to_uint32 x = U32.uint_to_t (U16.v x) val uint16_to_uint8 : a:U16.t -> Tot (b:U8.t{U8.v b = U16.v a % pow2 8}) let uint16_to_uint8 x = U8.uint_to_t (U16.v x % pow2 8) val uint32_to_uint64: a:U32.t -> Tot (b:U64.t{U64.v b = U32.v a}) let uint32_to_uint64 x = U64.uint_to_t (U32.v x) val uint32_to_uint16: a:U32.t -> Tot (b:U16.t{U16.v b = U32.v a % pow2 16}) let uint32_to_uint16 x = U16.uint_to_t (U32.v x % pow2 16) val uint32_to_uint8 : a:U32.t -> Tot (b:U8.t{U8.v b = U32.v a % pow2 8}) let uint32_to_uint8 x = U8.uint_to_t (U32.v x % pow2 8)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Int.Cast.fst" }
[ { "abbrev": true, "full_module": "FStar.Int64", "short_module": "I64" }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "I32" }, { "abbrev": true, "full_module": "FStar.Int16", "short_module": "I16" }, { "abbrev": true, "full_module": "FStar.Int8", "short_module": "I8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Int", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int", "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: FStar.UInt64.t -> b: FStar.UInt32.t{FStar.UInt32.v b = FStar.UInt64.v a % Prims.pow2 32}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t", "FStar.UInt32.uint_to_t", "Prims.op_Modulus", "FStar.UInt64.v", "Prims.pow2", "FStar.UInt32.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let uint64_to_uint32 x =
U32.uint_to_t (U64.v x % pow2 32)
false