1 /* Copyright (C) 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Goetz Lindenmaier
6 ** irprog.c: ir representation of a program
17 # include "irprog_t.h"
18 # include "irgraph_t.h"
21 # include "typegmod.h"
23 #define GLOBAL_TYPE_NAME "GlobalType"
25 /* A variable from where everything in the ir can be accessed. */
28 /* initializes ir_prog. Calles the constructor for an ir_prog. */
29 void init_irprog(void) {
33 /* Create a new ir prog. Automatically called by init_firm through
35 ir_prog *new_ir_prog (void) {
38 res = (ir_prog *) malloc (sizeof(ir_prog));
40 /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
41 res->graphs = NEW_ARR_F (ir_graph *, 1);
42 res->types = NEW_ARR_F (type *, 1);
43 res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
44 strlen(GLOBAL_TYPE_NAME)));
45 // @@@ Das ist hier das 2. mal!!
46 add_irp_type(res->glob_type);
48 res->const_code_irg = new_const_code_irg();
57 /** Functions to access the fields of ir_prog **/
60 /* Access the main routine of the compiled program. */
61 ir_graph *get_irp_main_irg() {
66 void set_irp_main_irg(ir_graph *main_irg) {
68 irp->main_irg = main_irg;
71 type *get_glob_type(void) {
73 return irp->glob_type = skip_tid(irp->glob_type);
76 /* Adds irg to the list of ir graphs in irp. */
77 void add_irp_irg(ir_graph *irg) {
79 assert(irp && irp->graphs);
80 ARR_APP1 (ir_graph *, irp->graphs, irg);
83 /* Removes irg from the list or irgs, shrinks the list by one.
84 @@@ does not work properly. */
85 void remove_irp_irg(ir_graph *irg){
89 for (i = 1; i < (ARR_LEN (irp->graphs)); i++) {
90 if (irp->graphs[i] == irg) {
91 for(; i < (ARR_LEN (irp->graphs)) - 1; i++) {
92 irp->graphs[i] = irp->graphs[i+1];
94 ARR_SETLEN(ir_graph*, irp->graphs, (ARR_LEN(irp->graphs)) - 1);
100 int get_irp_n_irgs() {
101 assert (irp && irp->graphs);
102 /* Strangely the first element of the array is NULL. Why?? */
103 return (ARR_LEN((irp)->graphs) - 1);
106 ir_graph *get_irp_irg(int pos){
107 assert (irp && irp->graphs);
108 /* Strangely the first element of the array is NULL. Why?? */
109 return irp->graphs[pos+1];
112 void set_irp_irg(int pos, ir_graph *irg) {
114 assert (pos < (ARR_LEN((irp)->graphs) - 1));
115 /* Strangely the first element of the array is NULL. Why?? */
116 irp->graphs[pos+1] = irg;
119 /* Adds type to the list of types in irp. */
120 void add_irp_type(type *typ) {
121 assert (typ != NULL);
123 ARR_APP1 (type *, irp->types, typ);
126 int get_irp_n_types (void) {
127 assert (irp && irp->types);
128 /* Strangely the first element of the array is NULL. Why?? */
129 return (ARR_LEN((irp)->types) - 1);
132 type *get_irp_type(int pos) {
133 assert (irp && irp->types);
134 /* Strangely the first element of the array is NULL. Why?? */
135 /* Don't set the skip_tid result so that no double entries are generated. */
136 return skip_tid(irp->types[pos+1]);
139 void set_irp_type(int pos, type *typ) {
141 assert (pos < (ARR_LEN((irp)->types) - 1));
142 /* Strangely the first element of the array is NULL. Why?? */
143 irp->types[pos+1] = typ;
147 int get_irp_new_node_nr() {
149 irp->max_node_nr = irp->max_node_nr + 1;
150 return irp->max_node_nr - 1;
154 ir_graph *get_const_code_irg()
156 return irp->const_code_irg;