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 INLINE void remove_irp_type_from_list (type *typ) {
36 for (i = 1; i < (ARR_LEN (irp->types)); i++) {
37 if (irp->types[i] == typ) {
38 for(; i < (ARR_LEN (irp->types)) - 1; i++) {
39 irp->types[i] = irp->types[i+1];
41 ARR_SETLEN(type*, irp->types, (ARR_LEN(irp->types)) - 1);
47 /* Create a new ir prog. Automatically called by init_firm through
49 ir_prog *new_ir_prog (void) {
52 res = (ir_prog *) malloc (sizeof(ir_prog));
54 /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
55 res->graphs = NEW_ARR_F (ir_graph *, 1);
56 res->types = NEW_ARR_F (type *, 1);
57 res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
58 strlen(GLOBAL_TYPE_NAME)));
59 /* Remove type from type list. Must be treated differently than
61 remove_irp_type_from_list(res->glob_type);
63 res->const_code_irg = new_const_code_irg();
72 /** Functions to access the fields of ir_prog **/
75 /* Access the main routine of the compiled program. */
76 ir_graph *get_irp_main_irg() {
81 void set_irp_main_irg(ir_graph *main_irg) {
83 irp->main_irg = main_irg;
86 type *get_glob_type(void) {
88 return irp->glob_type = skip_tid(irp->glob_type);
91 /* Adds irg to the list of ir graphs in irp. */
92 void add_irp_irg(ir_graph *irg) {
94 assert(irp && irp->graphs);
95 ARR_APP1 (ir_graph *, irp->graphs, irg);
98 /* Removes irg from the list or irgs, shrinks the list by one. */
99 void remove_irp_irg(ir_graph *irg){
103 for (i = 1; i < (ARR_LEN (irp->graphs)); i++) {
104 if (irp->graphs[i] == irg) {
105 for(; i < (ARR_LEN (irp->graphs)) - 1; i++) {
106 irp->graphs[i] = irp->graphs[i+1];
108 ARR_SETLEN(ir_graph*, irp->graphs, (ARR_LEN(irp->graphs)) - 1);
114 int get_irp_n_irgs() {
115 assert (irp && irp->graphs);
116 /* Strangely the first element of the array is NULL. Why?? */
117 return (ARR_LEN((irp)->graphs) - 1);
120 ir_graph *get_irp_irg(int pos){
121 assert (irp && irp->graphs);
122 /* Strangely the first element of the array is NULL. Why?? */
123 return irp->graphs[pos+1];
126 void set_irp_irg(int pos, ir_graph *irg) {
128 assert (pos < (ARR_LEN((irp)->graphs) - 1));
129 /* Strangely the first element of the array is NULL. Why?? */
130 irp->graphs[pos+1] = irg;
133 /* Adds type to the list of types in irp. */
134 void add_irp_type(type *typ) {
135 assert (typ != NULL);
137 ARR_APP1 (type *, irp->types, typ);
140 void remove_irp_type(type *typ) {
141 remove_irp_type_from_list (typ);
144 int get_irp_n_types (void) {
145 assert (irp && irp->types);
146 /* Strangely the first element of the array is NULL. Why?? */
147 return (ARR_LEN((irp)->types) - 1);
150 type *get_irp_type(int pos) {
151 assert (irp && irp->types);
152 /* Strangely the first element of the array is NULL. Why?? */
153 /* Don't set the skip_tid result so that no double entries are generated. */
154 return skip_tid(irp->types[pos+1]);
157 void set_irp_type(int pos, type *typ) {
159 assert (pos < (ARR_LEN((irp)->types) - 1));
160 /* Strangely the first element of the array is NULL. Why?? */
161 irp->types[pos+1] = typ;
165 int get_irp_new_node_nr() {
167 irp->max_node_nr = irp->max_node_nr + 1;
168 return irp->max_node_nr - 1;
172 ir_graph *get_const_code_irg()
174 return irp->const_code_irg;