text
stringlengths
0
601k
module Cached_string = struct type t = { section : Asm_section . t ; str : string ; comment : string option } include Identifiable . Make ( struct type nonrec t = t let compare { section = section1 ; str = str1 ; comment = comment1 } { section = section2 ; str = str2 ; comment = comment2 } = let c = Asm_section . compa...
module Make ( A : Asm_directives_intf . Arg ) : Asm_directives_intf . S = struct module Int8 = Numbers . Int8 module Int16 = Numbers . Int16 module Uint8 = Numbers . Uint8 module Uint16 = Numbers . Uint16 module Uint32 = Numbers . Uint32 module Uint64 = Numbers . Uint64 module D = A . D let sections_seen = ref [ ] let ...
module type Arg = sig val emit_line : string -> unit val get_file_num : string -> int module D : sig type constant val const_int64 : int64 -> constant val const_label : string -> constant val const_add : constant -> constant -> constant val const_sub : constant -> constant -> constant type data_type = | NONE | DWORD | ...
module type S = sig val switch_to_section : Asm_section . t -> unit val initialize : unit -> unit val int8 : ? comment : string -> Numbers . Int8 . t -> unit val int16 : ? comment : string -> Numbers . Int16 . t -> unit val int32 : ? comment : string -> Int32 . t -> unit val int64 : ? comment : string -> Int64 . t -> u...
type label = | Int of int | String of string
type t = { section : Asm_section . t ; label : label } type nonrec t = t let compare t1 t2 = Stdlib . compare t1 . label t2 . label let equal t1 t2 = compare t1 t2 = 0 let hash t = Hashtbl . hash t . label let print ppf t = match t . label with | Int i -> Format . fprintf ppf " L % d " i | String s -> Format . fprintf ...
let create_int section label = assert ( label >= 0 ) ; { section ; label = Int label }
let contains_escapable_char label = let found_escapable_char = ref false in String . iter ( fun c -> if Asm_symbol . should_be_escaped c then found_escapable_char := true ) label ; ! found_escapable_char
let create_string section label = assert ( not ( contains_escapable_char label ) ) ; { section ; label = String label }
let label_prefix = match Target_system . assembler ( ) with MacOS -> " L " | MASM | GAS_like -> " . L "
let encode ( t : t ) = match t . label with | Int label -> label_prefix ^ string_of_int label | String label -> label_prefix ^ label
let section t = t . section
let new_label_ref = ref ( fun _section -> Misc . fatal_error " [ Asm_label . initialize ] has not been called " )
let initialize ~ new_label = new_label_ref := fun section -> create_int section ( new_label ( ) )
let create ( section : Asm_section . t ) = ! new_label_ref section
let debug_info_label = lazy ( create ( DWARF Debug_info ) )
let debug_abbrev_label = lazy ( create ( DWARF Debug_abbrev ) )
let debug_aranges_label = lazy ( create ( DWARF Debug_aranges ) )
let debug_addr_label = lazy ( create ( DWARF Debug_addr ) )
let debug_loc_label = lazy ( create ( DWARF Debug_loc ) )
let debug_ranges_label = lazy ( create ( DWARF Debug_ranges ) )
let debug_loclists_label = lazy ( create ( DWARF Debug_loclists ) )
let debug_rnglists_label = lazy ( create ( DWARF Debug_rnglists ) )
let debug_str_label = lazy ( create ( DWARF Debug_str ) )
let debug_line_label = lazy ( create ( DWARF Debug_line ) )
let for_dwarf_section ( dwarf_section : Asm_section . dwarf_section ) = match dwarf_section with | Debug_info -> Lazy . force debug_info_label | Debug_abbrev -> Lazy . force debug_abbrev_label | Debug_aranges -> Lazy . force debug_aranges_label | Debug_addr -> Lazy . force debug_addr_label | Debug_loc -> Lazy . force d...
let for_section ( section : Asm_section . t ) = match section with DWARF dwarf_section -> for_dwarf_section dwarf_section
type dwarf_section = | Debug_info | Debug_abbrev | Debug_aranges | Debug_addr | Debug_loc | Debug_ranges | Debug_loclists | Debug_rnglists | Debug_str | Debug_line
type t = DWARF of dwarf_section
type section_details = { names : string list ; flags : string option ; args : string list }
let dwarf_sections_in_order ( ) = let sections = [ DWARF Debug_info ; DWARF Debug_abbrev ; DWARF Debug_aranges ; DWARF Debug_str ; DWARF Debug_line ] in let dwarf_version_dependent_sections = match ! Dwarf_flags . gdwarf_version with | Four -> [ DWARF Debug_loc ; DWARF Debug_ranges ] | Five -> [ DWARF Debug_addr ; DWAR...
let details t ~ first_occurrence = let names , flags , args = match t , Target_system . derived_system ( ) with | DWARF dwarf , MacOS_like -> let name = match dwarf with | Debug_info -> " __debug_info " | Debug_abbrev -> " __debug_abbrev " | Debug_aranges -> " __debug_aranges " | Debug_addr -> " __debug_addr " | Debug_...
let to_string t = let { names ; flags = _ ; args = _ } = details t ~ first_occurrence : true in String . concat " " names
let print ppf t = let str = match t with | DWARF Debug_info -> " ( DWARF Debug_info ) " | DWARF Debug_abbrev -> " ( DWARF Debug_abbrev ) " | DWARF Debug_aranges -> " ( DWARF Debug_aranges ) " | DWARF Debug_addr -> " ( DWARF Debug_addr ) " | DWARF Debug_loc -> " ( DWARF Debug_loc ) " | DWARF Debug_ranges -> " ( DWARF De...
let compare t1 t2 = Stdlib . compare t1 t2
let equal t1 t2 = Stdlib . compare t1 t2 = 0
let should_be_escaped = function | ' A ' . . ' Z ' | ' a ' . . ' z ' | ' 0 ' . . ' 9 ' | ' _ ' -> false | c -> true
module Thing = struct type t = string let compare = String . compare let equal = String . equal let hash = Hashtbl . hash let output chan t = Printf . fprintf chan " % s " t let print = Format . pp_print_string end
let create name = name
let escape name = let escaped_nb = ref 0 in for i = 0 to String . length name - 1 do if should_be_escaped ( String . unsafe_get name i ) then incr escaped_nb done ; if ! escaped_nb = 0 then name else let b = Buffer . create ( String . length name + ( 2 * ! escaped_nb ) ) in String . iter ( fun c -> if should_be_escaped...
let symbol_prefix ( ) = match Target_system . architecture ( ) with | IA32 | X86_64 | AArch64 -> begin match Target_system . derived_system ( ) with | Linux | Win32 | Win64 | MinGW_32 | MinGW_64 | Cygwin | FreeBSD | NetBSD | OpenBSD | Generic_BSD | Solaris | BeOS | GNU | Dragonfly | Unknown -> " " | MacOS_like -> " _ "...
let to_escaped_string ? suffix ~ symbol_prefix t = let suffix = match suffix with None -> " " | Some suffix -> suffix in symbol_prefix ^ escape t ^ suffix
let encode ? without_prefix t = let symbol_prefix = match without_prefix with None -> symbol_prefix ( ) | Some ( ) -> " " in to_escaped_string ~ symbol_prefix t
module S = struct type ' a t = ' a Core . asn type ' a element = ' a Core . element type ' a sequence = ' a Core . sequence include Asn_combinators let ( error , parse_error ) = Core . ( error , parse_error ) end
type ' a t = ' a S . t
type encoding = { mk_decoder : ' a . ' a t -> Cstruct . t -> ' a * Cstruct . t ; mk_encoder : ' a . ' a t -> ' a -> Asn_writer . t }
let ber = { mk_decoder = Asn_ber_der . R . compile_ber ; mk_encoder = Asn_ber_der . W . ber_to_writer ; }
let der = { mk_decoder = Asn_ber_der . R . compile_der ; mk_encoder = Asn_ber_der . W . der_to_writer ; }
type ' a codec = Codec of ( Cstruct . t -> ( ' a * Cstruct . t ) ) * ( ' a -> Asn_writer . t )
let codec { mk_encoder ; mk_decoder } asn = let ( ) = Core . validate asn in Codec ( mk_decoder asn , mk_encoder asn )
let encode ( Codec ( _ , enc ) ) a = Asn_writer . to_cstruct ( enc a )
let encode_into ( Codec ( _ , enc ) ) a = Asn_writer . to_writer ( enc a )
let decode ( Codec ( dec , _ ) ) b = try Ok ( dec b ) with Core . Parse_error err -> Error err
let ( ) @? oa a = match oa with Some x -> x | None -> a
module Seq = struct type ' r f = { f : ' a . ' a -> ' a asn -> ' r -> ' r } let rec fold_with_value : type a . ' r f -> ' r -> a -> a sequence -> ' r = fun f r a -> function | Last ( Required ( _ , asn ) ) -> f . f a asn r | Last ( Optional ( _ , asn ) ) -> ( match a with None -> r | Some a ' -> f . f a ' asn r ) | Pai...
module R = struct module G = Generic type config = { strict : bool } type coding = | Primitive of int | Constructed of int | Constructed_indefinite module Header = struct open Cstruct let error cs fmt = parse_error ( " Header : at % a : " ^^ fmt ) pp_cs cs let ck_redundant cs cfg ( n : int ) limit = if cfg . strict && ...
module W = struct let ( ) <+> = Writer . ( ) <+> let e_big_tag tag = let cons x = function [ ] -> [ x ] | xs -> ( x lor 0x80 ) :: xs in let rec loop acc = function | 0 -> acc | n -> loop ( cons ( n land 0x7f ) acc ) ( n lsr 7 ) in loop [ ] tag let e_big_length length = let rec loop acc = function | 0 -> acc | n -> loop...
module Int = struct type t = int let compare ( a : t ) b = compare a b let equal ( a : t ) b = a = b end
let clone_cs cs = let open Cstruct in let ds = create_unsafe ( length cs ) in blit cs 0 ds 0 ( length cs ) ; cs
type cls = [ ` Universal | ` Application | ` Private ]
let fix f = Fix ( f , Asn_cache . variant ( ) )
let map ? random f g asn = Iso ( f , g , random , asn )
let to_tag id = function | Some ` Application -> Tag . Application id | Some ` Private -> Tag . Private id | Some ` Universal -> Tag . Universal id | None -> Tag . Context_specific id
let explicit ? cls id asn = Explicit ( to_tag id cls , asn )
let rec implicit : type a . ? cls : cls -> int -> a asn -> a asn = fun ? cls id -> function Fix ( f , _ ) as asn -> implicit ? cls id ( f asn ) | Iso ( f , g , r , asn ) -> Iso ( f , g , r , implicit ? cls id asn ) | Choice ( _ , _ ) as asn -> explicit ? cls id asn | asn -> Implicit ( to_tag id cls , asn )
let bool = Prim Bool
let string tag = implicit ~ cls ` : Universal tag character_string
let utf8_string = string 0x0c
let numeric_string = string 0x12
let ( utc_time , generalized_time ) = let open Asn_prim . Time in let time ~ frac tag ( f , g ) = map ~ random ( : random ~ frac ) f g @@ implicit ~ cls ` : Universal tag character_string in time ~ frac : false 0x17 ( utc_time_of_string , of_utc_time ) , time ~ frac : true 0x18 ( gen_time_of_string , of_gen_time )
let int = let f n = try Z . to_int n with Z . Overflow -> parse_error " INTEGER : int overflow : % a " Z . pp_print n in map f Z . of_int integer
let enumerated f g = map f g @@ implicit ~ cls ` : Universal 0x0a int
let bit_string = Prim . Bits . ( map to_array of_array ( Prim Bits ) ) let f = function | 0 , cs -> cs | clip , cs -> let n = Cstruct . length cs in let last = Cstruct . get_uint8 cs ( n - 1 ) in let cs = clone_cs cs and last = last land ( lnot ( 1 lsl clip - 1 ) ) in Cstruct . set_uint8 cs ( n - 1 ) last ; cs in map f...
let bit_string_flags ( type a ) ( xs : ( int * a ) list ) = let cmp = compare in let module M1 = Map . Make ( struct type t = a let compare = cmp end ) in let module M2 = Map . Make ( Int ) in let aix , ixa = List . fold_left ( fun ( m1 , m2 ) ( i , x ) -> M1 . add x i m1 , M2 . add i x m2 ) ( M1 . empty , M2 . empty )...
let single a = Last a
let product2 fn a b = fn @@ a @ single b
let product3 fn a b c = map ( fun ( a , ( b , c ) ) -> ( a , b , c ) ) ( fun ( a , b , c ) -> ( a , ( b , c ) ) ) ( fn @@ a @ b @ single c )
let product4 fn a b c d = map ( fun ( a , ( b , ( c , d ) ) ) -> ( a , b , c , d ) ) ( fun ( a , b , c , d ) -> ( a , ( b , ( c , d ) ) ) ) ( fn @@ a @ b @ c @ single d )
let product5 fn a b c d e = map ( fun ( a , ( b , ( c , ( d , e ) ) ) ) -> ( a , b , c , d , e ) ) ( fun ( a , b , c , d , e ) -> ( a , ( b , ( c , ( d , e ) ) ) ) ) ( fn @@ a @ b @ c @ d @ single e )
let product6 fn a b c d e f = map ( fun ( a , ( b , ( c , ( d , ( e , f ) ) ) ) ) -> ( a , b , c , d , e , f ) ) ( fun ( a , b , c , d , e , f ) -> ( a , ( b , ( c , ( d , ( e , f ) ) ) ) ) ) ( fn @@ a @ b @ c @ d @ e @ single f )
let sequence seq = Sequence seq
let sequence2 a b = product2 sequence a b
let sequence_of asn = Sequence_of asn
let set seq = Set seq
let set2 a b = product2 set a b
let set_of asn = Set_of asn
let choice a b = Choice ( a , b )
let choice2 a b = map ( function L a -> ` C1 a | R b -> ` C2 b ) ( function ` C1 a -> L a | ` C2 b -> R b ) ( choice a b )
let choice3 a b c = map ( function L ( L a ) -> ` C1 a | L ( R b ) -> ` C2 b | R c -> ` C3 c ) ( function ` C1 a -> L ( L a ) | ` C2 b -> L ( R b ) | ` C3 c -> R c ) ( choice ( choice a b ) c )
let choice4 a b c d = map ( function | L ( L a ) -> ` C1 a | L ( R b ) -> ` C2 b | R ( L c ) -> ` C3 c | R ( R d ) -> ` C4 d ) ( function | ` C1 a -> L ( L a ) | ` C2 b -> L ( R b ) | ` C3 c -> R ( L c ) | ` C4 d -> R ( R d ) ) ( choice ( choice a b ) ( choice c d ) )
let choice5 a b c d e = map ( function | L ( L ( L a ) ) -> ` C1 a | L ( L ( R b ) ) -> ` C2 b | L ( R c ) -> ` C3 c | R ( L d ) -> ` C4 d | R ( R e ) -> ` C5 e ) ( function | ` C1 a -> L ( L ( L a ) ) | ` C2 b -> L ( L ( R b ) ) | ` C3 c -> L ( R c ) | ` C4 d -> R ( L d ) | ` C5 e -> R ( R e ) ) ( choice ( choice ( ch...
let choice6 a b c d e f = map ( function | L ( L ( L a ) ) -> ` C1 a | L ( L ( R b ) ) -> ` C2 b | L ( R c ) -> ` C3 c | R ( L ( L d ) ) -> ` C4 d | R ( L ( R e ) ) -> ` C5 e | R ( R f ) -> ` C6 f ) ( function | ` C1 a -> L ( L ( L a ) ) | ` C2 b -> L ( L ( R b ) ) | ` C3 c -> L ( R c ) | ` C4 d -> R ( L ( L d ) ) | ` ...
let id x = x
let const x _ = x
let ( . ) & f g x = f ( g x )
let opt def = function Some x -> x | _ -> def
type ' a endo = ' a -> ' a
type ( ' a , ' b ) sum = L of ' a | R of ' b
let ( strf , pf ) = Format . ( asprintf , fprintf )
let kstrf k fmt = Format . ( kfprintf ( fun _ -> flush_str_formatter ( ) |> k ) str_formatter fmt )