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){
129 for (i = 0; i < (ARR_LEN (irp->graphs)); i++) {
130 if (irp->graphs[i] == irg) {
131 for(; i < (ARR_LEN (irp->graphs)) - 1; i++) {
132 irp->graphs[i] = irp->graphs[i+1];
134 ARR_SETLEN(ir_graph*, irp->graphs, (ARR_LEN(irp->graphs)) - 1);
140 int (get_irp_n_irgs)(void) {
141 return __get_irp_n_irgs();
144 ir_graph *(get_irp_irg)(int pos){
145 return __get_irp_irg(pos);
148 void set_irp_irg(int pos, ir_graph *irg) {
150 assert (pos < (ARR_LEN((irp)->graphs)));
151 irp->graphs[pos] = irg;
154 /* Gets the number of graphs _and_ pseudo graphs. */
155 int get_irp_n_allirgs(void) {
156 /* We can not call get_irp_n_irgs, as we end up in a recursion ... */
157 return ARR_LEN((irp)->graphs) + get_irp_n_pseudo_irgs();
160 /* Returns the ir graph at position pos of all graphs (including
161 pseudo graphs). Visits first graphs, then pseudo graphs. */
162 ir_graph *get_irp_allirg(int pos) {
163 int n_irgs = get_irp_n_irgs();
165 return (irp)->graphs[pos];
167 return get_irp_pseudo_irg(pos-n_irgs);
171 /* Adds type to the list of types in irp. */
172 void add_irp_type(type *typ) {
173 assert (typ != NULL);
175 ARR_APP1 (type *, irp->types, typ);
178 void remove_irp_type(type *typ) {
179 remove_irp_type_from_list (typ);
182 int (get_irp_n_types) (void) {
183 return __get_irp_n_types();
186 type *(get_irp_type) (int pos) {
187 return __get_irp_type(pos);
190 void set_irp_type(int pos, type *typ) {
192 assert (pos < (ARR_LEN((irp)->types)));
193 irp->types[pos] = typ;
197 int get_irp_new_node_nr() {
199 irp->max_node_nr = irp->max_node_nr + 1;
200 return irp->max_node_nr - 1;
204 /*- File name / executable name or the like -*/
205 void set_irp_prog_name(ident *name) {
208 int irp_prog_name_is_set(void) {
209 return irp->name != new_id_from_str(INITAL_PROG_NAME);
211 ident *get_irp_prog_ident(void) {
214 const char *get_irp_prog_name(void) {
215 return get_id_str(irp->name);
219 ir_graph *(get_const_code_irg)(void)
221 return __get_const_code_irg();
224 irg_outs_state get_irp_ip_outs_state() {
225 return irp->outs_state;
228 void set_irp_ip_outs_inconsistent() {
229 irp->outs_state = outs_inconsistent;
232 void set_irp_ip_outedges(ir_node ** ip_outedges)
234 irp -> ip_outedges = ip_outedges;
237 ir_node** get_irp_ip_outedges(void)
239 return(irp -> ip_outedges);
243 irg_callee_info_state get_irp_callee_info_state(void) {
244 return irp->callee_info_state;
247 void set_irp_callee_info_state(irg_callee_info_state s) {
248 irp->callee_info_state = s;