25 #ifndef FIRM_ADT_ARRAY_H
26 #define FIRM_ADT_ARRAY_H
53 #define NEW_ARR_F(type, nelts) \
54 ((type *)ir_new_arr_f((nelts), sizeof(type) * (nelts)))
69 #define CLONE_ARR_F(type, arr) \
70 NEW_ARR_F(type, ARR_LEN((arr)))
84 #define DUP_ARR_F(type, arr) \
85 ((type*) memcpy(CLONE_ARR_F(type, (arr)), (arr), sizeof(type) * ARR_LEN((arr))))
92 #define DEL_ARR_F(arr) (ir_del_arr_f((void *)(arr)))
107 #define NEW_ARR_D(type, obstack, nelts) \
109 ? (type *)ir_new_arr_d((obstack), (nelts), sizeof(type) * (nelts)) \
110 : (type *)arr_mt_descr.elts)
126 #define CLONE_ARR_D(type, obstack, arr) \
127 NEW_ARR_D(type, (obstack), ARR_LEN((arr)))
142 #define DUP_ARR_D(type, obstack, arr) \
143 ((type*)memcpy(CLONE_ARR_D(type, (obstack), (arr)), (arr), sizeof(type) * ARR_LEN ((arr))))
150 #define ARR_LEN(arr) (ARR_VRFY((arr)), ARR_DESCR((arr))->nelts)
162 #define ARR_RESIZE(type, arr, n) \
163 ((arr) = (type*) ir_arr_resize((void *)(arr), (n), sizeof(type)))
174 #define ARR_SETLEN(type, arr, n) \
175 ((arr) = (type*) ir_arr_setlen((void *)(arr), (n), sizeof(type) * (n)))
186 #define ARR_EXTEND(type, arr, delta) \
187 ARR_RESIZE(type, (arr), ARR_LEN((arr)) + (delta))
199 #define ARR_EXTO(type, arr, n) \
201 if ((n) >= ARR_LEN(arr)) { ARR_RESIZE(type, arr, (n)+1); } \
211 #define ARR_APP1(type, arr, elt) \
212 (ARR_EXTEND(type, (arr), 1), (arr)[ARR_LEN((arr))-1] = (elt))
215 # define ARR_VRFY(arr) ((void)0)
216 # define ARR_IDX_VRFY(arr, idx) ((void)0)
219 # define ARR_VRFY(arr) ir_verify_arr(arr)
221 # define ARR_IDX_VRFY(arr, idx) \
222 assert((0 <= (idx)) && ((idx) < ARR_LEN((arr))))
241 struct obstack *obstack;
245 aligned_type elts[1];
248 extern ir_arr_descr arr_mt_descr;
250 FIRM_API void *ir_new_arr_f(
size_t nelts,
size_t elts_size);
251 FIRM_API void ir_del_arr_f(
void *elts);
252 FIRM_API void *ir_new_arr_d(
struct obstack *obstack,
size_t nelts,
size_t elts_size);
253 FIRM_API void *ir_arr_resize(
void *elts,
size_t nelts,
size_t elts_size);
254 FIRM_API void *ir_arr_setlen(
void *elts,
size_t nelts,
size_t elts_size);
255 FIRM_API void ir_verify_arr(
const void *elts);
257 #define ARR_ELTS_OFFS offsetof(ir_arr_descr, elts)
258 #define ARR_DESCR(elts) ((ir_arr_descr *)(void *)((char *)(elts) - ARR_ELTS_OFFS))
262 static inline void ARR_SHRINKLEN(
void *arr,
size_t new_len)
265 assert(ARR_DESCR(arr)->nelts >= new_len);
266 ARR_DESCR(arr)->nelts = new_len;