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.
19 # include "irprog_t.h"
20 # include "irgraph_t.h"
21 # include "pseudo_irg.h"
24 # include "typegmod.h"
26 #define GLOBAL_TYPE_NAME "GlobalType"
27 #define INITAL_PROG_NAME "no_name_set"
29 /* A variable from where everything in the ir can be accessed. */
31 ir_prog *get_irp() { return irp; }
33 /* initializes ir_prog. Calles the constructor for an ir_prog. */
34 void init_irprog(void) {
38 INLINE void remove_irp_type_from_list (type *typ) {
42 for (i = 0; i < (ARR_LEN (irp->types)); i++) {
44 for (i = ARR_LEN (irp->types) -1; i >= 0; i--) {
46 if (irp->types[i] == typ) {
47 for(; i < (ARR_LEN (irp->types)) - 1; i++) {
48 irp->types[i] = irp->types[i+1];
50 ARR_SETLEN(type*, irp->types, (ARR_LEN(irp->types)) - 1);
56 /* Create a new ir prog. Automatically called by init_firm through
58 ir_prog *new_ir_prog (void) {
61 res = (ir_prog *) malloc (sizeof(ir_prog));
62 memset(res, 0, sizeof(res));
64 /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
65 res->graphs = NEW_ARR_F (ir_graph *, 0);
66 res->pseudo_graphs = NEW_ARR_F (ir_graph *, 0);
67 res->types = NEW_ARR_F (type *, 0);
68 res->name = new_id_from_str(INITAL_PROG_NAME);
74 res->glob_type = new_type_class(new_id_from_str (GLOBAL_TYPE_NAME));
75 /* Remove type from type list. Must be treated differently than
77 remove_irp_type_from_list(res->glob_type);
79 res->const_code_irg = new_const_code_irg();
81 res->outs_state = outs_none;
82 res->ip_outedges = NULL;
87 /* frees all memory used by irp. Types in type list, irgs in irg
88 list and entities in global type must be freed by hand before. */
90 free_type(irp->glob_type);
91 /* @@@ * free_ir_graph(irp->const_code_irg); * ?? End has no in?? */
92 DEL_ARR_F(irp->graphs);
93 DEL_ARR_F(irp->types);
96 irp->const_code_irg = NULL;
99 /*- Functions to access the fields of ir_prog -*/
102 /* Access the main routine of the compiled program. */
103 ir_graph *get_irp_main_irg() {
105 return irp->main_irg;
108 void set_irp_main_irg(ir_graph *main_irg) {
110 irp->main_irg = main_irg;
113 type *(get_glob_type)(void) {
114 return __get_glob_type();
117 /* Adds irg to the list of ir graphs in irp. */
118 void add_irp_irg(ir_graph *irg) {
119 assert (irg != NULL);
120 assert(irp && irp->graphs);
121 ARR_APP1 (ir_graph *, irp->graphs, irg);
124 /* Removes irg from the list or irgs, shrinks the list by one. */
125 void remove_irp_irg(ir_graph *irg){
126 int i, found = false;
129 for (i = 0; i < (ARR_LEN (irp->graphs)); i++) {
130 if (irp->graphs[i] == irg) {
132 for(; i < (ARR_LEN (irp->graphs)) - 1; i++) {
133 irp->graphs[i] = irp->graphs[i+1];
135 ARR_SETLEN(ir_graph*, irp->graphs, (ARR_LEN(irp->graphs)) - 1);
140 for (i = 0; i < (ARR_LEN (irp->pseudo_graphs)); i++) {
141 if (irp->pseudo_graphs[i] == irg) {
142 for(; i < (ARR_LEN (irp->pseudo_graphs)) - 1; i++) {
143 irp->pseudo_graphs[i] = irp->pseudo_graphs[i+1];
145 ARR_SETLEN(ir_graph*, irp->pseudo_graphs, (ARR_LEN(irp->pseudo_graphs)) - 1);
152 int (get_irp_n_irgs)(void) {
153 return __get_irp_n_irgs();
156 ir_graph *(get_irp_irg)(int pos){
157 return __get_irp_irg(pos);
160 void set_irp_irg(int pos, ir_graph *irg) {
162 assert (pos < (ARR_LEN((irp)->graphs)));
163 irp->graphs[pos] = irg;
166 /* Gets the number of graphs _and_ pseudo graphs. */
167 int get_irp_n_allirgs(void) {
168 /* We can not call get_irp_n_irgs, as we end up in a recursion ... */
169 return ARR_LEN((irp)->graphs) + get_irp_n_pseudo_irgs();
172 /* Returns the ir graph at position pos of all graphs (including
173 pseudo graphs). Visits first graphs, then pseudo graphs. */
174 ir_graph *get_irp_allirg(int pos) {
175 int n_irgs = ARR_LEN((irp)->graphs);
178 return (irp)->graphs[pos];
180 return get_irp_pseudo_irg(pos-n_irgs);
185 /* Adds type to the list of types in irp. */
186 void add_irp_type(type *typ) {
187 assert (typ != NULL);
189 ARR_APP1 (type *, irp->types, typ);
192 void remove_irp_type(type *typ) {
193 remove_irp_type_from_list (typ);
196 int (get_irp_n_types) (void) {
197 return __get_irp_n_types();
200 type *(get_irp_type) (int pos) {
201 return __get_irp_type(pos);
204 void set_irp_type(int pos, type *typ) {
206 assert (pos < (ARR_LEN((irp)->types)));
207 irp->types[pos] = typ;
211 int get_irp_new_node_nr() {
213 irp->max_node_nr = irp->max_node_nr + 1;
214 return irp->max_node_nr - 1;
218 /*- File name / executable name or the like -*/
219 void set_irp_prog_name(ident *name) {
222 int irp_prog_name_is_set(void) {
223 return irp->name != new_id_from_str(INITAL_PROG_NAME);
225 ident *get_irp_prog_ident(void) {
228 const char *get_irp_prog_name(void) {
229 return get_id_str(irp->name);
233 ir_graph *(get_const_code_irg)(void)
235 return __get_const_code_irg();
238 irg_outs_state get_irp_ip_outs_state() {
239 return irp->outs_state;
242 void set_irp_ip_outs_inconsistent() {
243 irp->outs_state = outs_inconsistent;
246 void set_irp_ip_outedges(ir_node ** ip_outedges)
248 irp -> ip_outedges = ip_outedges;
251 ir_node** get_irp_ip_outedges(void)
253 return(irp -> ip_outedges);
257 irg_callee_info_state get_irp_callee_info_state(void) {
258 return irp->callee_info_state;
261 void set_irp_callee_info_state(irg_callee_info_state s) {
262 irp->callee_info_state = s;