3 * File name: ir/common/firm.c
4 * Purpose: Central firm functionality.
5 * Author: Martin Trapp, Christian Schaefer
6 * Modified by: Goetz Lindenmaier
9 * Copyright: (c) 1998-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
24 # include <libcore/lc_opts.h>
31 /* init functions are not public */
38 #include "irgraph_t.h"
41 #include "type_identify.h"
43 #include "irreflect_t.h"
45 #include "reassoc_t.h"
47 #include "iredges_t.h"
49 #include "firm_ycomp.h"
52 /* returns the firm root */
53 lc_opt_entry_t *firm_opt_get_root(void) {
54 static lc_opt_entry_t *grp = NULL;
56 grp = lc_opt_get_grp(lc_opt_root_grp(), "firm");
60 void firm_init_options(const char *arg_prefix, int argc, const char **argv) {
61 /* parse any init files for firm */
62 lc_opts_init("firm", firm_opt_get_root(), arg_prefix, argc, argv);
64 #endif /* WITH_LIBCORE */
67 init_firm(const firm_parameter_t *param)
69 firm_parameter_t def_params;
72 memset(&def_params, 0, sizeof(def_params));
75 /* check for reasonable size */
76 assert(param->size <= sizeof(def_params) && (param->size & 3) == 0 &&
77 "parameter struct not initialized ???");
78 size = sizeof(def_params);
79 if (param->size < size)
82 memcpy(&def_params, param, size);
85 /* initialize firm flags */
87 /* initialize all ident stuff */
88 init_ident(def_params.id_if, 1024);
89 /* initialize Firm hooks */
91 /* enhanced statistics, need idents and hooks */
92 firm_init_stat(def_params.enable_statistics);
93 /* Edges need hooks. */
95 /* create the type kinds. */
97 /* create an obstack and put all tarvals in a pdeq */
99 /* Builds a basic program representation, so modes can be added. */
101 /* initialize all modes an ir node can consist of */
103 /* initialize tarvals, and floating point arithmetic */
105 /* init graph construction */
107 /* kind of obstack initialization */
109 /* initialize all op codes an irnode can consist of */
111 /* called once for each run of this library */
112 init_cons(def_params.initialize_local_func);
113 /* initialize reassociation */
114 firm_init_reassociation();
115 /* Builds a construct allowing to access all information to be constructed
118 /* Initialize the type module ancd cr d construct some idents needed. */
119 firm_init_type(def_params.builtin_dbg, def_params.cc_mask);
120 /* initialize the entity module */
122 /* allocate a hash table. */
123 init_type_identify(def_params.ti_if);
124 /* Init reflection facility. */
127 /* Init architecture dependent optimizations. */
128 arch_dep_init(arch_dep_default_factory);
129 arch_dep_set_opts(arch_dep_mul_to_shift | arch_dep_div_by_const | arch_dep_mod_by_const);
131 firm_archops_init(def_params.arch_op_settings);
134 /* integrated debugger extension */
135 firm_init_debugger();
136 firm_init_ycomp_debugger(NULL, 0);
140 void free_firm(void) {
143 for (i = get_irp_n_irgs() - 1; i >= 0; --i)
144 free_ir_graph(get_irp_irg(i));
146 free_type_entities(get_glob_type());
147 for (i = get_irp_n_types() - 1; i >= 0; --i)
148 free_type_entities(get_irp_type(i));
150 for (i = get_irp_n_types() - 1; i >= 0; --i)
151 free_type(get_irp_type(i));
161 firm_finish_ycomp_debugger();
165 /* Returns the libFirm version number. */
166 void firm_get_version(firm_version_t *version) {
167 version->major = libFirm_VERSION_MAJOR;
168 version->minor = libFirm_VERSION_MINOR;