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
30 #ifdef HAVE_FIRM_REVISION_H
31 # include "firm_revision.h"
34 #include "firm_config.h"
48 /* init functions are not public */
55 #include "irgraph_t.h"
58 #include "opt_inline_t.h"
59 #include "scalar_replace.h"
62 #include "reassoc_t.h"
63 #include "funccall_t.h"
65 #include "iredges_t.h"
69 /* returns the firm root */
70 lc_opt_entry_t *firm_opt_get_root(void) {
71 static lc_opt_entry_t *grp = NULL;
73 grp = lc_opt_get_grp(lc_opt_root_grp(), "firm");
77 void firm_init_options(const char *arg_prefix, int argc, const char **argv) {
78 /* parse any init files for firm */
79 lc_opts_init("firm", firm_opt_get_root(), arg_prefix, argc, argv);
82 void init_firm(const firm_parameter_t *param)
84 firm_parameter_t def_params;
87 memset(&def_params, 0, sizeof(def_params));
90 /* check for reasonable size */
91 assert(param->size <= sizeof(def_params) && (param->size & 3) == 0 &&
92 "parameter struct not initialized ???");
93 size = sizeof(def_params);
94 if (param->size < size)
97 memcpy(&def_params, param, size);
100 /* initialize firm flags */
102 /* initialize all ident stuff */
103 init_ident(def_params.id_if, 1024);
104 /* initialize Firm hooks */
106 /* enhanced statistics, need idents and hooks */
107 firm_init_stat(def_params.enable_statistics);
108 /* Edges need hooks. */
110 /* create the type kinds. */
112 /* create an obstack and put all tarvals in a pdeq */
114 /* Builds a basic program representation, so modes can be added. */
116 /* initialize all modes an ir node can consist of */
118 /* initialize tarvals, and floating point arithmetic */
120 /* init graph construction */
122 /* kind of obstack initialization */
124 /* initialize all op codes an irnode can consist of */
126 /* called once for each run of this library */
127 firm_init_cons(def_params.initialize_local_func);
128 /* initialize reassociation */
129 firm_init_reassociation();
130 /* initialize function call optimization */
131 firm_init_funccalls();
132 /* initialize function inlining */
134 /* initialize scalar replacement */
135 firm_init_scalar_replace();
136 /* Builds a construct allowing to access all information to be constructed
139 /* Initialize the type module and construct some idents needed. */
140 firm_init_type(def_params.builtin_dbg, def_params.cc_mask);
141 /* initialize the entity module */
143 /* allocate a hash table. */
144 init_type_identify(def_params.ti_if);
145 /* class cast optimization */
146 firm_init_class_casts_opt();
148 /* Init architecture dependent optimizations. */
149 arch_dep_init(arch_dep_default_factory);
150 arch_dep_set_opts(0);
152 firm_archops_init(def_params.arch_op_settings);
155 /* integrated debugger extension */
156 firm_init_debugger();
160 void free_firm(void) {
163 for (i = get_irp_n_irgs() - 1; i >= 0; --i)
164 free_ir_graph(get_irp_irg(i));
166 free_type_entities(get_glob_type());
167 for (i = get_irp_n_types() - 1; i >= 0; --i)
168 free_type_entities(get_irp_type(i));
170 for (i = get_irp_n_types() - 1; i >= 0; --i)
171 free_type(get_irp_type(i));
182 /* Returns the libFirm version number. */
183 void firm_get_version(firm_version_t *version) {
184 version->major = libfirm_VERSION_MAJOR;
185 version->minor = libfirm_VERSION_MINOR;
186 #ifdef libfirm_VERSION_REVISION
187 version->revision = libfirm_VERSION_REVISION;
189 version->revision = "";