1 /* Copyright (C) 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Goetz Lindenmaier
6 ** irprog.c: ir representation of a program
13 #define GLOBAL_TYPE_NAME "GlobalType"
15 /* A variable from where everything in the ir can be accessed. */
18 /* initializes ir_prog. Calles the constructor for an ir_prog. */
19 void init_irprog(void) {
23 /* Create a new ir prog. Automatically called by init_firm through
25 ir_prog *new_ir_prog (void) {
28 res = (ir_prog *) malloc (sizeof(ir_prog));
31 /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
32 res->graphs = NEW_ARR_F (ir_graph *, 1);
33 res->types = NEW_ARR_F (type *, 1);
34 res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
35 strlen(GLOBAL_TYPE_NAME)));
36 add_irp_type((type *)res->glob_type);
41 /** Functions to access the fields of ir_prog **/
44 /* Access the main routine of the compiled program. */
45 ir_graph *get_irp_main_irg() {
50 void set_irp_main_irg(ir_graph *main_irg) {
52 irp->main_irg = main_irg;
55 type_class *get_glob_type(void) {
57 return irp->glob_type;
60 /* Adds irg to the list of ir graphs in irp. */
61 void add_irp_irg(ir_graph *irg) {
63 assert(irp && irp->graphs);
64 ARR_APP1 (ir_graph *, irp->graphs, irg);
67 int get_irp_n_irgs() {
68 assert (irp && irp->graphs);
69 /* Strangely the first element of the array is NULL. Why?? */
70 return (ARR_LEN((irp)->graphs) - 1);
73 ir_graph *get_irp_irg(int pos){
74 assert (irp && irp->graphs);
75 /* Strangely the first element of the array is NULL. Why?? */
76 return irp->graphs[pos+1];
79 void set_irp_irg(int pos, ir_graph *irg) {
81 assert (pos < (ARR_LEN((irp)->graphs) - 1));
82 /* Strangely the first element of the array is NULL. Why?? */
83 irp->graphs[pos+1] = irg;
86 /* Adds type to the list of types in irp. */
87 void add_irp_type(type *typ) {
90 ARR_APP1 (type *, irp->types, typ);
93 int get_irp_n_types (void) {
94 assert (irp && irp->types);
95 /* Strangely the first element of the array is NULL. Why?? */
96 return (ARR_LEN((irp)->types) - 1);
99 type *get_irp_type(int pos) {
100 assert (irp && irp->types);
101 /* Strangely the first element of the array is NULL. Why?? */
102 return irp->types[pos+1];
106 void set_irp_type(int pos, type *typ) {
108 assert (pos < (ARR_LEN((irp)->types) - 1));
109 /* Strangely the first element of the array is NULL. Why?? */
110 irp->types[pos+1] = typ;
114 int get_irp_new_node_nr() {
116 irp->max_node_nr = irp->max_node_nr + 1;
117 return irp->max_node_nr - 1;