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