3 * File name: ir/ir/irprog.c
4 * Purpose: Entry point to the representation of a whole program.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 2000-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
21 # include "irprog_t.h"
22 # include "irgraph_t.h"
23 # include "pseudo_irg.h"
26 # include "typegmod.h"
28 #define GLOBAL_TYPE_NAME "GlobalType"
29 #define INITAL_PROG_NAME "no_name_set"
31 /* A variable from where everything in the ir can be accessed. */
33 ir_prog *get_irp() { return irp; }
35 /* initializes ir_prog. Calles the constructor for an ir_prog. */
36 void init_irprog(void) {
40 INLINE void remove_irp_type_from_list (type *typ) {
44 for (i = 0; i < (ARR_LEN (irp->types)); i++) {
46 for (i = ARR_LEN (irp->types) -1; i >= 0; i--) {
48 if (irp->types[i] == typ) {
49 for(; i < (ARR_LEN (irp->types)) - 1; i++) {
50 irp->types[i] = irp->types[i+1];
52 ARR_SETLEN(type*, irp->types, (ARR_LEN(irp->types)) - 1);
58 /* Create a new ir prog. Automatically called by init_firm through
60 ir_prog *new_ir_prog (void) {
63 res = (ir_prog *) xmalloc (sizeof(ir_prog));
64 memset(res, 0, sizeof(res));
66 /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
67 res->graphs = NEW_ARR_F (ir_graph *, 0);
68 res->pseudo_graphs = NEW_ARR_F (ir_graph *, 0);
69 res->types = NEW_ARR_F (type *, 0);
70 res->name = new_id_from_str(INITAL_PROG_NAME);
76 res->glob_type = new_type_class(new_id_from_str (GLOBAL_TYPE_NAME));
77 /* Remove type from type list. Must be treated differently than
79 remove_irp_type_from_list(res->glob_type);
81 res->const_code_irg = new_const_code_irg();
83 res->outs_state = outs_none;
84 res->ip_outedges = NULL;
89 /* frees all memory used by irp. Types in type list, irgs in irg
90 list and entities in global type must be freed by hand before. */
92 free_type(irp->glob_type);
93 /* @@@ * free_ir_graph(irp->const_code_irg); * ?? End has no in?? */
94 DEL_ARR_F(irp->graphs);
95 DEL_ARR_F(irp->types);
98 irp->const_code_irg = NULL;
101 /*- Functions to access the fields of ir_prog -*/
104 /* Access the main routine of the compiled program. */
105 ir_graph *get_irp_main_irg() {
107 return irp->main_irg;
110 void set_irp_main_irg(ir_graph *main_irg) {
112 irp->main_irg = main_irg;
115 type *(get_glob_type)(void) {
116 return __get_glob_type();
119 /* Adds irg to the list of ir graphs in irp. */
120 void add_irp_irg(ir_graph *irg) {
121 assert (irg != NULL);
122 assert(irp && irp->graphs);
123 ARR_APP1 (ir_graph *, irp->graphs, irg);
126 /* Removes irg from the list or irgs, shrinks the list by one. */
127 void remove_irp_irg(ir_graph *irg){
128 int i, found = false;
131 for (i = 0; i < (ARR_LEN (irp->graphs)); i++) {
132 if (irp->graphs[i] == irg) {
134 for(; i < (ARR_LEN (irp->graphs)) - 1; i++) {
135 irp->graphs[i] = irp->graphs[i+1];
137 ARR_SETLEN(ir_graph*, irp->graphs, (ARR_LEN(irp->graphs)) - 1);
142 for (i = 0; i < (ARR_LEN (irp->pseudo_graphs)); i++) {
143 if (irp->pseudo_graphs[i] == irg) {
144 for(; i < (ARR_LEN (irp->pseudo_graphs)) - 1; i++) {
145 irp->pseudo_graphs[i] = irp->pseudo_graphs[i+1];
147 ARR_SETLEN(ir_graph*, irp->pseudo_graphs, (ARR_LEN(irp->pseudo_graphs)) - 1);
154 int (get_irp_n_irgs)(void) {
155 return __get_irp_n_irgs();
158 ir_graph *(get_irp_irg)(int pos){
159 return __get_irp_irg(pos);
162 void set_irp_irg(int pos, ir_graph *irg) {
164 assert (pos < (ARR_LEN((irp)->graphs)));
165 irp->graphs[pos] = irg;
168 /* Gets the number of graphs _and_ pseudo graphs. */
169 int get_irp_n_allirgs(void) {
170 /* We can not call get_irp_n_irgs, as we end up in a recursion ... */
171 return ARR_LEN((irp)->graphs) + get_irp_n_pseudo_irgs();
174 /* Returns the ir graph at position pos of all graphs (including
175 pseudo graphs). Visits first graphs, then pseudo graphs. */
176 ir_graph *get_irp_allirg(int pos) {
177 int n_irgs = ARR_LEN((irp)->graphs);
180 return (irp)->graphs[pos];
182 return get_irp_pseudo_irg(pos-n_irgs);
187 /* Adds type to the list of types in irp. */
188 void add_irp_type(type *typ) {
189 assert (typ != NULL);
191 ARR_APP1 (type *, irp->types, typ);
194 void remove_irp_type(type *typ) {
195 remove_irp_type_from_list (typ);
198 int (get_irp_n_types) (void) {
199 return __get_irp_n_types();
202 type *(get_irp_type) (int pos) {
203 return __get_irp_type(pos);
206 void set_irp_type(int pos, type *typ) {
208 assert (pos < (ARR_LEN((irp)->types)));
209 irp->types[pos] = typ;
213 int get_irp_new_node_nr() {
215 irp->max_node_nr = irp->max_node_nr + 1;
216 return irp->max_node_nr - 1;
220 /*- File name / executable name or the like -*/
221 void set_irp_prog_name(ident *name) {
224 int irp_prog_name_is_set(void) {
225 return irp->name != new_id_from_str(INITAL_PROG_NAME);
227 ident *get_irp_prog_ident(void) {
230 const char *get_irp_prog_name(void) {
231 return get_id_str(irp->name);
235 ir_graph *(get_const_code_irg)(void)
237 return __get_const_code_irg();
240 irg_outs_state get_irp_ip_outs_state() {
241 return irp->outs_state;
244 void set_irp_ip_outs_inconsistent() {
245 irp->outs_state = outs_inconsistent;
248 void set_irp_ip_outedges(ir_node ** ip_outedges)
250 irp -> ip_outedges = ip_outedges;
253 ir_node** get_irp_ip_outedges(void)
255 return(irp -> ip_outedges);
259 irg_callee_info_state get_irp_callee_info_state(void) {
260 return irp->callee_info_state;
263 void set_irp_callee_info_state(irg_callee_info_state s) {
264 irp->callee_info_state = s;