ast2firm: Implement casting from complex to real types.
[cparser] / driver / firm_timing.c
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2012 Michael Beck <mm.beck@gmx.net>
4  */
5
6 /**
7  * @file
8  * @brief timing for the Firm compiler
9  */
10 #include "firm_timing.h"
11
12 #include <libfirm/adt/xmalloc.h>
13
14 static int timers_inited;
15
16 typedef struct timer_info_t {
17         struct timer_info_t *next;
18         char                *description;
19         ir_timer_t          *timer;
20 } timer_info_t;
21
22 static timer_info_t *infos;
23 static timer_info_t *last_info;
24
25 void timer_register(ir_timer_t *timer, const char *description)
26 {
27         timer_info_t *info = XMALLOCZ(timer_info_t);
28
29         info->description = xstrdup(description);
30         info->timer       = timer;
31
32         if (last_info != NULL) {
33                 last_info->next = info;
34         } else {
35                 infos = info;
36         }
37         last_info = info;
38 }
39
40 void timer_init(void)
41 {
42         timers_inited = 1;
43 }
44
45 void timer_term(FILE *f)
46 {
47         timer_info_t *info;
48         timer_info_t *next;
49
50         for (info = infos; info != NULL; info = next) {
51                 ir_timer_t *timer = info->timer;
52                 if (f != NULL) {
53                         double      val         = (double)ir_timer_elapsed_usec(timer) / 1000.0;
54                         const char *description = info->description;
55                         fprintf(f, "%-60s %10.3f msec\n", description, val);
56                 }
57
58                 ir_timer_free(timer);
59                 xfree(info->description);
60                 next = info->next;
61                 xfree(info);
62         }
63         infos = NULL;
64         last_info = NULL;
65
66         timers_inited = 0;
67 }
68
69 void timer_push(ir_timer_t *timer)
70 {
71         if (timers_inited)
72                 ir_timer_push(timer);
73 }
74
75 void timer_pop(ir_timer_t *timer)
76 {
77         if (timers_inited)
78                 ir_timer_pop(timer);
79 }
80
81 void timer_start(ir_timer_t *timer)
82 {
83         if (timers_inited)
84                 ir_timer_start(timer);
85 }
86
87 void timer_stop(ir_timer_t *timer)
88 {
89         if (timers_inited)
90                 ir_timer_stop(timer);
91 }