X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fadt%2Futil.h;h=105ceafcba385c732350c7aefdf7c1fba264ddba;hb=c795dad1d14f1b54dd32a6107ac26a22c089c957;hp=d38254029f2f8487fd267c507f0d07e4047d9ae5;hpb=a25fd62c30b2f4562dc598ab74d5200a99d248a7;p=libfirm diff --git a/ir/adt/util.h b/ir/adt/util.h index d38254029..105ceafcb 100644 --- a/ir/adt/util.h +++ b/ir/adt/util.h @@ -1,25 +1,32 @@ -/** - * @file util.h - * @date 31.05.2005 - * @author Sebastian Hack +/* + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. * - * Some utility macros. + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. * - * Copyright (C) 2005 Universitaet Karlsruhe - * Released under the GPL + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. */ -#ifndef _UTIL_H -#define _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. + * @file + * @date 31.05.2005 + * @author Sebastian Hack + * @brief Miscelaneous utility macros. */ -#define offset_of(type, member) \ - ((char *) &(((type *) 0)->member) - (char *) 0) +#ifndef FIRM_ADT_UTIL_H +#define FIRM_ADT_UTIL_H + +#include /** * Make pointer to the struct from a pointer to a member of that struct. @@ -28,15 +35,38 @@ * @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))) +#define firm_container_of(ptr, type, member) \ + ((type *) ((char *) (ptr) - offsetof(type, member))) + +/** + * Returns size of a static array. Warning: This returns invalid values for + * dynamically allocated arrays. + * + * @param a static array + */ +#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) + +#undef MIN +#undef MAX +#define MAX(x, y) ((x) > (y) ? (x) : (y)) +#define MIN(x, y) ((x) < (y) ? (x) : (y)) + +/** + * Three valued compare as demanded by e.g. qsort(3) + * @param c A number. + * @param d Another number. + * @return 0 if c == d, -1 if c < d, 1 if c > d. + */ +#define QSORT_CMP(c, d) (((c) > (d)) - ((c) < (d))) + +/** + * convert an integer into pointer + */ +#define INT_TO_PTR(v) ((void *)((char *)0 + (v))) /** - * Get the number of elements of a static array. - * @param arr The static array. - * @return The number of elements in that array. + * convert a pointer into an integer */ -#define array_size(arr) \ - (sizeof(arr) / sizeof((arr)[0])) +#define PTR_TO_INT(v) (((char *)(v) - (char *)0)) -#endif /* _UTIL_H */ +#endif