treatment of pseudo irgs
[libfirm] / ir / ir / irprog.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irprog.h
4  * Purpose:     Entry point to the representation of a whole program.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:     2000
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2000-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14 * @file irprog.h
15 *
16 * ir representation of a program.
17 *
18 * @author Goetz Lindenmaier
19 *
20 * This file defines a construct that keeps all information about a
21 * program:
22 *   - A reference point to the method to be executed on program start.
23 *   - A list of all procedures.
24 *   - A list of all types.
25 *   - A global type that contais all global variables and procedures that do
26 *     not belong to a class.  This type represents the data segment of the
27 *     program.  It is not the base class of
28 *     all classes in a class hierarchy (as, e.g., "object" in java).
29 *   - A degenerated graph that contains constant expressions.
30 *   - interprocedural outs state.
31 *   - a flag indicating validity of the interprocedural representation.
32 *   - the output file name
33 */
34
35 # ifndef _IRPROG_H_
36 # define _IRPROG_H_
37
38 # include "irnode.h"
39 # include "type.h"
40
41
42 /**
43  * Datastructure that holds central information about a program
44  *
45  * Preliminary documentation ;-)
46  *
47  * - main_irg:  The ir graph that is the entry point to the program.
48  *              (Anything not reachable from here may be optimized away.
49  *              If we want to translate libraries or the like correctly
50  *              we must replace this by a list.)
51  * - irg:       List of all ir graphs in the program.
52  * - type:      A list containing all types known to the translated program.
53  *              Some types can have several entries in this list (as a result of
54  *              using exchange_types()).
55  * - glob_type: The unique global type that is owner of all global entities.
56  *
57  */
58 typedef struct ir_prog ir_prog;
59
60 /**
61  * A variable from where everything in the ir can be accessed.
62  * This variable contains the irp, the "immediate representation program".
63  * This variable should be considered constant. Moreover, one should use get_irp()
64  * to get access the the irp.
65  *
66  * @note
67  *      Think of the irp as the "handle" of libFirm.
68  */
69 extern ir_prog *irp;
70
71 /**
72  * Returns the access points from where everything in the ir can be accessed.
73  *
74  * @see irp
75  */
76 ir_prog *get_irp(void);
77
78 /** Creates a new ir_prog, returns it and sets irp with it.
79  *  Automatically called by init_firm() through init_irprog. */
80 ir_prog *new_ir_prog (void);
81
82 /** frees all memory used by irp.  Types in type list and irgs in irg
83  *  list must be freed by hand before. */
84 void     free_ir_prog(void);
85
86 /** Sets the file name / executable name or the like. Initially the
87     ident 'no_name_set'. */
88 void   set_irp_prog_name (ident *name);
89
90 /** Returns true if the user ever set a program name */
91 int    irp_prog_name_is_set(void);
92
93 /** Gets the file name / executable name or the like.
94  */
95 ident *get_irp_prog_ident(void);
96
97 /** Gets the file name / executable name or the like.
98  */
99 const char *get_irp_prog_name (void);
100
101 /** Gets the main routine of the compiled program. */
102 ir_graph *get_irp_main_irg(void);
103
104 /** Sets the main routine of the compiled program. */
105 void      set_irp_main_irg(ir_graph *main_irg);
106
107 /** Adds irg to the list of ir graphs in irp. */
108 void      add_irp_irg(ir_graph *irg);
109
110 /** Removes irg from the list of irgs, deallocates it and
111     shrinks the list by one. */
112 void      remove_irp_irg(ir_graph *irg);
113
114 /** Returns the number of ir graphs in the irp. */
115 int       get_irp_n_irgs(void);
116
117 /** Returns the ir graph at position pos in the irp. */
118 ir_graph *get_irp_irg(int pos);
119
120 /** Sets the ir graph at position pos. */
121 void      set_irp_irg(int pos, ir_graph *irg);
122
123 /** Gets the number of graphs _and_ pseudo graphs. */
124 int       get_irp_n_allirgs(void);
125
126 /** Returns the ir graph at position pos of all graphs (including
127  pseudo graphs).  Visits first graphs, then pseudo graphs. */
128 ir_graph *get_irp_allirg(int pos);
129
130
131 /** Returns the "global" type of the irp. */
132 type *get_glob_type(void);
133
134 /** Adds type to the list of types in irp. */
135 void  add_irp_type(type *typ);
136
137 /** Removes type from the list of types, deallocates it and
138     shrinks the list by one. */
139 void  remove_irp_type(type *typ);
140
141 /** Returns the number of all types in the irp. */
142 int   get_irp_n_types(void);
143
144 /** Returns the type at position pos in the irp. */
145 type *get_irp_type(int pos);
146
147 /** Overwrites the type at position pos with another type. */
148 void  set_irp_type(int pos, type *typ);
149
150 /**  Return the graph for global constants.
151  *
152  *   Returns an irgraph that only contains constant expressions for
153  *   constant entities.  Do not use any access function for this
154  *   graph, do not generate code for this graph.  This graph contains
155  *   only one block.  The constant expressions may not contain control
156  *   flow.
157  *   Walking the graph starting from any node will not reach the block
158  *   or any controlflow.
159  *   See also copy_const_code() in entity.h.
160  */
161 ir_graph *get_const_code_irg(void);
162
163 irg_outs_state get_irp_ip_outs_state(void);
164 void           set_irp_ip_outs_inconsistent(void);
165
166
167 irg_callee_info_state get_irp_callee_info_state(void);
168 void                  set_irp_callee_info_state(irg_callee_info_state s);
169
170 #endif /* ifndef _IRPROG_H_ */