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"
51 /* returns the firm root */
52 lc_opt_entry_t *firm_opt_get_root(void) {
53 static lc_opt_entry_t *grp = NULL;
55 grp = lc_opt_get_grp(lc_opt_root_grp(), "firm");
59 void firm_init_options(const char *arg_prefix, int argc, const char **argv) {
60 /* parse any init files for firm */
61 lc_opts_init("firm", firm_opt_get_root(), arg_prefix, argc, argv);
63 #endif /* WITH_LIBCORE */
65 void init_firm(const firm_parameter_t *param)
67 firm_parameter_t def_params;
70 memset(&def_params, 0, sizeof(def_params));
73 /* check for reasonable size */
74 assert(param->size <= sizeof(def_params) && (param->size & 3) == 0 &&
75 "parameter struct not initialized ???");
76 size = sizeof(def_params);
77 if (param->size < size)
80 memcpy(&def_params, param, size);
83 /* initialize firm flags */
85 /* initialize all ident stuff */
86 init_ident(def_params.id_if, 1024);
87 /* initialize Firm hooks */
89 /* enhanced statistics, need idents and hooks */
90 firm_init_stat(def_params.enable_statistics);
91 /* Edges need hooks. */
93 /* create the type kinds. */
95 /* create an obstack and put all tarvals in a pdeq */
97 /* Builds a basic program representation, so modes can be added. */
99 /* initialize all modes an ir node can consist of */
101 /* initialize tarvals, and floating point arithmetic */
103 /* init graph construction */
105 /* kind of obstack initialization */
107 /* initialize all op codes an irnode can consist of */
109 /* called once for each run of this library */
110 init_cons(def_params.initialize_local_func);
111 /* initialize reassociation */
112 firm_init_reassociation();
113 /* Builds a construct allowing to access all information to be constructed
116 /* Initialize the type module ancd cr d construct some idents needed. */
117 firm_init_type(def_params.builtin_dbg, def_params.cc_mask);
118 /* initialize the entity module */
120 /* allocate a hash table. */
121 init_type_identify(def_params.ti_if);
122 /* Init reflection facility. */
125 /* Init architecture dependent optimizations. */
126 arch_dep_init(arch_dep_default_factory);
127 arch_dep_set_opts(arch_dep_mul_to_shift | arch_dep_div_by_const | arch_dep_mod_by_const);
129 firm_archops_init(def_params.arch_op_settings);
132 /* integrated debugger extension */
133 firm_init_debugger();
137 void free_firm(void) {
140 for (i = get_irp_n_irgs() - 1; i >= 0; --i)
141 free_ir_graph(get_irp_irg(i));
143 free_type_entities(get_glob_type());
144 for (i = get_irp_n_types() - 1; i >= 0; --i)
145 free_type_entities(get_irp_type(i));
147 for (i = get_irp_n_types() - 1; i >= 0; --i)
148 free_type(get_irp_type(i));
159 /* Returns the libFirm version number. */
160 void firm_get_version(firm_version_t *version) {
161 version->major = libFirm_VERSION_MAJOR;
162 version->minor = libFirm_VERSION_MINOR;