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