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