2 * Copyright (C) 1995-2007 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 * File name: ir/ir/irprog.h
23 * Purpose: Entry point to the representation of a whole program.
24 * Author: Goetz Lindenmaier
28 * Copyright: (c) 2000-2003 Universität Karlsruhe
34 * ir representation of a program.
36 * @author Goetz Lindenmaier
38 * This file defines a construct that keeps all information about a
40 * - A reference point to the method to be executed on program start.
41 * - A list of all procedures.
42 * - A list of all types.
43 * - A global type that contais all global variables and procedures that do
44 * not belong to a class. This type represents the data segment of the
45 * program. It is not the base class of
46 * all classes in a class hierarchy (as, e.g., "object" in java).
47 * - A degenerated graph that contains constant expressions.
48 * - interprocedural outs state.
49 * - a flag indicating validity of the interprocedural representation.
50 * - the output file name
53 #ifndef _FIRM_IR_IRPROG_H_
54 #define _FIRM_IR_IRPROG_H_
56 #include "firm_types.h"
61 * Datastructure that holds central information about a program
63 * Preliminary documentation ;-)
65 * - main_irg: The ir graph that is the entry point to the program.
66 * (Anything not reachable from here may be optimized away.
67 * If we want to translate libraries or the like correctly
68 * we must replace this by a list.)
69 * - irg: List of all ir graphs in the program.
70 * - type: A list containing all types known to the translated program.
71 * Some types can have several entries in this list (as a result of
72 * using exchange_types()).
73 * - glob_type: The unique global type that is owner of all global entities.
76 typedef struct ir_prog ir_prog;
79 * A variable from where everything in the ir can be accessed.
80 * This variable contains the irp, the "immediate representation program".
81 * This variable should be considered constant. Moreover, one should use get_irp()
82 * to get access the the irp.
85 * Think of the irp as the "handle" of libFirm.
90 * Returns the access points from where everything in the ir can be accessed.
94 ir_prog *get_irp(void);
96 /** Creates a new ir_prog, returns it and sets irp with it.
97 * Automatically called by init_firm() through init_irprog. */
98 ir_prog *new_ir_prog (void);
100 /** frees all memory used by irp. Types in type list and irgs in irg
101 * list must be freed by hand before. */
102 void free_ir_prog(void);
104 /** Sets the file name / executable name or the like. Initially the
105 ident 'no_name_set'. */
106 void set_irp_prog_name (ident *name);
108 /** Returns true if the user ever set a program name */
109 int irp_prog_name_is_set(void);
111 /** Gets the file name / executable name or the like.
113 ident *get_irp_prog_ident(void);
115 /** Gets the file name / executable name or the like.
117 const char *get_irp_prog_name (void);
119 /** Gets the main routine of the compiled program. */
120 ir_graph *get_irp_main_irg(void);
122 /** Sets the main routine of the compiled program. */
123 void set_irp_main_irg(ir_graph *main_irg);
125 /** Adds irg to the list of ir graphs in irp. */
126 void add_irp_irg(ir_graph *irg);
128 /** Removes irg from the list of irgs and
129 shrinks the list by one. */
130 void remove_irp_irg_from_list(ir_graph *irg);
131 /** Removes irg from the list of irgs, deallocates it and
132 shrinks the list by one. */
133 void remove_irp_irg(ir_graph *irg);
135 /** Returns the number of ir graphs in the irp. */
136 int get_irp_n_irgs(void);
138 /** Returns the ir graph at position pos in the irp. */
139 ir_graph *get_irp_irg(int pos);
141 /** Sets the ir graph at position pos. */
142 void set_irp_irg(int pos, ir_graph *irg);
144 /** Gets the number of graphs _and_ pseudo graphs. */
145 int get_irp_n_allirgs(void);
147 /** Returns the ir graph at position pos of all graphs (including
148 pseudo graphs). Visits first graphs, then pseudo graphs. */
149 ir_graph *get_irp_allirg(int pos);
152 * Returns the "global" type of the irp.
153 * Upon creation this is an empty class type.
155 ir_type *get_glob_type(void);
158 * Returns the "thread local storage" type of the irp.
159 * Upon creation this is an empty struct type.
161 ir_type *get_tls_type(void);
163 /** Adds type to the list of types in irp. */
164 void add_irp_type(ir_type *typ);
166 /** Removes type from the list of types, deallocates it and
167 shrinks the list by one. */
168 void remove_irp_type(ir_type *typ);
170 /** Returns the number of all types in the irp. */
171 int get_irp_n_types(void);
173 /** Returns the type at position pos in the irp. */
174 ir_type *get_irp_type(int pos);
176 /** Overwrites the type at position pos with another type. */
177 void set_irp_type(int pos, ir_type *typ);
179 /** Returns the number of all modes in the irp. */
180 int get_irp_n_modes(void);
182 /** Returns the mode at position pos in the irp. */
183 ir_mode *get_irp_mode(int pos);
185 /** Adds opcode to the list of opcodes in irp. */
186 void add_irp_opcode(ir_op *opcode);
188 /** Removes opcode from the list of opcodes, deallocates it and
189 shrinks the list by one. */
190 void remove_irp_opcode(ir_op *opcode);
192 /** Returns the number of all opcodes in the irp. */
193 int get_irp_n_opcodes(void);
195 /** Returns the opcode at position pos in the irp. */
196 ir_op *get_irp_opcode(int pos);
198 /** Sets the generic function pointer of all opcodes to NULL */
199 void clear_irp_opcodes_generic_func(void);
202 /** Return the graph for global constants.
204 * Returns an irgraph that only contains constant expressions for
205 * constant entities. Do not use any access function for this
206 * graph, do not generate code for this graph. This graph contains
207 * only one block. The constant expressions may not contain control
209 * Walking the graph starting from any node will not reach the block
210 * or any controlflow.
211 * See also copy_const_code() in entity.h.
213 ir_graph *get_const_code_irg(void);
216 /** The phase state for the program.
218 * The phase state of the whole program is
219 * building: if at least one graph is state_building
220 * or one type is incomplete.
221 * high: all graphs are in state high or low, all types are constructed.
222 * low: all graphs are in state low, all types are in state layout fixed.
224 irg_phase_state get_irp_phase_state(void);
225 void set_irp_phase_state(irg_phase_state s);
227 irg_outs_state get_irp_ip_outs_state(void);
228 void set_irp_ip_outs_inconsistent(void);
231 irg_callee_info_state get_irp_callee_info_state(void);
232 void set_irp_callee_info_state(irg_callee_info_state s);
234 #endif /* ifndef _FIRM_IR_IRPROG_H_ */