misc.h 2.33 KB
Newer Older
Götz Lindenmaier's avatar
Götz Lindenmaier committed
1
2
3
4
5
6
7
8
9
10
11
/*
 * Project:     libFIRM
 * File name:   ir/common/misc.h
 * Purpose:     Misc. declarations.
 * Author:      Markus Armbruster
 * Modified by:
 * Created:     1999 by getting from fiasco
 * CVS-ID:      $Id$
 * Copyright:   (c) 1995, 1996 Markus Armbruster
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */
Christian Schäfer's avatar
Christian Schäfer committed
12

Boris Boesler's avatar
Boris Boesler committed
13

Götz Lindenmaier's avatar
Götz Lindenmaier committed
14
15
#ifndef _MISC_H_
#define _MISC_H_
Christian Schäfer's avatar
Christian Schäfer committed
16
17
18
19
20
21
22
23
24
25
26
27
28

/* Declare alloca() */

#ifdef __GNUC__
  /* @@@ on a true GNU system, this is defined by stdlib.h */
# undef alloca
# define alloca(size) __builtin_alloca (size)
#else
# if HAVE_ALLOCA_H
#   include <alloca.h>
# else
#   if defined(_AIX) && !defined(C_ALLOCA)
      /* if your version of AIX chokes on this, use gcc @@@ or alloca.o */
Till Riedel's avatar
Till Riedel committed
29
    #pragma alloca
Christian Schäfer's avatar
Christian Schäfer committed
30
31
32
33
34
35
36
37
38
39
#   else
#     ifndef alloca /* predefined by HP cc +Olibcalls */
void *alloca ();
#     endif
#   endif
# endif
#endif


#include "host.h"
40
#include <stdbool.h>
Christian Schäfer's avatar
Christian Schäfer committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

/* Alignment of nodes, cf common/tag.h, a power of two.

   Most nodes are allocated from obstacks and therefore are aligned
   identically on the obstacks' alignment boundary.  We'd like gcc to
   align *all* nodes identically to avoid its cast-align warning and
   perhaps allow for better code.  Since the common node alignment is
   not known in time, we use an educated guess and check it against
   the correct value later.  */
#define NODE_ALIGN ALIGNOF (struct { void *p; int i; })


/* Miscellaneous */

#ifndef MAX
# define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
# define MIN(a,b) ((a) > (b) ? (b) : (a))
#endif

#define IS_POW2(n) ((((n)-1) & (n)) == 0)

typedef int (*cmp_fun) (const void *, const void *);


/* xmalloc() & friends.

   The macros set tmalloc_tag to __FILE__, the functions leave it
   alone.  Use the latter if you set it yourself.  See tmalloc.c for
   details.  */

extern void *xmalloc (size_t);
extern void *xrealloc (void *, size_t);
extern char *xstrdup (const char *);
extern void xnomem (void);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
77
extern void free (void *);
Christian Schäfer's avatar
Christian Schäfer committed
78
79
80
81
82
83
84
85
86
87
88
89
90

# define xmalloc(size) (XMALLOC_TRACE (xmalloc) ((size)))
# define xrealloc(ptr, size) (XMALLOC_TRACE (xrealloc) ((ptr), (size)))
# define xstrdup(str) (XMALLOC_TRACE (xstrdup) ((str)))
# define xfree(ptr) (XMALLOC_TRACE free ((ptr)))

#if defined(HAVE_GNU_MALLOC) && defined(DEBUG)
extern const char *tmalloc_tag;
# define XMALLOC_TRACE tmalloc_tag = __FILE__,
#else
# define XMALLOC_TRACE
#endif

Götz Lindenmaier's avatar
Götz Lindenmaier committed
91
#endif /* _MISC_H_ */