2025-10-01 11:25:38 -07:00
|
|
|
/* SPDX-License-Identifier: BSD-2-Clause */
|
|
|
|
|
/* Copyright 2007-2025 The NASM Authors - All Rights Reserved */
|
2007-04-13 19:58:42 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* compiler.h
|
|
|
|
|
*
|
|
|
|
|
* Compiler-specific macros for NASM. Feel free to add support for
|
|
|
|
|
* other compilers in here.
|
2007-10-02 21:53:51 -07:00
|
|
|
*
|
|
|
|
|
* This header file should be included before any other header.
|
2007-04-13 19:58:42 +00:00
|
|
|
*/
|
|
|
|
|
|
2007-10-02 21:53:51 -07:00
|
|
|
#ifndef NASM_COMPILER_H
|
|
|
|
|
#define NASM_COMPILER_H 1
|
2007-04-13 20:06:41 +00:00
|
|
|
|
2016-07-14 13:51:01 -07:00
|
|
|
/*
|
|
|
|
|
* At least DJGPP and Cygwin have broken header files if __STRICT_ANSI__
|
|
|
|
|
* is defined.
|
|
|
|
|
*/
|
|
|
|
|
#ifdef __GNUC__
|
2016-01-27 14:29:40 -08:00
|
|
|
# undef __STRICT_ANSI__
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-18 11:57:53 -08:00
|
|
|
/* On Microsoft platforms we support multibyte character sets in filenames */
|
|
|
|
|
#define _MBCS 1
|
|
|
|
|
|
2023-10-11 12:06:18 -07:00
|
|
|
#include "autoconf/attribute.h"
|
|
|
|
|
|
2007-04-13 20:06:41 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2016-10-04 17:01:59 -07:00
|
|
|
# include "config/config.h"
|
2008-06-10 13:00:27 -07:00
|
|
|
#else
|
2019-08-16 00:08:27 -07:00
|
|
|
# if defined(_MSC_VER) && (_MSC_VER >= 1310)
|
|
|
|
|
# include "config/msvc.h"
|
|
|
|
|
# elif defined(__WATCOMC__)
|
|
|
|
|
# include "config/watcom.h"
|
|
|
|
|
# else
|
|
|
|
|
# include "config/unknown.h"
|
|
|
|
|
# endif
|
|
|
|
|
/* This unconditionally defines some macros we really want */
|
|
|
|
|
# include "config/unconfig.h"
|
2016-10-04 17:01:59 -07:00
|
|
|
#endif /* Configuration file */
|
2007-04-13 19:58:42 +00:00
|
|
|
|
2007-10-11 12:50:24 -07:00
|
|
|
/* This is required to get the standard <inttypes.h> macros when compiling
|
|
|
|
|
with a C++ compiler. This must be defined *before* <inttypes.h> is
|
|
|
|
|
included, directly or indirectly. */
|
|
|
|
|
#define __STDC_CONSTANT_MACROS 1
|
|
|
|
|
#define __STDC_LIMIT_MACROS 1
|
|
|
|
|
#define __STDC_FORMAT_MACROS 1
|
|
|
|
|
|
2016-03-08 12:14:55 -08:00
|
|
|
#ifdef HAVE_INTTYPES_H
|
|
|
|
|
# include <inttypes.h>
|
|
|
|
|
#else
|
|
|
|
|
# include "nasmint.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-12-20 02:29:58 -08:00
|
|
|
#include <assert.h>
|
2007-09-28 10:50:20 -07:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdarg.h>
|
2007-10-02 21:53:51 -07:00
|
|
|
#include <stdio.h>
|
2018-12-12 14:34:34 -08:00
|
|
|
#include <stdlib.h>
|
2018-12-26 06:32:37 -08:00
|
|
|
#include <string.h>
|
2017-02-20 00:36:53 -08:00
|
|
|
#include <limits.h>
|
2020-06-01 12:32:35 -07:00
|
|
|
#include <errno.h>
|
2007-09-28 10:50:20 -07:00
|
|
|
|
2018-12-27 12:46:55 -08:00
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
|
# include <strings.h>
|
|
|
|
|
#endif
|
2016-10-19 13:13:38 -07:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
|
# include <sys/types.h>
|
|
|
|
|
#endif
|
2017-04-24 13:28:14 -07:00
|
|
|
|
2025-09-30 09:31:40 -07:00
|
|
|
/*
|
|
|
|
|
* This is impossible to do 100% accurately, because the actual type
|
|
|
|
|
* of size_t may differ from its range.
|
|
|
|
|
*/
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
# define PRIz "I" /* Needed for msvcrt, not ucrt */
|
|
|
|
|
#elif defined(PRINTF_SUPPORTS_Z) || \
|
|
|
|
|
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
|
|
|
|
|
# define PRIz "z"
|
|
|
|
|
#elif SIZE_MAX == UINT_MAX
|
|
|
|
|
# define PRIz ""
|
|
|
|
|
#elif SIZE_MAX == ULONG_MAX
|
|
|
|
|
# define PRIz "l"
|
|
|
|
|
#elif SIZE_MAX == ULONGLONG_MAX
|
|
|
|
|
# define PRIz "ll"
|
|
|
|
|
#else
|
|
|
|
|
# error "Unable to determine printf format for size_t"
|
|
|
|
|
#endif
|
|
|
|
|
#define PRIzd PRIz "u" /* size_t is always unsigned */
|
|
|
|
|
#define PRIzu PRIz "u"
|
|
|
|
|
#define PRIzu PRIz "u"
|
|
|
|
|
#define PRIzx PRIz "x"
|
|
|
|
|
#define PRIzX PRIz "X"
|
|
|
|
|
|
2025-08-29 01:46:57 -07:00
|
|
|
#ifdef HAVE_STDBIT_H
|
|
|
|
|
|
|
|
|
|
# include <stdbit.h>
|
|
|
|
|
|
|
|
|
|
# undef WORDS_LITTLEENDIAN
|
|
|
|
|
# undef WORDS_BIGENDIAN
|
|
|
|
|
# if __STDC_ENDIAN_NATIVE__ == __STDC_ENDIAN_LITTLE__
|
|
|
|
|
# define WORDS_LITTLEENDIAN 1
|
|
|
|
|
# elif __STDC_ENDIAN_NATIVE__ == __STDC_ENDIAN_BIG__
|
|
|
|
|
# define WORDS_BIGENDIAN 1
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
#else /* No <stdbit.h> */
|
|
|
|
|
|
|
|
|
|
# ifdef HAVE_ENDIAN_H
|
|
|
|
|
# include <endian.h>
|
|
|
|
|
# elif defined(HAVE_SYS_ENDIAN_H)
|
|
|
|
|
# include <sys/endian.h>
|
|
|
|
|
# elif defined(HAVE_MACHINE_ENDIAN_H)
|
|
|
|
|
# include <machine/endian.h>
|
|
|
|
|
# endif
|
2017-04-24 12:58:30 -07:00
|
|
|
|
|
|
|
|
/*
|
2017-04-25 12:51:17 -07:00
|
|
|
* If we have BYTE_ORDER defined, or the compiler provides
|
|
|
|
|
* __BIG_ENDIAN__ or __LITTLE_ENDIAN__, trust it over what autoconf
|
|
|
|
|
* came up with, especially since autoconf obviously can't figure
|
|
|
|
|
* things out for a universal compiler.
|
2017-04-24 12:58:30 -07:00
|
|
|
*/
|
2025-08-29 01:46:57 -07:00
|
|
|
# if defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
|
|
|
|
|
# undef WORDS_LITTLEENDIAN
|
|
|
|
|
# undef WORDS_BIGENDIAN
|
2017-04-24 12:58:30 -07:00
|
|
|
# define WORDS_BIGENDIAN 1
|
2025-08-29 01:46:57 -07:00
|
|
|
# elif defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
|
|
|
|
|
# undef WORDS_LITTLEENDIAN
|
|
|
|
|
# undef WORDS_BIGENDIAN
|
|
|
|
|
# define WORDS_LITTLEENDIAN 1
|
|
|
|
|
# elif defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
|
|
|
|
|
# undef WORDS_LITTLEENDIAN
|
|
|
|
|
# undef WORDS_BIGENDIAN
|
|
|
|
|
# if BYTE_ORDER == LITTLE_ENDIAN
|
|
|
|
|
# define WORDS_LITTLEENDIAN 1
|
|
|
|
|
# elif BYTE_ORDER == BIG_ENDIAN
|
|
|
|
|
# define WORDS_BIGENDIAN 1
|
|
|
|
|
# endif
|
2017-04-24 12:58:30 -07:00
|
|
|
# endif
|
2025-08-29 01:46:57 -07:00
|
|
|
|
2017-04-24 12:58:30 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Define this to 1 for faster performance if this is a littleendian
|
2017-04-25 12:51:17 -07:00
|
|
|
* platform *and* it can do arbitrary unaligned memory references. It
|
|
|
|
|
* is safe to leave it defined to 0 even if that is true.
|
2017-04-24 12:58:30 -07:00
|
|
|
*/
|
|
|
|
|
#if defined(__386__) || defined(__i386__) || defined(__x86_64__) \
|
|
|
|
|
|| defined(_M_IX86) || defined(_M_X64)
|
|
|
|
|
# define X86_MEMORY 1
|
2017-04-25 12:51:17 -07:00
|
|
|
# undef WORDS_BIGENDIAN
|
|
|
|
|
# undef WORDS_LITTLEENDIAN
|
|
|
|
|
# define WORDS_LITTLEENDIAN 1
|
2017-04-24 12:58:30 -07:00
|
|
|
#else
|
|
|
|
|
# define X86_MEMORY 0
|
|
|
|
|
#endif
|
2016-10-19 13:13:38 -07:00
|
|
|
|
2016-03-08 12:14:55 -08:00
|
|
|
/* Some versions of MSVC have these only with underscores in front */
|
2007-09-28 10:50:20 -07:00
|
|
|
#ifndef HAVE_SNPRINTF
|
|
|
|
|
# ifdef HAVE__SNPRINTF
|
|
|
|
|
# define snprintf _snprintf
|
|
|
|
|
# else
|
|
|
|
|
int snprintf(char *, size_t, const char *, ...);
|
|
|
|
|
# endif
|
2007-09-17 13:53:14 -07:00
|
|
|
#endif
|
|
|
|
|
|
2007-09-28 10:50:20 -07:00
|
|
|
#ifndef HAVE_VSNPRINTF
|
2014-11-26 10:44:19 +03:00
|
|
|
# ifdef HAVE__VSNPRINTF
|
2007-09-28 10:50:20 -07:00
|
|
|
# define vsnprintf _vsnprintf
|
|
|
|
|
# else
|
|
|
|
|
int vsnprintf(char *, size_t, const char *, va_list);
|
|
|
|
|
# endif
|
2007-09-17 13:53:14 -07:00
|
|
|
#endif
|
|
|
|
|
|
2017-02-23 19:23:10 -08:00
|
|
|
#if !defined(HAVE_STRLCPY) || !HAVE_DECL_STRLCPY
|
2009-08-10 15:56:52 -07:00
|
|
|
size_t strlcpy(char *, const char *, size_t);
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-09-16 13:25:39 -07:00
|
|
|
/* C++ and C23 have bool, false, and true as proper keywords */
|
2025-10-12 13:05:55 -07:00
|
|
|
#if !defined(__cplusplus) && (__STDC_VERSION__ < 202311L)
|
2016-02-18 00:54:30 -08:00
|
|
|
# ifdef HAVE_STDBOOL_H
|
2007-10-10 14:58:45 -07:00
|
|
|
# include <stdbool.h>
|
2025-09-16 13:25:39 -07:00
|
|
|
# elif defined(HAVE___BOOL)
|
2019-08-09 23:50:20 +03:00
|
|
|
typedef _Bool bool;
|
2016-02-18 00:54:30 -08:00
|
|
|
# define false 0
|
|
|
|
|
# define true 1
|
2007-10-10 14:58:45 -07:00
|
|
|
# else
|
2025-09-16 13:25:39 -07:00
|
|
|
/* This is a bit dangerous, because casting to this ersatz bool
|
|
|
|
|
will not produce the same result as the standard (bool) cast.
|
2025-10-12 12:48:32 -07:00
|
|
|
Instead, use the explicit construct !!x instead of relying on
|
|
|
|
|
implicit conversions or casts. */
|
2008-06-10 13:00:27 -07:00
|
|
|
typedef enum bool { false, true } bool;
|
2007-10-10 14:58:45 -07:00
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-07-06 17:13:02 -07:00
|
|
|
/* Create a NULL pointer of the same type as the address of
|
|
|
|
|
the argument, without actually evaluating said argument. */
|
|
|
|
|
#define nullas(p) (0 ? &(p) : NULL)
|
|
|
|
|
|
|
|
|
|
/* Convert an offsetted NULL pointer dereference to a size_t offset.
|
|
|
|
|
Technically non-portable as taking the offset from a NULL pointer
|
|
|
|
|
is undefined behavior, but... */
|
|
|
|
|
#define null_offset(p) ((size_t)((const char *)&(p) - (const char *)NULL))
|
|
|
|
|
|
2008-10-30 10:52:08 -07:00
|
|
|
/* Provide a substitute for offsetof() if we don't have one. This
|
|
|
|
|
variant works on most (but not *all*) systems... */
|
|
|
|
|
#ifndef offsetof
|
2020-07-06 17:13:02 -07:00
|
|
|
# define offsetof(t,m) null_offset(((t *)NULL)->m)
|
2008-10-30 10:52:08 -07:00
|
|
|
#endif
|
|
|
|
|
|
2020-07-06 12:39:14 -07:00
|
|
|
/* If typeof is defined as a macro, assume we have typeof even if
|
|
|
|
|
HAVE_TYPEOF is not declared (e.g. due to not using autoconf.) */
|
|
|
|
|
#ifdef typeof
|
|
|
|
|
# define HAVE_TYPEOF 1
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* This is like offsetof(), but takes an object rather than a type. */
|
2018-12-14 00:27:59 -08:00
|
|
|
#ifndef offsetin
|
2020-07-06 12:39:14 -07:00
|
|
|
# ifdef HAVE_TYPEOF
|
|
|
|
|
# define offsetin(p,m) offsetof(typeof(p),m)
|
|
|
|
|
# else
|
2020-07-06 17:13:02 -07:00
|
|
|
# define offsetin(p,m) null_offset(nullas(p)->m)
|
2020-07-06 12:50:12 -07:00
|
|
|
# endif
|
2018-12-14 00:27:59 -08:00
|
|
|
#endif
|
|
|
|
|
|
2008-10-30 10:52:08 -07:00
|
|
|
/* The container_of construct: if p is a pointer to member m of
|
|
|
|
|
container class c, then return a pointer to the container of which
|
|
|
|
|
*p is a member. */
|
|
|
|
|
#ifndef container_of
|
|
|
|
|
# define container_of(p, c, m) ((c *)((char *)(p) - offsetof(c,m)))
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-10-26 18:49:29 -07:00
|
|
|
/* Some misguided platforms hide the defs for these */
|
2017-02-23 19:23:10 -08:00
|
|
|
#if defined(HAVE_STRCASECMP) && !HAVE_DECL_STRCASECMP
|
2007-10-26 18:49:29 -07:00
|
|
|
int strcasecmp(const char *, const char *);
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-02-23 19:23:10 -08:00
|
|
|
#if defined(HAVE_STRICMP) && !HAVE_DECL_STRICMP
|
2007-10-26 18:49:29 -07:00
|
|
|
int stricmp(const char *, const char *);
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-02-23 19:23:10 -08:00
|
|
|
#if defined(HAVE_STRNCASECMP) && !HAVE_DECL_STRNCASECMP
|
2007-10-26 18:49:29 -07:00
|
|
|
int strncasecmp(const char *, const char *, size_t);
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-02-23 19:23:10 -08:00
|
|
|
#if defined(HAVE_STRNICMP) && !HAVE_DECL_STRNICMP
|
2007-10-26 18:49:29 -07:00
|
|
|
int strnicmp(const char *, const char *, size_t);
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-02-23 19:23:10 -08:00
|
|
|
#if defined(HAVE_STRSEP) && !HAVE_DECL_STRSEP
|
2007-10-26 18:49:29 -07:00
|
|
|
char *strsep(char **, const char *);
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-02-23 19:23:10 -08:00
|
|
|
#if !HAVE_DECL_STRNLEN
|
|
|
|
|
size_t strnlen(const char *s, size_t maxlen);
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-12-26 06:22:47 -08:00
|
|
|
#ifndef HAVE_MEMPCPY
|
|
|
|
|
static inline void *mempcpy(void *dst, const void *src, size_t n)
|
|
|
|
|
{
|
2018-12-26 06:49:18 -08:00
|
|
|
return (char *)memcpy(dst, src, n) + n;
|
2018-12-26 06:22:47 -08:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-11-07 10:26:03 -08:00
|
|
|
#ifndef HAVE_MEMPSET
|
|
|
|
|
static inline void *mempset(void *dst, int c, size_t n)
|
|
|
|
|
{
|
|
|
|
|
return (char *)memset(dst, c, n) + n;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-09-27 13:34:42 -07:00
|
|
|
/*
|
|
|
|
|
* Hack to support external-linkage inline functions
|
|
|
|
|
*/
|
2018-02-20 12:34:17 -08:00
|
|
|
#ifndef HAVE_STDC_INLINE
|
|
|
|
|
# ifdef __GNUC__
|
|
|
|
|
# ifdef __GNUC_STDC_INLINE__
|
|
|
|
|
# define HAVE_STDC_INLINE
|
|
|
|
|
# else
|
|
|
|
|
# define HAVE_GNU_INLINE
|
|
|
|
|
# endif
|
|
|
|
|
# elif defined(__GNUC_GNU_INLINE__)
|
|
|
|
|
/* Some other compiler implementing only GNU inline semantics? */
|
|
|
|
|
# define HAVE_GNU_INLINE
|
|
|
|
|
# elif defined(__STDC_VERSION__)
|
|
|
|
|
# if __STDC_VERSION__ >= 199901L
|
|
|
|
|
# define HAVE_STDC_INLINE
|
|
|
|
|
# endif
|
2017-09-27 13:34:42 -07:00
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_STDC_INLINE
|
|
|
|
|
# define extern_inline inline
|
|
|
|
|
#elif defined(HAVE_GNU_INLINE)
|
|
|
|
|
# define extern_inline extern inline
|
2018-02-20 12:34:17 -08:00
|
|
|
# define inline_prototypes
|
2017-09-27 13:34:42 -07:00
|
|
|
#else
|
|
|
|
|
# define inline_prototypes
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-06-10 09:35:26 -07:00
|
|
|
/*
|
|
|
|
|
* Hints to the compiler that a particular branch of code is more or
|
|
|
|
|
* less likely to be taken.
|
|
|
|
|
*/
|
2025-10-03 10:46:07 -07:00
|
|
|
#ifdef HAVE___BUILTIN_EXPECT
|
2025-10-12 12:48:32 -07:00
|
|
|
# define likely(x) __builtin_expect(!!(x), true)
|
|
|
|
|
# define unlikely(x) __builtin_expect(!!(x), false)
|
2008-06-10 09:35:26 -07:00
|
|
|
#else
|
2025-10-12 12:48:32 -07:00
|
|
|
# define likely(x) (!!(x))
|
|
|
|
|
# define unlikely(x) (!!(x))
|
2025-09-16 13:25:39 -07:00
|
|
|
#endif
|
|
|
|
|
|
2025-10-03 10:46:07 -07:00
|
|
|
#ifdef HAVE___BUILTIN_PREFETCH
|
|
|
|
|
# define prefetch(x) __builtin_prefetch(x)
|
|
|
|
|
#else
|
|
|
|
|
# define prefetch(x) ((void)(x))
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-09-16 13:25:39 -07:00
|
|
|
/*
|
|
|
|
|
* Attributes
|
|
|
|
|
*/
|
|
|
|
|
|
2019-08-16 00:08:27 -07:00
|
|
|
#define safe_alloc never_null malloc_func
|
|
|
|
|
#define safe_alloc_ptr never_null_ptr malloc_func_ptr
|
2016-05-25 03:56:34 -07:00
|
|
|
|
2019-08-16 00:08:27 -07:00
|
|
|
#define safe_malloc(s) safe_alloc alloc_size_func1(s)
|
|
|
|
|
#define safe_malloc2(s1,s2) safe_alloc alloc_size_func2(s1,s2)
|
|
|
|
|
#define safe_realloc(s) never_null alloc_size_func1(s)
|
|
|
|
|
#define safe_malloc_ptr(s) safe_alloc_ptr alloc_size_func1_ptr(s)
|
|
|
|
|
#define safe_malloc2_ptr(s1,s2) safe_alloc_ptr alloc_size_func2_ptr(s1,s2)
|
|
|
|
|
#define safe_realloc_ptr(s) never_null_ptr alloc_size_func1_ptr(s)
|
2018-05-30 11:40:42 -07:00
|
|
|
|
2009-07-01 22:01:07 -07:00
|
|
|
/*
|
|
|
|
|
* How to tell the compiler that a function doesn't return
|
|
|
|
|
*/
|
2025-09-16 15:27:34 -07:00
|
|
|
#ifdef HAVE_STDNORETURN_H
|
2016-12-20 02:29:58 -08:00
|
|
|
# include <stdnoreturn.h>
|
2025-09-16 13:25:39 -07:00
|
|
|
# define no_return noreturn
|
2017-04-06 13:48:54 -07:00
|
|
|
#elif defined(_MSC_VER)
|
2025-09-16 13:25:39 -07:00
|
|
|
# define no_return __declspec(noreturn)
|
2009-07-01 22:01:07 -07:00
|
|
|
#else
|
2025-09-16 13:25:39 -07:00
|
|
|
# define no_return noreturn_func
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Function priority: pure < reproducible < unsequenced < const */
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_FUNC_ATTRIBUTE_REPRODUCIBLE
|
|
|
|
|
# undef reproducible_func
|
|
|
|
|
# define reproducible_func pure_func
|
|
|
|
|
# undef reproducible_func_ptr
|
|
|
|
|
# define reproducible_func_ptr pure_func_ptr
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_FUNC_ATTRIBUTE_UNSEQUENCED
|
|
|
|
|
# undef unsequenced_func
|
|
|
|
|
# define unsequenced_func reproducible_func
|
|
|
|
|
# undef unsequenced_func_ptr
|
|
|
|
|
# define unsequenced_func_ptr reproducible_func_ptr
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_FUNC_ATTRIBUTE_CONST
|
|
|
|
|
# undef const_func
|
|
|
|
|
# define const_func reproducible_func
|
|
|
|
|
# undef const_func_ptr
|
|
|
|
|
# define const_func_ptr reproducible_func_ptr
|
2018-02-22 14:52:50 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A fatal function is both unlikely and no_return
|
|
|
|
|
*/
|
2025-09-16 13:25:39 -07:00
|
|
|
#define fatal_func no_return unlikely_func void
|
|
|
|
|
#define static_fatal_func no_return unlikely_func static void
|
2018-02-22 14:52:50 -08:00
|
|
|
|
2016-02-02 16:01:43 -08:00
|
|
|
/*
|
|
|
|
|
* How to tell the compiler that a function takes a printf-like string
|
|
|
|
|
*/
|
2019-08-16 00:08:27 -07:00
|
|
|
#define printf_func(fmt, list) format_func3(printf,fmt,list)
|
|
|
|
|
#define printf_func_ptr(fmt, list) format_func3_ptr(printf,fmt,list)
|
2020-07-30 17:30:20 -07:00
|
|
|
#define vprintf_func(fmt) format_func3(printf,fmt,0)
|
|
|
|
|
#define vprintf_func_ptr(fmt) format_func3_ptr(printf,fmt,0)
|
2016-11-15 14:01:37 -08:00
|
|
|
|
2017-11-29 16:05:05 -08:00
|
|
|
/* Determine probabilistically if something is a compile-time constant */
|
2017-11-29 16:48:27 -08:00
|
|
|
#ifdef HAVE___BUILTIN_CONSTANT_P
|
2018-12-15 20:21:09 +03:00
|
|
|
# if defined(__GNUC__) && (__GNUC__ >= 5)
|
|
|
|
|
# define is_constant(x) __builtin_constant_p((x))
|
|
|
|
|
# else
|
|
|
|
|
# define is_constant(x) false
|
|
|
|
|
# endif
|
2017-11-29 16:05:05 -08:00
|
|
|
#else
|
|
|
|
|
# define is_constant(x) false
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-12-14 14:21:16 -08:00
|
|
|
/*
|
|
|
|
|
* If we can guarantee that a particular expression is constant, use it,
|
|
|
|
|
* otherwise use a different version.
|
|
|
|
|
*/
|
|
|
|
|
#if defined(__GNUC__) && (__GNUC__ >= 3)
|
|
|
|
|
# define not_pedantic_start \
|
|
|
|
|
_Pragma("GCC diagnostic push") \
|
|
|
|
|
_Pragma("GCC diagnostic ignored \"-Wpedantic\"")
|
|
|
|
|
# define not_pedantic_end \
|
|
|
|
|
_Pragma("GCC diagnostic pop")
|
|
|
|
|
#else
|
|
|
|
|
# define not_pedantic_start
|
|
|
|
|
# define not_pedantic_end
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE___BUILTIN_CHOOSE_EXPR
|
|
|
|
|
# define if_constant(x,y) __builtin_choose_expr(is_constant(x),(x),(y))
|
|
|
|
|
#else
|
|
|
|
|
# define if_constant(x,y) (y)
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-12-12 14:34:34 -08:00
|
|
|
/*
|
|
|
|
|
* The autoconf documentation states:
|
|
|
|
|
*
|
|
|
|
|
* `va_copy'
|
|
|
|
|
* The C99 standard provides `va_copy' for copying `va_list'
|
|
|
|
|
* variables. It may be available in older environments too, though
|
|
|
|
|
* possibly as `__va_copy' (e.g., `gcc' in strict pre-C99 mode).
|
|
|
|
|
* These can be tested with `#ifdef'. A fallback to `memcpy (&dst,
|
|
|
|
|
* &src, sizeof (va_list))' gives maximum portability.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef va_copy
|
|
|
|
|
# ifdef __va_copy
|
|
|
|
|
# define va_copy(dst,src) __va_copy(dst,src)
|
|
|
|
|
# else
|
|
|
|
|
# define va_copy(dst,src) memcpy(&(dst),&(src),sizeof(va_list))
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-06-01 13:10:46 -07:00
|
|
|
/*
|
|
|
|
|
* If SIZE_MAX is not defined, rely on size_t being unsigned
|
|
|
|
|
*/
|
|
|
|
|
#ifndef SIZE_MAX
|
|
|
|
|
# define SIZE_MAX (((size_t)0) - 1)
|
|
|
|
|
#endif
|
|
|
|
|
|
Major changes to a number of subsystems to improve matching
Work through a number of changes toward making matching a lot saner,
both to reduce the number of patterns to generate for APX but also to
make a number of code patterns simpler.
This replaces a fair number of byte codes.
Improve a number of error messages, especially related to overflows.
Move process_insn() from nasm.c to assemble.c, as it really is the
primary entry point to the assembler module.
Reorder some prefixes. In particular, F2/F3 override 66 when used as a
mandatory prefix, so it makes more sense for them to be closer to the
opcode.
Move a lot more information into struct insn. It is better to have it
in one place; memory consumption is not an issue because struct insn
is transient information.
Get rid of "optimization levels" and replace it with a mask of
flags. That was already halfway done; complete the job.
Replace seg:offset in struct out_data with a struct location. It would
be better to extend this to more places, too.
The ARx and SMx flags are now explicit bitmasks, instead of having a
couple of hard-coded ranges.
Add __func__ to assert or panic messages.
Because of prefix and message changes, a number of travis tests had to
be audited and updated.
Fix a number of instruction patterns which had .128 when they ought to
be .lig. This is no longer a minor issue with the disassembler: for
AVX10, the pattern vector length determines how SAE/RC are encoded,
and there is no valid 128-bit encoding. However, with .lig the 512-bit
encoding can be used.
Separate "o64nw" into two pieces: opsize 64 and "nw" = "REX.w not necessary". The
latter can be included in non-64-bit patterns. "o64" still set REX.W
since that is still the common thing.
New "osz" bytecode: emit an OSP *or* REX.W depending on the current
mode and operand size. Useful for special cases like "nop" where "o64
nop" probably wants to be encoded as "48 90".
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-07 17:13:44 -07:00
|
|
|
/*
|
|
|
|
|
* Current function name, if available, otherwise NULL
|
|
|
|
|
*/
|
|
|
|
|
#ifdef HAVE_FUNC_NAME
|
|
|
|
|
# define NASM_FUNC __func__
|
|
|
|
|
#else
|
|
|
|
|
# define NASM_FUNC NULL
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-02-20 00:36:53 -08:00
|
|
|
/* Watcom doesn't handle switch statements with 64-bit types, hack around it */
|
2017-02-28 23:05:17 -08:00
|
|
|
#ifdef __WATCOMC__
|
2017-02-20 00:36:53 -08:00
|
|
|
# define BOGUS_CASE 0x76543210
|
|
|
|
|
|
|
|
|
|
static inline unsigned int watcom_switch_hack(uint64_t x)
|
|
|
|
|
{
|
2017-03-01 00:52:48 -08:00
|
|
|
if (x > (uint64_t)UINT_MAX)
|
2017-02-20 00:36:53 -08:00
|
|
|
return BOGUS_CASE;
|
|
|
|
|
else
|
|
|
|
|
return (unsigned int)x;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-23 17:25:31 -08:00
|
|
|
# define switch(x) switch(sizeof(x) > sizeof(unsigned int) \
|
|
|
|
|
? watcom_switch_hack(x) : (unsigned int)(x))
|
|
|
|
|
|
|
|
|
|
/* This is to make sure BOGUS_CASE doesn't conflict with anything real... */
|
2017-02-20 00:36:53 -08:00
|
|
|
# define default case BOGUS_CASE: default
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-10-13 17:53:42 -07:00
|
|
|
#ifndef unreachable /* C23 defines as a macro in <stddef.h> */
|
|
|
|
|
# ifdef HAVE___BUILTIN_UNREACHABLE
|
|
|
|
|
# define unreachable() __builtin_unreachable()
|
|
|
|
|
# else
|
|
|
|
|
# define unreachable() do { abort(); } while(1)
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-11-07 14:32:16 -08:00
|
|
|
/* This should be set from main() */
|
|
|
|
|
extern const char *_progname;
|
|
|
|
|
|
2007-10-02 21:53:51 -07:00
|
|
|
#endif /* NASM_COMPILER_H */
|