Skip to content

Commit e5b59af

Browse files
committed
Moved the timing facility to a seperate file.
1 parent 6087efa commit e5b59af

File tree

5 files changed

+68
-54
lines changed

5 files changed

+68
-54
lines changed

cparser/Parse.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ let preprocessed_file transfs name sourcefile =
4848
let rec inf = Datatypes.S inf in
4949
let ast : Cabs.definition list =
5050
Obj.magic
51-
(match Clflags.time2 "Parsing"
51+
(match Timing.time2 "Parsing"
5252
Parser.translation_unit_file inf (Lexer.tokens_stream lb) with
5353
| Parser.Parser.Inter.Fail_pr ->
5454
(* Theoretically impossible : implies inconsistencies
5555
between grammars. *)
5656
Cerrors.fatal_error "Internal error while parsing"
5757
| Parser.Parser.Inter.Timeout_pr -> assert false
5858
| Parser.Parser.Inter.Parsed_pr (ast, _ ) -> ast) in
59-
let p1 = Clflags.time "Elaboration" Elab.elab_file ast in
60-
Clflags.time2 "Emulations" transform_program t p1
59+
let p1 = Timing.time "Elaboration" Elab.elab_file ast in
60+
Timing.time2 "Emulations" transform_program t p1
6161
with
6262
| Cerrors.Abort ->
6363
[] in

driver/Clflags.ml

-50
Original file line numberDiff line numberDiff line change
@@ -54,53 +54,3 @@ let option_small_data =
5454
then 8 else 0)
5555
let option_small_const = ref (!option_small_data)
5656
let option_timings = ref false
57-
58-
(** Timing facility *)
59-
60-
let timers : (string * float) list ref = ref []
61-
62-
let add_to_timer name time =
63-
let rec add = function
64-
| [] -> [name, time]
65-
| (name1, time1 as nt1) :: rem ->
66-
if name1 = name then (name1, time1 +. time) :: rem else nt1 :: add rem
67-
in timers := add !timers
68-
69-
let time name fn arg =
70-
if not !option_timings then
71-
fn arg
72-
else begin
73-
let start = Sys.time() in
74-
try
75-
let res = fn arg in
76-
add_to_timer name (Sys.time() -. start);
77-
res
78-
with x ->
79-
add_to_timer name (Sys.time() -. start);
80-
raise x
81-
end
82-
83-
let time2 name fn arg1 arg2 = time name (fun () -> fn arg1 arg2) ()
84-
let time3 name fn arg1 arg2 arg3 = time name (fun () -> fn arg1 arg2 arg3) ()
85-
86-
let time_coq name fn arg =
87-
if not !option_timings then
88-
fn arg
89-
else begin
90-
let start = Sys.time() in
91-
try
92-
let res = fn arg in
93-
add_to_timer (Camlcoq.camlstring_of_coqstring name) (Sys.time() -. start);
94-
res
95-
with x ->
96-
add_to_timer (Camlcoq.camlstring_of_coqstring name) (Sys.time() -. start);
97-
raise x
98-
end
99-
100-
let print_timers () =
101-
if !option_timings then
102-
List.iter
103-
(fun (name, time) -> Printf.printf "%7.2fs %s\n" time name)
104-
!timers
105-
106-
let _ = at_exit print_timers

driver/Driver.ml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
open Printf
1414
open Camlcoq
1515
open Clflags
16+
open Timing
1617

1718
(* Location of the compatibility library *)
1819

driver/Timing.ml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
(* *********************************************************************)
2+
(* *)
3+
(* The Compcert verified compiler *)
4+
(* *)
5+
(* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *)
6+
(* *)
7+
(* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *)
8+
(* is distributed under the terms of the INRIA Non-Commercial *)
9+
(* License Agreement. *)
10+
(* *)
11+
(* *********************************************************************)
12+
13+
open Clflags
14+
15+
(** Timing facility *)
16+
17+
let timers : (string * float) list ref = ref []
18+
19+
let add_to_timer name time =
20+
let rec add = function
21+
| [] -> [name, time]
22+
| (name1, time1 as nt1) :: rem ->
23+
if name1 = name then (name1, time1 +. time) :: rem else nt1 :: add rem
24+
in timers := add !timers
25+
26+
let time name fn arg =
27+
if not !option_timings then
28+
fn arg
29+
else begin
30+
let start = Sys.time() in
31+
try
32+
let res = fn arg in
33+
add_to_timer name (Sys.time() -. start);
34+
res
35+
with x ->
36+
add_to_timer name (Sys.time() -. start);
37+
raise x
38+
end
39+
40+
let time2 name fn arg1 arg2 = time name (fun () -> fn arg1 arg2) ()
41+
let time3 name fn arg1 arg2 arg3 = time name (fun () -> fn arg1 arg2 arg3) ()
42+
43+
let time_coq name fn arg =
44+
if not !option_timings then
45+
fn arg
46+
else begin
47+
let start = Sys.time() in
48+
try
49+
let res = fn arg in
50+
add_to_timer (Camlcoq.camlstring_of_coqstring name) (Sys.time() -. start);
51+
res
52+
with x ->
53+
add_to_timer (Camlcoq.camlstring_of_coqstring name) (Sys.time() -. start);
54+
raise x
55+
end
56+
57+
let print_timers () =
58+
if !option_timings then
59+
List.iter
60+
(fun (name, time) -> Printf.printf "%7.2fs %s\n" time name)
61+
!timers
62+
63+
let _ = at_exit print_timers

extraction/extraction.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Extract Constant Compiler.print_RTL => "PrintRTL.print_if".
104104
Extract Constant Compiler.print_LTL => "PrintLTL.print_if".
105105
Extract Constant Compiler.print_Mach => "PrintMach.print_if".
106106
Extract Constant Compiler.print => "fun (f: 'a -> unit) (x: 'a) -> f x; x".
107-
Extract Constant Compiler.time => "Clflags.time_coq".
107+
Extract Constant Compiler.time => "Timing.time_coq".
108108

109109
(*Extraction Inline Compiler.apply_total Compiler.apply_partial.*)
110110

0 commit comments

Comments
 (0)