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.
13 /* Ini file in local directory */
14 #define LOCAL_INI_FILE "firm.ini"
16 /* Includes to determine user's home directory */
19 #define HOME_DIR_INI_FILE LOCAL_INI_FILE
21 #include <sys/types.h>
23 #define HOME_DIR_INI_FILE ".firmrc"
37 #include <libcore/lc_opts.h>
42 # include "irflag_t.h"
44 /* init functions are not public */
47 # include "irprog_t.h"
48 # include "irnode_t.h"
49 # include "irmode_t.h"
50 # include "ircons_t.h"
51 # include "irgraph_t.h"
53 # include "entity_t.h"
54 # include "type_identify.h"
55 # include "firmstat.h"
56 # include "irreflect_t.h"
58 # include "reassoc_t.h"
60 # include "iredges_t.h"
61 # include "debugger.h"
64 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");
74 init_firm(const firm_parameter_t *param)
76 firm_parameter_t def_params;
79 memset(&def_params, 0, sizeof(def_params));
82 /* check for reasonable size */
83 assert(param->size <= sizeof(def_params) && (param->size & 3) == 0 &&
84 "parameter struct not initialized ???");
85 size = sizeof(def_params);
86 if (param->size < size)
89 memcpy(&def_params, param, size);
92 /* initialize firm flags */
94 /* initialize all ident stuff */
95 init_ident(def_params.id_if, 1024);
96 /* initialize Firm hooks */
98 /* enhanced statistics, need idents and hooks */
99 firm_init_stat(def_params.enable_statistics);
100 /* Edges need hooks. */
102 /* create the type kinds. */
104 /* create an obstack and put all tarvals in a pdeq */
106 /* Builds a basic program representation, so modes can be added. */
108 /* initialize all modes an ir node can consist of */
110 /* initialize tarvals, and floating point arithmetic */
112 /* init graph construction */
114 /* kind of obstack initialization */
116 /* initialize all op codes an irnode can consist of */
118 /* called once for each run of this library */
119 init_cons(def_params.initialize_local_func);
120 /* initialize reassociation */
121 firm_init_reassociation();
122 /* Builds a construct allowing to access all information to be constructed
125 /* Initialize the type module ancd cr d construct some idents needed. */
126 firm_init_type(def_params.builtin_dbg, def_params.cc_mask);
127 /* initialize the entity module */
129 /* allocate a hash table. */
130 init_type_identify(def_params.ti_if);
131 /* Init reflection facility. */
134 /* Init architecture dependent optimizations. */
135 arch_dep_init(arch_dep_default_factory);
136 arch_dep_set_opts(arch_dep_mul_to_shift | arch_dep_div_by_const | arch_dep_mod_by_const);
138 firm_archops_init(def_params.arch_op_settings);
141 /* integrated debugger extension */
142 firm_init_debugger();
151 SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, path);
152 strncat(path, "\\", sizeof(path));
155 strcpy(path, getpwuid(getuid())->pw_dir);
156 strncat(path, "/", sizeof(path));
159 strncat(path, HOME_DIR_INI_FILE, sizeof(path));
161 /* Process ini file in user's home. */
162 f = fopen(path, "rt");
164 lc_opt_from_file(path, f, NULL);
168 /* Process ini file in current directory. */
169 f = fopen(LOCAL_INI_FILE, "rt");
171 lc_opt_from_file(LOCAL_INI_FILE, f, NULL);
175 /* process arguments from the command line */
176 lc_opt_from_argv(firm_opt_get_root(), def_params.arg_prefix, def_params.argc, def_params.argv, NULL);
181 void free_firm(void) {
184 for (i = get_irp_n_irgs() - 1; i >= 0; --i)
185 free_ir_graph(get_irp_irg(i));
187 free_type_entities(get_glob_type());
188 for (i = get_irp_n_types() - 1; i >= 0; --i)
189 free_type_entities(get_irp_type(i));
191 for (i = get_irp_n_types() - 1; i >= 0; --i)
192 free_type(get_irp_type(i));
203 /* Returns the libFirm version number. */
204 void firm_get_version(firm_version_t *version) {
205 version->major = libFirm_VERSION_MAJOR;
206 version->minor = libFirm_VERSION_MINOR;