1 /* Copyright (C) 2000 by Universitaet Karlsruhe
4 * Authors: Goetz Lindenmaier
6 * irprog.c: ir representation of a program
17 # include "irprog_t.h"
18 # include "irgraph_t.h"
21 # include "typegmod.h"
23 #define GLOBAL_TYPE_NAME "GlobalType"
25 /* A variable from where everything in the ir can be accessed. */
27 ir_prog *get_irp() { return irp; }
29 /* initializes ir_prog. Calles the constructor for an ir_prog. */
30 void init_irprog(void) {
34 INLINE void remove_irp_type_from_list (type *typ) {
37 for (i = 1; i < (ARR_LEN (irp->types)); i++) {
38 if (irp->types[i] == typ) {
39 for(; i < (ARR_LEN (irp->types)) - 1; i++) {
40 irp->types[i] = irp->types[i+1];
42 ARR_SETLEN(type*, irp->types, (ARR_LEN(irp->types)) - 1);
48 /* Create a new ir prog. Automatically called by init_firm through
50 ir_prog *new_ir_prog (void) {
53 res = (ir_prog *) malloc (sizeof(ir_prog));
55 /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
56 res->graphs = NEW_ARR_F (ir_graph *, 1);
57 res->types = NEW_ARR_F (type *, 1);
63 res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
64 strlen(GLOBAL_TYPE_NAME)));
65 /* Remove type from type list. Must be treated differently than
67 remove_irp_type_from_list(res->glob_type);
69 res->const_code_irg = new_const_code_irg();
75 /** Functions to access the fields of ir_prog **/
78 /* Access the main routine of the compiled program. */
79 ir_graph *get_irp_main_irg() {
84 void set_irp_main_irg(ir_graph *main_irg) {
86 irp->main_irg = main_irg;
89 type *get_glob_type(void) {
91 return irp->glob_type = skip_tid(irp->glob_type);
94 /* Adds irg to the list of ir graphs in irp. */
95 void add_irp_irg(ir_graph *irg) {
97 assert(irp && irp->graphs);
98 ARR_APP1 (ir_graph *, irp->graphs, irg);
101 /* Removes irg from the list or irgs, shrinks the list by one. */
102 void remove_irp_irg(ir_graph *irg){
106 for (i = 1; i < (ARR_LEN (irp->graphs)); i++) {
107 if (irp->graphs[i] == irg) {
108 for(; i < (ARR_LEN (irp->graphs)) - 1; i++) {
109 irp->graphs[i] = irp->graphs[i+1];
111 ARR_SETLEN(ir_graph*, irp->graphs, (ARR_LEN(irp->graphs)) - 1);
117 int get_irp_n_irgs() {
118 assert (irp && irp->graphs);
119 /* Strangely the first element of the array is NULL. Why?? */
120 return (ARR_LEN((irp)->graphs) - 1);
123 ir_graph *get_irp_irg(int pos){
124 assert (irp && irp->graphs);
125 /* Strangely the first element of the array is NULL. Why?? */
126 return irp->graphs[pos+1];
129 void set_irp_irg(int pos, ir_graph *irg) {
131 assert (pos < (ARR_LEN((irp)->graphs) - 1));
132 /* Strangely the first element of the array is NULL. Why?? */
133 irp->graphs[pos+1] = irg;
136 /* Adds type to the list of types in irp. */
137 void add_irp_type(type *typ) {
138 assert (typ != NULL);
140 ARR_APP1 (type *, irp->types, typ);
143 void remove_irp_type(type *typ) {
144 remove_irp_type_from_list (typ);
147 int get_irp_n_types (void) {
148 assert (irp && irp->types);
149 /* Strangely the first element of the array is NULL. Why?? */
150 return (ARR_LEN((irp)->types) - 1);
153 type *get_irp_type(int pos) {
154 assert (irp && irp->types);
155 /* Strangely the first element of the array is NULL. Why?? */
156 /* Don't set the skip_tid result so that no double entries are generated. */
157 return skip_tid(irp->types[pos+1]);
160 void set_irp_type(int pos, type *typ) {
162 assert (pos < (ARR_LEN((irp)->types) - 1));
163 /* Strangely the first element of the array is NULL. Why?? */
164 irp->types[pos+1] = typ;
168 int get_irp_new_node_nr() {
170 irp->max_node_nr = irp->max_node_nr + 1;
171 return irp->max_node_nr - 1;
175 ir_graph *get_const_code_irg()
177 return irp->const_code_irg;