Search
lxdream.org :: lxdream/src/x86dasm/ansidecl.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/x86dasm/ansidecl.h
changeset 362:dc40e2064dc4
author nkeynes
date Tue Aug 28 08:46:54 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add the i386 disassembler from binutils (why write your own if you don't
have to) to use for translator validation
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/x86dasm/ansidecl.h Tue Aug 28 08:46:54 2007 +0000
1.3 @@ -0,0 +1,346 @@
1.4 +/* ANSI and traditional C compatability macros
1.5 + Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
1.6 + Free Software Foundation, Inc.
1.7 + This file is part of the GNU C Library.
1.8 +
1.9 +This program is free software; you can redistribute it and/or modify
1.10 +it under the terms of the GNU General Public License as published by
1.11 +the Free Software Foundation; either version 2 of the License, or
1.12 +(at your option) any later version.
1.13 +
1.14 +This program is distributed in the hope that it will be useful,
1.15 +but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 +GNU General Public License for more details.
1.18 +
1.19 +You should have received a copy of the GNU General Public License
1.20 +along with this program; if not, write to the Free Software
1.21 +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
1.22 +
1.23 +/* ANSI and traditional C compatibility macros
1.24 +
1.25 + ANSI C is assumed if __STDC__ is #defined.
1.26 +
1.27 + Macro ANSI C definition Traditional C definition
1.28 + ----- ---- - ---------- ----------- - ----------
1.29 + ANSI_PROTOTYPES 1 not defined
1.30 + PTR `void *' `char *'
1.31 + PTRCONST `void *const' `char *'
1.32 + LONG_DOUBLE `long double' `double'
1.33 + const not defined `'
1.34 + volatile not defined `'
1.35 + signed not defined `'
1.36 + VA_START(ap, var) va_start(ap, var) va_start(ap)
1.37 +
1.38 + Note that it is safe to write "void foo();" indicating a function
1.39 + with no return value, in all K+R compilers we have been able to test.
1.40 +
1.41 + For declaring functions with prototypes, we also provide these:
1.42 +
1.43 + PARAMS ((prototype))
1.44 + -- for functions which take a fixed number of arguments. Use this
1.45 + when declaring the function. When defining the function, write a
1.46 + K+R style argument list. For example:
1.47 +
1.48 + char *strcpy PARAMS ((char *dest, char *source));
1.49 + ...
1.50 + char *
1.51 + strcpy (dest, source)
1.52 + char *dest;
1.53 + char *source;
1.54 + { ... }
1.55 +
1.56 +
1.57 + VPARAMS ((prototype, ...))
1.58 + -- for functions which take a variable number of arguments. Use
1.59 + PARAMS to declare the function, VPARAMS to define it. For example:
1.60 +
1.61 + int printf PARAMS ((const char *format, ...));
1.62 + ...
1.63 + int
1.64 + printf VPARAMS ((const char *format, ...))
1.65 + {
1.66 + ...
1.67 + }
1.68 +
1.69 + For writing functions which take variable numbers of arguments, we
1.70 + also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros. These
1.71 + hide the differences between K+R <varargs.h> and C89 <stdarg.h> more
1.72 + thoroughly than the simple VA_START() macro mentioned above.
1.73 +
1.74 + VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end.
1.75 + Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls
1.76 + corresponding to the list of fixed arguments. Then use va_arg
1.77 + normally to get the variable arguments, or pass your va_list object
1.78 + around. You do not declare the va_list yourself; VA_OPEN does it
1.79 + for you.
1.80 +
1.81 + Here is a complete example:
1.82 +
1.83 + int
1.84 + printf VPARAMS ((const char *format, ...))
1.85 + {
1.86 + int result;
1.87 +
1.88 + VA_OPEN (ap, format);
1.89 + VA_FIXEDARG (ap, const char *, format);
1.90 +
1.91 + result = vfprintf (stdout, format, ap);
1.92 + VA_CLOSE (ap);
1.93 +
1.94 + return result;
1.95 + }
1.96 +
1.97 +
1.98 + You can declare variables either before or after the VA_OPEN,
1.99 + VA_FIXEDARG sequence. Also, VA_OPEN and VA_CLOSE are the beginning
1.100 + and end of a block. They must appear at the same nesting level,
1.101 + and any variables declared after VA_OPEN go out of scope at
1.102 + VA_CLOSE. Unfortunately, with a K+R compiler, that includes the
1.103 + argument list. You can have multiple instances of VA_OPEN/VA_CLOSE
1.104 + pairs in a single function in case you need to traverse the
1.105 + argument list more than once.
1.106 +
1.107 + For ease of writing code which uses GCC extensions but needs to be
1.108 + portable to other compilers, we provide the GCC_VERSION macro that
1.109 + simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
1.110 + wrappers around __attribute__. Also, __extension__ will be #defined
1.111 + to nothing if it doesn't work. See below.
1.112 +
1.113 + This header also defines a lot of obsolete macros:
1.114 + CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID,
1.115 + AND, DOTS, NOARGS. Don't use them. */
1.116 +
1.117 +#ifndef _ANSIDECL_H
1.118 +#define _ANSIDECL_H 1
1.119 +
1.120 +/* Every source file includes this file,
1.121 + so they will all get the switch for lint. */
1.122 +/* LINTLIBRARY */
1.123 +
1.124 +/* Using MACRO(x,y) in cpp #if conditionals does not work with some
1.125 + older preprocessors. Thus we can't define something like this:
1.126 +
1.127 +#define HAVE_GCC_VERSION(MAJOR, MINOR) \
1.128 + (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
1.129 +
1.130 +and then test "#if HAVE_GCC_VERSION(2,7)".
1.131 +
1.132 +So instead we use the macro below and test it against specific values. */
1.133 +
1.134 +/* This macro simplifies testing whether we are using gcc, and if it
1.135 + is of a particular minimum version. (Both major & minor numbers are
1.136 + significant.) This macro will evaluate to 0 if we are not using
1.137 + gcc at all. */
1.138 +#ifndef GCC_VERSION
1.139 +#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
1.140 +#endif /* GCC_VERSION */
1.141 +
1.142 +#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) || (defined(__alpha) && defined(__cplusplus))
1.143 +/* All known AIX compilers implement these things (but don't always
1.144 + define __STDC__). The RISC/OS MIPS compiler defines these things
1.145 + in SVR4 mode, but does not define __STDC__. */
1.146 +/* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
1.147 + C++ compilers, does not define __STDC__, though it acts as if this
1.148 + was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
1.149 +
1.150 +#define ANSI_PROTOTYPES 1
1.151 +#define PTR void *
1.152 +#define PTRCONST void *const
1.153 +#define LONG_DOUBLE long double
1.154 +
1.155 +/* PARAMS is often defined elsewhere (e.g. by libintl.h), so wrap it in
1.156 + a #ifndef. */
1.157 +#ifndef PARAMS
1.158 +#define PARAMS(ARGS) ARGS
1.159 +#endif
1.160 +
1.161 +#define VPARAMS(ARGS) ARGS
1.162 +#define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR)
1.163 +
1.164 +/* variadic function helper macros */
1.165 +/* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's
1.166 + use without inhibiting further decls and without declaring an
1.167 + actual variable. */
1.168 +#define VA_OPEN(AP, VAR) { va_list AP; va_start(AP, VAR); { struct Qdmy
1.169 +#define VA_CLOSE(AP) } va_end(AP); }
1.170 +#define VA_FIXEDARG(AP, T, N) struct Qdmy
1.171 +
1.172 +#undef const
1.173 +#undef volatile
1.174 +#undef signed
1.175 +
1.176 +/* inline requires special treatment; it's in C99, and GCC >=2.7 supports
1.177 + it too, but it's not in C89. */
1.178 +#undef inline
1.179 +#if __STDC_VERSION__ > 199901L
1.180 +/* it's a keyword */
1.181 +#else
1.182 +# if GCC_VERSION >= 2007
1.183 +# define inline __inline__ /* __inline__ prevents -pedantic warnings */
1.184 +# else
1.185 +# define inline /* nothing */
1.186 +# endif
1.187 +#endif
1.188 +
1.189 +/* These are obsolete. Do not use. */
1.190 +#ifndef IN_GCC
1.191 +#define CONST const
1.192 +#define VOLATILE volatile
1.193 +#define SIGNED signed
1.194 +
1.195 +#define PROTO(type, name, arglist) type name arglist
1.196 +#define EXFUN(name, proto) name proto
1.197 +#define DEFUN(name, arglist, args) name(args)
1.198 +#define DEFUN_VOID(name) name(void)
1.199 +#define AND ,
1.200 +#define DOTS , ...
1.201 +#define NOARGS void
1.202 +#endif /* ! IN_GCC */
1.203 +
1.204 +#else /* Not ANSI C. */
1.205 +
1.206 +#undef ANSI_PROTOTYPES
1.207 +#define PTR char *
1.208 +#define PTRCONST PTR
1.209 +#define LONG_DOUBLE double
1.210 +
1.211 +#define PARAMS(args) ()
1.212 +#define VPARAMS(args) (va_alist) va_dcl
1.213 +#define VA_START(va_list, var) va_start(va_list)
1.214 +
1.215 +#define VA_OPEN(AP, VAR) { va_list AP; va_start(AP); { struct Qdmy
1.216 +#define VA_CLOSE(AP) } va_end(AP); }
1.217 +#define VA_FIXEDARG(AP, TYPE, NAME) TYPE NAME = va_arg(AP, TYPE)
1.218 +
1.219 +/* some systems define these in header files for non-ansi mode */
1.220 +#undef const
1.221 +#undef volatile
1.222 +#undef signed
1.223 +#undef inline
1.224 +#define const
1.225 +#define volatile
1.226 +#define signed
1.227 +#define inline
1.228 +
1.229 +#ifndef IN_GCC
1.230 +#define CONST
1.231 +#define VOLATILE
1.232 +#define SIGNED
1.233 +
1.234 +#define PROTO(type, name, arglist) type name ()
1.235 +#define EXFUN(name, proto) name()
1.236 +#define DEFUN(name, arglist, args) name arglist args;
1.237 +#define DEFUN_VOID(name) name()
1.238 +#define AND ;
1.239 +#define DOTS
1.240 +#define NOARGS
1.241 +#endif /* ! IN_GCC */
1.242 +
1.243 +#endif /* ANSI C. */
1.244 +
1.245 +/* Define macros for some gcc attributes. This permits us to use the
1.246 + macros freely, and know that they will come into play for the
1.247 + version of gcc in which they are supported. */
1.248 +
1.249 +#if (GCC_VERSION < 2007)
1.250 +# define __attribute__(x)
1.251 +#endif
1.252 +
1.253 +/* Attribute __malloc__ on functions was valid as of gcc 2.96. */
1.254 +#ifndef ATTRIBUTE_MALLOC
1.255 +# if (GCC_VERSION >= 2096)
1.256 +# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
1.257 +# else
1.258 +# define ATTRIBUTE_MALLOC
1.259 +# endif /* GNUC >= 2.96 */
1.260 +#endif /* ATTRIBUTE_MALLOC */
1.261 +
1.262 +/* Attributes on labels were valid as of gcc 2.93. */
1.263 +#ifndef ATTRIBUTE_UNUSED_LABEL
1.264 +# if (GCC_VERSION >= 2093)
1.265 +# define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
1.266 +# else
1.267 +# define ATTRIBUTE_UNUSED_LABEL
1.268 +# endif /* GNUC >= 2.93 */
1.269 +#endif /* ATTRIBUTE_UNUSED_LABEL */
1.270 +
1.271 +#ifndef ATTRIBUTE_UNUSED
1.272 +#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
1.273 +#endif /* ATTRIBUTE_UNUSED */
1.274 +
1.275 +/* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the
1.276 + identifier name. */
1.277 +#if ! defined(__cplusplus) || (GCC_VERSION >= 3004)
1.278 +# define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED
1.279 +#else /* !__cplusplus || GNUC >= 3.4 */
1.280 +# define ARG_UNUSED(NAME) NAME
1.281 +#endif /* !__cplusplus || GNUC >= 3.4 */
1.282 +
1.283 +#ifndef ATTRIBUTE_NORETURN
1.284 +#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
1.285 +#endif /* ATTRIBUTE_NORETURN */
1.286 +
1.287 +/* Attribute `nonnull' was valid as of gcc 3.3. */
1.288 +#ifndef ATTRIBUTE_NONNULL
1.289 +# if (GCC_VERSION >= 3003)
1.290 +# define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
1.291 +# else
1.292 +# define ATTRIBUTE_NONNULL(m)
1.293 +# endif /* GNUC >= 3.3 */
1.294 +#endif /* ATTRIBUTE_NONNULL */
1.295 +
1.296 +/* Attribute `pure' was valid as of gcc 3.0. */
1.297 +#ifndef ATTRIBUTE_PURE
1.298 +# if (GCC_VERSION >= 3000)
1.299 +# define ATTRIBUTE_PURE __attribute__ ((__pure__))
1.300 +# else
1.301 +# define ATTRIBUTE_PURE
1.302 +# endif /* GNUC >= 3.0 */
1.303 +#endif /* ATTRIBUTE_PURE */
1.304 +
1.305 +/* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
1.306 + This was the case for the `printf' format attribute by itself
1.307 + before GCC 3.3, but as of 3.3 we need to add the `nonnull'
1.308 + attribute to retain this behavior. */
1.309 +#ifndef ATTRIBUTE_PRINTF
1.310 +#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
1.311 +#define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
1.312 +#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
1.313 +#define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
1.314 +#define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
1.315 +#define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
1.316 +#endif /* ATTRIBUTE_PRINTF */
1.317 +
1.318 +/* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL. A
1.319 + NULL format specifier was allowed as of gcc 3.3. */
1.320 +#ifndef ATTRIBUTE_NULL_PRINTF
1.321 +# if (GCC_VERSION >= 3003)
1.322 +# define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
1.323 +# else
1.324 +# define ATTRIBUTE_NULL_PRINTF(m, n)
1.325 +# endif /* GNUC >= 3.3 */
1.326 +# define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
1.327 +# define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
1.328 +# define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
1.329 +# define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
1.330 +# define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
1.331 +#endif /* ATTRIBUTE_NULL_PRINTF */
1.332 +
1.333 +/* Attribute `sentinel' was valid as of gcc 3.5. */
1.334 +#ifndef ATTRIBUTE_SENTINEL
1.335 +# if (GCC_VERSION >= 3005)
1.336 +# define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
1.337 +# else
1.338 +# define ATTRIBUTE_SENTINEL
1.339 +# endif /* GNUC >= 3.5 */
1.340 +#endif /* ATTRIBUTE_SENTINEL */
1.341 +
1.342 +/* We use __extension__ in some places to suppress -pedantic warnings
1.343 + about GCC extensions. This feature didn't work properly before
1.344 + gcc 2.8. */
1.345 +#if GCC_VERSION < 2008
1.346 +#define __extension__
1.347 +#endif
1.348 +
1.349 +#endif /* ansidecl.h */
.