Add is_Conv().
[libfirm] / ir / ir / irprog.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Entry point to the representation of a whole program.
23  * @author  Goetz Lindenmaier
24  * @date    2000
25  * @version $Id$
26  * @summary
27  *  ir representation of a program.
28  *
29  *  This file defines a construct that keeps all information about a
30  *  program:
31  *   - A reference point to the method to be executed on program start.
32  *   - A list of all procedures.
33  *   - A list of all types.
34  *   - A global type that contais all global variables and procedures that do
35  *     not belong to a class.  This type represents the data segment of the
36  *     program.  It is not the base class of
37  *     all classes in a class hierarchy (as, e.g., "object" in java).
38  *   - A degenerated graph that contains constant expressions.
39  *   - interprocedural outs state.
40  *   - a flag indicating validity of the interprocedural representation.
41  *   - the output file name
42  */
43 #ifndef FIRM_IR_IRPROG_H
44 #define FIRM_IR_IRPROG_H
45
46 #include "firm_types.h"
47 #include "irgraph.h"
48
49
50 /**
51  * Datastructure that holds central information about a program
52  *
53  * Preliminary documentation ;-)
54  *
55  * - main_irg:  The ir graph that is the entry point to the program.
56  *              (Anything not reachable from here may be optimized away.
57  *              If we want to translate libraries or the like correctly
58  *              we must replace this by a list.)
59  * - irg:       List of all ir graphs in the program.
60  * - type:      A list containing all types known to the translated program.
61  *              Some types can have several entries in this list (as a result of
62  *              using exchange_types()).
63  * - glob_type: The unique global type that is owner of all global entities.
64  *
65  */
66 typedef struct ir_prog ir_prog;
67
68 /**
69  * A variable from where everything in the ir can be accessed.
70  * This variable contains the irp, the "immediate representation program".
71  * This variable should be considered constant. Moreover, one should use get_irp()
72  * to get access the the irp.
73  *
74  * @note
75  *      Think of the irp as the "handle" of libFirm.
76  */
77 extern ir_prog *irp;
78
79 /**
80  * Returns the access points from where everything in the ir can be accessed.
81  *
82  * @see irp
83  */
84 ir_prog *get_irp(void);
85
86 /** Creates a new ir_prog, returns it and sets irp with it.
87  *  Automatically called by init_firm() through init_irprog. */
88 ir_prog *new_ir_prog (void);
89
90 /** frees all memory used by irp.  Types in type list and irgs in irg
91  *  list must be freed by hand before. */
92 void     free_ir_prog(void);
93
94 /** Sets the file name / executable name or the like. Initially the
95     ident 'no_name_set'. */
96 void   set_irp_prog_name (ident *name);
97
98 /** Returns true if the user ever set a program name */
99 int    irp_prog_name_is_set(void);
100
101 /** Gets the file name / executable name or the like.
102  */
103 ident *get_irp_prog_ident(void);
104
105 /** Gets the file name / executable name or the like.
106  */
107 const char *get_irp_prog_name (void);
108
109 /** Gets the main routine of the compiled program. */
110 ir_graph *get_irp_main_irg(void);
111
112 /** Sets the main routine of the compiled program. */
113 void      set_irp_main_irg(ir_graph *main_irg);
114
115 /** Adds irg to the list of ir graphs in irp. */
116 void      add_irp_irg(ir_graph *irg);
117
118 /** Removes irg from the list of irgs and
119     shrinks the list by one. */
120 void      remove_irp_irg_from_list(ir_graph *irg);
121 /** Removes irg from the list of irgs, deallocates it and
122     shrinks the list by one. */
123 void      remove_irp_irg(ir_graph *irg);
124
125 /** Returns the number of ir graphs in the irp. */
126 int       get_irp_n_irgs(void);
127
128 /** Returns the ir graph at position pos in the irp. */
129 ir_graph *get_irp_irg(int pos);
130
131 /** Sets the ir graph at position pos. */
132 void      set_irp_irg(int pos, ir_graph *irg);
133
134 /** Gets the number of graphs _and_ pseudo graphs. */
135 int       get_irp_n_allirgs(void);
136
137 /** Returns the ir graph at position pos of all graphs (including
138  pseudo graphs).  Visits first graphs, then pseudo graphs. */
139 ir_graph *get_irp_allirg(int pos);
140
141 /**
142  * Returns the "global" type of the irp.
143  * Upon creation this is an empty class type.
144  */
145 ir_type *get_glob_type(void);
146
147 /**
148  * Returns the "thread local storage" type of the irp.
149  * Upon creation this is an empty struct type.
150  */
151 ir_type *get_tls_type(void);
152
153 /** Adds type to the list of types in irp. */
154 void  add_irp_type(ir_type *typ);
155
156 /** Removes type from the list of types, deallocates it and
157     shrinks the list by one. */
158 void  remove_irp_type(ir_type *typ);
159
160 /** Returns the number of all types in the irp. */
161 int   get_irp_n_types(void);
162
163 /** Returns the type at position pos in the irp. */
164 ir_type *get_irp_type(int pos);
165
166 /** Overwrites the type at position pos with another type. */
167 void  set_irp_type(int pos, ir_type *typ);
168
169 /** Returns the number of all modes in the irp. */
170 int   get_irp_n_modes(void);
171
172 /** Returns the mode at position pos in the irp. */
173 ir_mode *get_irp_mode(int pos);
174
175 /** Adds opcode to the list of opcodes in irp. */
176 void  add_irp_opcode(ir_op *opcode);
177
178 /** Removes opcode from the list of opcodes, deallocates it and
179     shrinks the list by one. */
180 void  remove_irp_opcode(ir_op *opcode);
181
182 /** Returns the number of all opcodes in the irp. */
183 int   get_irp_n_opcodes(void);
184
185 /** Returns the opcode at position pos in the irp. */
186 ir_op *get_irp_opcode(int pos);
187
188 /** Sets the generic function pointer of all opcodes to NULL */
189 void  clear_irp_opcodes_generic_func(void);
190
191
192 /**  Return the graph for global constants.
193  *
194  *   Returns an irgraph that only contains constant expressions for
195  *   constant entities.  Do not use any access function for this
196  *   graph, do not generate code for this graph.  This graph contains
197  *   only one block.  The constant expressions may not contain control
198  *   flow.
199  *   Walking the graph starting from any node will not reach the block
200  *   or any controlflow.
201  *   See also copy_const_code() in entity.h.
202  */
203 ir_graph *get_const_code_irg(void);
204
205
206 /** The phase state for the program.
207  *
208  *  The phase state of the whole program is
209  *   building:  if at least one graph is state_building
210  *              or one type is incomplete.
211  *   high:      all graphs are in state high or low, all types are constructed.
212  *   low:       all graphs are in state low, all types are in state layout fixed.
213  */
214 irg_phase_state get_irp_phase_state(void);
215 void            set_irp_phase_state(irg_phase_state s);
216
217 irg_outs_state get_irp_ip_outs_state(void);
218 void           set_irp_ip_outs_inconsistent(void);
219
220
221 irg_callee_info_state get_irp_callee_info_state(void);
222 void                  set_irp_callee_info_state(irg_callee_info_state s);
223
224 #endif