2 * Copyright (C) 1995-2007 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 #include "firm_config.h"
40 # include <libcore/lc_opts.h>
46 /* init functions are not public */
53 #include "irgraph_t.h"
58 #include "reassoc_t.h"
60 #include "iredges_t.h"
64 /* returns the firm root */
65 lc_opt_entry_t *firm_opt_get_root(void) {
66 static lc_opt_entry_t *grp = NULL;
68 grp = lc_opt_get_grp(lc_opt_root_grp(), "firm");
72 void firm_init_options(const char *arg_prefix, int argc, const char **argv) {
73 /* parse any init files for firm */
74 lc_opts_init("firm", firm_opt_get_root(), arg_prefix, argc, argv);
76 #endif /* WITH_LIBCORE */
78 void init_firm(const firm_parameter_t *param)
80 firm_parameter_t def_params;
83 memset(&def_params, 0, sizeof(def_params));
86 /* check for reasonable size */
87 assert(param->size <= sizeof(def_params) && (param->size & 3) == 0 &&
88 "parameter struct not initialized ???");
89 size = sizeof(def_params);
90 if (param->size < size)
93 memcpy(&def_params, param, size);
96 /* initialize firm flags */
98 /* initialize all ident stuff */
99 init_ident(def_params.id_if, 1024);
100 /* initialize Firm hooks */
102 /* enhanced statistics, need idents and hooks */
103 firm_init_stat(def_params.enable_statistics);
104 /* Edges need hooks. */
106 /* create the type kinds. */
108 /* create an obstack and put all tarvals in a pdeq */
110 /* Builds a basic program representation, so modes can be added. */
112 /* initialize all modes an ir node can consist of */
114 /* initialize tarvals, and floating point arithmetic */
116 /* init graph construction */
118 /* kind of obstack initialization */
120 /* initialize all op codes an irnode can consist of */
122 /* called once for each run of this library */
123 init_cons(def_params.initialize_local_func);
124 /* initialize reassociation */
125 firm_init_reassociation();
126 /* Builds a construct allowing to access all information to be constructed
129 /* Initialize the type module and construct some idents needed. */
130 firm_init_type(def_params.builtin_dbg, def_params.cc_mask);
131 /* initialize the entity module */
133 /* allocate a hash table. */
134 init_type_identify(def_params.ti_if);
136 /* Init architecture dependent optimizations. */
137 arch_dep_init(arch_dep_default_factory);
138 arch_dep_set_opts(arch_dep_mul_to_shift | arch_dep_div_by_const | arch_dep_mod_by_const);
140 firm_archops_init(def_params.arch_op_settings);
143 /* integrated debugger extension */
144 firm_init_debugger();
148 void free_firm(void) {
151 for (i = get_irp_n_irgs() - 1; i >= 0; --i)
152 free_ir_graph(get_irp_irg(i));
154 free_type_entities(get_glob_type());
155 for (i = get_irp_n_types() - 1; i >= 0; --i)
156 free_type_entities(get_irp_type(i));
158 for (i = get_irp_n_types() - 1; i >= 0; --i)
159 free_type(get_irp_type(i));
170 /* Returns the libFirm version number. */
171 void firm_get_version(firm_version_t *version) {
172 version->major = libfirm_VERSION_MAJOR;
173 version->minor = libfirm_VERSION_MINOR;
174 version->micro = libfirm_VERSION_MICRO;