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