sparc: pattern to match xnor
[libfirm] / include / libfirm / irprog.h
1 /*
2  * Copyright (C) 1995-2008 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  * @brief
27  *  Intermediate Representation (IR) 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 contains 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  *   - the output file name
40  */
41 #ifndef FIRM_IR_IRPROG_H
42 #define FIRM_IR_IRPROG_H
43
44 #include "firm_types.h"
45 #include "irgraph.h"
46 #include "begin.h"
47
48 typedef enum ir_segment_t {
49         IR_SEGMENT_FIRST,
50         /** "normal" global data */
51         IR_SEGMENT_GLOBAL = IR_SEGMENT_FIRST,
52         /** thread local storage segment */
53         IR_SEGMENT_THREAD_LOCAL,
54         /**
55          * the constructors segment. Contains pointers to functions which are
56          * executed on module initialization (program start or when a library is
57          * dynamically loaded)
58          */
59         IR_SEGMENT_CONSTRUCTORS,
60         /** like constructors, but functions are executed on module exit */
61         IR_SEGMENT_DESTRUCTORS,
62
63         IR_SEGMENT_LAST = IR_SEGMENT_DESTRUCTORS
64 } ir_segment_t;
65
66 /**
67  * A variable pointing to the current irp (program or module).
68  * This variable should be considered constant. Moreover, one should use get_irp()
69  * to get access the the irp.
70  *
71  * @note
72  *      Think of the irp as the "handle" of a program.
73  */
74 FIRM_API ir_prog *irp;
75
76 #ifndef NDEBUG
77 FIRM_API void irp_reserve_resources(ir_prog *irp, ir_resources_t resources);
78 FIRM_API void irp_free_resources(ir_prog *irp, ir_resources_t resources);
79 FIRM_API ir_resources_t irp_resources_reserved(const ir_prog *irp);
80 #else
81 #define irp_reserve_resources(irp, resources)
82 #define irp_free_resources(irp, resources)
83 #define irp_resources_reserved(irp)   0
84 #endif
85
86 /**
87  * Returns the current irp from where everything in the current module
88  * can be accessed.
89  *
90  * @see irp
91  */
92 FIRM_API ir_prog *get_irp(void);
93
94 /**
95  * Set current irp
96  */
97 FIRM_API void set_irp(ir_prog *irp);
98
99 /**
100  * Creates a new ir_prog (a module or compilation unit).
101  * Note: This does not set irp to the newly created ir_prog
102  *
103  * @param name  the name of this irp (module)
104  */
105 FIRM_API ir_prog *new_ir_prog(const char *name);
106
107 /** frees all memory used by irp.  Types in type list and irgs in irg
108  *  list must be freed by hand before. */
109 FIRM_API void free_ir_prog(void);
110
111 /** Sets the file name / executable name or the like. Initially the
112     ident 'no_name_set'. */
113 FIRM_API void set_irp_prog_name(ident *name);
114
115 /** Returns true if the user ever set a program name */
116 FIRM_API int irp_prog_name_is_set(void);
117
118 /** Gets the name of the current irp. */
119 FIRM_API ident *get_irp_ident(void);
120
121 /** Gets the name of the current irp. */
122 FIRM_API const char *get_irp_name(void);
123
124 /** Gets the main routine of the compiled program. */
125 FIRM_API ir_graph *get_irp_main_irg(void);
126
127 /** Sets the main routine of the compiled program. */
128 FIRM_API void set_irp_main_irg(ir_graph *main_irg);
129
130 /** Adds irg to the list of ir graphs in the current irp. */
131 FIRM_API void add_irp_irg(ir_graph *irg);
132
133 /** Removes irg from the list of irgs and
134     shrinks the list by one. */
135 FIRM_API void remove_irp_irg_from_list(ir_graph *irg);
136 /** Removes irg from the list of irgs, deallocates it and
137     shrinks the list by one. */
138 FIRM_API void remove_irp_irg(ir_graph *irg);
139
140 /** returns the biggest not used irg index number */
141 FIRM_API int get_irp_last_idx(void);
142
143 /** Returns the number of ir graphs in the irp. */
144 FIRM_API int get_irp_n_irgs(void);
145
146 /** Returns the ir graph at position pos in the irp. */
147 FIRM_API ir_graph *get_irp_irg(int pos);
148
149 /** Sets the ir graph at position pos. */
150 FIRM_API void set_irp_irg(int pos, ir_graph *irg);
151
152 /**
153  * Returns the type containing the entities for a segment.
154  *
155  * @param segment  the segment
156  */
157 FIRM_API ir_type *get_segment_type(ir_segment_t segment);
158
159 /**
160  * @brief Changes a segment segment type for the program.
161  * (use with care)
162  */
163 FIRM_API void set_segment_type(ir_segment_t segment, ir_type *new_type);
164
165 /**
166  * Returns the "global" type of the irp.
167  * Upon creation this is an empty class type.
168  * This is a convenience function for get_segment_type(IR_SEGMENT_GLOBAL)
169  */
170 FIRM_API ir_type *get_glob_type(void);
171
172 /**
173  * Returns the "thread local storage" type of the irp.
174  * Upon creation this is an empty struct type.
175  * This is a convenience function for get_segment_type(IR_SEGMENT_THREAD_LOCAL)
176  */
177 FIRM_API ir_type *get_tls_type(void);
178
179 /** Adds type to the list of types in irp. */
180 FIRM_API void add_irp_type(ir_type *typ);
181
182 /** Removes type from the list of types, deallocates it and
183     shrinks the list by one. */
184 FIRM_API void remove_irp_type(ir_type *typ);
185
186 /**
187  * Returns the number of all types in the irp.
188  * @deprecated
189  */
190 FIRM_API int get_irp_n_types(void);
191
192 /**
193  * Returns the type at position pos in the irp.
194  * @deprecated
195  */
196 FIRM_API ir_type *get_irp_type(int pos);
197
198 /**
199  * Overwrites the type at position pos with another type.
200  * @deprecated
201  */
202 FIRM_API void set_irp_type(int pos, ir_type *typ);
203
204 /** Returns the number of all modes in the irp. */
205 FIRM_API int get_irp_n_modes(void);
206
207 /** Returns the mode at position pos in the irp. */
208 FIRM_API ir_mode *get_irp_mode(int pos);
209
210 /** Adds opcode to the list of opcodes in irp. */
211 FIRM_API void add_irp_opcode(ir_op *opcode);
212
213 /** Removes opcode from the list of opcodes, deallocates it and
214     shrinks the list by one. */
215 FIRM_API void remove_irp_opcode(ir_op *opcode);
216
217 /** Returns the number of all opcodes in the irp. */
218 FIRM_API int get_irp_n_opcodes(void);
219
220 /** Returns the opcode at position pos in the irp. */
221 FIRM_API ir_op *get_irp_opcode(int pos);
222
223 /** Sets the generic function pointer of all opcodes to NULL */
224 FIRM_API void clear_irp_opcodes_generic_func(void);
225
226
227 /**  Return the graph for global constants of the current irp.
228  *
229  *   Returns an irgraph that only contains constant expressions for
230  *   constant entities.  Do not use any access function for this
231  *   graph, do not generate code for this graph.  This graph contains
232  *   only one block.  The constant expressions may not contain control
233  *   flow.
234  *   Walking the graph starting from any node will not reach the block
235  *   or any controlflow.
236  *   See also copy_const_code() in entity.h.
237  */
238 FIRM_API ir_graph *get_const_code_irg(void);
239
240
241 /** The phase state for the program.
242  *
243  *  The phase state of the whole program is
244  *   building:  if at least one graph is state_building
245  *              or one type is incomplete.
246  *   high:      all graphs are in state high or low, all types are constructed.
247  *   low:       all graphs are in state low, all types are in state layout fixed.
248  */
249 FIRM_API irg_phase_state get_irp_phase_state(void);
250 FIRM_API void            set_irp_phase_state(irg_phase_state s);
251
252 FIRM_API irg_outs_state get_irp_ip_outs_state(void);
253 FIRM_API void           set_irp_ip_outs_inconsistent(void);
254
255 /**
256  * Creates an ir_prog pass for set_irp_phase_state().
257  *
258  * @param name   the name of this pass or NULL
259  * @param state  the state to set
260  *
261  * @return  the newly created ir_prog pass
262  */
263 FIRM_API ir_prog_pass_t *set_irp_phase_state_pass(const char *name,
264                                                   irg_phase_state state);
265
266 FIRM_API irg_callee_info_state get_irp_callee_info_state(void);
267 FIRM_API void                  set_irp_callee_info_state(irg_callee_info_state s);
268
269 /** Returns a new, unique exception region number. */
270 FIRM_API ir_exc_region_t get_irp_next_region_nr(void);
271
272 /** Returns a new, unique label number. */
273 FIRM_API ir_label_t get_irp_next_label_nr(void);
274
275 /** Add a new global asm include. */
276 FIRM_API void add_irp_asm(ident *asm_string);
277
278 /** Return the number of global asm includes. */
279 FIRM_API int get_irp_n_asms(void);
280
281 /** Return the global asm include at position pos. */
282 FIRM_API ident *get_irp_asm(int pos);
283
284 #include "end.h"
285
286 #endif