Initial revision
[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
9 /* Declare alloca() */
10
11 #ifdef __GNUC__
12   /* @@@ on a true GNU system, this is defined by stdlib.h */
13 # undef alloca
14 # define alloca(size) __builtin_alloca (size)
15 #else
16 # if HAVE_ALLOCA_H
17 #   include <alloca.h>
18 # else
19 #   if defined(_AIX) && !defined(C_ALLOCA)
20       /* if your version of AIX chokes on this, use gcc @@@ or alloca.o */
21 #pragma alloca
22 #   else
23 #     ifndef alloca /* predefined by HP cc +Olibcalls */
24 void *alloca ();
25 #     endif
26 #   endif
27 # endif
28 #endif
29
30
31 #include "host.h"
32
33
34 /* Alignment of nodes, cf common/tag.h, a power of two.
35
36    Most nodes are allocated from obstacks and therefore are aligned
37    identically on the obstacks' alignment boundary.  We'd like gcc to
38    align *all* nodes identically to avoid its cast-align warning and
39    perhaps allow for better code.  Since the common node alignment is
40    not known in time, we use an educated guess and check it against
41    the correct value later.  */
42 #define NODE_ALIGN ALIGNOF (struct { void *p; int i; })
43
44
45 /* Miscellaneous */
46
47 #ifndef MAX
48 # define MAX(a,b) ((a) > (b) ? (a) : (b))
49 #endif
50 #ifndef MIN
51 # define MIN(a,b) ((a) > (b) ? (b) : (a))
52 #endif
53
54 #define IS_POW2(n) ((((n)-1) & (n)) == 0)
55
56 typedef unsigned char bool;
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
71 # define xmalloc(size) (XMALLOC_TRACE (xmalloc) ((size)))
72 # define xrealloc(ptr, size) (XMALLOC_TRACE (xrealloc) ((ptr), (size)))
73 # define xstrdup(str) (XMALLOC_TRACE (xstrdup) ((str)))
74 # define xfree(ptr) (XMALLOC_TRACE free ((ptr)))
75
76 #if defined(HAVE_GNU_MALLOC) && defined(DEBUG)
77 extern const char *tmalloc_tag;
78 # define XMALLOC_TRACE tmalloc_tag = __FILE__,
79 #else
80 # define XMALLOC_TRACE
81 #endif
82
83 #endif