1 /* Copyright (C) 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Goetz Lindenmaier
6 ** irprog.c: ir representation of a program
13 #define GLOBAL_TYPE_NAME "GlobalType"
15 /* initializes ir_prog. Calles the constructor for an ir_prog. */
16 void init_irprog(void) {
20 /* Create a new ir prog. Automatically called by init_firm through init_irprog. */
21 ir_prog *new_ir_prog (void) {
24 res = (ir_prog *) malloc (sizeof(ir_prog));
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);
37 /** Functions to access the fields of ir_prog **/
40 /* Access the main routine of the compiled program. */
41 ir_graph *get_irp_main_irg() {
46 void set_irp_main_irg(ir_graph *main_irg) {
48 irp->main_irg = main_irg;
51 type_class *get_glob_type(void) {
53 return irp->glob_type;
56 /* Adds irg to the list of ir graphs in irp. */
57 void add_irp_irg(ir_graph *irg) {
59 assert(irp && irp->graphs);
60 ARR_APP1 (ir_graph *, irp->graphs, irg);
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);
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];
75 void set_irp_irg(int pos, ir_graph *irg) {
77 assert (pos < (ARR_LEN((irp)->graphs) - 1));
78 /* Strangely the first element of the array is NULL. Why?? */
79 irp->graphs[pos+1] = irg;
82 /* Adds type to the list of types in irp. */
83 void add_irp_type(type *typ) {
86 ARR_APP1 (type *, irp->types, typ);
89 int get_irp_n_types (void) {
90 assert (irp && irp->types);
91 /* Strangely the first element of the array is NULL. Why?? */
92 return (ARR_LEN((irp)->types) - 1);
95 type *get_irp_type(int pos) {
96 assert (irp && irp->types);
97 /* Strangely the first element of the array is NULL. Why?? */
98 return irp->types[pos+1];
102 void set_irp_type(int pos, type *typ) {
104 assert (pos < (ARR_LEN((irp)->types) - 1));
105 /* Strangely the first element of the array is NULL. Why?? */
106 irp->types[pos+1] = typ;
110 int get_irp_new_node_nr() {
112 irp->max_node_nr = irp->max_node_nr + 1;
113 return irp->max_node_nr - 1;