disabled show after showgraph, as it is (or was?) buggy
[libfirm] / ir / ana2 / pto.c
1 /* -*- c -*- */
2
3 /*
4    Project:     libFIRM
5    File name:   ir/ana/pto.c
6    Purpose:     Entry to PTO
7    Author:      Florian
8    Modified by:
9    Created:     Tue Nov 23 18:37:09 CET 2004
10    CVS-ID:      $Id$
11    Copyright:   (c) 1999-2004 Universität Karlsruhe
12    Licence:     This file is protected by the GPL -  GNU GENERAL PUBLIC LICENSE.
13 */
14
15 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
18
19 /*
20  pto: Entry to PTO
21 */
22
23 #ifdef HAVE_STRING_H
24 # include <string.h>
25 #endif
26
27 # include "pto.h"
28
29 # include "irnode_t.h"
30 # include "irprog.h"
31 # include "xmalloc.h"
32
33 # include "pto_debug.h"
34 # include "pto_init.h"
35 # include "pto_name.h"
36 # include "pto_ctx.h"
37 # include "ecg.h"
38
39 /* Local Defines: */
40
41 /* Local Data Types: */
42
43 /* Local Variables: */
44 extern char *spaces;
45
46 /* Local Prototypes: */
47
48 /* ===================================================
49    Local Implementation:
50    =================================================== */
51
52 /* Helper to pto_init */
53 static void pto_init_graph_wrapper (graph_info_t *ginfo, void *_unused)
54 {
55   ir_graph *graph = ginfo->graph;
56
57   pto_init_graph (graph);
58 }
59
60 /* ===================================================
61    Exported Implementation:
62    =================================================== */
63 /* Initialise the module (not in pto_init.c because it's the entry to pto) */
64 void pto_init (int lvl)
65 {
66   set_dbg_lvl (lvl);
67
68   ecg_init (1);
69
70   /* Initialise the name module */
71   pto_name_init ();
72
73   /* Initialise the init module */
74   pto_init_init ();
75
76   /* allocate ctx-sens names for allocs and set ... etc etc */
77   pto_init_type_names ();
78
79   /* initialise all graphs with the static names */
80   ecg_iterate_graphs (pto_init_graph_wrapper, NULL);
81
82   /* debugging only */
83   spaces = xmalloc (512 * sizeof (char));
84   memset (spaces, ' ', 512);
85   spaces += 511;
86   *spaces = '\0';
87
88   /* initialise for the CTX-sensitive ecg-traversal */
89   set_curr_ctx (get_main_ctx ());
90 }
91
92 void pto_run (void)
93 {
94   ir_graph *save;
95   ir_graph *graph = get_irp_main_irg ();
96
97   pto_reset_graph_pto (graph, 0);
98   fake_main_args (graph);
99
100   DBGPRINT (1, (stdout, "START PTO\n"));
101   DBGPRINT (1, (stdout, "START GRAPH (0x%08x) of \"%s.%s\"\n",
102                 (int) graph,
103                 get_type_name (get_entity_owner (get_irg_entity (graph))),
104                 get_entity_name (get_irg_entity (graph))));
105
106   /* we need some kind of environment here: NULL */
107   save = get_current_ir_graph ();
108   pto_graph (graph, 0, NULL);
109   set_current_ir_graph (save);
110
111   DBGPRINT (1, (stdout, "END   PTO\n"));
112 }
113
114 /* Dump all interesting stuff to a bunch of files */
115 void pto_dump (void)
116 {
117   pto_dump_names ("names.dot");
118 }
119
120 void pto_cleanup (void)
121 {
122   /* todo: clean up our own mess */
123   spaces -= 511;                /* hope that all changes to spaces are
124                                    properly nested */
125   memset (spaces, 0x00, 512);
126   free (spaces);
127
128   /* Cleanup the name module */
129   pto_name_cleanup ();
130   /* Cleanup the Init module */
131   pto_init_cleanup ();
132
133   /* clean up ecg infos */
134   ecg_cleanup ();
135 }
136
137 \f
138 /*
139   $Log$
140   Revision 1.17  2005/01/10 17:26:34  liekweg
141   fixup printfs, don't put environments on the stack
142
143   Revision 1.16  2004/12/22 14:43:14  beck
144   made allocations C-like
145
146   Revision 1.15  2004/12/21 14:26:53  beck
147   removed C99 constructs
148
149   Revision 1.14  2004/12/20 17:41:14  liekweg
150   __unused -> _unused
151
152   Revision 1.13  2004/12/20 17:34:34  liekweg
153   fix recursion handling
154
155   Revision 1.12  2004/12/02 16:17:51  beck
156   fixed config.h include
157
158   Revision 1.11  2004/11/30 15:49:27  liekweg
159   include 'dump'
160
161   Revision 1.10  2004/11/30 14:46:41  liekweg
162   Correctly reset main graph; remove dbugging stuff
163
164   Revision 1.9  2004/11/26 16:01:56  liekweg
165   debugging annotations
166
167   Revision 1.8  2004/11/24 14:54:21  liekweg
168   Added pto.c as main entry point
169
170
171 */