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"
60 #include "reassoc_t.h"
61 #include "funccall_t.h"
63 #include "iredges_t.h"
66 /* returns the firm root */
67 lc_opt_entry_t *firm_opt_get_root(void) {
68 static lc_opt_entry_t *grp = NULL;
70 grp = lc_opt_get_grp(lc_opt_root_grp(), "firm");
74 void firm_init_options(const char *arg_prefix, int argc, const char **argv) {
75 /* parse any init files for firm */
76 lc_opts_init("firm", firm_opt_get_root(), arg_prefix, argc, argv);
79 void init_firm(const firm_parameter_t *param)
81 firm_parameter_t def_params;
84 memset(&def_params, 0, sizeof(def_params));
87 /* check for reasonable size */
88 assert(param->size <= sizeof(def_params) && (param->size & 3) == 0 &&
89 "parameter struct not initialized ???");
90 size = sizeof(def_params);
91 if (param->size < size)
94 memcpy(&def_params, param, size);
97 /* initialize firm flags */
99 /* initialize all ident stuff */
100 init_ident(def_params.id_if, 1024);
101 /* initialize Firm hooks */
103 /* enhanced statistics, need idents and hooks */
104 firm_init_stat(def_params.enable_statistics);
105 /* Edges need hooks. */
107 /* create the type kinds. */
109 /* create an obstack and put all tarvals in a pdeq */
111 /* Builds a basic program representation, so modes can be added. */
113 /* initialize all modes an ir node can consist of */
115 /* initialize tarvals, and floating point arithmetic */
117 /* init graph construction */
119 /* kind of obstack initialization */
121 /* initialize all op codes an irnode can consist of */
123 /* called once for each run of this library */
124 firm_init_cons(def_params.initialize_local_func);
125 /* initialize reassociation */
126 firm_init_reassociation();
127 /* initialize function call optimization */
128 firm_init_funccalls();
129 /* Builds a construct allowing to access all information to be constructed
132 /* Initialize the type module and construct some idents needed. */
133 firm_init_type(def_params.builtin_dbg, def_params.cc_mask);
134 /* initialize the entity module */
136 /* allocate a hash table. */
137 init_type_identify(def_params.ti_if);
139 /* Init architecture dependent optimizations. */
140 arch_dep_init(arch_dep_default_factory);
141 arch_dep_set_opts(0);
143 firm_archops_init(def_params.arch_op_settings);
146 /* integrated debugger extension */
147 firm_init_debugger();
151 void free_firm(void) {
154 for (i = get_irp_n_irgs() - 1; i >= 0; --i)
155 free_ir_graph(get_irp_irg(i));
157 free_type_entities(get_glob_type());
158 for (i = get_irp_n_types() - 1; i >= 0; --i)
159 free_type_entities(get_irp_type(i));
161 for (i = get_irp_n_types() - 1; i >= 0; --i)
162 free_type(get_irp_type(i));
173 /* Returns the libFirm version number. */
174 void firm_get_version(firm_version_t *version) {
175 version->major = libfirm_VERSION_MAJOR;
176 version->minor = libfirm_VERSION_MINOR;
177 #ifdef libfirm_VERSION_REVISION
178 version->revision = libfirm_VERSION_REVISION;
180 version->revision = "";