added new licence header
[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  * Project:     libFIRM
22  * File name:   ir/ir/irprog.h
23  * Purpose:     Entry point to the representation of a whole program.
24  * Author:      Goetz Lindenmaier
25  * Modified by:
26  * Created:     2000
27  * CVS-ID:      $Id$
28  * Copyright:   (c) 2000-2003 Universität Karlsruhe
29  */
30
31 /**
32  * @file irprog.h
33  *
34  * ir representation of a program.
35  *
36  * @author Goetz Lindenmaier
37  *
38  * This file defines a construct that keeps all information about a
39  * program:
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
51  */
52
53 #ifndef _FIRM_IR_IRPROG_H_
54 #define _FIRM_IR_IRPROG_H_
55
56 #include "firm_types.h"
57 #include "irgraph.h"
58
59
60 /**
61  * Datastructure that holds central information about a program
62  *
63  * Preliminary documentation ;-)
64  *
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.
74  *
75  */
76 typedef struct ir_prog ir_prog;
77
78 /**
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.
83  *
84  * @note
85  *      Think of the irp as the "handle" of libFirm.
86  */
87 extern ir_prog *irp;
88
89 /**
90  * Returns the access points from where everything in the ir can be accessed.
91  *
92  * @see irp
93  */
94 ir_prog *get_irp(void);
95
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);
99
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);
103
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);
107
108 /** Returns true if the user ever set a program name */
109 int    irp_prog_name_is_set(void);
110
111 /** Gets the file name / executable name or the like.
112  */
113 ident *get_irp_prog_ident(void);
114
115 /** Gets the file name / executable name or the like.
116  */
117 const char *get_irp_prog_name (void);
118
119 /** Gets the main routine of the compiled program. */
120 ir_graph *get_irp_main_irg(void);
121
122 /** Sets the main routine of the compiled program. */
123 void      set_irp_main_irg(ir_graph *main_irg);
124
125 /** Adds irg to the list of ir graphs in irp. */
126 void      add_irp_irg(ir_graph *irg);
127
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);
134
135 /** Returns the number of ir graphs in the irp. */
136 int       get_irp_n_irgs(void);
137
138 /** Returns the ir graph at position pos in the irp. */
139 ir_graph *get_irp_irg(int pos);
140
141 /** Sets the ir graph at position pos. */
142 void      set_irp_irg(int pos, ir_graph *irg);
143
144 /** Gets the number of graphs _and_ pseudo graphs. */
145 int       get_irp_n_allirgs(void);
146
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);
150
151 /**
152  * Returns the "global" type of the irp.
153  * Upon creation this is an empty class type.
154  */
155 ir_type *get_glob_type(void);
156
157 /**
158  * Returns the "thread local storage" type of the irp.
159  * Upon creation this is an empty struct type.
160  */
161 ir_type *get_tls_type(void);
162
163 /** Adds type to the list of types in irp. */
164 void  add_irp_type(ir_type *typ);
165
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);
169
170 /** Returns the number of all types in the irp. */
171 int   get_irp_n_types(void);
172
173 /** Returns the type at position pos in the irp. */
174 ir_type *get_irp_type(int pos);
175
176 /** Overwrites the type at position pos with another type. */
177 void  set_irp_type(int pos, ir_type *typ);
178
179 /** Returns the number of all modes in the irp. */
180 int   get_irp_n_modes(void);
181
182 /** Returns the mode at position pos in the irp. */
183 ir_mode *get_irp_mode(int pos);
184
185 /** Adds opcode to the list of opcodes in irp. */
186 void  add_irp_opcode(ir_op *opcode);
187
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);
191
192 /** Returns the number of all opcodes in the irp. */
193 int   get_irp_n_opcodes(void);
194
195 /** Returns the opcode at position pos in the irp. */
196 ir_op *get_irp_opcode(int pos);
197
198 /** Sets the generic function pointer of all opcodes to NULL */
199 void  clear_irp_opcodes_generic_func(void);
200
201
202 /**  Return the graph for global constants.
203  *
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
208  *   flow.
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.
212  */
213 ir_graph *get_const_code_irg(void);
214
215
216 /** The phase state for the program.
217  *
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.
223  */
224 irg_phase_state get_irp_phase_state(void);
225 void            set_irp_phase_state(irg_phase_state s);
226
227 irg_outs_state get_irp_ip_outs_state(void);
228 void           set_irp_ip_outs_inconsistent(void);
229
230
231 irg_callee_info_state get_irp_callee_info_state(void);
232 void                  set_irp_callee_info_state(irg_callee_info_state s);
233
234 #endif /* ifndef _FIRM_IR_IRPROG_H_ */