minor bug fix to previous changes
[libfirm] / ir / common / misc.h
1 /* Misc. declarations.
2    Copyright (C) 1995, 1996 Markus Armbruster
3    All rights reserved. */
4
5 #ifndef _MISC_H_
6 #define _MISC_H_
7
8 /* Declare alloca() */
9
10 #ifdef __GNUC__
11   /* @@@ on a true GNU system, this is defined by stdlib.h */
12 # undef alloca
13 # define alloca(size) __builtin_alloca (size)
14 #else
15 # if HAVE_ALLOCA_H
16 #   include <alloca.h>
17 # else
18 #   if defined(_AIX) && !defined(C_ALLOCA)
19       /* if your version of AIX chokes on this, use gcc @@@ or alloca.o */
20 #pragma alloca
21 #   else
22 #     ifndef alloca /* predefined by HP cc +Olibcalls */
23 void *alloca ();
24 #     endif
25 #   endif
26 # endif
27 #endif
28
29
30 #include "host.h"
31 #include "bool.h"
32
33 /* Alignment of nodes, cf common/tag.h, a power of two.
34
35    Most nodes are allocated from obstacks and therefore are aligned
36    identically on the obstacks' alignment boundary.  We'd like gcc to
37    align *all* nodes identically to avoid its cast-align warning and
38    perhaps allow for better code.  Since the common node alignment is
39    not known in time, we use an educated guess and check it against
40    the correct value later.  */
41 #define NODE_ALIGN ALIGNOF (struct { void *p; int i; })
42
43
44 /* Miscellaneous */
45
46 #ifndef MAX
47 # define MAX(a,b) ((a) > (b) ? (a) : (b))
48 #endif
49 #ifndef MIN
50 # define MIN(a,b) ((a) > (b) ? (b) : (a))
51 #endif
52
53 #define IS_POW2(n) ((((n)-1) & (n)) == 0)
54
55 typedef int (*cmp_fun) (const void *, const void *);
56
57
58 /* xmalloc() & friends.
59
60    The macros set tmalloc_tag to __FILE__, the functions leave it
61    alone.  Use the latter if you set it yourself.  See tmalloc.c for
62    details.  */
63
64 extern void *xmalloc (size_t);
65 extern void *xrealloc (void *, size_t);
66 extern char *xstrdup (const char *);
67 extern void xnomem (void);
68
69 # define xmalloc(size) (XMALLOC_TRACE (xmalloc) ((size)))
70 # define xrealloc(ptr, size) (XMALLOC_TRACE (xrealloc) ((ptr), (size)))
71 # define xstrdup(str) (XMALLOC_TRACE (xstrdup) ((str)))
72 # define xfree(ptr) (XMALLOC_TRACE free ((ptr)))
73
74 #if defined(HAVE_GNU_MALLOC) && defined(DEBUG)
75 extern const char *tmalloc_tag;
76 # define XMALLOC_TRACE tmalloc_tag = __FILE__,
77 #else
78 # define XMALLOC_TRACE
79 #endif
80
81 #endif /* _MISC_H_ */