2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Central firm functionality.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier
28 #ifdef HAVE_FIRM_REVISION_H
29 # include "firm_revision.h"
42 /* init functions are not public */
49 #include "irgraph_t.h"
52 #include "opt_inline_t.h"
53 #include "scalar_replace.h"
56 #include "reassoc_t.h"
57 #include "funccall_t.h"
59 #include "iredges_t.h"
60 #include "irmemory_t.h"
65 /* returns the firm root */
66 lc_opt_entry_t *firm_opt_get_root(void) {
67 static lc_opt_entry_t *grp = NULL;
69 grp = lc_opt_get_grp(lc_opt_root_grp(), "firm");
73 void firm_init_options(const char *arg_prefix, int argc, const char **argv) {
74 /* parse commandline */
75 lc_opt_from_argv(firm_opt_get_root(), arg_prefix, argc, argv, NULL);
78 void init_firm(const firm_parameter_t *param)
80 firm_parameter_t def_params;
83 /* for historical reasons be_init must be run first */
86 memset(&def_params, 0, sizeof(def_params));
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)
96 memcpy(&def_params, param, size);
99 /* initialize firm flags */
101 /* initialize all ident stuff */
102 init_ident(def_params.id_if, 1024);
103 /* initialize Firm hooks */
105 /* enhanced statistics, need idents and hooks */
106 firm_init_stat(def_params.enable_statistics);
107 /* Edges need hooks. */
109 /* create the type kinds. */
111 /* create an obstack and put all tarvals in a pdeq */
112 init_tarval_1(0l, /* support_quad_precision */0);
113 /* Builds a basic program representation, so modes can be added. */
115 /* initialize all modes an ir node can consist of */
117 /* initialize tarvals, and floating point arithmetic */
119 /* init graph construction */
121 /* kind of obstack initialization */
123 /* initialize all op codes an irnode can consist of */
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 */
133 /* initialize scalar replacement */
134 firm_init_scalar_replace();
135 /* Builds a construct allowing to access all information to be constructed
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 */
142 /* allocate a hash table. */
143 init_type_identify(def_params.ti_if);
144 /* class cast optimization */
145 firm_init_class_casts_opt();
146 /* memory disambiguation */
147 firm_init_memory_disambiguator();
149 /* Init architecture dependent optimizations. */
150 arch_dep_init(arch_dep_default_factory);
151 arch_dep_set_opts(0);
154 /* integrated debugger extension */
155 firm_init_debugger();
159 void free_firm(void) {
162 for (i = get_irp_n_irgs() - 1; i >= 0; --i)
163 free_ir_graph(get_irp_irg(i));
164 for (i = get_irp_n_pseudo_irgs() - 1; i >= 0; --i)
165 free_ir_graph(get_irp_pseudo_irg(i));
167 free_type_entities(get_glob_type());
168 for (i = get_irp_n_types() - 1; i >= 0; --i)
169 free_type_entities(get_irp_type(i));
171 for (i = get_irp_n_types() - 1; i >= 0; --i)
172 free_type(get_irp_type(i));
184 /* Returns the libFirm version number. */
185 void firm_get_version(firm_version_t *version) {
186 version->major = libfirm_VERSION_MAJOR;
187 version->minor = libfirm_VERSION_MINOR;
188 #ifdef libfirm_VERSION_REVISION
189 version->revision = libfirm_VERSION_REVISION;
191 version->revision = "";