fix ir_finish, freeing of irps/irgs
[libfirm] / ir / common / firm.c
1 /*
2  * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief     Central firm functionality.
23  * @author    Martin Trapp, Christian Schaefer, Goetz Lindenmaier
24  */
25 #include "config.h"
26
27 #include "firm_revision.h"
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "lc_opts.h"
33
34 #include "ident_t.h"
35 #include "firm.h"
36 #include "irflag_t.h"
37 #include "tv_t.h"
38 #include "tpop_t.h"
39 #include "irprog_t.h"
40 #include "irnode_t.h"
41 #include "irmode_t.h"
42 #include "ircons_t.h"
43 #include "irgraph_t.h"
44 #include "type_t.h"
45 #include "entity_t.h"
46 #include "firmstat.h"
47 #include "irarch.h"
48 #include "irhooks.h"
49 #include "iredges_t.h"
50 #include "irmemory_t.h"
51 #include "opt_init.h"
52 #include "debugger.h"
53 #include "be_t.h"
54 #include "irtools.h"
55
56 /* returns the firm root */
57 lc_opt_entry_t *firm_opt_get_root(void)
58 {
59         static lc_opt_entry_t *grp = NULL;
60         if (!grp)
61                 grp = lc_opt_get_grp(lc_opt_root_grp(), "firm");
62         return grp;
63 }
64
65 void ir_init(void)
66 {
67         /* for historical reasons be_init must be run first */
68         firm_be_init();
69
70         /* initialize firm flags */
71         firm_init_flags();
72         /* initialize all ident stuff */
73         init_ident();
74         /* Edges need hooks. */
75         init_edges();
76         /* create the type kinds. */
77         init_tpop();
78         /* create an obstack and put all tarvals in a pdeq */
79         init_tarval_1(0l, /* support_quad_precision */0);
80         /* Builds a basic program representation, so modes can be added. */
81         init_irprog_1();
82         /* initialize all modes an ir node can consist of */
83         init_mode();
84         /* initialize tarvals, and floating point arithmetic */
85         init_tarval_2();
86         /* init graph construction */
87         firm_init_irgraph();
88         /* kind of obstack initialization */
89         firm_init_mangle();
90         /* initialize all op codes an irnode can consist of */
91         init_op();
92         /* initialize reassociation */
93         firm_init_reassociation();
94         /* initialize function call optimization */
95         firm_init_funccalls();
96         /* initialize function inlining */
97         firm_init_inline();
98         /* initialize scalar replacement */
99         firm_init_scalar_replace();
100         /* Builds a construct allowing to access all information to be constructed
101            later. */
102         init_irprog_2();
103         /* Initialize the type module and construct some idents needed. */
104         ir_init_type();
105         /* initialize the entity module */
106         ir_init_entity();
107         /* class cast optimization */
108         firm_init_class_casts_opt();
109         /* memory disambiguation */
110         firm_init_memory_disambiguator();
111         firm_init_loop_opt();
112
113         /* Init architecture dependent optimizations. */
114         arch_dep_set_opts(arch_dep_none);
115
116         init_irnode();
117
118 #ifdef DEBUG_libfirm
119         /* integrated debugger extension */
120         firm_init_debugger();
121 #endif
122 }
123
124 void ir_finish(void)
125 {
126         free_ir_prog();
127
128         ir_finish_entity();
129         ir_finish_type();
130
131         finish_tarval();
132         finish_mode();
133         finish_tpop();
134         finish_ident();
135
136         firm_be_finish();
137 }
138
139 unsigned ir_get_version_major(void)
140 {
141         return libfirm_VERSION_MAJOR;
142 }
143
144 unsigned ir_get_version_minor(void)
145 {
146         return libfirm_VERSION_MINOR;
147 }
148
149 const char *ir_get_version_revision(void)
150 {
151 #ifdef libfirm_VERSION_REVISION
152         return libfirm_VERSION_REVISION;
153 #else
154         return "";
155 #endif
156 }
157
158 const char *ir_get_version_build(void)
159 {
160         return "";
161 }