added missing include directory
[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 #  include <string.h>
24
25 # include "pto.h"
26
27 # include "irnode.h"
28 # include "irprog.h"
29 # include "xmalloc.h"
30
31 # include "pto_debug.h"
32 # include "pto_init.h"
33 # include "pto_name.h"
34 # include "pto_ctx.h"
35 # include "ecg.h"
36
37 /* Local Defines: */
38
39 /* Local Data Types: */
40
41 /* Local Variables: */
42 extern char *spaces;
43
44 /* Local Prototypes: */
45
46 /* ===================================================
47    Local Implementation:
48    =================================================== */
49
50 /* Helper to pto_init */
51 static void pto_init_graph_wrapper (graph_info_t *ginfo, void *__unused)
52 {
53   ir_graph *graph = ginfo->graph;
54
55   pto_init_graph (graph);
56 }
57
58 /* ===================================================
59    Exported Implementation:
60    =================================================== */
61 /* Initialise the module (not in pto_init.c because it's the entry to pto) */
62 void pto_init (int lvl)
63 {
64   set_dbg_lvl (lvl);
65
66   ecg_init (1);
67
68   /* Initialise the name module */
69   pto_name_init ();
70
71   /* Initialise the init module */
72   pto_init_init ();
73
74   /* allocate ctx-sens names for allocs and set ... etc etc */
75   pto_init_type_names ();
76
77   /* initialise all graphs with the static names */
78   ecg_iterate_graphs (pto_init_graph_wrapper, NULL);
79
80   /* debugging only */
81   spaces = (char*) xmalloc (512 * sizeof (char));
82   memset (spaces, ' ', 512);
83   spaces += 511;
84   *spaces = '\0';
85
86   /* initialise for the CTX-sensitive ecg-traversal */
87   set_curr_ctx (get_main_ctx ());
88 }
89
90 void pto_run ()
91 {
92   ir_graph *graph = get_irp_main_irg ();
93
94   pto_reset_graph_pto (graph, 0);
95   fake_main_args (graph);
96
97   DBGPRINT (1, (stdout, "START PTO\n"));
98   DBGPRINT (1, (stdout, "START GRAPH (0x%08x) of \"%s.%s\"\n",
99                 (int) graph,
100                 get_type_name (get_entity_owner (get_irg_entity (graph))),
101                 get_entity_name (get_irg_entity (graph))));
102
103   /* do we need some kind of environment here? */
104   pto_graph (graph, 0);
105
106   DBGPRINT (1, (stdout, "END   PTO\n"));
107 }
108
109 /* Dump all interesting stuff to a bunch of files */
110 void pto_dump ()
111 {
112   pto_dump_names ("names.dot");
113 }
114
115 void pto_cleanup ()
116 {
117   /* todo: clean up our own mess */
118   spaces -= 511;                /* hope that all changes to spaces are
119                                    properly nested */
120   memset (spaces, 0x00, 512);
121   free (spaces);
122
123   /* Cleanup the name module */
124   pto_name_cleanup ();
125   /* Cleanup the Init module */
126   pto_init_cleanup ();
127
128   /* clean up ecg infos */
129   ecg_cleanup ();
130 }
131
132 \f
133 /*
134   $Log$
135   Revision 1.11  2004/11/30 15:49:27  liekweg
136   include 'dump'
137
138   Revision 1.10  2004/11/30 14:46:41  liekweg
139   Correctly reset main graph; remove dbugging stuff
140
141   Revision 1.9  2004/11/26 16:01:56  liekweg
142   debugging annotations
143
144   Revision 1.8  2004/11/24 14:54:21  liekweg
145   Added pto.c as main entry point
146
147
148 */