type list fixes
[libfirm] / ir / ir / irprog_t.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    Entry point to the representation of a whole program 0-- private header.
23  * @author   Goetz Lindenmaier
24  * @date     2000
25  */
26 #ifndef FIRM_IR_IRPROG_T_H
27 #define FIRM_IR_IRPROG_T_H
28
29 #include "irprog.h"
30 #include "irtypes.h"
31 #include "irtypeinfo.h"
32 #include "irmemory.h"
33
34 #include "callgraph.h"
35
36 #include "array.h"
37
38 /** Adds mode to the list of modes in irp. */
39 void add_irp_mode(ir_mode *mode);
40
41 /* inline functions */
42 static inline ir_type *get_segment_type_(ir_segment_t segment)
43 {
44         assert(segment <= IR_SEGMENT_LAST);
45         return irp->segment_types[segment];
46 }
47
48 static inline ir_type *get_glob_type_(void)
49 {
50         return get_segment_type_(IR_SEGMENT_GLOBAL);
51 }
52
53 static inline ir_type *get_tls_type_(void)
54 {
55         return get_segment_type_(IR_SEGMENT_THREAD_LOCAL);
56 }
57
58 static inline size_t get_irp_n_irgs_(void)
59 {
60         assert(irp && irp->graphs);
61         return ARR_LEN(irp->graphs);
62 }
63
64 static inline ir_graph *get_irp_irg_(size_t pos)
65 {
66         assert(pos < ARR_LEN(irp->graphs));
67         return irp->graphs[pos];
68 }
69
70 static inline size_t get_irp_n_types_(void)
71 {
72         assert(irp && irp->types);
73         return ARR_LEN(irp->types);
74 }
75
76 static inline ir_type *get_irp_type_(size_t pos)
77 {
78         assert(irp->types);
79         assert(pos < ARR_LEN(irp->types));
80         /* Don't set the skip_tid result so that no double entries are generated. */
81         return irp->types[pos];
82 }
83
84 static inline size_t get_irp_n_modes_(void)
85 {
86         assert(irp->modes);
87         return ARR_LEN(irp->modes);
88 }
89
90 static inline ir_mode *get_irp_mode_(size_t pos)
91 {
92         assert(irp && irp->modes);
93         return irp->modes[pos];
94 }
95
96 static inline size_t get_irp_n_opcodes_(void)
97 {
98         assert(irp && irp->opcodes);
99         return ARR_LEN(irp->opcodes);
100 }
101
102 static inline ir_op *get_irp_opcode_(size_t pos)
103 {
104         assert(irp && irp->opcodes);
105         return irp->opcodes[pos];
106 }
107
108 /** Returns a new, unique number to number nodes or the like. */
109 static inline long get_irp_new_node_nr(void)
110 {
111         assert(irp);
112         return irp->max_node_nr++;
113 }
114
115 static inline size_t get_irp_new_irg_idx(void)
116 {
117         assert(irp);
118         return irp->max_irg_idx++;
119 }
120
121 static inline ir_graph *get_const_code_irg_(void)
122 {
123         return irp->const_code_irg;
124 }
125
126 /** Returns a new, unique exception region number. */
127 static inline ir_exc_region_t get_irp_next_region_nr_(void)
128 {
129         assert(irp);
130         return ++irp->last_region_nr;
131 }
132
133 /** Returns a new, unique label number. */
134 static inline ir_label_t get_irp_next_label_nr_(void)
135 {
136         assert(irp);
137         return ++irp->last_label_nr;
138 }
139
140 /** Whether optimizations should dump irgs */
141 static inline int get_irp_optimization_dumps_(void)
142 {
143         assert(irp);
144         return irp->optimization_dumps;
145 }
146
147 /** Set optimizations to dump irgs */
148 static inline void enable_irp_optimization_dumps_(void)
149 {
150         assert(irp);
151         irp->optimization_dumps = 1;
152 }
153
154 void      set_irp_ip_outedges(ir_node ** ip_outedges);
155 ir_node** get_irp_ip_outedges(void);
156
157 /** initializes ir_prog. Constructs only the basic lists */
158 void init_irprog_1(void);
159
160 /** Completes ir_prog. */
161 void init_irprog_2(void);
162
163 /** Adds type to the list of types in irp. */
164 FIRM_API void add_irp_type(ir_type *typ);
165
166 /** Removes type from the list of types, deallocates it and
167     shrinks the list by one. */
168 FIRM_API void remove_irp_type(ir_type *typ);
169
170 /* Inline functions. */
171 #define get_irp_n_irgs()                 get_irp_n_irgs_()
172 #define get_irp_irg(pos)                 get_irp_irg_(pos)
173 #define get_irp_n_types()                get_irp_n_types_()
174 #define get_irp_type(pos)                get_irp_type_(pos)
175 #define get_irp_n_modes()                get_irp_n_modes_()
176 #define get_irp_mode(pos)                get_irp_mode_(pos)
177 #define get_irp_n_opcodes()              get_irp_n_opcodes_()
178 #define get_irp_opcode(pos)              get_irp_opcode_(pos)
179 #define get_const_code_irg()             get_const_code_irg_()
180 #define get_segment_type(s)              get_segment_type_(s)
181 #define get_glob_type()                  get_glob_type_()
182 #define get_tls_type()                   get_tls_type_()
183 #define get_irp_next_region_nr()         get_irp_next_region_nr_()
184 #define get_irp_next_label_nr()          get_irp_next_label_nr_()
185 #define get_irp_optimization_dumps()     get_irp_optimization_dumps_()
186 #define enable_irp_optimization_dumps()  enable_irp_optimization_dumps_()
187
188 #endif