From cb625e131029ac033685403fb87181533748a276 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Sat, 29 Jan 2011 03:07:07 +0000 Subject: [PATCH] Simplyfied firm arrays by deleting useless macro and union. [r28280] --- include/libfirm/adt/array.h | 32 ++++++++++++-------------------- ir/adt/array.c | 8 ++++---- ir/adt/array_t.h | 2 +- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/include/libfirm/adt/array.h b/include/libfirm/adt/array.h index 7e610ec86..bf3a1fcd7 100644 --- a/include/libfirm/adt/array.h +++ b/include/libfirm/adt/array.h @@ -104,7 +104,7 @@ #define NEW_ARR_D(type, obstack, nelts) \ ( nelts \ ? (type *)ir_new_arr_d((obstack), (nelts), sizeof(type) * (nelts)) \ - : (type *)arr_mt_descr.v.elts) + : (type *)arr_mt_descr.elts) /** * Creates a new dynamic array with the same number of elements as a @@ -228,28 +228,20 @@ typedef union { long l; } aligned_type; -/** - * Construct an array header. - */ -#define ARR_STRUCT(type, rnelts) \ - struct { \ - int magic; \ - size_t eltsize; \ - union { \ - struct obstack *obstack; /* dynamic: allocated on this obstack */ \ - size_t allocated; /* flexible: #slots allocated */ \ - } u; \ - size_t nelts; \ - union { \ - type elts[(rnelts)]; \ - aligned_type align[1]; \ - } v; \ - } /** * The array descriptor header type. */ -typedef ARR_STRUCT(aligned_type, 1) ir_arr_descr; +typedef struct { + int magic; /**< array magic. */ + size_t eltsize; /**< size of array elements. */ + union { + struct obstack *obstack; /**< for obstack array: the obstack. */ + size_t allocated; /**< number of allocated elements. */ + } u; + size_t nelts; /**< current length of the array. */ + aligned_type elts[1]; /**< start of the array data. */ +} ir_arr_descr; extern ir_arr_descr arr_mt_descr; @@ -260,7 +252,7 @@ FIRM_API void *ir_arr_resize(void *elts, size_t nelts, size_t elts_size); FIRM_API void *ir_arr_setlen(void *elts, size_t nelts, size_t elts_size); FIRM_API void ir_verify_arr(const void *elts); -#define ARR_ELTS_OFFS offsetof(ir_arr_descr, v.elts) +#define ARR_ELTS_OFFS offsetof(ir_arr_descr, elts) #define ARR_DESCR(elts) ((ir_arr_descr *)(void *)((char *)(elts) - ARR_ELTS_OFFS)) #include "../end.h" diff --git a/ir/adt/array.c b/ir/adt/array.c index 675239fea..a225628e1 100644 --- a/ir/adt/array.c +++ b/ir/adt/array.c @@ -86,7 +86,7 @@ void *ir_new_arr_d(struct obstack *obstack, size_t nelts, size_t elts_size) ARR_SET_DBGINF(dp, ARR_D_MAGIC, elts_size/nelts); dp->u.obstack = obstack; dp->nelts = nelts; - return dp->v.elts; + return dp->elts; } /** @@ -107,7 +107,7 @@ void *ir_new_arr_f(size_t nelts, size_t elts_size) newa = (ir_arr_descr*)xmalloc(ARR_ELTS_OFFS+elts_size); ARR_SET_DBGINF(newa, ARR_F_MAGIC, nelts ? elts_size/nelts : 0); newa->u.allocated = newa->nelts = nelts; - return newa->v.elts; + return newa->elts; } /** @@ -153,7 +153,7 @@ void *ir_arr_setlen (void *elts, size_t nelts, size_t elts_size) dp = (ir_arr_descr*) xrealloc(dp, ARR_ELTS_OFFS+elts_size); dp->u.allocated = dp->nelts = nelts; - return dp->v.elts; + return dp->elts; } /** @@ -190,7 +190,7 @@ void *ir_arr_resize(void *elts, size_t nelts, size_t eltsize) } dp->nelts = nelts; - return dp->v.elts; + return dp->elts; } #ifdef DEBUG_libfirm diff --git a/ir/adt/array_t.h b/ir/adt/array_t.h index 778aeed7c..60e2c116b 100644 --- a/ir/adt/array_t.h +++ b/ir/adt/array_t.h @@ -52,7 +52,7 @@ #define NEW_ARR_A(type, var, n) \ do { \ size_t nelts = (n); \ - (var) = (type *)((ir_arr_descr *)alloca(ARR_ELTS_OFFS + sizeof(type) * nelts))->v.elts; \ + (var) = (type *)((ir_arr_descr *)alloca(ARR_ELTS_OFFS + sizeof(type) * nelts))->elts; \ ARR_SET_DBGINF(ARR_DESCR ((var)), ARR_A_MAGIC, sizeof (type)); \ (void)(ARR_DESCR((var))->nelts = nelts); \ } while (0) -- 2.20.1