the calling conventions are now part of the type (as expected), not of the graph
[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 "entity_t.h"
36 # include "type_identify.h"
37 # include "firmstat.h"
38 # include "irreflect_t.h"
39 # include "irarch.h"
40 # include "reassoc_t.h"
41 # include "irhooks.h"
42 # include "iredges_t.h"
43 # include "debugger.h"
44
45 void
46 init_firm(const firm_parameter_t *param)
47 {
48   firm_parameter_t def_params;
49   unsigned int     size;
50
51   memset(&def_params, 0, sizeof(def_params));
52
53   if (param) {
54     /* check for reasonable size */
55     assert(param->size <= sizeof(def_params) && (param->size & 3) == 0 &&
56            "parameter struct not initialized ???");
57     size = sizeof(def_params);
58     if (param->size < size)
59       size = param->size;
60
61     memcpy(&def_params, param, size);
62   }
63
64   /* initialize all ident stuff */
65   init_ident(def_params.id_if, 1024);
66   /* initialize Firm hooks */
67   init_hooks();
68   /* enhanced statistics, need idents and hooks */
69   init_stat(def_params.enable_statistics);
70   /* Edges need hooks. */
71   init_edges();
72   /* create the type kinds. */
73   init_tpop();
74   /* create an obstack and put all tarvals in a pdeq */
75   init_tarval_1();
76   /* Builds a basic program representation, so modes can be added. */
77   init_irprog_1();
78   /* initialize all modes an ir node can consist of */
79   init_mode();
80   /* initialize tarvals, and floating point arithmetic */
81   init_tarval_2();
82   /* init graph construction */
83   firm_init_irgraph();
84   /* kind of obstack initialization */
85   firm_init_mangle();
86   /* initialize all op codes an irnode can consist of */
87   init_op();
88   /* called once for each run of this library */
89   init_cons(def_params.initialize_local_func);
90   /* initialize reassociation */
91   firm_init_reassociation();
92   /* Builds a construct allowing to access all information to be constructed
93      later. */
94   init_irprog_2();
95   /* Initialize the type module and construct some idents needed. */
96   firm_init_type(def_params.builtin_dbg, def_params.cc_mask);
97   /* initialize the entity module */
98   firm_init_entity();
99   /* allocate a hash table. */
100   init_type_identify(def_params.ti_if);
101   /* Init reflection facility. */
102   firm_init_rflct();
103
104   /* Init architecture dependent optimizations. */
105   arch_dep_init(arch_dep_default_factory);
106   arch_dep_set_opts(arch_dep_mul_to_shift | arch_dep_div_by_const | arch_dep_mod_by_const);
107
108   firm_archops_init(def_params.arch_op_settings);
109
110 #ifndef NDEBUG
111   /* integrated debugger extension */
112   firm_init_debugger();
113 #endif
114 }
115
116
117 void free_firm(void) {
118   int i;
119
120   for (i = get_irp_n_irgs() - 1; i >= 0; --i)
121     free_ir_graph(get_irp_irg(i));
122
123   free_type_entities(get_glob_type());
124   for (i = get_irp_n_types() - 1; i >= 0; --i)
125     free_type_entities(get_irp_type(i));
126
127   for (i = get_irp_n_types() - 1; i >= 0; --i)
128     free_type(get_irp_type(i));
129
130   free_ir_prog();
131
132   finish_tarval();
133   finish_op();
134   finish_mode();
135   finish_tpop();
136   finish_ident();
137 }