text
stringlengths
0
601k
let boxed_integer_mark name = function | Pnativeint -> Printf . sprintf " Nativeint . % s " name | Pint32 -> Printf . sprintf " Int32 . % s " name | Pint64 -> Printf . sprintf " Int64 . % s " name
let print_boxed_integer name ppf bi = fprintf ppf " % s " ( boxed_integer_mark name bi ) ; ;
let print_bigarray name unsafe kind ppf layout = fprintf ppf " Bigarray . % s [ % s , % s ] " ( if unsafe then " unsafe_ " ^ name else name ) ( match kind with | Pbigarray_unknown -> " generic " | Pbigarray_float32 -> " float32 " | Pbigarray_float64 -> " float64 " | Pbigarray_sint8 -> " sint8 " | Pbigarray_uint8 -> " u...
let record_rep ppf r = match r with | Record_regular -> fprintf ppf " regular " | Record_inlined i -> fprintf ppf " inlined ( % i ) " i | Record_unboxed false -> fprintf ppf " unboxed " | Record_unboxed true -> fprintf ppf " inlined ( unboxed ) " | Record_float -> fprintf ppf " float " | Record_extension path -> fprint...
let block_shape ppf shape = match shape with | None | Some [ ] -> ( ) | Some l when List . for_all ( ( ) = Pgenval ) l -> ( ) | Some [ elt ] -> Format . fprintf ppf " ( % s ) " ( field_kind elt ) | Some ( h :: t ) -> Format . fprintf ppf " ( % s " ( field_kind h ) ; List . iter ( fun elt -> Format . fprintf ppf " , % s...
let integer_comparison ppf = function | Ceq -> fprintf ppf " " == | Cne -> fprintf ppf " " != | Clt -> fprintf ppf " " < | Cle -> fprintf ppf " " <= | Cgt -> fprintf ppf " " > | Cge -> fprintf ppf " " >=
let float_comparison ppf = function | CFeq -> fprintf ppf " . " == | CFneq -> fprintf ppf " . " != | CFlt -> fprintf ppf " . " < | CFnlt -> fprintf ppf " . " !< | CFle -> fprintf ppf " . " <= | CFnle -> fprintf ppf " . " !<= | CFgt -> fprintf ppf " . " > | CFngt -> fprintf ppf " . " !> | CFge -> fprintf ppf " . " >= | ...
let primitive ppf = function | Pidentity -> fprintf ppf " id " | Pbytes_to_string -> fprintf ppf " bytes_to_string " | Pbytes_of_string -> fprintf ppf " bytes_of_string " | Pignore -> fprintf ppf " ignore " | Prevapply -> fprintf ppf " revapply " | Pdirapply -> fprintf ppf " dirapply " | Pgetglobal id -> fprintf ppf " ...
let name_of_primitive = function | Pidentity -> " Pidentity " | Pbytes_of_string -> " Pbytes_of_string " | Pbytes_to_string -> " Pbytes_to_string " | Pignore -> " Pignore " | Prevapply -> " Prevapply " | Pdirapply -> " Pdirapply " | Pgetglobal _ -> " Pgetglobal " | Psetglobal _ -> " Psetglobal " | Pmakeblock _ -> " Pma...
let function_attribute ppf { inline ; specialise ; local ; is_a_functor ; stub } = if is_a_functor then fprintf ppf " is_a_functor @ " ; if stub then fprintf ppf " stub @ " ; begin match inline with | Default_inline -> ( ) | Always_inline -> fprintf ppf " always_inline @ " | Never_inline -> fprintf ppf " never_inline @...
let apply_tailcall_attribute ppf tailcall = if tailcall then fprintf ppf " @@ tailcall "
let apply_inlined_attribute ppf = function | Default_inline -> ( ) | Always_inline -> fprintf ppf " always_inline " | Never_inline -> fprintf ppf " never_inline " | Unroll i -> fprintf ppf " never_inline ( % i ) " i
let apply_specialised_attribute ppf = function | Default_specialise -> ( ) | Always_specialise -> fprintf ppf " always_specialise " | Never_specialise -> fprintf ppf " never_specialise "
let rec lam ppf = function | Lvar id -> Ident . print ppf id | Lconst cst -> struct_const ppf cst | Lapply ap -> let lams ppf largs = List . iter ( fun l -> fprintf ppf " @ % a " lam l ) largs in fprintf ppf " [ @< 2 ( > apply @ % a % a % a % a % a ) ] " @ lam ap . ap_func lams ap . ap_args apply_tailcall_attribute ap ...
let program ppf { code } = lambda ppf code
let label ppf l = Format . fprintf ppf " L % i " l
let instr ppf i = begin match i . desc with | Lend -> ( ) | Lprologue -> fprintf ppf " prologue " | Lop op -> begin match op with | Ialloc _ | Icall_ind _ | Icall_imm _ | Iextcall _ -> fprintf ppf " [ @< 1 { >% a } ] , " @@ regsetaddr i . live | _ -> ( ) end ; operation op i . arg ppf i . res | Lreloadretaddr -> fprint...
let rec all_instr ppf i = match i . desc with | Lend -> ( ) | _ -> fprintf ppf " % a , @% a " instr i all_instr i . next
let fundecl ppf f = let dbg = if Debuginfo . is_none f . fun_dbg then " " else " " ^ Debuginfo . to_string f . fun_dbg in fprintf ppf " [ @< v 2 >% s :% s , @% a ] " @ f . fun_name dbg all_instr f . fun_body
let reg ppf r = if not ( Reg . anonymous r ) then fprintf ppf " % s " ( Reg . name r ) else fprintf ppf " % s " ( match r . typ with Val -> " V " | Addr -> " A " | Int -> " I " | Float -> " F " ) ; fprintf ppf " /% i " r . stamp ; begin match r . loc with | Unknown -> ( ) | Reg r -> fprintf ppf " [ % s ] " ( Proc . reg...
let regs ppf v = match Array . length v with | 0 -> ( ) | 1 -> reg ppf v . ( 0 ) | n -> reg ppf v . ( 0 ) ; for i = 1 to n - 1 do fprintf ppf " % a " reg v . ( i ) done
let regset ppf s = let first = ref true in Reg . Set . iter ( fun r -> if ! first then begin first := false ; fprintf ppf " % a " reg r end else fprintf ppf " @ % a " reg r ) s
let regsetaddr ppf s = let first = ref true in Reg . Set . iter ( fun r -> if ! first then begin first := false ; fprintf ppf " % a " reg r end else fprintf ppf " @ % a " reg r ; match r . typ with | Val -> fprintf ppf " " * | Addr -> fprintf ppf " " ! | _ -> ( ) ) s
let intcomp = function | Isigned c -> Printf . sprintf " % ss " ( Printcmm . integer_comparison c ) | Iunsigned c -> Printf . sprintf " % su " ( Printcmm . integer_comparison c )
let floatcomp c = Printf . sprintf " % sf " ( Printcmm . float_comparison c )
let intop = function | Iadd -> " + " | Isub -> " - " | Imul -> " * " | Imulh -> " * h " | Idiv -> " div " | Imod -> " mod " | Iand -> " & " | Ior -> " | " | Ixor -> " ^ " | Ilsl -> " << " | Ilsr -> " >> u " | Iasr -> " >> s " | Icomp cmp -> intcomp cmp | Icheckbound { label_after_error ; spacetime_index ; } -> if not C...
let test tst ppf arg = match tst with | Itruetest -> reg ppf arg . ( 0 ) | Ifalsetest -> fprintf ppf " not % a " reg arg . ( 0 ) | Iinttest cmp -> fprintf ppf " % a % s % a " reg arg . ( 0 ) ( intcomp cmp ) reg arg . ( 1 ) | Iinttest_imm ( cmp , n ) -> fprintf ppf " % a % s % i " reg arg . ( 0 ) ( intcomp cmp ) n | Ifl...
let operation op arg ppf res = if Array . length res > 0 then fprintf ppf " % a := " regs res ; match op with | Imove -> regs ppf arg | Ispill -> fprintf ppf " % a ( spill ) " regs arg | Ireload -> fprintf ppf " % a ( reload ) " regs arg | Iconst_int n -> fprintf ppf " % s " ( Nativeint . to_string n ) | Iconst_float f...
let rec instr ppf i = if ! Clflags . dump_live then begin fprintf ppf " [ @< 1 { >% a " regsetaddr i . live ; if Array . length i . arg > 0 then fprintf ppf " @ +@ % a " regs i . arg ; fprintf ppf " } ] , " ; @@ if ! Clflags . dump_avail then begin let module RAS = Reg_availability_set in fprintf ppf " [ @< 1 > AB { =%...
let fundecl ppf f = let dbg = if Debuginfo . is_none f . fun_dbg then " " else " " ^ Debuginfo . to_string f . fun_dbg in fprintf ppf " [ @< v 2 >% s ( % a ) % s , @% a ] " @ f . fun_name regs f . fun_args dbg instr f . fun_body
let phase msg ppf f = fprintf ppf " *** % s . @% a . " @ msg fundecl f
let interference ppf r = let interf ppf = List . iter ( fun r -> fprintf ppf " @ % a " reg r ) r . interf in fprintf ppf " [ @< 2 >% a :% t ] . " @@ reg r interf
let interferences ppf ( ) = fprintf ppf " *** Interferences . " ; @ List . iter ( interference ppf ) ( Reg . all_registers ( ) )
let interval ppf i = let interv ppf = List . iter ( fun r -> fprintf ppf " @ [ % d ; % d ] " r . rbegin r . rend ) i . ranges in fprintf ppf " [ @< 2 >% a :% t ] . " @@ reg i . reg interv
let intervals ppf ( ) = fprintf ppf " *** Intervals . " ; @ List . iter ( interval ppf ) ( Interval . all_fixed_intervals ( ) ) ; List . iter ( interval ppf ) ( Interval . all_intervals ( ) )
let preference ppf r = let prefs ppf = List . iter ( fun ( r , w ) -> fprintf ppf " @ % a weight % i " reg r w ) r . prefer in fprintf ppf " [ @< 2 >% a : % t ] . " @@ reg r prefs
let preferences ppf ( ) = fprintf ppf " *** Preferences . " ; @ List . iter ( preference ppf ) ( Reg . all_registers ( ) )
let value_kind ppf = function | Boxed_value -> fprintf ppf " value " | Tagged_int -> fprintf ppf " tagged_int " | Normalized_int -> fprintf ppf " normalized_int " | Unboxed_int -> fprintf ppf " int " | Unboxed_int32 -> fprintf ppf " int32 " | Unboxed_int64 -> fprintf ppf " int64 " | Unboxed_nativeint -> fprintf ppf " n...
let value_kinds ppf l = List . iter ( fun vk -> fprintf ppf " @ % a " value_kind vk ) vk l
let rec expr ppf = function | Mconst cst -> Printjlambda . const ppf cst | Moffset ( e , n ) n -> fprintf ppf [ " @< 2 ( > offset @ % a @ % d ) d ] " @ expr e n | Mdynamicoffset ( e1 , e2 ) e2 -> fprintf ppf [ " @< 2 ( > dynamicoffset @ % a @ % a ) a ] " @ expr e1 expr e2 | Mcreateglobal ( s , cn ) cn -> fprintf ppf [ ...
let macroinstr ppf fundecls = let idents ppf l = List . iter ( fun id -> fprintf ppf " @ % a " Ident . print id ) id l in let reprs ppf l = List . iter ( fun r -> fprintf ppf " @ % a " Printlambda . repr r ) r l in let fundecl ppf { fun_name ; fun_args ; fun_params ; fun_return ; fun_body } = fprintf ppf [ ( " @ functi...
let constant out = function | ConstBool true -> fprintf out " true " | ConstBool false -> fprintf out " false " | ConstInt i -> fprintf out " % ld " i
let binop out = function | OpAdd -> fprintf out " " + | OpSub -> fprintf out " " - | OpMul -> fprintf out " " * | OpLt -> fprintf out " " < | OpAnd -> fprintf out " " &&
let rec expr0 out = function | EConst c -> fprintf out " % a " constant c | EGetVar x -> fprintf out " % s " x | EThis -> fprintf out " this " | EMethodCall ( o , c , es ) -> fprintf out " % a . % s ( % a ) " expr0 o c ( sep_list comma expr ) es | EArrayGet ( ea , ei ) -> fprintf out " % a [ % a ] " expr0 ea expr ei | ...
let rec instr out = function | ISetVar ( x , e ) -> fprintf out " % s = % a ; " x expr e | IArraySet ( id , ei , ev ) -> fprintf out " % s [ % a ] = % a ; " id expr ei expr ev | IIf ( c , i1 , i2 ) -> fprintf out " if ( % a ) % a % telse % a " expr c instr i1 nl instr i2 | IWhile ( c , i ) -> fprintf out " while ( % a ...
let typ out = function | TypInt -> fprintf out " int " | TypBool -> fprintf out " boolean " | TypIntArray -> fprintf out " int [ ] " | Typ id -> fprintf out " % s " id
let binding out ( x , t ) = fprintf out " % a % s " typ t x
let metho out ( name , m ) = fprintf out " public % a % s ( % a ) { % a % a % t % t } " typ m . result name ( sep_list comma binding ) m . formals ( term_list semicolon ( indent indentation binding ) ) m . locals ( list ( indent indentation instr ) ) m . body ( indent_t indentation ( fun out -> fprintf out " return % a...
let clas out ( name , c ) = ( match c . extends with | None -> fprintf out " class % s { % a % a % t } " name | Some class_name -> fprintf out " class % s extends % s { % a % a % t } " name class_name ) ( term_list semicolon ( indent indentation binding ) ) c . attributes ( list ( indent indentation metho ) ) c . metho...
let print_program out ( p : MJ . program ) : unit = fprintf out " class % s { % t % t } % t % a " p . name ( indent_t indentation ( fun out -> fprintf out " public static void main ( String [ ] % s ) { % a % t } " p . main_args ( indent indentation instr ) p . main nl ) ) nl nl ( sep_list nl clas ) p . defs
let rec pp_pattern ppf pat = pp_pattern_desc ppf pat . Typedtree . pat_desc | Typedtree . Tpat_any -> fprintf ppf " _ " | Typedtree . Tpat_var id -> fprintf ppf " % s " ( Ident . name id ) | Typedtree . Tpat_alias ( pat , id ) -> fprintf ppf " % s as % a " ( Ident . name id ) pp_pattern pat | Typedtree . Tpat_constant ...
let pp_label_description ppf lbl_desc = fprintf ppf " % a :@ % a " Printbasic . pp_mutable_flag lbl_desc . Typedtree . fld_mut Printtypes . pp_ml_type_scheme lbl_desc . Typedtree . fld_scheme ; ;
let rec pp_signature ppf signature = let iter_pp_signature_item = Printbasic . iter_pp " " pp_signature_item in fprintf ppf " % a " iter_pp_signature_item signature | Typedtree . Tsig_value ( ident , scheme ) -> fprintf ppf " val [ @ % s :@ % a ] " @ ( Ident . name ident ) Printtypes . pp_ml_type_scheme scheme ; | Type...
let rec pp_structure_excs ppf structure = let iter_pp_structure_excs = Printbasic . iter_pp " " pp_struct_item_excs in fprintf ppf " % a " iter_pp_structure_excs structure | Typedtree . Tstr_eval e -> fprintf ppf " - [ :@@ % a ] " @ Printtypes . pp_phi_type e . Typedtree . exp_exn | Typedtree . Tstr_value ( _ , binding...
let pp_toplevel_toplevel ppf ( typed_phrase , phrase_type ) = match typed_phrase with | Typedtree . Ptop_def [ Typedtree . Tstr_eval e ] -> fprintf ppf " - [ :@ % a . ] " @@ Printtypes . pp_ml_type e . Typedtree . exp_type ; fprintf ppf " [ :@\ % a ] " @ Printtypes . pp_phi_type e . Typedtree . exp_exn | Typedtree . Pt...
let rec pp_core_type ppf core_ty = pp_core_type_desc ppf core_ty . Parsetree . ptyp_desc pp_core_type core_tys pp_core_type core_tys ( fun ppf s -> fprintf ppf " % s " s ) strlst | Parsetree . Ptyp_any -> fprintf ppf " any " | Parsetree . Ptyp_var var_name -> fprintf ppf " ' % s " var_name | Parsetree . Ptyp_arrow ( co...
let rec pp_pattern ppf pat = pp_pattern_desc ppf pat . Parsetree . ppat_desc | Parsetree . Ppat_any -> fprintf ppf " _ " | Parsetree . Ppat_var var_name -> fprintf ppf " % s " var_name | Parsetree . Ppat_alias ( pat , alias_name ) -> fprintf ppf " % a as % s " pp_pattern pat alias_name | Parsetree . Ppat_constant const...
let rec pp_expression ppf expr = pp_expression_desc ppf expr . Parsetree . pexp_desc Printbasic . iter_pp " and " ( fun ppf ( pat , expr ) -> bindings Printbasic . iter_pp " | " ( fun ppf ( pat , expr ) -> bindings | Parsetree . Pexp_ident lident -> Printbasic . pp_longident ppf lident | Parsetree . Pexp_constant const...
let pp_directive_argument ppf = function | Parsetree . Pdir_none -> ( ) | Parsetree . Pdir_string str -> fprintf ppf " % s " str | Parsetree . Pdir_int i -> fprintf ppf " % d " i | Parsetree . Pdir_ident longident -> fprintf ppf " % a " Printbasic . pp_longident longident ; ;
let pp_toplevel_phrase ppf = function | Parsetree . Ptop_def structure -> pp_structure ppf structure | Parsetree . Ptop_dir ( dir_name , dir_arg ) -> fprintf ppf " #% s % a " dir_name pp_directive_argument dir_arg ; ;
let pretty_const c = match c with
let rec pretty_val ppf v = match v . pat_extra with ( cstr , _loc , _attrs ) :: rem -> begin match cstr with | Tpat_unpack -> fprintf ppf " [ ( @ module % a ) ] " @ pretty_val { v with pat_extra = rem } | Tpat_constraint _ -> fprintf ppf " [ ( @% a : _ ) ] " @ pretty_val { v with pat_extra = rem } | Tpat_type _ -> fpri...
let top_pretty ppf v = fprintf ppf " [ @% a ] " @@? pretty_val v
let pretty_pat p = top_pretty Format . str_formatter p ; prerr_string ( Format . flush_str_formatter ( ) )
type matrix = pattern list list
let pretty_line fmt = List . iter ( fun p -> Format . fprintf fmt " " ; < top_pretty fmt p ; Format . fprintf fmt " " ; > )
let pretty_matrix fmt ( pss : matrix ) = Format . fprintf fmt " begin matrix \ n " ; List . iter ( fun ps -> pretty_line fmt ps ; Format . fprintf fmt " \ n " ) pss ; Format . fprintf fmt " end matrix \ n " %!
let identifierBuff buffer id = printList buffer append " . " id
let commentedId buffer id = match id with | Some ids -> append buffer " /* " ; identifierBuff buffer ids ; append buffer " " */ ; newline buffer | _ -> ( )
let rec typeExpressionBuff buffer ( tp : Typ . t ) = match ! tp with | Typ . TId ( id , _ ) -> identifierBuff buffer id | Typ . TInt ( n , _ ) -> append buffer ( string_of_int n ) | Typ . TComposed ( id , args , _ ) -> identifierBuff buffer id ; append buffer " ( " ; typeExpressionListBuff buffer args ; append buffer "...
let instanceBuff buffer inst = match inst with | NoInst -> ( ) | Named id -> identifierBuff buffer id ; append buffer " " : | This -> append buffer " this " :
let rec tagBuff buffer ( tag : tag ) = match tag with | TInt ( n , _ ) -> append buffer n | TId ( s , _ ) -> identifierBuff buffer s | TReal ( n , _ ) -> append buffer n | TBool ( b , _ ) -> append buffer b | TString ( s , _ ) -> append buffer s | TFun ( id , args , _ ) -> identifierBuff buffer id ; append buffer " ( "...
let tagsBuff buffer tags = match tags with | [ ] -> ( ) | _ -> append buffer " [ " @ ; printList buffer tagBuff " , " tags ; append buffer " ] "
let rec lhsExpressionBuff buffer ( lhs : lhs_exp ) = match lhs with | LWild { typ = Some tp } -> append buffer " ( _ " : ; typeExpressionBuff buffer tp ; append buffer " ) " | LWild _ -> append buffer " _ " | LId ( id , None , _ ) -> identifierBuff buffer id | LId ( id , Some tp , _ ) -> append buffer " ( " ; identifie...
let identifierStr id = let print_buffer = makePrintBuffer ( ) in identifierBuff print_buffer id ; contents print_buffer
let stmtListStr e = let print_buffer = makePrintBuffer ( ) in stmtListBuff print_buffer e ; contents print_buffer
let stmtStr e = let print_buffer = makePrintBuffer ( ) in stmtBuff print_buffer e ; contents print_buffer
let lhsExpressionStr e = let print_buffer = makePrintBuffer ( ) in lhsExpressionBuff print_buffer e ; contents print_buffer
let expressionStr e = let print_buffer = makePrintBuffer ( ) in expressionBuff print_buffer e ; contents print_buffer
let typeStr ( e : Typ . t ) = let print_buffer = makePrintBuffer ( ) in typeExpressionBuff print_buffer e ; contents print_buffer
let rec pp_core_type prio ppf core_ty = pp_core_type_desc prio ppf core_ty . Scopedtree . ptyp_desc ( pp_core_type 0 ) core_tys ( pp_core_type 0 ) core_tys ( fun ppf s -> fprintf ppf " % s " s ) strlst | Scopedtree . Ptyp_any -> assert false | Scopedtree . Ptyp_var var_name -> fprintf ppf " ' % s " var_name | Scopedtre...
let rec pp_pattern ppf pat = pp_pattern_desc ppf pat . Scopedtree . ppat_desc | Scopedtree . Ppat_any -> fprintf ppf " _ " | Scopedtree . Ppat_var var_ident -> fprintf ppf " % s " ( Ident . name var_ident ) | Scopedtree . Ppat_alias ( pat , alias_name ) -> fprintf ppf " % a as % s " pp_pattern pat ( Ident . name alias_...
let rec pp_expression ppf expr = pp_expression_desc ppf expr . Scopedtree . pexp_desc Printbasic . iter_pp " and " ( fun ppf ( pat , expr ) -> bindings Printbasic . iter_pp " " | ( fun ppf ( pat , expr ) -> bindings | Scopedtree . Pexp_ident path -> Path . pp_path ppf path | Scopedtree . Pexp_constant constant -> Print...
let pp_directive_argument ppf = function | Scopedtree . Pdir_none -> ( ) | Scopedtree . Pdir_string str -> fprintf ppf " % s " str | Scopedtree . Pdir_int i -> fprintf ppf " % d " i | Scopedtree . Pdir_ident path -> fprintf ppf " % a " Path . pp_path path ; ;
let pp_toplevel_phrase ppf = function | Scopedtree . Ptop_def structure -> pp_structure ppf structure | Scopedtree . Ptop_dir ( dir_name , dir_arg ) -> fprintf ppf " #% s % a " dir_name pp_directive_argument dir_arg ; ;
let rec longident ppf = function | Lident s -> pp_print_string ppf s | Ldot ( p , s ) -> fprintf ppf " % a . % s " longident p s | Lapply ( p1 , p2 ) -> fprintf ppf " % a ( % a ) " longident p1 longident p2
let ( ) = Env . print_longident := longident
module Out_name = struct let create x = { printed_name = x } let print x = x . printed_name let set out_name x = out_name . printed_name <- x end
let printing_env = ref Env . empty
let human_unique n id = Printf . sprintf " % s /% d " ( Ident . name id ) n
type namespace = | Type | Module | Module_type | Class | Class_type | Other
module Namespace = struct let id = function | Type -> 0 | Module -> 1 | Module_type -> 2 | Class -> 3 | Class_type -> 4 | Other -> 5 let size = 1 + id Other let show = function | Type -> " type " | Module -> " module " | Module_type -> " module type " | Class -> " class " | Class_type -> " class type " | Other -> " " l...
module Conflicts = struct module M = String . Map type explanation = { kind : namespace ; name : string ; root_name : string ; location : Location . t } let explanations = ref M . empty let collect_explanation namespace n id = let name = human_unique n id in let root_name = Ident . name id in if not ( M . mem name ! ex...
let enabled = ref true
let enable b = enabled := b
type mapping = | Need_unique_name of int Ident . Map . t | Uniquely_associated_to of Ident . t * out_name | Associated_to_pervasives of out_name
let add_hid_id id map = let new_id = 1 + Ident . Map . fold ( fun _ -> max ) map hid_start in new_id , Ident . Map . add id new_id map
let find_hid id map = try Ident . Map . find id map , map with Not_found -> add_hid_id id map
let pervasives name = " Stdlib . " ^ name
let map = Array . make Namespace . size M . empty