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));
57 /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
58 res->graphs = NEW_ARR_F (ir_graph *, 1);
59 res->types = NEW_ARR_F (type *, 1);
66 res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
67 strlen(GLOBAL_TYPE_NAME)));
68 /* Remove type from type list. Must be treated differently than
70 remove_irp_type_from_list(res->glob_type);
72 res->const_code_irg = new_const_code_irg();
78 /** Functions to access the fields of ir_prog **/
81 /* Access the main routine of the compiled program. */
82 ir_graph *get_irp_main_irg() {
87 void set_irp_main_irg(ir_graph *main_irg) {
89 irp->main_irg = main_irg;
92 type *get_glob_type(void) {
94 return irp->glob_type = skip_tid(irp->glob_type);
97 /* Adds irg to the list of ir graphs in irp. */
98 void add_irp_irg(ir_graph *irg) {
100 assert(irp && irp->graphs);
101 ARR_APP1 (ir_graph *, irp->graphs, irg);
104 /* Removes irg from the list or irgs, shrinks the list by one. */
105 void remove_irp_irg(ir_graph *irg){
109 for (i = 1; i < (ARR_LEN (irp->graphs)); i++) {
110 if (irp->graphs[i] == irg) {
111 for(; i < (ARR_LEN (irp->graphs)) - 1; i++) {
112 irp->graphs[i] = irp->graphs[i+1];
114 ARR_SETLEN(ir_graph*, irp->graphs, (ARR_LEN(irp->graphs)) - 1);
120 int get_irp_n_irgs() {
121 assert (irp && irp->graphs);
122 /* Strangely the first element of the array is NULL. Why?? */
123 return (ARR_LEN((irp)->graphs) - 1);
126 ir_graph *get_irp_irg(int pos){
127 assert (irp && irp->graphs);
128 /* Strangely the first element of the array is NULL. Why?? */
129 return irp->graphs[pos+1];
132 void set_irp_irg(int pos, ir_graph *irg) {
134 assert (pos < (ARR_LEN((irp)->graphs) - 1));
135 /* Strangely the first element of the array is NULL. Why?? */
136 irp->graphs[pos+1] = irg;
139 /* Adds type to the list of types in irp. */
140 void add_irp_type(type *typ) {
141 assert (typ != NULL);
143 ARR_APP1 (type *, irp->types, typ);
146 void remove_irp_type(type *typ) {
147 remove_irp_type_from_list (typ);
150 int get_irp_n_types (void) {
151 assert (irp && irp->types);
152 /* Strangely the first element of the array is NULL. Why?? */
153 return (ARR_LEN((irp)->types) - 1);
156 type *get_irp_type(int pos) {
157 assert (irp && irp->types);
158 /* Strangely the first element of the array is NULL. Why?? */
159 /* Don't set the skip_tid result so that no double entries are generated. */
160 return skip_tid(irp->types[pos+1]);
163 void set_irp_type(int pos, type *typ) {
165 assert (pos < (ARR_LEN((irp)->types) - 1));
166 /* Strangely the first element of the array is NULL. Why?? */
167 irp->types[pos+1] = typ;
171 int get_irp_new_node_nr() {
173 irp->max_node_nr = irp->max_node_nr + 1;
174 return irp->max_node_nr - 1;
178 /** File name / executable name or the like **/
179 void set_irp_prog_name(ident *name) {
182 ident *get_irp_prog_ident(void) {
185 const char *get_irp_prog_name(void) {
186 return get_id_str(irp->name);
190 ir_graph *get_const_code_irg(void)
192 return irp->const_code_irg;