Loads do not remove any nodes from the exec after sets. Also fix a 'node leak'.
[libfirm] / ir / ana2 / pto.c
1 /* -*- c -*- */
2
3 /*
4  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
5  *
6  * This file is part of libFirm.
7  *
8  * This file may be distributed and/or modified under the terms of the
9  * GNU General Public License version 2 as published by the Free Software
10  * Foundation and appearing in the file LICENSE.GPL included in the
11  * packaging of this file.
12  *
13  * Licensees holding valid libFirm Professional Edition licenses may use
14  * this file in accordance with the libFirm Commercial License.
15  * Agreement provided with the Software.
16  *
17  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE.
20  */
21
22 /**
23  * @file
24  * @brief   Entry to PTO
25  * @author  Florian
26  * @date    Tue Nov 23 18:37:09 CET 2004
27  * @version $Id$
28  */
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 /*
34  pto: Entry to PTO
35 */
36
37 #ifdef HAVE_STRING_H
38 # include <string.h>
39 #endif
40
41 # include "pto.h"
42
43 # include "irnode_t.h"
44 # include "irprog.h"
45 # include "xmalloc.h"
46
47 # include "pto_debug.h"
48 # include "pto_init.h"
49 # include "pto_name.h"
50 # include "pto_ctx.h"
51 # include "ecg.h"
52
53 /* Local Defines: */
54
55 /* Local Data Types: */
56
57 /* Local Variables: */
58 extern char *spaces;
59
60 /* Local Prototypes: */
61
62 /* ===================================================
63    Local Implementation:
64    =================================================== */
65
66 /* Helper to pto_init */
67 static void pto_init_graph_wrapper (graph_info_t *ginfo, void *_unused)
68 {
69   ir_graph *graph = ginfo->graph;
70
71   pto_init_graph (graph);
72 }
73
74 /* ===================================================
75    Exported Implementation:
76    =================================================== */
77 /* Initialise the module (not in pto_init.c because it's the entry to pto) */
78 void pto_init (int lvl)
79 {
80   set_dbg_lvl (lvl);
81
82   ecg_init (1);
83
84   /* Initialise the name module */
85   pto_name_init ();
86
87   /* Initialise the init module */
88   pto_init_init ();
89
90   /* allocate ctx-sens names for allocs and set ... etc etc */
91   pto_init_type_names ();
92
93   /* initialise all graphs with the static names */
94   ecg_iterate_graphs (pto_init_graph_wrapper, NULL);
95
96   /* debugging only */
97   spaces = xmalloc (512 * sizeof (char));
98   memset (spaces, ' ', 512);
99   spaces += 511;
100   *spaces = '\0';
101
102   /* initialise for the CTX-sensitive ecg-traversal */
103   set_curr_ctx (get_main_ctx ());
104 }
105
106 void pto_run (void)
107 {
108   ir_graph *save;
109   ir_graph *graph = get_irp_main_irg ();
110
111   pto_reset_graph_pto (graph, 0);
112   fake_main_args (graph);
113
114   DBGPRINT (1, (stdout, "START PTO\n"));
115   DBGPRINT (1, (stdout, "START GRAPH (0x%08x) of \"%s.%s\"\n",
116                 (int) graph,
117                 get_type_name (get_entity_owner (get_irg_entity (graph))),
118                 get_entity_name (get_irg_entity (graph))));
119
120   /* we need some kind of environment here: NULL */
121   save = get_current_ir_graph ();
122   pto_graph (graph, 0, NULL);
123   set_current_ir_graph (save);
124
125   DBGPRINT (1, (stdout, "END   PTO\n"));
126 }
127
128 /* Dump all interesting stuff to a bunch of files */
129 void pto_dump (void)
130 {
131   pto_dump_names ("names.dot");
132 }
133
134 void pto_cleanup (void)
135 {
136   /* todo: clean up our own mess */
137   spaces -= 511;                /* hope that all changes to spaces are
138                                    properly nested */
139   memset (spaces, 0x00, 512);
140   free (spaces);
141
142   /* Cleanup the name module */
143   pto_name_cleanup ();
144   /* Cleanup the Init module */
145   pto_init_cleanup ();
146
147   /* clean up ecg infos */
148   ecg_cleanup ();
149 }
150
151 \f
152 /*
153   $Log$
154   Revision 1.17  2005/01/10 17:26:34  liekweg
155   fixup printfs, don't put environments on the stack
156
157   Revision 1.16  2004/12/22 14:43:14  beck
158   made allocations C-like
159
160   Revision 1.15  2004/12/21 14:26:53  beck
161   removed C99 constructs
162
163   Revision 1.14  2004/12/20 17:41:14  liekweg
164   __unused -> _unused
165
166   Revision 1.13  2004/12/20 17:34:34  liekweg
167   fix recursion handling
168
169   Revision 1.12  2004/12/02 16:17:51  beck
170   fixed config.h include
171
172   Revision 1.11  2004/11/30 15:49:27  liekweg
173   include 'dump'
174
175   Revision 1.10  2004/11/30 14:46:41  liekweg
176   Correctly reset main graph; remove dbugging stuff
177
178   Revision 1.9  2004/11/26 16:01:56  liekweg
179   debugging annotations
180
181   Revision 1.8  2004/11/24 14:54:21  liekweg
182   Added pto.c as main entry point
183
184
185 */