Debian Codegraph @

kernel/nativelibrary.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Names
12 open Declarations
13 open Mod_declarations
14 open Modops
15 open Nativecode
16
17 (** This file implements separate compilation for libraries in the native
18 compiler *)
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 (* XXX I believe it makes no sense to extract module types *)
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 (* This function expects the contents of the module to be part of [env] already *)
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