fix a bunch of warnings (reported by cparser)
[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 "firm_timing.h"
9
10 #include <libfirm/adt/xmalloc.h>
11
12 static int timers_inited;
13
14 typedef struct timer_info_t {
15         struct timer_info_t *next;
16         char                *description;
17         ir_timer_t          *timer;
18 } timer_info_t;
19
20 static timer_info_t *infos;
21 static timer_info_t *last_info;
22
23 void timer_register(ir_timer_t *timer, const char *description)
24 {
25         timer_info_t *info = XMALLOCZ(timer_info_t);
26
27         info->description = xstrdup(description);
28         info->timer       = timer;
29
30         if (last_info != NULL) {
31                 last_info->next = info;
32         } else {
33                 infos = info;
34         }
35         last_info = info;
36 }
37
38 void timer_init(void)
39 {
40         timers_inited = 1;
41 }
42
43 void timer_term(FILE *f)
44 {
45         timer_info_t *info;
46         timer_info_t *next;
47
48         for (info = infos; info != NULL; info = next) {
49                 ir_timer_t *timer = info->timer;
50                 double      val         = (double)ir_timer_elapsed_usec(timer) / 1000.0;
51                 const char *description = info->description;
52                 fprintf(f, "%-45s %8.3f msec\n", description, val);
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         (void) timer;
74         if (timers_inited)
75                 ir_timer_pop();
76 }
77
78 void timer_start(ir_timer_t *timer)
79 {
80         if (timers_inited)
81                 ir_timer_start(timer);
82 }
83
84 void timer_stop(ir_timer_t *timer)
85 {
86         if (timers_inited)
87                 ir_timer_stop(timer);
88 }