end block can not be optimized away any more.
[libfirm] / ir / ir / irprog.c
1 /* Copyright (C) 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
3 **
4 ** Authors: Goetz Lindenmaier
5 **
6 ** irprog.c: ir representation of a program
7 */
8
9 #ifdef HAVE_CONFIG_H
10 # include <config.h>
11 #endif
12
13 # include "irprog_t.h"
14 # include "array.h"
15 # include "obst.h"
16
17 #define GLOBAL_TYPE_NAME "GlobalType"
18
19 /* A variable from where everything in the ir can be accessed. */
20 ir_prog *irp;
21
22 /* initializes ir_prog. Calles the constructor for an ir_prog. */
23 void init_irprog(void) {
24   new_ir_prog ();
25 }
26
27 /* Create a new ir prog. Automatically called by init_firm through
28    init_irprog. */
29 ir_prog *new_ir_prog (void) {
30   ir_prog *res;
31
32   res = (ir_prog *) malloc (sizeof(ir_prog));
33   irp = res;
34
35   /* res->obst      = (struct obstack *) xmalloc (sizeof (struct obstack)); */
36   res->graphs = NEW_ARR_F (ir_graph *, 1);
37   res->types  = NEW_ARR_F (type *, 1);
38   res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
39                                                strlen(GLOBAL_TYPE_NAME)));
40   add_irp_type((type *)res->glob_type);
41
42 #ifdef DEBUG_libfirm
43   res->max_node_nr = 1;
44 #endif
45
46   return res;
47 }
48
49 /** Functions to access the fields of ir_prog **/
50
51
52 /* Access the main routine of the compiled program. */
53 ir_graph *get_irp_main_irg() {
54   assert (irp);
55   return irp->main_irg;
56 }
57
58 void set_irp_main_irg(ir_graph *main_irg) {
59   assert (irp);
60   irp->main_irg = main_irg;
61 }
62
63 type_class *get_glob_type(void) {
64   assert(irp);
65   return irp->glob_type;
66 }
67
68 /* Adds irg to the list of ir graphs in irp. */
69 void      add_irp_irg(ir_graph *irg) {
70   assert (irg != NULL);
71   assert(irp && irp->graphs);
72   ARR_APP1 (ir_graph *, irp->graphs, irg);
73 }
74
75 int get_irp_n_irgs() {
76   assert (irp && irp->graphs);
77   /* Strangely the first element of the array is NULL.  Why??  */
78   return (ARR_LEN((irp)->graphs) - 1);
79 }
80
81 ir_graph *get_irp_irg(int pos){
82   assert (irp && irp->graphs);
83   /* Strangely the first element of the array is NULL.  Why??  */
84   return irp->graphs[pos+1];
85 }
86
87 void set_irp_irg(int pos, ir_graph *irg) {
88   assert (irp && irg);
89   assert (pos < (ARR_LEN((irp)->graphs) - 1));
90   /* Strangely the first element of the array is NULL.  Why??  */
91   irp->graphs[pos+1] = irg;
92 }
93
94 /* Adds type to the list of types in irp. */
95 void add_irp_type(type *typ) {
96   assert (typ != NULL);
97   assert(irp);
98   ARR_APP1 (type *, irp->types, typ);
99 }
100
101 int get_irp_n_types (void) {
102   assert (irp && irp->types);
103   /* Strangely the first element of the array is NULL.  Why??  */
104   return (ARR_LEN((irp)->types) - 1);
105 }
106
107 type *get_irp_type(int pos) {
108   assert (irp && irp->types);
109   /* Strangely the first element of the array is NULL.  Why??  */
110   return irp->types[pos+1];
111
112 }
113
114 void  set_irp_type(int pos, type *typ) {
115   assert (irp && typ);
116   assert (pos < (ARR_LEN((irp)->types) - 1));
117   /* Strangely the first element of the array is NULL.  Why??  */
118   irp->types[pos+1] = typ;
119
120 }
121
122 #ifdef DEBUG_libfirm
123 int get_irp_new_node_nr() {
124   assert(irp);
125   irp->max_node_nr = irp->max_node_nr + 1;
126   return irp->max_node_nr - 1;
127 }
128 #endif