switch scalar replacement to new style debug output
[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 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #ifdef HAVE_FIRM_REVISION_H
31 # include "firm_revision.h"
32 #endif
33
34 #include "firm_config.h"
35
36 #ifdef HAVE_STRING_H
37 # include <string.h>
38 #endif
39 #ifdef HAVE_STDIO_H
40 # include <stdio.h>
41 #endif
42
43 #include "lc_opts.h"
44
45 #include "ident_t.h"
46 #include "firm.h"
47 #include "irflag_t.h"
48 /* init functions are not public */
49 #include "tv_t.h"
50 #include "tpop_t.h"
51 #include "irprog_t.h"
52 #include "irnode_t.h"
53 #include "irmode_t.h"
54 #include "ircons_t.h"
55 #include "irgraph_t.h"
56 #include "type_t.h"
57 #include "entity_t.h"
58 #include "opt_inline_t.h"
59 #include "scalar_replace.h"
60 #include "firmstat.h"
61 #include "irarch.h"
62 #include "reassoc_t.h"
63 #include "funccall_t.h"
64 #include "irhooks.h"
65 #include "iredges_t.h"
66 #include "debugger.h"
67
68 /* returns the firm root */
69 lc_opt_entry_t *firm_opt_get_root(void) {
70         static lc_opt_entry_t *grp = NULL;
71         if(!grp)
72                 grp = lc_opt_get_grp(lc_opt_root_grp(), "firm");
73         return grp;
74 }
75
76 void firm_init_options(const char *arg_prefix, int argc, const char **argv) {
77         /* parse any init files for firm */
78         lc_opts_init("firm", firm_opt_get_root(), arg_prefix, argc, argv);
79 }
80
81 void init_firm(const firm_parameter_t *param)
82 {
83         firm_parameter_t def_params;
84         unsigned int     size;
85
86         memset(&def_params, 0, sizeof(def_params));
87
88         if (param) {
89                 /* check for reasonable size */
90                 assert(param->size <= sizeof(def_params) && (param->size & 3) == 0 &&
91                                 "parameter struct not initialized ???");
92                 size = sizeof(def_params);
93                 if (param->size < size)
94                         size = param->size;
95
96                 memcpy(&def_params, param, size);
97         }
98
99         /* initialize firm flags */
100         firm_init_flags();
101         /* initialize all ident stuff */
102         init_ident(def_params.id_if, 1024);
103         /* initialize Firm hooks */
104         firm_init_hooks();
105         /* enhanced statistics, need idents and hooks */
106         firm_init_stat(def_params.enable_statistics);
107         /* Edges need hooks. */
108         init_edges();
109         /* create the type kinds. */
110         init_tpop();
111         /* create an obstack and put all tarvals in a pdeq */
112         init_tarval_1(0l);
113         /* Builds a basic program representation, so modes can be added. */
114         init_irprog_1();
115         /* initialize all modes an ir node can consist of */
116         init_mode();
117         /* initialize tarvals, and floating point arithmetic */
118         init_tarval_2();
119         /* init graph construction */
120         firm_init_irgraph();
121         /* kind of obstack initialization */
122         firm_init_mangle();
123         /* initialize all op codes an irnode can consist of */
124         init_op();
125         /* called once for each run of this library */
126         firm_init_cons(def_params.initialize_local_func);
127         /* initialize reassociation */
128         firm_init_reassociation();
129         /* initialize function call optimization */
130         firm_init_funccalls();
131         /* initialize function inlining */
132         firm_init_inline();
133         /* initialize scalar replacement */
134         firm_init_scalar_replace();
135         /* Builds a construct allowing to access all information to be constructed
136            later. */
137         init_irprog_2();
138         /* Initialize the type module and construct some idents needed. */
139         firm_init_type(def_params.builtin_dbg, def_params.cc_mask);
140         /* initialize the entity module */
141         firm_init_entity();
142         /* allocate a hash table. */
143         init_type_identify(def_params.ti_if);
144
145         /* Init architecture dependent optimizations. */
146         arch_dep_init(arch_dep_default_factory);
147         arch_dep_set_opts(0);
148
149         firm_archops_init(def_params.arch_op_settings);
150
151 #ifdef DEBUG_libfirm
152         /* integrated debugger extension */
153         firm_init_debugger();
154 #endif
155 }
156
157 void free_firm(void) {
158         int i;
159
160         for (i = get_irp_n_irgs() - 1; i >= 0; --i)
161                 free_ir_graph(get_irp_irg(i));
162
163         free_type_entities(get_glob_type());
164         for (i = get_irp_n_types() - 1; i >= 0; --i)
165                 free_type_entities(get_irp_type(i));
166
167         for (i = get_irp_n_types() - 1; i >= 0; --i)
168                 free_type(get_irp_type(i));
169
170         finish_op();
171         free_ir_prog();
172
173         finish_tarval();
174         finish_mode();
175         finish_tpop();
176         finish_ident();
177 }
178
179 /* Returns the libFirm version number. */
180 void firm_get_version(firm_version_t *version) {
181         version->major    = libfirm_VERSION_MAJOR;
182         version->minor    = libfirm_VERSION_MINOR;
183 #ifdef libfirm_VERSION_REVISION
184         version->revision = libfirm_VERSION_REVISION;
185 #else
186         version->revision = "";
187 #endif
188         version->build    = "";
189 }