- 2009 patch
[cparser] / driver / firm_timing.c
1 /**
2  * @file firm_timing.c -- timing for the Firm compiler
3  *
4  * (C) 2006-2009  Michael Beck   beck@ipd.info.uni-karlsruhe.de
5  *
6  * $Id$
7  */
8 #include <libfirm/timing.h>
9 #include "firm_timing.h"
10
11 static const char *tv_names[] = {
12 #define DEFTIMEVAR(x, y, z)     y,
13 #include "firm_timing.def"
14         NULL
15 #undef DEFTIMEVAR
16 };
17
18 static const char *tv_desc[] = {
19 #define DEFTIMEVAR(x, y, z)     z,
20 #include "firm_timing.def"
21         NULL
22 #undef DEFTIMEVAR
23 };
24
25 static ir_timer_t *timers[TV_LAST];
26 static int timers_inited;
27
28 void timer_init(void) {
29         int i;
30
31         for (i = 0; i < TV_LAST; ++i) {
32                 timers[i] = ir_timer_register(tv_names[i], tv_desc[i]);
33         }
34
35         timers_inited = 1;
36 }
37
38 void timer_term(FILE *f) {
39         int i;
40
41         for (i = 0; i < TV_LAST; ++i) {
42                 double val = (double)ir_timer_elapsed_usec(timers[i]) / 1000.0;
43                 fprintf(f, "%-30s %8.3f msec\n", tv_desc[i], val);
44         }
45
46         timers_inited = 0;
47 }
48
49 void timer_push(int timer) {
50         if (timers_inited)
51                 ir_timer_push(timers[timer]);
52 }
53
54 void timer_pop(void) {
55         if (timers_inited)
56                 ir_timer_pop();
57 }
58
59 void timer_start(int timer) {
60         if (timers_inited)
61                 ir_timer_start(timers[timer]);
62 }
63
64 void timer_stop(int timer) {
65         if (timers_inited)
66                 ir_timer_stop(timers[timer]);
67 }