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