1 /* Copyright (C) 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Goetz Lindenmaier
6 ** irprog.c: ir representation of a program
13 # include "irprog_t.h"
16 # include "typegmod.h"
18 #define GLOBAL_TYPE_NAME "GlobalType"
20 /* A variable from where everything in the ir can be accessed. */
23 /* initializes ir_prog. Calles the constructor for an ir_prog. */
24 void init_irprog(void) {
28 /* Create a new ir prog. Automatically called by init_firm through
30 ir_prog *new_ir_prog (void) {
33 res = (ir_prog *) malloc (sizeof(ir_prog));
36 /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
37 res->graphs = NEW_ARR_F (ir_graph *, 1);
38 res->types = NEW_ARR_F (type *, 1);
39 res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
40 strlen(GLOBAL_TYPE_NAME)));
41 add_irp_type((type *)res->glob_type);
50 /** Functions to access the fields of ir_prog **/
53 /* Access the main routine of the compiled program. */
54 ir_graph *get_irp_main_irg() {
59 void set_irp_main_irg(ir_graph *main_irg) {
61 irp->main_irg = main_irg;
64 type *get_glob_type(void) {
66 return irp->glob_type = skip_tid(irp->glob_type);
69 /* Adds irg to the list of ir graphs in irp. */
70 void add_irp_irg(ir_graph *irg) {
72 assert(irp && irp->graphs);
73 ARR_APP1 (ir_graph *, irp->graphs, irg);
76 int get_irp_n_irgs() {
77 assert (irp && irp->graphs);
78 /* Strangely the first element of the array is NULL. Why?? */
79 return (ARR_LEN((irp)->graphs) - 1);
82 ir_graph *get_irp_irg(int pos){
83 assert (irp && irp->graphs);
84 /* Strangely the first element of the array is NULL. Why?? */
85 return irp->graphs[pos+1];
88 void set_irp_irg(int pos, ir_graph *irg) {
90 assert (pos < (ARR_LEN((irp)->graphs) - 1));
91 /* Strangely the first element of the array is NULL. Why?? */
92 irp->graphs[pos+1] = irg;
95 /* Adds type to the list of types in irp. */
96 void add_irp_type(type *typ) {
99 ARR_APP1 (type *, irp->types, typ);
102 int get_irp_n_types (void) {
103 assert (irp && irp->types);
104 /* Strangely the first element of the array is NULL. Why?? */
105 return (ARR_LEN((irp)->types) - 1);
108 type *get_irp_type(int pos) {
109 assert (irp && irp->types);
110 /* Strangely the first element of the array is NULL. Why?? */
111 /* Don't set the skip_id result so that no double entries are generated. */
112 return skip_id(irp->types[pos+1]);
115 void set_irp_type(int pos, type *typ) {
117 assert (pos < (ARR_LEN((irp)->types) - 1));
118 /* Strangely the first element of the array is NULL. Why?? */
119 irp->types[pos+1] = typ;
123 int get_irp_new_node_nr() {
125 irp->max_node_nr = irp->max_node_nr + 1;
126 return irp->max_node_nr - 1;