1 /* Copyright (C) 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Goetz Lindenmaier
6 ** irprog.c: ir representation of a program
15 # include "irprog_t.h"
16 # include "irgraph_t.h"
19 # include "typegmod.h"
21 #define GLOBAL_TYPE_NAME "GlobalType"
23 /* A variable from where everything in the ir can be accessed. */
26 /* initializes ir_prog. Calles the constructor for an ir_prog. */
27 void init_irprog(void) {
31 /* Create a new ir prog. Automatically called by init_firm through
33 ir_prog *new_ir_prog (void) {
36 res = (ir_prog *) malloc (sizeof(ir_prog));
39 /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
40 res->graphs = NEW_ARR_F (ir_graph *, 1);
41 res->types = NEW_ARR_F (type *, 1);
42 res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
43 strlen(GLOBAL_TYPE_NAME)));
44 add_irp_type((type *)res->glob_type);
46 res->const_code_irg = new_const_code_irg();
55 /** Functions to access the fields of ir_prog **/
58 /* Access the main routine of the compiled program. */
59 ir_graph *get_irp_main_irg() {
64 void set_irp_main_irg(ir_graph *main_irg) {
66 irp->main_irg = main_irg;
69 type *get_glob_type(void) {
71 return irp->glob_type = skip_tid(irp->glob_type);
74 /* Adds irg to the list of ir graphs in irp. */
75 void add_irp_irg(ir_graph *irg) {
77 assert(irp && irp->graphs);
78 ARR_APP1 (ir_graph *, irp->graphs, irg);
81 /* Removes irg from the list or irgs, shrinks the list by one.
82 @@@ does not work properly. */
83 void remove_irp_irg(ir_graph *irg){
86 for (i = 1; i < (ARR_LEN (irp->graphs))-1; i++)
87 if (irp->graphs[i+1] == irg) {
88 for(i++; i < (ARR_LEN (irp->graphs)) - 1; i++)
89 irp->graphs[i] = irp->graphs[i+1];
90 ARR_SETLEN(ir_graph*, irp->graphs, (ARR_LEN(irp->graphs)) - 1);
95 int get_irp_n_irgs() {
96 assert (irp && irp->graphs);
97 /* Strangely the first element of the array is NULL. Why?? */
98 return (ARR_LEN((irp)->graphs) - 1);
101 ir_graph *get_irp_irg(int pos){
102 assert (irp && irp->graphs);
103 /* Strangely the first element of the array is NULL. Why?? */
104 return irp->graphs[pos+1];
107 void set_irp_irg(int pos, ir_graph *irg) {
109 assert (pos < (ARR_LEN((irp)->graphs) - 1));
110 /* Strangely the first element of the array is NULL. Why?? */
111 irp->graphs[pos+1] = irg;
114 /* Adds type to the list of types in irp. */
115 void add_irp_type(type *typ) {
116 assert (typ != NULL);
118 ARR_APP1 (type *, irp->types, typ);
121 int get_irp_n_types (void) {
122 assert (irp && irp->types);
123 /* Strangely the first element of the array is NULL. Why?? */
124 return (ARR_LEN((irp)->types) - 1);
127 type *get_irp_type(int pos) {
128 assert (irp && irp->types);
129 /* Strangely the first element of the array is NULL. Why?? */
130 /* Don't set the skip_tid result so that no double entries are generated. */
131 return skip_tid(irp->types[pos+1]);
134 void set_irp_type(int pos, type *typ) {
136 assert (pos < (ARR_LEN((irp)->types) - 1));
137 /* Strangely the first element of the array is NULL. Why?? */
138 irp->types[pos+1] = typ;
142 int get_irp_new_node_nr() {
144 irp->max_node_nr = irp->max_node_nr + 1;
145 return irp->max_node_nr - 1;
149 ir_graph *get_const_code_irg()
151 return irp->const_code_irg;