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