X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fadt%2Futil.h;h=1e93e3f1be7ec248c56a1c75cd4f0fdc139515dd;hb=ce6161a7e42a48f7422b7babcc64d8ace18e2687;hp=a5d1fe1e480c0d1bf72f477b285887c62e6f8b3f;hpb=974215da1a935f250766874d0f7a7ddfa34bc4ef;p=libfirm diff --git a/ir/adt/util.h b/ir/adt/util.h index a5d1fe1e4..1e93e3f1b 100644 --- a/ir/adt/util.h +++ b/ir/adt/util.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -26,14 +26,7 @@ #ifndef FIRM_ADT_UTIL_H #define FIRM_ADT_UTIL_H -/** - * Get the offset of a member of a struct. - * @param type The type of the struct member is in. - * @param member The name of the member. - * @return The offset of member in type in bytes. - */ -#define offset_of(type, member) \ - ((char *) &(((type *) 0)->member) - (char *) 0) +#include /** * Make pointer to the struct from a pointer to a member of that struct. @@ -42,43 +35,15 @@ * @param member The name of the member. * @return A pointer to the struct member is in. */ -#define container_of(ptr, type, member) \ - ((type *) ((char *) (ptr) - offset_of(type, member))) - -/** - * Get the number of elements of a static array. - * @param arr The static array. - * @return The number of elements in that array. - */ -#define array_size(arr) \ - (sizeof(arr) / sizeof((arr)[0])) +#define firm_container_of(ptr, type, member) \ + ((type *) ((char *) (ptr) - offsetof(type, member))) /** - * Asserts that the constant expression x is not zero at compiletime. name has - * to be a unique identifier. + * Returns size of a static array. Warning: This returns invalid values for + * dynamically allocated arrays. * - * @note This uses the fact, that double case labels are not allowed. - */ -#define COMPILETIME_ASSERT(x, name) \ - static __attribute__((unused)) void compiletime_assert_##name (int h) { \ - switch(h) { case 0: case (x): ; } \ - } - -#ifdef __GNUC__ -/** - * Indicates to the compiler that the value of x is very likely 1 - * @note Only use this in speed critical code and when you are sure x is often 1 - */ -#define LIKELY(x) __builtin_expect((x), 1) - -/** - * Indicates to the compiler that it's very likely that x is 0 - * @note Only use this in speed critical code and when you are sure x is often 0 + * @param a static array */ -#define UNLIKELY(x) __builtin_expect((x), 0) -#else -#define LIKELY(x) x -#define UNLIKELY(x) x -#endif +#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) #endif