fix cases where compoundlits are constant/get an entity
[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 #include "firm_timing.h"
7
8 #include <libfirm/adt/xmalloc.h>
9
10 static int timers_inited;
11
12 typedef struct timer_info_t {
13         struct timer_info_t *next;
14         char                *description;
15         ir_timer_t          *timer;
16 } timer_info_t;
17
18 static timer_info_t *infos;
19 static timer_info_t *last_info;
20
21 void timer_register(ir_timer_t *timer, const char *description)
22 {
23         timer_info_t *info = XMALLOCZ(timer_info_t);
24
25         info->description = xstrdup(description);
26         info->timer       = timer;
27
28         if (last_info != NULL) {
29                 last_info->next = info;
30         } else {
31                 infos = info;
32         }
33         last_info = info;
34 }
35
36 void timer_init(void)
37 {
38         timers_inited = 1;
39 }
40
41 void timer_term(FILE *f)
42 {
43         timer_info_t *info;
44         timer_info_t *next;
45
46         for (info = infos; info != NULL; info = next) {
47                 ir_timer_t *timer = info->timer;
48                 if (f != NULL) {
49                         double      val         = (double)ir_timer_elapsed_usec(timer) / 1000.0;
50                         const char *description = info->description;
51                         fprintf(f, "%-60s %10.3f msec\n", description, val);
52                 }
53
54                 ir_timer_free(timer);
55                 xfree(info->description);
56                 next = info->next;
57                 xfree(info);
58         }
59         infos = NULL;
60         last_info = NULL;
61
62         timers_inited = 0;
63 }
64
65 void timer_push(ir_timer_t *timer)
66 {
67         if (timers_inited)
68                 ir_timer_push(timer);
69 }
70
71 void timer_pop(ir_timer_t *timer)
72 {
73         if (timers_inited)
74                 ir_timer_pop(timer);
75 }
76
77 void timer_start(ir_timer_t *timer)
78 {
79         if (timers_inited)
80                 ir_timer_start(timer);
81 }
82
83 void timer_stop(ir_timer_t *timer)
84 {
85         if (timers_inited)
86                 ir_timer_stop(timer);
87 }