text stringlengths 0 601k |
|---|
let test2 ( ) = if not ( testcopy [ | 1 ; 2 ; 3 ; 4 ; 5 ] ) | then print_string " Test2 : failed on int array \ n " ; if not ( testcopy [ | 1 . 2 ; 2 . 3 ; 3 . 4 ; 4 . 5 ] ) | then print_string " Test2 : failed on float array \ n " ; if not ( testcopy [ " | un " ; " deux " ; " trois " ] ) | then print_string " Test2 : ... |
module AbstractFloat = ( struct type t = float let to_float x = x let from_float x = x end : sig type t val to_float : t -> float val from_float : float -> t end ) |
let test3 ( ) = let t1 = AbstractFloat . from_float 1 . 0 and t2 = AbstractFloat . from_float 2 . 0 and t3 = AbstractFloat . from_float 3 . 0 in let v = [ | t1 ; t2 ; t3 ] | in let w = Array . make 2 t1 in let u = Array . copy v in if not ( AbstractFloat . to_float v . ( 0 ) = 1 . 0 && AbstractFloat . to_float v . ( 1 ... |
let test4 ( ) = let a = bigarray 0 in let b = Array . sub a 50 10 in if b <> [ | 50 ; 51 ; 52 ; 53 ; 54 ; 55 ; 56 ; 57 ; 58 ; 59 ] | then print_string " Test4 : failed \ n " |
let test5 ( ) = if Array . append [ | 1 ; 2 ; 3 ] | [ | 4 ; 5 ] | <> [ | 1 ; 2 ; 3 ; 4 ; 5 ] | then print_string " Test5 : failed on int arrays \ n " ; if Array . append [ | 1 . 0 ; 2 . 0 ; 3 . 0 ] | [ | 4 . 0 ; 5 . 0 ] | <> [ | 1 . 0 ; 2 . 0 ; 3 . 0 ; 4 . 0 ; 5 . 0 ] | then print_string " Test5 : failed on float array... |
let test6 ( ) = let a = [ | 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ] | in let b = Array . concat [ a ; a ; a ; a ; a ; a ; a ; a ; a ; a ] in if not ( Array . length b = 100 && b . ( 6 ) = 6 && b . ( 42 ) = 2 && b . ( 99 ) = 9 ) then print_string " Test6 : failed \ n " |
let test7 ( ) = let a = Array . make 10 " a " in let b = [ | " b1 " ; " b2 " ; " b3 " ] | in Array . blit b 0 a 5 3 ; if a <> [ " | a " ; " a " ; " a " ; " a " ; " a " ; " b1 " ; " b2 " ; " b3 " ; " a " ; " a " ] | || b <> [ " | b1 " ; " b2 " ; " b3 " ] | then print_string " Test7 : failed ( 1 ) \ n " ; Array . blit a ... |
let test8 ( ) = ( try ignore ( Array . sub [ ] || 0 1 ) ; print_string " Test 8 . 1 : failed \ n " with Invalid_argument _ -> ( ) ) ; ( try ignore ( Array . sub [ | 3 ; 4 ] | 1 ( - 1 ) ) ; print_string " Test 8 . 2 : failed \ n " with Invalid_argument _ -> ( ) ) ; ( try ignore ( Array . sub [ | 3 ; 4 ] | max_int 1 ) ; ... |
let _ = test1 ( ) ; test2 ( ) ; test3 ( ) ; test4 ( ) ; test5 ( ) ; test6 ( ) ; test7 ( ) ; test8 ( ) ; exit 0 |
type error = | Assembler_error of string | Mismatched_for_pack of string option | Asm_generation of string * Emitaux . error |
let cmm_invariants ppf fd_cmm = let print_fundecl = if ! Clflags . dump_cmm then Printcmm . fundecl else fun ppf fdecl -> Format . fprintf ppf " % s " fdecl . fun_name in if ! Clflags . cmm_invariants && Cmm_invariants . run ppf fd_cmm then Misc . fatal_errorf " Cmm invariants failed on following fundecl . :@% a . " @ ... |
let liveness phrase = Liveness . fundecl phrase ; phrase |
let dump_if ppf flag message phrase = if ! flag then Printmach . phase message ppf phrase |
let pass_dump_if ppf flag message phrase = dump_if ppf flag message phrase ; phrase |
let pass_dump_linear_if ppf flag message phrase = if ! flag then fprintf ppf " *** % s . @% a . " @ message Printlinear . fundecl phrase ; phrase |
let start_from_emit = ref true |
let should_save_before_emit ( ) = should_save_ir_after Compiler_pass . Scheduling && ( not ! start_from_emit ) |
let linear_unit_info = { Linear_format . unit_name = " " ; items = [ ] ; for_pack = None ; } |
let reset ( ) = start_from_emit := false ; if should_save_before_emit ( ) then begin linear_unit_info . unit_name <- Compilenv . current_unit_name ( ) ; linear_unit_info . items <- [ ] ; linear_unit_info . for_pack <- ! Clflags . for_package ; end |
let save_data dl = if should_save_before_emit ( ) then begin linear_unit_info . items <- Linear_format . ( Data dl ) :: linear_unit_info . items end ; dl |
let save_linear f = if should_save_before_emit ( ) then begin linear_unit_info . items <- Linear_format . ( Func f ) :: linear_unit_info . items end ; f |
let write_linear prefix = if should_save_before_emit ( ) then begin let filename = Compiler_pass . ( to_output_filename Scheduling ~ prefix ) in linear_unit_info . items <- List . rev linear_unit_info . items ; Linear_format . save filename linear_unit_info end |
let should_emit ( ) = not ( should_stop_after Compiler_pass . Scheduling ) |
let if_emit_do f x = if should_emit ( ) then f x else ( ) |
let emit_begin_assembly = if_emit_do Emit . begin_assembly |
let emit_end_assembly = if_emit_do Emit . end_assembly |
let emit_data = if_emit_do Emit . data |
let emit_fundecl fd = if should_emit ( ) then begin try Profile . record ~ accumulate : true " emit " Emit . fundecl fd with Emitaux . Error e -> raise ( Error ( Asm_generation ( fd . Linear . fun_name , e ) ) ) end |
let rec regalloc ~ ppf_dump round fd = if round > 50 then fatal_error ( fd . Mach . fun_name ^ " : function too complex , cannot complete register allocation " ) ; dump_if ppf_dump dump_live " Liveness analysis " fd ; let num_stack_slots = if ! use_linscan then begin Interval . build_intervals fd ; if ! dump_interval t... |
let ( ) ++ x f = f x |
let compile_fundecl ~ ppf_dump fd_cmm = Proc . init ( ) ; Reg . reset ( ) ; fd_cmm ++ Profile . record ~ accumulate : true " cmm_invariants " ( cmm_invariants ppf_dump ) ++ Profile . record ~ accumulate : true " selection " Selection . fundecl ++ pass_dump_if ppf_dump dump_selection " After instruction selection " ++ P... |
let compile_data dl = dl ++ save_data ++ emit_data |
let compile_phrase ~ ppf_dump p = if ! dump_cmm then fprintf ppf_dump " % a . " @ Printcmm . phrase p ; match p with | Cfunction fd -> compile_fundecl ~ ppf_dump fd | Cdata dl -> compile_data dl |
let compile_genfuns ~ ppf_dump f = List . iter ( function | ( Cfunction { fun_name = name } ) as ph when f name -> compile_phrase ~ ppf_dump ph | _ -> ( ) ) ( Cmm_helpers . generic_functions true [ Compilenv . current_unit_infos ( ) ] ) |
let compile_unit ~ output_prefix ~ asm_filename ~ keep_asm ~ obj_filename gen = reset ( ) ; let create_asm = should_emit ( ) && ( keep_asm || not ! Emitaux . binary_backend_available ) in Emitaux . create_asm_file := create_asm ; Misc . try_finally ~ exceptionally ( : fun ( ) -> remove_file obj_filename ) ( fun ( ) -> ... |
let end_gen_implementation ? toplevel ~ ppf_dump ( clambda : Clambda . with_constants ) = emit_begin_assembly ( ) ; clambda ++ Profile . record " cmm " Cmmgen . compunit ++ Profile . record " compile_phrases " ( List . iter ( compile_phrase ~ ppf_dump ) ) ++ ( fun ( ) -> ( ) ) ; ( match toplevel with None -> ( ) | Some... |
type middle_end = backend ( : module Backend_intf . S ) -> filename : string -> prefixname : string -> ppf_dump : Format . formatter -> Lambda . program -> Clambda . with_constants |
let asm_filename output_prefix = if ! keep_asm_file || ! Emitaux . binary_backend_available then output_prefix ^ ext_asm else Filename . temp_file " camlasm " ext_asm |
let compile_implementation ? toplevel ~ backend ~ filename ~ prefixname ~ middle_end ~ ppf_dump ( program : Lambda . program ) = compile_unit ~ output_prefix : prefixname ~ asm_filename ( : asm_filename prefixname ) ~ keep_asm :! keep_asm_file ~ obj_filename ( : prefixname ^ ext_obj ) ( fun ( ) -> Ident . Set . iter Co... |
let linear_gen_implementation filename = let open Linear_format in let linear_unit_info , _ = restore filename in ( match ! Clflags . for_package , linear_unit_info . for_pack with | None , None -> ( ) | Some expected , Some saved when String . equal expected saved -> ( ) | _ , saved -> raise ( Error ( Mismatched_for_p... |
let compile_implementation_linear output_prefix ~ progname = compile_unit ~ output_prefix ~ asm_filename ( : asm_filename output_prefix ) ~ keep_asm :! keep_asm_file ~ obj_filename ( : output_prefix ^ ext_obj ) ( fun ( ) -> linear_gen_implementation progname ) |
let report_error ppf = function | Assembler_error file -> fprintf ppf " Assembler error , input left in file % a " Location . print_filename file | Mismatched_for_pack saved -> let msg = function | None -> " without - for - pack " | Some s -> " with - for - pack " ^ s in fprintf ppf " This input file cannot be compiled... |
let ( ) = Location . register_error_of_exn ( function | Error err -> Some ( Location . error_of_printer_file report_error err ) | _ -> None ) |
type error = File_not_found of string | Archiver_error of string |
let default_ui_export_info = if Config . flambda then Cmx_format . Flambda Export_info . empty else Cmx_format . Clambda Clambda . Value_unknown |
let read_info name = let filename = try Load_path . find name with Not_found -> raise ( Error ( File_not_found name ) ) in let ( info , crc ) = Compilenv . read_unit_info filename in info . ui_force_link <- info . ui_force_link || ! Clflags . link_everything ; info . ui_export_info <- default_ui_export_info ; ( Filenam... |
let create_archive file_list lib_name = let archive_name = Filename . remove_extension lib_name ^ ext_lib in let outchan = open_out_bin lib_name in Misc . try_finally ~ always ( : fun ( ) -> close_out outchan ) ~ exceptionally ( : fun ( ) -> remove_file lib_name ; remove_file archive_name ) ( fun ( ) -> output_string o... |
let report_error ppf = function | File_not_found name -> fprintf ppf " Cannot find file % s " name | Archiver_error name -> fprintf ppf " Error while creating the library % s " name |
let ( ) = Location . register_error_of_exn ( function | Error err -> Some ( Location . error_of_printer_file report_error err ) | _ -> None ) |
type error = | File_not_found of filepath | Not_an_object_file of filepath | Missing_implementations of ( modname * string list ) list | Inconsistent_interface of modname * filepath * filepath | Inconsistent_implementation of modname * filepath * filepath | Assembler_error of filepath | Linking_error of int | Multiple_... |
module Cmi_consistbl = Consistbl . Make ( Misc . Stdlib . String ) |
let crc_interfaces = Cmi_consistbl . create ( ) |
let interfaces = ref ( [ ] : string list ) |
module Cmx_consistbl = Consistbl . Make ( Misc . Stdlib . String ) |
let crc_implementations = Cmx_consistbl . create ( ) |
let implementations = ref ( [ ] : string list ) |
let implementations_defined = ref ( [ ] : ( string * string ) list ) |
let cmx_required = ref ( [ ] : string list ) |
let check_consistency file_name unit crc = begin try List . iter ( fun ( name , crco ) -> interfaces := name :: ! interfaces ; match crco with None -> ( ) | Some crc -> if name = unit . ui_name then Cmi_consistbl . set crc_interfaces name crc file_name else Cmi_consistbl . check crc_interfaces name crc file_name ) unit... |
let extract_crc_interfaces ( ) = Cmi_consistbl . extract ! interfaces crc_interfaces |
let extract_crc_implementations ( ) = Cmx_consistbl . extract ! implementations crc_implementations |
let lib_ccobjs = ref [ ] |
let lib_ccopts = ref [ ] |
let add_ccobjs origin l = if not ! Clflags . no_auto_link then begin lib_ccobjs := l . lib_ccobjs @ ! lib_ccobjs ; let replace_origin = Misc . replace_substring ~ before " :$ CAMLORIGIN " ~ after : origin in lib_ccopts := List . map replace_origin l . lib_ccopts @ ! lib_ccopts end |
let runtime_lib ( ) = let libname = " libasmrun " ^ ! Clflags . runtime_variant ^ ext_lib in try if ! Clflags . nopervasives || not ! Clflags . with_runtime then [ ] else [ Load_path . find libname ] with Not_found -> raise ( Error ( File_not_found libname ) ) |
let missing_globals = ( Hashtbl . create 17 : ( string , string list ref ) Hashtbl . t ) |
let is_required name = try ignore ( Hashtbl . find missing_globals name ) ; true with Not_found -> false |
let add_required by ( name , _crc ) = try let rq = Hashtbl . find missing_globals name in rq := by :: ! rq with Not_found -> Hashtbl . add missing_globals name ( ref [ by ] ) |
let remove_required name = Hashtbl . remove missing_globals name |
let extract_missing_globals ( ) = let mg = ref [ ] in Hashtbl . iter ( fun md rq -> mg := ( md , ! rq ) :: ! mg ) missing_globals ; ! mg |
type file = | Unit of string * unit_infos * Digest . t | Library of string * library_infos |
let object_file_name_of_file = function | Unit ( fname , _ , _ ) -> Some ( Filename . chop_suffix fname " . cmx " ^ ext_obj ) | Library ( fname , infos ) -> let obj_file = Filename . chop_suffix fname " . cmxa " ^ ext_lib in if infos . lib_units = [ ] && not ( Sys . file_exists obj_file ) then None else Some obj_file |
let read_file obj_name = let file_name = try Load_path . find obj_name with Not_found -> raise ( Error ( File_not_found obj_name ) ) in if Filename . check_suffix file_name " . cmx " then begin let ( info , crc ) = read_unit_info file_name in Unit ( file_name , info , crc ) end else if Filename . check_suffix file_name... |
let scan_file file tolink = match file with | Unit ( file_name , info , crc ) -> remove_required info . ui_name ; List . iter ( add_required file_name ) info . ui_imports_cmx ; ( info , file_name , crc ) :: tolink | Library ( file_name , infos ) -> add_ccobjs ( Filename . dirname file_name ) infos ; List . fold_right (... |
let force_linking_of_startup ~ ppf_dump = Asmgen . compile_phrase ~ ppf_dump ( Cmm . Cdata ( [ Cmm . Csymbol_address " caml_startup " ] ) ) |
let make_globals_map units_list ~ crc_interfaces = let crc_interfaces = String . Tbl . of_seq ( List . to_seq crc_interfaces ) in let defined = List . map ( fun ( unit , _ , impl_crc ) -> let intf_crc = String . Tbl . find crc_interfaces unit . ui_name in String . Tbl . remove crc_interfaces unit . ui_name ; ( unit . u... |
let make_startup_file ~ ppf_dump units_list ~ crc_interfaces = let compile_phrase p = Asmgen . compile_phrase ~ ppf_dump p in Location . input_name := " caml_startup " ; Compilenv . reset " _startup " ; Emit . begin_assembly ( ) ; let name_list = List . flatten ( List . map ( fun ( info , _ , _ ) -> info . ui_defines )... |
let make_shared_startup_file ~ ppf_dump units = let compile_phrase p = Asmgen . compile_phrase ~ ppf_dump p in Location . input_name := " caml_startup " ; Compilenv . reset " _shared_startup " ; Emit . begin_assembly ( ) ; List . iter compile_phrase ( Cmm_helpers . generic_functions true ( List . map fst units ) ) ; co... |
let call_linker_shared file_list output_name = let exitcode = Ccomp . call_linker Ccomp . Dll output_name file_list " " in if not ( exitcode = 0 ) then raise ( Error ( Linking_error exitcode ) ) |
let link_shared ~ ppf_dump objfiles output_name = Profile . record_call output_name ( fun ( ) -> let obj_infos = List . map read_file objfiles in let units_tolink = List . fold_right scan_file obj_infos [ ] in List . iter ( fun ( info , file_name , crc ) -> check_consistency file_name info crc ) units_tolink ; Clflags ... |
let call_linker file_list startup_file output_name = let main_dll = ! Clflags . output_c_object && Filename . check_suffix output_name Config . ext_dll and main_obj_runtime = ! Clflags . output_complete_object in let files = startup_file :: ( List . rev file_list ) in let files , c_lib = if ( not ! Clflags . output_c_o... |
let link ~ ppf_dump objfiles output_name = Profile . record_call output_name ( fun ( ) -> let stdlib = " stdlib . cmxa " in let stdexit = " std_exit . cmx " in let objfiles = if ! Clflags . nopervasives then objfiles else if ! Clflags . output_c_object then stdlib :: objfiles else stdlib :: ( objfiles @ [ stdexit ] ) i... |
let report_error ppf = function | File_not_found name -> fprintf ppf " Cannot find file % s " name | Not_an_object_file name -> fprintf ppf " The file % a is not a compilation unit description " Location . print_filename name | Missing_implementations l -> let print_references ppf = function | [ ] -> ( ) | r1 :: rl -> ... |
let ( ) = Location . register_error_of_exn ( function | Error err -> Some ( Location . error_of_printer_file report_error err ) | _ -> None ) |
let reset ( ) = Cmi_consistbl . clear crc_interfaces ; Cmx_consistbl . clear crc_implementations ; implementations_defined := [ ] ; cmx_required := [ ] ; interfaces := [ ] ; implementations := [ ] ; lib_ccobjs := [ ] ; lib_ccopts := [ ] |
type error = Illegal_renaming of string * string * string | Forward_reference of string * string | Wrong_for_pack of string * string | Linking_error | Assembler_error of string | File_not_found of string |
type pack_member_kind = PM_intf | PM_impl of unit_infos |
type pack_member = { pm_file : string ; pm_name : string ; pm_kind : pack_member_kind } |
let read_member_info pack_path file = ( let name = String . capitalize_ascii ( Filename . basename ( chop_extensions file ) ) in let kind = if Filename . check_suffix file " . cmi " then PM_intf else begin let ( info , crc ) = Compilenv . read_unit_info file in if info . ui_name <> name then raise ( Error ( Illegal_ren... |
let check_units members = let rec check forbidden = function [ ] -> ( ) | mb :: tl -> begin match mb . pm_kind with | PM_intf -> ( ) | PM_impl infos -> List . iter ( fun ( unit , _ ) -> if List . mem unit forbidden then raise ( Error ( Forward_reference ( mb . pm_file , unit ) ) ) ) infos . ui_imports_cmx end ; check (... |
let make_package_object ~ ppf_dump members targetobj targetname coercion ~ backend = Profile . record_call ( Printf . sprintf " pack ( % s ) " targetname ) ( fun ( ) -> let objtemp = if ! Clflags . keep_asm_file then Filename . remove_extension targetobj ^ " . pack " ^ Config . ext_obj else Filename . temp_file ( Compi... |
let get_export_info ui = assert ( Config . flambda ) ; match ui . ui_export_info with | Clambda _ -> assert false | Flambda info -> info |
let get_approx ui = assert ( not Config . flambda ) ; match ui . ui_export_info with | Flambda _ -> assert false | Clambda info -> info |
let build_package_cmx members cmxfile = let unit_names = List . map ( fun m -> m . pm_name ) members in let filter lst = List . filter ( fun ( name , _crc ) -> not ( List . mem name unit_names ) ) lst in let union lst = List . fold_left ( List . fold_left ( fun accu n -> if List . mem n accu then accu else n :: accu ) ... |
let package_object_files ~ ppf_dump files targetcmx targetobj targetname coercion ~ backend = let pack_path = match ! Clflags . for_package with | None -> targetname | Some p -> p ^ " . " ^ targetname in let members = map_left_right ( read_member_info pack_path ) files in check_units members ; make_package_object ~ ppf... |
let package_files ~ ppf_dump initial_env files targetcmx ~ backend = let files = List . map ( fun f -> try Load_path . find f with Not_found -> raise ( Error ( File_not_found f ) ) ) files in let prefix = chop_extensions targetcmx in let targetcmi = prefix ^ " . cmi " in let targetobj = Filename . remove_extension targ... |
let report_error ppf = function Illegal_renaming ( name , file , id ) -> fprintf ppf " Wrong file naming : % a @ contains the code for \ @ % s when % s was expected " Location . print_filename file name id | Forward_reference ( file , ident ) -> fprintf ppf " Forward reference to % s in file % a " ident Location . prin... |
let ( ) = Location . register_error_of_exn ( function | Error err -> Some ( Location . error_of_printer_file report_error err ) | _ -> None ) |
module type S = Asm_directives_intf . S |
module type Arg = Asm_directives_intf . Arg |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.