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));
38 /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
39 res->graphs = NEW_ARR_F (ir_graph *, 1);
40 res->types = NEW_ARR_F (type *, 1);
41 res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
42 strlen(GLOBAL_TYPE_NAME)));
43 add_irp_type((type *)res->glob_type);
45 res->const_code_irg = new_const_code_irg();
54 /** Functions to access the fields of ir_prog **/
57 /* Access the main routine of the compiled program. */
58 ir_graph *get_irp_main_irg() {
63 void set_irp_main_irg(ir_graph *main_irg) {
65 irp->main_irg = main_irg;
68 type *get_glob_type(void) {
70 return irp->glob_type = skip_tid(irp->glob_type);
73 /* Adds irg to the list of ir graphs in irp. */
74 void add_irp_irg(ir_graph *irg) {
76 assert(irp && irp->graphs);
77 ARR_APP1 (ir_graph *, irp->graphs, irg);
80 /* Removes irg from the list or irgs, shrinks the list by one.
81 @@@ does not work properly. */
82 void remove_irp_irg(ir_graph *irg){
85 for (i = 1; i < (ARR_LEN (irp->graphs))-1; i++)
86 if (irp->graphs[i+1] == irg) {
87 for(i++; i < (ARR_LEN (irp->graphs)) - 1; i++)
88 irp->graphs[i] = irp->graphs[i+1];
89 ARR_SETLEN(ir_graph*, irp->graphs, (ARR_LEN(irp->graphs)) - 1);
94 int get_irp_n_irgs() {
95 assert (irp && irp->graphs);
96 /* Strangely the first element of the array is NULL. Why?? */
97 return (ARR_LEN((irp)->graphs) - 1);
100 ir_graph *get_irp_irg(int pos){
101 assert (irp && irp->graphs);
102 /* Strangely the first element of the array is NULL. Why?? */
103 return irp->graphs[pos+1];
106 void set_irp_irg(int pos, ir_graph *irg) {
108 assert (pos < (ARR_LEN((irp)->graphs) - 1));
109 /* Strangely the first element of the array is NULL. Why?? */
110 irp->graphs[pos+1] = irg;
113 /* Adds type to the list of types in irp. */
114 void add_irp_type(type *typ) {
115 assert (typ != NULL);
117 ARR_APP1 (type *, irp->types, typ);
120 int get_irp_n_types (void) {
121 assert (irp && irp->types);
122 /* Strangely the first element of the array is NULL. Why?? */
123 return (ARR_LEN((irp)->types) - 1);
126 type *get_irp_type(int pos) {
127 assert (irp && irp->types);
128 /* Strangely the first element of the array is NULL. Why?? */
129 /* Don't set the skip_tid result so that no double entries are generated. */
130 return skip_tid(irp->types[pos+1]);
133 void set_irp_type(int pos, type *typ) {
135 assert (pos < (ARR_LEN((irp)->types) - 1));
136 /* Strangely the first element of the array is NULL. Why?? */
137 irp->types[pos+1] = typ;
141 int get_irp_new_node_nr() {
143 irp->max_node_nr = irp->max_node_nr + 1;
144 return irp->max_node_nr - 1;
148 ir_graph *get_const_code_irg()
150 return irp->const_code_irg;