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