*** 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 init_irprog. */
21 ir_prog *new_ir_prog (void) {
22   ir_prog *res;
23
24   res = (ir_prog *) malloc (sizeof(ir_prog));
25   irp = res;
26
27   /* res->obst      = (struct obstack *) xmalloc (sizeof (struct obstack)); */
28   res->graphs = NEW_ARR_F (ir_graph *, 1);
29   res->types  = NEW_ARR_F (type *, 1);
30   res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
31                                                strlen(GLOBAL_TYPE_NAME)));
32   add_irp_type((type *)res->glob_type);
33
34   return res;
35 }
36
37 /** Functions to access the fields of ir_prog **/
38
39
40 /* Access the main routine of the compiled program. */
41 ir_graph *get_irp_main_irg() {
42   assert (irp);
43   return irp->main_irg;
44 }
45
46 void set_irp_main_irg(ir_graph *main_irg) {
47   assert (irp);
48   irp->main_irg = main_irg;
49 }
50
51 type_class *get_glob_type(void) {
52   assert(irp);
53   return irp->glob_type;
54 }
55
56 /* Adds irg to the list of ir graphs in irp. */
57 void      add_irp_irg(ir_graph *irg) {
58   assert (irg != NULL);
59   assert(irp && irp->graphs);
60   ARR_APP1 (ir_graph *, irp->graphs, irg);
61 }
62
63 int get_irp_n_irgs() {
64   assert (irp && irp->graphs);
65   /* Strangely the first element of the array is NULL.  Why??  */
66   return (ARR_LEN((irp)->graphs) - 1);
67 }
68
69 ir_graph *get_irp_irg(int pos){
70   assert (irp && irp->graphs);
71   /* Strangely the first element of the array is NULL.  Why??  */
72   return irp->graphs[pos+1];
73 }
74
75 /* Adds type to the list of types in irp. */
76 void add_irp_type(type *typ) {
77   assert (typ != NULL);
78   assert(irp);
79   ARR_APP1 (type *, irp->types, typ);
80 }
81
82 int get_irp_new_node_nr() {
83   assert(irp);
84   irp->max_node_nr = irp->max_node_nr + 1;
85   return irp->max_node_nr - 1;
86 }