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"
23 # include "typegmod.h"
25 #define GLOBAL_TYPE_NAME "GlobalType"
27 /* A variable from where everything in the ir can be accessed. */
29 ir_prog *get_irp() { return irp; }
31 /* initializes ir_prog. Calles the constructor for an ir_prog. */
32 void init_irprog(void) {
36 INLINE void remove_irp_type_from_list (type *typ) {
39 for (i = 1; i < (ARR_LEN (irp->types)); i++) {
40 if (irp->types[i] == typ) {
41 for(; i < (ARR_LEN (irp->types)) - 1; i++) {
42 irp->types[i] = irp->types[i+1];
44 ARR_SETLEN(type*, irp->types, (ARR_LEN(irp->types)) - 1);
50 /* Create a new ir prog. Automatically called by init_firm through
52 ir_prog *new_ir_prog (void) {
55 res = (ir_prog *) malloc (sizeof(ir_prog));
56 memset(res, 0, sizeof(res));
58 /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
59 res->graphs = NEW_ARR_F (ir_graph *, 1);
60 res->types = NEW_ARR_F (type *, 1);
67 res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
68 strlen(GLOBAL_TYPE_NAME)));
69 /* Remove type from type list. Must be treated differently than
71 remove_irp_type_from_list(res->glob_type);
73 res->const_code_irg = new_const_code_irg();
75 res->outs_state = no_outs;
76 res->ip_outedges = NULL;
81 /* frees all memory used by irp. Types in type list, irgs in irg
82 list and entities in global type must be freed by hand before. */
84 free_type(irp->glob_type);
85 /* @@@ * free_ir_graph(irp->const_code_irg); * ?? End has no in?? */
86 DEL_ARR_F(irp->graphs);
87 DEL_ARR_F(irp->types);
90 irp->const_code_irg = NULL;
93 /*- Functions to access the fields of ir_prog -*/
96 /* Access the main routine of the compiled program. */
97 ir_graph *get_irp_main_irg() {
102 void set_irp_main_irg(ir_graph *main_irg) {
104 irp->main_irg = main_irg;
107 type *get_glob_type(void) {
109 return irp->glob_type = skip_tid(irp->glob_type);
112 /* Adds irg to the list of ir graphs in irp. */
113 void add_irp_irg(ir_graph *irg) {
114 assert (irg != NULL);
115 assert(irp && irp->graphs);
116 ARR_APP1 (ir_graph *, irp->graphs, irg);
119 /* Removes irg from the list or irgs, shrinks the list by one. */
120 void remove_irp_irg(ir_graph *irg){
124 for (i = 1; i < (ARR_LEN (irp->graphs)); i++) {
125 if (irp->graphs[i] == irg) {
126 for(; i < (ARR_LEN (irp->graphs)) - 1; i++) {
127 irp->graphs[i] = irp->graphs[i+1];
129 ARR_SETLEN(ir_graph*, irp->graphs, (ARR_LEN(irp->graphs)) - 1);
135 int get_irp_n_irgs() {
136 assert (irp && irp->graphs);
137 /* Strangely the first element of the array is NULL. Why?? */
138 return (ARR_LEN((irp)->graphs) - 1);
141 ir_graph *get_irp_irg(int pos){
142 assert (irp && irp->graphs);
143 /* Strangely the first element of the array is NULL. Why?? */
144 return irp->graphs[pos+1];
147 void set_irp_irg(int pos, ir_graph *irg) {
149 assert (pos < (ARR_LEN((irp)->graphs) - 1));
150 /* Strangely the first element of the array is NULL. Why?? */
151 irp->graphs[pos+1] = irg;
154 /* Adds type to the list of types in irp. */
155 void add_irp_type(type *typ) {
156 assert (typ != NULL);
158 ARR_APP1 (type *, irp->types, typ);
161 void remove_irp_type(type *typ) {
162 remove_irp_type_from_list (typ);
165 int get_irp_n_types (void) {
166 assert (irp && irp->types);
167 /* Strangely the first element of the array is NULL. Why?? */
168 return (ARR_LEN((irp)->types) - 1);
171 type *get_irp_type(int pos) {
172 assert (irp && irp->types);
173 /* Strangely the first element of the array is NULL. Why?? */
174 /* Don't set the skip_tid result so that no double entries are generated. */
175 return skip_tid(irp->types[pos+1]);
178 void set_irp_type(int pos, type *typ) {
180 assert (pos < (ARR_LEN((irp)->types) - 1));
181 /* Strangely the first element of the array is NULL. Why?? */
182 irp->types[pos+1] = typ;
186 int get_irp_new_node_nr() {
188 irp->max_node_nr = irp->max_node_nr + 1;
189 return irp->max_node_nr - 1;
193 /*- File name / executable name or the like -*/
194 void set_irp_prog_name(ident *name) {
197 ident *get_irp_prog_ident(void) {
200 const char *get_irp_prog_name(void) {
201 return get_id_str(irp->name);
205 ir_graph *get_const_code_irg(void)
207 return irp->const_code_irg;
210 irg_outs_state get_irp_ip_outs_state() {
211 return irp->outs_state;
213 void set_irp_ip_outs_inconsistent() {
214 irp->outs_state = outs_inconsistent;
216 void set_irp_ip_outedges(ir_node ** ip_outedges)
218 irp -> ip_outedges = ip_outedges;
221 ir_node** get_irp_ip_outedges(void)
223 return(irp -> ip_outedges);