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