Commit cb625e13 authored by Michael Beck's avatar Michael Beck
Browse files

Simplyfied firm arrays by deleting useless macro and union.

[r28280]
parent f4054b69
...@@ -104,7 +104,7 @@ ...@@ -104,7 +104,7 @@
#define NEW_ARR_D(type, obstack, nelts) \ #define NEW_ARR_D(type, obstack, nelts) \
( nelts \ ( nelts \
? (type *)ir_new_arr_d((obstack), (nelts), sizeof(type) * (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 * Creates a new dynamic array with the same number of elements as a
...@@ -228,28 +228,20 @@ typedef union { ...@@ -228,28 +228,20 @@ typedef union {
long l; long l;
} aligned_type; } 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. * 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; 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); ...@@ -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_arr_setlen(void *elts, size_t nelts, size_t elts_size);
FIRM_API void ir_verify_arr(const void *elts); 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)) #define ARR_DESCR(elts) ((ir_arr_descr *)(void *)((char *)(elts) - ARR_ELTS_OFFS))
#include "../end.h" #include "../end.h"
......
...@@ -86,7 +86,7 @@ void *ir_new_arr_d(struct obstack *obstack, size_t nelts, size_t elts_size) ...@@ -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); ARR_SET_DBGINF(dp, ARR_D_MAGIC, elts_size/nelts);
dp->u.obstack = obstack; dp->u.obstack = obstack;
dp->nelts = nelts; 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) ...@@ -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); newa = (ir_arr_descr*)xmalloc(ARR_ELTS_OFFS+elts_size);
ARR_SET_DBGINF(newa, ARR_F_MAGIC, nelts ? elts_size/nelts : 0); ARR_SET_DBGINF(newa, ARR_F_MAGIC, nelts ? elts_size/nelts : 0);
newa->u.allocated = newa->nelts = nelts; 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) ...@@ -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 = (ir_arr_descr*) xrealloc(dp, ARR_ELTS_OFFS+elts_size);
dp->u.allocated = dp->nelts = nelts; 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) ...@@ -190,7 +190,7 @@ void *ir_arr_resize(void *elts, size_t nelts, size_t eltsize)
} }
dp->nelts = nelts; dp->nelts = nelts;
return dp->v.elts; return dp->elts;
} }
#ifdef DEBUG_libfirm #ifdef DEBUG_libfirm
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
#define NEW_ARR_A(type, var, n) \ #define NEW_ARR_A(type, var, n) \
do { \ do { \
size_t nelts = (n); \ 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)); \ ARR_SET_DBGINF(ARR_DESCR ((var)), ARR_A_MAGIC, sizeof (type)); \
(void)(ARR_DESCR((var))->nelts = nelts); \ (void)(ARR_DESCR((var))->nelts = nelts); \
} while (0) } while (0)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment