Statistics
| Branch: | Revision:

root / compiler.h @ 01e26b0e

History | View | Annotate | Download (2.3 kB)

1 5c026320 Luiz Capitulino
/* public domain */
2 5c026320 Luiz Capitulino
3 5c026320 Luiz Capitulino
#ifndef COMPILER_H
4 5c026320 Luiz Capitulino
#define COMPILER_H
5 5c026320 Luiz Capitulino
6 5c026320 Luiz Capitulino
#include "config-host.h"
7 5c026320 Luiz Capitulino
8 f8b72754 Stefan Weil
/*----------------------------------------------------------------------------
9 f8b72754 Stefan Weil
| The macro QEMU_GNUC_PREREQ tests for minimum version of the GNU C compiler.
10 f8b72754 Stefan Weil
| The code is a copy of SOFTFLOAT_GNUC_PREREQ, see softfloat-macros.h.
11 f8b72754 Stefan Weil
*----------------------------------------------------------------------------*/
12 f8b72754 Stefan Weil
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
13 f8b72754 Stefan Weil
# define QEMU_GNUC_PREREQ(maj, min) \
14 f8b72754 Stefan Weil
         ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
15 f8b72754 Stefan Weil
#else
16 f8b72754 Stefan Weil
# define QEMU_GNUC_PREREQ(maj, min) 0
17 f8b72754 Stefan Weil
#endif
18 f8b72754 Stefan Weil
19 5c026320 Luiz Capitulino
#define QEMU_NORETURN __attribute__ ((__noreturn__))
20 f8b72754 Stefan Weil
21 87751797 Stefan Weil
#if QEMU_GNUC_PREREQ(3, 4)
22 5c026320 Luiz Capitulino
#define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
23 5c026320 Luiz Capitulino
#else
24 5c026320 Luiz Capitulino
#define QEMU_WARN_UNUSED_RESULT
25 5c026320 Luiz Capitulino
#endif
26 5c026320 Luiz Capitulino
27 0f7fdd34 Stefan Weil
#if defined(_WIN32)
28 0f7fdd34 Stefan Weil
# define QEMU_PACKED __attribute__((gcc_struct, packed))
29 0f7fdd34 Stefan Weil
#else
30 0f7fdd34 Stefan Weil
# define QEMU_PACKED __attribute__((packed))
31 0f7fdd34 Stefan Weil
#endif
32 0f7fdd34 Stefan Weil
33 ea8f978f Dong Xu Wang
#define cat(x,y) x ## y
34 ea8f978f Dong Xu Wang
#define cat2(x,y) cat(x,y)
35 5c026320 Luiz Capitulino
#define QEMU_BUILD_BUG_ON(x) \
36 ea8f978f Dong Xu Wang
    typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1];
37 5c026320 Luiz Capitulino
38 5c026320 Luiz Capitulino
#if defined __GNUC__
39 f8b72754 Stefan Weil
# if !QEMU_GNUC_PREREQ(4, 4)
40 5c026320 Luiz Capitulino
   /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
41 5c026320 Luiz Capitulino
#  define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2)))
42 5c026320 Luiz Capitulino
#  define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
43 5c026320 Luiz Capitulino
# else
44 5c026320 Luiz Capitulino
   /* Use gnu_printf when supported (qemu uses standard format strings). */
45 5c026320 Luiz Capitulino
#  define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2)))
46 5c026320 Luiz Capitulino
#  define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
47 95df51a4 Stefan Weil
#  if defined(_WIN32)
48 95df51a4 Stefan Weil
    /* Map __printf__ to __gnu_printf__ because we want standard format strings
49 95df51a4 Stefan Weil
     * even when MinGW or GLib include files use __printf__. */
50 95df51a4 Stefan Weil
#   define __printf__ __gnu_printf__
51 95df51a4 Stefan Weil
#  endif
52 5c026320 Luiz Capitulino
# endif
53 1f001dc7 Paolo Bonzini
# if defined(__APPLE__)
54 1f001dc7 Paolo Bonzini
#  define QEMU_WEAK_ALIAS(newname, oldname) \
55 1f001dc7 Paolo Bonzini
        static typeof(oldname) weak_##newname __attribute__((unused, weakref(#oldname)))
56 1f001dc7 Paolo Bonzini
#  define QEMU_WEAK_REF(newname, oldname) (weak_##newname ? weak_##newname : oldname)
57 1f001dc7 Paolo Bonzini
# else
58 1f001dc7 Paolo Bonzini
#  define QEMU_WEAK_ALIAS(newname, oldname) \
59 67d223be Paolo Bonzini
        typeof(oldname) newname __attribute__((weak, alias (#oldname)))
60 1f001dc7 Paolo Bonzini
#  define QEMU_WEAK_REF(newname, oldname) newname
61 1f001dc7 Paolo Bonzini
# endif
62 5c026320 Luiz Capitulino
#else
63 5c026320 Luiz Capitulino
#define GCC_ATTR /**/
64 5c026320 Luiz Capitulino
#define GCC_FMT_ATTR(n, m)
65 67d223be Paolo Bonzini
#define QEMU_WEAK_ALIAS(newname, oldname) \
66 67d223be Paolo Bonzini
        _Pragma("weak " #newname "=" #oldname)
67 5c026320 Luiz Capitulino
#endif
68 5c026320 Luiz Capitulino
69 5c026320 Luiz Capitulino
#endif /* COMPILER_H */