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