Primitive, Pointer, Array and Method types are anonymous now
[libfirm] / ir / common / firm.c
1 /*
2  * Copyright (C) 1995-2008 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  * @version   $Id$
25  */
26 #include "config.h"
27
28 #ifdef HAVE_FIRM_REVISION_H
29 # include "firm_revision.h"
30 #endif
31
32 #include <string.h>
33 #include <stdio.h>
34
35 #include "lc_opts.h"
36
37 #include "ident_t.h"
38 #include "firm.h"
39 #include "irflag_t.h"
40 /* init functions are not public */
41 #include "tv_t.h"
42 #include "tpop_t.h"
43 #include "irprog_t.h"
44 #include "irnode_t.h"
45 #include "irmode_t.h"
46 #include "ircons_t.h"
47 #include "irgraph_t.h"
48 #include "type_t.h"
49 #include "entity_t.h"
50 #include "firmstat.h"
51 #include "irarch.h"
52 #include "irhooks.h"
53 #include "iredges_t.h"
54 #include "irmemory_t.h"
55 #include "opt_init.h"
56 #include "debugger.h"
57 #include "be_t.h"
58
59 /* returns the firm root */
60 lc_opt_entry_t *firm_opt_get_root(void)
61 {
62         static lc_opt_entry_t *grp = NULL;
63         if (!grp)
64                 grp = lc_opt_get_grp(lc_opt_root_grp(), "firm");
65         return grp;
66 }
67
68 void ir_init(const firm_parameter_t *param)
69 {
70         firm_parameter_t def_params;
71         unsigned int     size;
72
73         /* for historical reasons be_init must be run first */
74         firm_be_init();
75
76         memset(&def_params, 0, sizeof(def_params));
77
78         if (param) {
79                 /* check for reasonable size */
80                 assert(param->size <= sizeof(def_params) && (param->size & 3) == 0 &&
81                                 "parameter struct not initialized ???");
82                 size = sizeof(def_params);
83                 if (param->size < size)
84                         size = param->size;
85
86                 memcpy(&def_params, param, size);
87         }
88
89         /* initialize firm flags */
90         firm_init_flags();
91         /* initialize all ident stuff */
92         init_ident(def_params.id_if, 1024);
93         /* enhanced statistics, need idents and hooks */
94         firm_init_stat(def_params.enable_statistics);
95         /* Edges need hooks. */
96         init_edges();
97         /* create the type kinds. */
98         init_tpop();
99         /* create an obstack and put all tarvals in a pdeq */
100         init_tarval_1(0l, /* support_quad_precision */0);
101         /* Builds a basic program representation, so modes can be added. */
102         init_irprog_1();
103         /* initialize all modes an ir node can consist of */
104         init_mode();
105         /* initialize tarvals, and floating point arithmetic */
106         init_tarval_2();
107         /* init graph construction */
108         firm_init_irgraph();
109         /* kind of obstack initialization */
110         firm_init_mangle();
111         /* initialize all op codes an irnode can consist of */
112         init_op();
113         /* called once for each run of this library */
114         firm_init_cons(def_params.initialize_local_func);
115         /* initialize reassociation */
116         firm_init_reassociation();
117         /* initialize function call optimization */
118         firm_init_funccalls();
119         /* initialize function inlining */
120         firm_init_inline();
121         /* initialize scalar replacement */
122         firm_init_scalar_replace();
123         /* Builds a construct allowing to access all information to be constructed
124            later. */
125         init_irprog_2();
126         /* Initialize the type module and construct some idents needed. */
127         firm_init_type(def_params.cc_mask);
128         /* initialize the entity module */
129         firm_init_entity();
130         /* class cast optimization */
131         firm_init_class_casts_opt();
132         /* memory disambiguation */
133         firm_init_memory_disambiguator();
134         firm_init_loop_opt();
135
136         /* Init architecture dependent optimizations. */
137         arch_dep_init(arch_dep_default_factory);
138         arch_dep_set_opts(0);
139
140 #ifdef DEBUG_libfirm
141         /* integrated debugger extension */
142         firm_init_debugger();
143 #endif
144 }
145
146 void ir_finish(void)
147 {
148         int i;
149
150         for (i = get_irp_n_irgs() - 1; i >= 0; --i)
151                 free_ir_graph(get_irp_irg(i));
152         for (i = get_irp_n_pseudo_irgs() - 1; i >= 0; --i)
153                 free_ir_graph(get_irp_pseudo_irg(i));
154
155         free_type_entities(get_glob_type());
156         for (i = get_irp_n_types() - 1; i >= 0; --i)
157                 free_type_entities(get_irp_type(i));
158
159         for (i = get_irp_n_types() - 1; i >= 0; --i)
160                 free_type(get_irp_type(i));
161
162         free_ir_prog();
163
164         finish_tarval();
165         finish_mode();
166         finish_tpop();
167         finish_ident();
168
169         firm_be_finish();
170 }
171
172 unsigned ir_get_version_major(void)
173 {
174         return libfirm_VERSION_MAJOR;
175 }
176
177 unsigned ir_get_version_minor(void)
178 {
179         return libfirm_VERSION_MINOR;
180 }
181
182 const char *ir_get_version_revision(void)
183 {
184 #ifdef libfirm_VERSION_REVISION
185         return libfirm_VERSION_REVISION;
186 #else
187         return "";
188 #endif
189 }
190
191 const char *ir_get_version_build(void)
192 {
193         return "";
194 }