*** 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
37 /** Functions to access the fields of ir_prog **/
38 type_class *get_glob_type(void) {
39   assert(irp);
40   return irp->glob_type;
41 }
42
43 /* Adds irg to the list of ir graphs in irp. */
44 void      add_irp_irg(ir_graph *irg) {
45   assert (irg != NULL);
46   assert(irp);
47   ARR_APP1 (ir_graph *, irp->graphs, irg);
48 }
49
50 /* Adds type to the list of types in irp. */
51 void      add_irp_type(type *typ) {
52   assert (typ != NULL);
53   assert(irp);
54   ARR_APP1 (type *, irp->types, typ);
55 }
56
57 int       get_irp_new_node_nr() {
58   assert(irp);
59   irp->max_node_nr = irp->max_node_nr + 1;
60   return irp->max_node_nr - 1;
61 }