added firm_ycomp debugger extension
[libfirm] / ir / common / firm.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/common/firm.c
4  * Purpose:     Central firm functionality.
5  * Author:      Martin Trapp, Christian Schaefer
6  * Modified by: Goetz Lindenmaier
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12 #ifdef HAVE_CONFIG_H
13 # include "config.h"
14 #endif
15
16 #ifdef HAVE_STRING_H
17 # include <string.h>
18 #endif
19 #ifdef HAVE_STDIO_H
20 # include <stdio.h>
21 #endif
22
23 #ifdef WITH_LIBCORE
24 # include <libcore/lc_opts.h>
25 #endif
26
27 #include "ident_t.h"
28 #include "firm.h"
29 #include "irflag_t.h"
30 #include "mangle.h"
31 /* init functions are not public */
32 #include "tv_t.h"
33 #include "tpop_t.h"
34 #include "irprog_t.h"
35 #include "irnode_t.h"
36 #include "irmode_t.h"
37 #include "ircons_t.h"
38 #include "irgraph_t.h"
39 #include "type_t.h"
40 #include "entity_t.h"
41 #include "type_identify.h"
42 #include "firmstat.h"
43 #include "irreflect_t.h"
44 #include "irarch.h"
45 #include "reassoc_t.h"
46 #include "irhooks.h"
47 #include "iredges_t.h"
48 #include "debugger.h"
49 #include "firm_ycomp.h"
50
51 #ifdef WITH_LIBCORE
52 /* returns the firm root */
53 lc_opt_entry_t *firm_opt_get_root(void) {
54         static lc_opt_entry_t *grp = NULL;
55         if(!grp)
56                 grp = lc_opt_get_grp(lc_opt_root_grp(), "firm");
57         return grp;
58 }
59
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);
63 }
64 #endif /* WITH_LIBCORE */
65
66 void
67 init_firm(const firm_parameter_t *param)
68 {
69   firm_parameter_t def_params;
70   unsigned int     size;
71
72   memset(&def_params, 0, sizeof(def_params));
73
74   if (param) {
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)
80       size = param->size;
81
82     memcpy(&def_params, param, size);
83   }
84
85   /* initialize firm flags */
86   firm_init_flags();
87   /* initialize all ident stuff */
88   init_ident(def_params.id_if, 1024);
89   /* initialize Firm hooks */
90   firm_init_hooks();
91   /* enhanced statistics, need idents and hooks */
92   firm_init_stat(def_params.enable_statistics);
93   /* Edges need hooks. */
94   init_edges();
95   /* create the type kinds. */
96   init_tpop();
97   /* create an obstack and put all tarvals in a pdeq */
98   init_tarval_1(0l);
99   /* Builds a basic program representation, so modes can be added. */
100   init_irprog_1();
101   /* initialize all modes an ir node can consist of */
102   init_mode();
103   /* initialize tarvals, and floating point arithmetic */
104   init_tarval_2();
105   /* init graph construction */
106   firm_init_irgraph();
107   /* kind of obstack initialization */
108   firm_init_mangle();
109   /* initialize all op codes an irnode can consist of */
110   init_op();
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
116      later. */
117   init_irprog_2();
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 */
121   firm_init_entity();
122   /* allocate a hash table. */
123   init_type_identify(def_params.ti_if);
124   /* Init reflection facility. */
125   firm_init_rflct();
126
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);
130
131   firm_archops_init(def_params.arch_op_settings);
132
133 #ifndef NDEBUG
134   /* integrated debugger extension */
135   firm_init_debugger();
136   firm_init_ycomp_debugger(NULL, 0);
137 #endif
138 }
139
140 void free_firm(void) {
141   int i;
142
143   for (i = get_irp_n_irgs() - 1; i >= 0; --i)
144     free_ir_graph(get_irp_irg(i));
145
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));
149
150   for (i = get_irp_n_types() - 1; i >= 0; --i)
151     free_type(get_irp_type(i));
152
153   finish_op();
154   free_ir_prog();
155
156   finish_tarval();
157   finish_mode();
158   finish_tpop();
159   finish_ident();
160 #ifndef NDEBUG
161   firm_finish_ycomp_debugger();
162 #endif
163 }
164
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;
169 }