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