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(void) { return irp; }
35 /* initializes ir_prog. Calles the constructor for an ir_prog. */
36 void init_irprog(void) {
40 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 = xmalloc (sizeof(*res));
64 memset(res, 0, sizeof(*res));
66 /* res->obst = xmalloc (sizeof(*res->obst)); */
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;
85 res->trouts_state = outs_none;
86 res->class_cast_state = ir_class_casts_transitive;
91 /* frees all memory used by irp. Types in type list, irgs in irg
92 list and entities in global type must be freed by hand before. */
93 void free_ir_prog(void) {
94 free_type(irp->glob_type);
95 /* @@@ * free_ir_graph(irp->const_code_irg); * ?? End has no in?? */
96 DEL_ARR_F(irp->graphs);
97 DEL_ARR_F(irp->types);
100 irp->const_code_irg = NULL;
103 /*- Functions to access the fields of ir_prog -*/
106 /* Access the main routine of the compiled program. */
107 ir_graph *get_irp_main_irg(void) {
109 return irp->main_irg;
112 void set_irp_main_irg(ir_graph *main_irg) {
114 irp->main_irg = main_irg;
117 type *(get_glob_type)(void) {
118 return __get_glob_type();
121 /* Adds irg to the list of ir graphs in irp. */
122 void add_irp_irg(ir_graph *irg) {
123 assert (irg != NULL);
124 assert(irp && irp->graphs);
125 ARR_APP1 (ir_graph *, irp->graphs, irg);
128 /* Removes irg from the list or irgs, shrinks the list by one. */
129 void remove_irp_irg_from_list(ir_graph *irg){
130 int i, found = false;
132 for (i = 0; i < (ARR_LEN (irp->graphs)); i++) {
133 if (irp->graphs[i] == irg) {
135 for(; i < (ARR_LEN (irp->graphs)) - 1; i++) {
136 irp->graphs[i] = irp->graphs[i+1];
138 ARR_SETLEN(ir_graph*, irp->graphs, (ARR_LEN(irp->graphs)) - 1);
143 for (i = 0; i < (ARR_LEN (irp->pseudo_graphs)); i++) {
144 if (irp->pseudo_graphs[i] == irg) {
145 for(; i < (ARR_LEN (irp->pseudo_graphs)) - 1; i++) {
146 irp->pseudo_graphs[i] = irp->pseudo_graphs[i+1];
148 ARR_SETLEN(ir_graph*, irp->pseudo_graphs, (ARR_LEN(irp->pseudo_graphs)) - 1);
155 /* Removes irg from the list or irgs, shrinks the list by one. */
156 void remove_irp_irg(ir_graph *irg){
159 remove_irp_irg_from_list(irg);
162 int (get_irp_n_irgs)(void) {
163 return __get_irp_n_irgs();
166 ir_graph *(get_irp_irg)(int pos){
167 return __get_irp_irg(pos);
170 void set_irp_irg(int pos, ir_graph *irg) {
172 assert (pos < (ARR_LEN((irp)->graphs)));
173 irp->graphs[pos] = irg;
176 /* Gets the number of graphs _and_ pseudo graphs. */
177 int get_irp_n_allirgs(void) {
178 /* We can not call get_irp_n_irgs, as we end up in a recursion ... */
179 return ARR_LEN((irp)->graphs) + get_irp_n_pseudo_irgs();
182 /* Returns the ir graph at position pos of all graphs (including
183 pseudo graphs). Visits first graphs, then pseudo graphs. */
184 ir_graph *get_irp_allirg(int pos) {
185 int n_irgs = ARR_LEN((irp)->graphs);
188 return (irp)->graphs[pos];
190 return get_irp_pseudo_irg(pos-n_irgs);
195 /* Adds type to the list of types in irp. */
196 void add_irp_type(type *typ) {
197 assert (typ != NULL);
199 ARR_APP1 (type *, irp->types, typ);
202 void remove_irp_type(type *typ) {
203 remove_irp_type_from_list (typ);
206 int (get_irp_n_types) (void) {
207 return __get_irp_n_types();
210 type *(get_irp_type) (int pos) {
211 return __get_irp_type(pos);
214 void set_irp_type(int pos, type *typ) {
216 assert (pos < (ARR_LEN((irp)->types)));
217 irp->types[pos] = typ;
221 int get_irp_new_node_nr() {
223 irp->max_node_nr = irp->max_node_nr + 1;
224 return irp->max_node_nr - 1;
228 /*- File name / executable name or the like -*/
229 void set_irp_prog_name(ident *name) {
232 int irp_prog_name_is_set(void) {
233 return irp->name != new_id_from_str(INITAL_PROG_NAME);
235 ident *get_irp_prog_ident(void) {
238 const char *get_irp_prog_name(void) {
239 return get_id_str(irp->name);
243 ir_graph *(get_const_code_irg)(void)
245 return __get_const_code_irg();
248 irg_phase_state get_irp_phase_state(void) {
249 return irp->phase_state;
251 void set_irp_phase_state(irg_phase_state s) {
252 irp->phase_state = s;
255 irg_outs_state get_irp_ip_outs_state() {
256 return irp->outs_state;
259 void set_irp_ip_outs_inconsistent() {
260 irp->outs_state = outs_inconsistent;
263 void set_irp_ip_outedges(ir_node ** ip_outedges)
265 irp->ip_outedges = ip_outedges;
268 ir_node** get_irp_ip_outedges(void)
270 return irp->ip_outedges;
274 irg_callee_info_state get_irp_callee_info_state(void) {
275 return irp->callee_info_state;
278 void set_irp_callee_info_state(irg_callee_info_state s) {
279 irp->callee_info_state = s;