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