added call to init_hooks
[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
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
16
17 #ifdef HAVE_STRING_H
18 # include <string.h>
19 #endif
20
21 # include <stdio.h>
22
23 # include "ident_t.h"
24 # include "firm.h"
25 # include "mangle.h"
26 /* init functions are not public */
27 # include "tv_t.h"
28 # include "tpop_t.h"
29 # include "irprog_t.h"
30 # include "irnode_t.h"
31 # include "irmode_t.h"
32 # include "ircons_t.h"
33 # include "irgraph_t.h"
34 # include "type_t.h"
35 # include "type_identify.h"
36 # include "firmstat.h"
37 # include "irreflect_t.h"
38 # include "irarch.h"
39 # include "reassoc_t.h"
40 # include "irhooks.h"
41
42 void
43 init_firm(const firm_parameter_t *param)
44 {
45   firm_parameter_t def_params;
46   unsigned int     size;
47
48   memset(&def_params, 0, sizeof(def_params));
49
50   if (param) {
51     /* check for reasonale size */
52     assert(param->size <= sizeof(def_params) && (param->size & 3) == 0 &&
53            "parameter struct not initialized ???");
54     size = sizeof(def_params);
55     if (param->size < size)
56       size = param->size;
57
58     memcpy(&def_params, param, size);
59   }
60
61   /* initialize all ident stuff */
62   init_ident(def_params.id_if, 1024);
63   /* initialize Firm hooks */
64   init_hooks();
65   /* enhanced statistics, need idents and hooks */
66   init_stat(def_params.enable_statistics);
67   /* create the type kinds. */
68   init_tpop();
69   /* create an obstack and put all tarvals in a pdeq */
70   init_tarval_1();
71   /* initialize all modes an ir node can consist of */
72   init_mode();
73   /* initialize tarvals, and floating point arithmetic */
74   init_tarval_2();
75   /* init graph construction */
76   init_irgraph();
77   /* kind of obstack initialization */
78   firm_init_mangle();
79   /* initalize all op codes an irnode can consist of */
80   init_op();
81   /* called once for each run of this library */
82   init_cons(def_params.initialize_local_func);
83   /* initialize reassociation */
84   firm_init_reassociation();
85   /* Builds a construct allowing to access all information to be constructed
86      later. */
87   init_irprog();
88   /* Constructs some idents needed. */
89   init_type();
90   init_entity();
91   /* allocate a hash table. */
92   init_type_identify(def_params.ti_if);
93   /* Init reflection facility. */
94   init_rflct();
95
96   /* Init architecture dependent optimizations. */
97   arch_dep_init(arch_dep_default_factory);
98   arch_dep_set_opts(arch_dep_mul_to_shift | arch_dep_div_by_const | arch_dep_mod_by_const);
99 }
100
101
102 void free_firm(void) {
103   int i;
104
105   for (i = 0; i < get_irp_n_irgs(); i++)
106     free_ir_graph(get_irp_irg(i));
107
108   for (i = 0; i < get_irp_n_types(); i++) {
109     free_type_entities(get_irp_type(i));
110     free_type(get_irp_type(i));
111   }
112
113   free_type_entities(get_glob_type());
114   free_ir_prog();
115
116   finish_tarval();
117   finish_op();
118   finish_mode();
119   finish_tpop();
120   finish_ident();
121 }