More infos for the librarycally challenged folks
[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 # include "irarch.h"
34
35 void
36 init_firm(const firm_parameter_t *param)
37 {
38   firm_parameter_t def_params;
39   unsigned int     size;
40
41   memset(&def_params, 0, sizeof(def_params));
42
43   if (param) {
44     /* check for reasonale size */
45     assert(param->size <= sizeof(def_params) && (param->size & 3) == 0 &&
46            "parameter struct not initialized ???");
47     size = sizeof(def_params);
48     if (param->size < size)
49       size = param->size;
50
51     memcpy(&def_params, param, size);
52   }
53
54   /* initialize all ident stuff */
55   init_ident(def_params.id_if, 1024);
56   /* enhanced statistics, need idents */
57   init_stat(def_params.enable_statistics);
58   /* create the type kinds. */
59   init_tpop();
60   /* create an obstack and put all tarvals in a pdeq */
61   init_tarval_1();
62   /* initialize all modes an ir node can consist of */
63   init_mode();
64   /* initialize tarvals, and floating point arithmetic */
65   init_tarval_2();
66   /* init graph construction */
67   init_irgraph();
68   /* kind of obstack initialization */
69   firm_init_mangle();
70   /* initalize all op codes an irnode can consist of */
71   init_op();
72   /* called once for each run of this library */
73   init_cons(def_params.initialize_local_func);
74   /* Builds a construct allowing to access all information to be constructed
75      later. */
76   init_irprog();
77   /* Constructs some idents needed. */
78   init_type();
79   /* allocate a hash table. */
80   init_type_identify(def_params.ti_if);
81   /* Init reflection facility. */
82   init_rflct();
83
84   /* Init architecture dependent optimizations. */
85   arch_dep_init(arch_dep_default_factory);
86   arch_dep_set_opts(arch_dep_mul_to_shift | arch_dep_div_to_shift | arch_dep_mod_to_shift);
87 }
88
89
90 void free_firm(void) {
91   int i;
92
93   for (i = 0; i < get_irp_n_irgs(); i++)
94     free_ir_graph(get_irp_irg(i));
95
96   for (i = 0; i < get_irp_n_types(); i++) {
97     free_type_entities(get_irp_type(i));
98     free_type(get_irp_type(i));
99   }
100
101   free_type_entities(get_glob_type());
102   free_ir_prog();
103
104   finish_tarval();
105   finish_op();
106   finish_mode();
107   finish_tpop();
108   finish_ident();
109 }