]> Git Repo - qemu.git/blame - include/qemu/compiler.h
hw/i386: add device tree support
[qemu.git] / include / qemu / compiler.h
CommitLineData
5c026320
LC
1/* public domain */
2
3#ifndef COMPILER_H
4#define COMPILER_H
5
5c026320 6
f8b72754
SW
7/*----------------------------------------------------------------------------
8| The macro QEMU_GNUC_PREREQ tests for minimum version of the GNU C compiler.
9| The code is a copy of SOFTFLOAT_GNUC_PREREQ, see softfloat-macros.h.
10*----------------------------------------------------------------------------*/
11#if defined(__GNUC__) && defined(__GNUC_MINOR__)
12# define QEMU_GNUC_PREREQ(maj, min) \
13 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
14#else
15# define QEMU_GNUC_PREREQ(maj, min) 0
16#endif
17
5c026320 18#define QEMU_NORETURN __attribute__ ((__noreturn__))
f8b72754 19
87751797 20#if QEMU_GNUC_PREREQ(3, 4)
5c026320
LC
21#define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
22#else
23#define QEMU_WARN_UNUSED_RESULT
24#endif
25
a31bdae5
DB
26#if QEMU_GNUC_PREREQ(4, 0)
27#define QEMU_SENTINEL __attribute__((sentinel))
28#else
29#define QEMU_SENTINEL
30#endif
31
58099c80
RH
32#if QEMU_GNUC_PREREQ(4, 3)
33#define QEMU_ARTIFICIAL __attribute__((always_inline, artificial))
34#else
35#define QEMU_ARTIFICIAL
36#endif
37
0f7fdd34
SW
38#if defined(_WIN32)
39# define QEMU_PACKED __attribute__((gcc_struct, packed))
40#else
41# define QEMU_PACKED __attribute__((packed))
42#endif
43
911a4d22
EC
44#define QEMU_ALIGNED(X) __attribute__((aligned(X)))
45
49120868
PM
46#ifndef glue
47#define xglue(x, y) x ## y
48#define glue(x, y) xglue(x, y)
49#define stringify(s) tostring(s)
50#define tostring(s) #s
51#endif
52
53#ifndef likely
54#if __GNUC__ < 3
55#define __builtin_expect(x, n) (x)
56#endif
57
58#define likely(x) __builtin_expect(!!(x), 1)
59#define unlikely(x) __builtin_expect(!!(x), 0)
60#endif
61
62#ifndef container_of
63#define container_of(ptr, type, member) ({ \
64 const typeof(((type *) 0)->member) *__mptr = (ptr); \
65 (type *) ((char *) __mptr - offsetof(type, member));})
66#endif
67
68/* Convert from a base type to a parent type, with compile time checking. */
69#ifdef __GNUC__
70#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
71 char __attribute__((unused)) offset_must_be_zero[ \
72 -offsetof(type, field)]; \
73 container_of(dev, type, field);}))
74#else
75#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
76#endif
77
78#define typeof_field(type, field) typeof(((type *)0)->field)
79#define type_check(t1,t2) ((t1*)0 - (t2*)0)
80
5c026320 81#define QEMU_BUILD_BUG_ON(x) \
24134c4e 82 typedef char glue(qemu_build_bug_on__,__LINE__)[(x)?-1:1] __attribute__((unused));
5c026320
LC
83
84#if defined __GNUC__
f8b72754 85# if !QEMU_GNUC_PREREQ(4, 4)
5c026320 86 /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
5c026320
LC
87# define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
88# else
89 /* Use gnu_printf when supported (qemu uses standard format strings). */
5c026320 90# define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
95df51a4
SW
91# if defined(_WIN32)
92 /* Map __printf__ to __gnu_printf__ because we want standard format strings
93 * even when MinGW or GLib include files use __printf__. */
94# define __printf__ __gnu_printf__
95# endif
5c026320
LC
96# endif
97#else
5c026320
LC
98#define GCC_FMT_ATTR(n, m)
99#endif
100
101#endif /* COMPILER_H */
This page took 0.282233 seconds and 4 git commands to generate.