Simplify printing string initializers.
[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                 double      val         = (double)ir_timer_elapsed_usec(timer) / 1000.0;
49                 const char *description = info->description;
50                 fprintf(f, "%-45s %8.3f msec\n", description, val);
51
52                 ir_timer_free(timer);
53                 xfree(info->description);
54                 next = info->next;
55                 xfree(info);
56         }
57         infos = NULL;
58         last_info = NULL;
59
60         timers_inited = 0;
61 }
62
63 void timer_push(ir_timer_t *timer)
64 {
65         if (timers_inited)
66                 ir_timer_push(timer);
67 }
68
69 void timer_pop(ir_timer_t *timer)
70 {
71         (void) timer;
72         if (timers_inited)
73                 ir_timer_pop();
74 }
75
76 void timer_start(ir_timer_t *timer)
77 {
78         if (timers_inited)
79                 ir_timer_start(timer);
80 }
81
82 void timer_stop(ir_timer_t *timer)
83 {
84         if (timers_inited)
85                 ir_timer_stop(timer);
86 }