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