11 #ifndef FIRM_ADT_ARRAY_H
12 #define FIRM_ADT_ARRAY_H
46 extern ir_arr_descr arr_mt_descr;
59 FIRM_API
void *ir_new_arr_f(
size_t nelts,
size_t elts_size);
73 FIRM_API
void *ir_new_arr_d(
struct obstack *obstack,
size_t nelts,
size_t elts_size);
88 FIRM_API
void *ir_arr_resize(
void *elts,
size_t nelts,
size_t elts_size);
102 FIRM_API
void *ir_arr_setlen(
void *elts,
size_t nelts,
size_t elts_size);
104 FIRM_API
void ir_verify_arr(
const void *elts);
106 #define ARR_ELTS_OFFS offsetof(ir_arr_descr, elts)
107 #define ARR_DESCR(elts) ((ir_arr_descr *)(void *)((char *)(elts) - ARR_ELTS_OFFS))
111 static inline void ARR_SHRINKLEN(
void *arr,
size_t new_len)
116 assert(ARR_DESCR(arr)->nelts >= new_len);
117 ARR_DESCR(arr)->nelts = new_len;
134 #define NEW_ARR_F(type, nelts) \
135 ((type *)ir_new_arr_f((nelts), sizeof(type) * (nelts)))
140 #define NEW_ARR_FZ(type, nelts) \
141 ((type*)memset(NEW_ARR_F(type, (nelts)), 0, sizeof(type) * (nelts)))
155 #define DUP_ARR_F(type, arr) \
156 ((type*)memcpy(NEW_ARR_F(type, ARR_LEN((arr))), (arr), sizeof(type) * ARR_LEN((arr))))
177 #define NEW_ARR_D(type, obstack, nelts) \
179 ? (type *)ir_new_arr_d((obstack), (nelts), sizeof(type) * (nelts)) \
180 : (type *)arr_mt_descr.elts)
185 #define NEW_ARR_DZ(type, obstack, nelts) \
186 ((type*)memset(NEW_ARR_D(type, (obstack), (nelts)), 0, sizeof(type) * (nelts)))
201 #define DUP_ARR_D(type, obstack, arr) \
202 ((type*)memcpy(NEW_ARR_D(type, (obstack), ARR_LEN((arr))), (arr), sizeof(type) * ARR_LEN ((arr))))
209 static inline size_t ARR_LEN(
void const *
const arr)
214 return ARR_DESCR(arr)->nelts;
227 #define ARR_RESIZE(type, arr, n) \
228 ((arr) = (type*) ir_arr_resize((void *)(arr), (n), sizeof(type)))
239 #define ARR_SETLEN(type, arr, n) \
240 ((arr) = (type*) ir_arr_setlen((void *)(arr), (n), sizeof(type) * (n)))
251 #define ARR_EXTEND(type, arr, delta) \
252 ARR_RESIZE(type, (arr), ARR_LEN((arr)) + (delta))
264 #define ARR_EXTO(type, arr, n) \
266 if ((n) >= ARR_LEN(arr)) { ARR_RESIZE(type, arr, (n)+1); } \
276 #define ARR_APP1(type, arr, elt) \
277 (ARR_EXTEND(type, (arr), 1), (arr)[ARR_LEN((arr))-1] = (elt))
static size_t ARR_LEN(void const *const arr)
Returns the length of an array.
void DEL_ARR_F(void *arr)
Delete a flexible array.