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