2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Entry point to the representation of a whole program.
23 * @author Goetz Lindenmaier
27 * Intermediate Representation (IR) of a program.
29 * This file defines a construct that keeps all information about a
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 * - interprocedural outs state.
40 * - a flag indicating validity of the interprocedural representation.
41 * - the output file name
43 #ifndef FIRM_IR_IRPROG_H
44 #define FIRM_IR_IRPROG_H
46 #include "firm_types.h"
50 * Datastructure that holds central information about a program
52 * Preliminary documentation ;-)
54 * - main_irg: The ir graph that is the entry point to the program.
55 * (Anything not reachable from here may be optimized away.
56 * If we want to translate libraries or the like correctly
57 * we must replace this by a list.)
58 * - irg: List of all ir graphs in the program.
59 * - type: A list containing all types known to the translated program.
60 * Some types can have several entries in this list (as a result of
61 * using exchange_types()).
62 * - glob_type: The unique global type that is owner of all global entities.
65 typedef struct ir_prog ir_prog;
68 * A variable from where everything in the ir can be accessed.
69 * This variable contains the irp, the "immediate representation program".
70 * This variable should be considered constant. Moreover, one should use get_irp()
71 * to get access the the irp.
74 * Think of the irp as the "handle" of libFirm.
79 * Returns the access points from where everything in the ir can be accessed.
83 ir_prog *get_irp(void);
85 /** Creates a new ir_prog, returns it and sets irp with it.
86 * Automatically called by init_firm() through init_irprog. */
87 ir_prog *new_ir_prog(void);
89 /** frees all memory used by irp. Types in type list and irgs in irg
90 * list must be freed by hand before. */
91 void free_ir_prog(void);
93 /** Sets the file name / executable name or the like. Initially the
94 ident 'no_name_set'. */
95 void set_irp_prog_name(ident *name);
97 /** Returns true if the user ever set a program name */
98 int irp_prog_name_is_set(void);
100 /** Gets the file name / executable name or the like.
102 ident *get_irp_prog_ident(void);
104 /** Gets the file name / executable name or the like.
106 const char *get_irp_prog_name (void);
108 /** Gets the main routine of the compiled program. */
109 ir_graph *get_irp_main_irg(void);
111 /** Sets the main routine of the compiled program. */
112 void set_irp_main_irg(ir_graph *main_irg);
114 /** Adds irg to the list of ir graphs in irp. */
115 void add_irp_irg(ir_graph *irg);
117 /** Removes irg from the list of irgs and
118 shrinks the list by one. */
119 void remove_irp_irg_from_list(ir_graph *irg);
120 /** Removes irg from the list of irgs, deallocates it and
121 shrinks the list by one. */
122 void remove_irp_irg(ir_graph *irg);
124 /** returns the biggest not used irg index number */
125 int get_irp_last_idx(void);
127 /** Returns the number of ir graphs in the irp. */
128 int get_irp_n_irgs(void);
130 /** Returns the ir graph at position pos in the irp. */
131 ir_graph *get_irp_irg(int pos);
133 /** Sets the ir graph at position pos. */
134 void set_irp_irg(int pos, ir_graph *irg);
136 /** Gets the number of graphs _and_ pseudo graphs. */
137 int get_irp_n_allirgs(void);
139 /** Returns the ir graph at position pos of all graphs (including
140 pseudo graphs). Visits first graphs, then pseudo graphs. */
141 ir_graph *get_irp_allirg(int pos);
144 * Returns the "global" type of the irp.
145 * Upon creation this is an empty class type.
147 ir_type *get_glob_type(void);
150 * Returns the "thread local storage" type of the irp.
151 * Upon creation this is an empty struct type.
153 ir_type *get_tls_type(void);
156 * returns the constructors type containing entities that should be put in
157 * the constructos section. (The constructors section contains pointers to
158 * module constructor functions)
160 ir_type *get_constructors_type(void);
162 /** Adds type to the list of types in irp. */
163 void add_irp_type(ir_type *typ);
165 /** Removes type from the list of types, deallocates it and
166 shrinks the list by one. */
167 void remove_irp_type(ir_type *typ);
169 /** Returns the number of all types in the irp. */
170 int get_irp_n_types(void);
172 /** Returns the type at position pos in the irp. */
173 ir_type *get_irp_type(int pos);
175 /** Overwrites the type at position pos with another type. */
176 void set_irp_type(int pos, ir_type *typ);
178 /** Returns the number of all modes in the irp. */
179 int get_irp_n_modes(void);
181 /** Returns the mode at position pos in the irp. */
182 ir_mode *get_irp_mode(int pos);
184 /** Adds opcode to the list of opcodes in irp. */
185 void add_irp_opcode(ir_op *opcode);
187 /** Removes opcode from the list of opcodes, deallocates it and
188 shrinks the list by one. */
189 void remove_irp_opcode(ir_op *opcode);
191 /** Returns the number of all opcodes in the irp. */
192 int get_irp_n_opcodes(void);
194 /** Returns the opcode at position pos in the irp. */
195 ir_op *get_irp_opcode(int pos);
197 /** Sets the generic function pointer of all opcodes to NULL */
198 void clear_irp_opcodes_generic_func(void);
201 /** Return the graph for global constants.
203 * Returns an irgraph that only contains constant expressions for
204 * constant entities. Do not use any access function for this
205 * graph, do not generate code for this graph. This graph contains
206 * only one block. The constant expressions may not contain control
208 * Walking the graph starting from any node will not reach the block
209 * or any controlflow.
210 * See also copy_const_code() in entity.h.
212 ir_graph *get_const_code_irg(void);
215 /** The phase state for the program.
217 * The phase state of the whole program is
218 * building: if at least one graph is state_building
219 * or one type is incomplete.
220 * high: all graphs are in state high or low, all types are constructed.
221 * low: all graphs are in state low, all types are in state layout fixed.
223 irg_phase_state get_irp_phase_state(void);
224 void set_irp_phase_state(irg_phase_state s);
226 irg_outs_state get_irp_ip_outs_state(void);
227 void set_irp_ip_outs_inconsistent(void);
230 irg_callee_info_state get_irp_callee_info_state(void);
231 void set_irp_callee_info_state(irg_callee_info_state s);
233 /** Returns a new, unique exception region number. */
234 ir_exc_region_t get_irp_next_region_nr(void);
236 /** Returns a new, unique label number. */
237 ir_label_t get_irp_next_label_nr(void);