| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Names |
| 12 |
open Declarations |
| 13 |
open Mod_declarations |
| 14 |
open Modops |
| 15 |
open Nativecode |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
let rec translate_mod mp cenv env mod_expr acc = |
| 21 |
match mod_expr with |
| 22 |
| NoFunctor struc -> |
| 23 |
List.fold_left (translate_field mp cenv env) acc struc |
| 24 |
| MoreFunctor _ -> acc |
| 25 |
|
| 26 |
|
| 27 |
and translate_modtype mp cenv env mod_expr reso acc = |
| 28 |
match mod_expr with |
| 29 |
| NoFunctor struc -> |
| 30 |
let env' = add_structure mp struc reso env in |
| 31 |
List.fold_left (translate_field mp cenv env') acc struc |
| 32 |
| MoreFunctor _ -> acc |
| 33 |
|
| 34 |
and translate_field mp cenv env acc (l,x) = |
| 35 |
match x with |
| 36 |
| SFBconst cb -> |
| 37 |
let con = Constant.make2 mp l in |
| 38 |
(debug_native_compiler (fun () -> |
| 39 |
let msg = Printf.sprintf "Compiling constant %s..." (Constant.to_string con) in |
| 40 |
Pp.str msg)); |
| 41 |
compile_constant_field cenv env con acc cb |
| 42 |
| SFBmind mb -> |
| 43 |
(debug_native_compiler (fun () -> |
| 44 |
let id = mb.mind_packets.(0).mind_typename in |
| 45 |
let msg = Printf.sprintf "Compiling inductive %s..." (Id.to_string id) in |
| 46 |
Pp.str msg)); |
| 47 |
compile_mind_field cenv mp l acc mb |
| 48 |
| SFBrules rrb -> |
| 49 |
(debug_native_compiler (fun () -> |
| 50 |
let msg = Printf.sprintf "Not Compiling rules %s..." (Id.to_string l) in |
| 51 |
Pp.str msg)); |
| 52 |
compile_rewrite_rules env l acc rrb |
| 53 |
| SFBmodule md -> |
| 54 |
let mp = MPdot (mp, l) in |
| 55 |
(debug_native_compiler (fun () -> |
| 56 |
let msg = |
| 57 |
Printf.sprintf "Compiling module %s..." (ModPath.to_string mp) |
| 58 |
in |
| 59 |
Pp.str msg)); |
| 60 |
translate_mod mp cenv env (mod_type md) acc |
| 61 |
| SFBmodtype mdtyp -> |
| 62 |
let mp = MPdot (mp, l) in |
| 63 |
(debug_native_compiler (fun () -> |
| 64 |
let msg = |
| 65 |
Printf.sprintf "Compiling module type %s..." (ModPath.to_string mp) |
| 66 |
in |
| 67 |
Pp.str msg)); |
| 68 |
translate_modtype mp cenv env (mod_type mdtyp) (mod_delta mdtyp) acc |
| 69 |
|
| 70 |
|
| 71 |
let dump_library mp env mod_expr = |
| 72 |
debug_native_compiler (fun () -> Pp.str "Compiling library..."); |
| 73 |
match mod_expr with |
| 74 |
| NoFunctor struc -> |
| 75 |
let t0 = Sys.time () in |
| 76 |
let cenv = Nativecode.make_cenv () in |
| 77 |
let mlcode = |
| 78 |
List.fold_left (translate_field mp cenv env) [] struc |
| 79 |
in |
| 80 |
let t1 = Sys.time () in |
| 81 |
let time_info = Format.sprintf "Time spent generating this code: %.5fs" (t1-.t0) in |
| 82 |
let mlcode = add_header_comment (List.rev mlcode) time_info in |
| 83 |
let symbols = Nativecode.get_cenv_symbols cenv in |
| 84 |
mlcode, symbols |
| 85 |
| _ -> assert false |