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