Fix AVR target to define ints properly (#12817)
* Fix AVR target to define ints properly * Fix more than AVR target * Test to see how robust not using stdint is * Fix for namespaces using cstdint * Fix for pre C++11 compilers when using namespaces
This commit is contained in:
parent
61d89aae11
commit
65fd95bf85
1 changed files with 69 additions and 9 deletions
|
|
@ -17,6 +17,7 @@ __DMC__
|
||||||
__POCC__
|
__POCC__
|
||||||
__TINYC__
|
__TINYC__
|
||||||
__clang__
|
__clang__
|
||||||
|
__AVR__
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -258,16 +259,28 @@ __clang__
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
/* C99 compiler? */
|
/* C99 compiler? */
|
||||||
#if (defined(__STD_VERSION__) && (__STD_VERSION__ >= 199901))
|
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))
|
||||||
# define HAVE_STDINT_H
|
# define HAVE_STDINT_H
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__LCC__) || defined(__DMC__) || defined(__POCC__)
|
/* Known compiler with stdint.h that doesn't fit the general pattern? */
|
||||||
|
#if defined(__LCC__) || defined(__DMC__) || defined(__POCC__) || \
|
||||||
|
defined(__AVR__) || (defined(__cplusplus) && (__cplusplus < 201103))
|
||||||
# define HAVE_STDINT_H
|
# define HAVE_STDINT_H
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (!defined(HAVE_STDINT_H) && defined(__cplusplus) && (__cplusplus >= 201103))
|
||||||
|
# define HAVE_CSTDINT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* wrap all Nim typedefs into namespace Nim */
|
/* wrap all Nim typedefs into namespace Nim */
|
||||||
#ifdef USE_NIM_NAMESPACE
|
#ifdef USE_NIM_NAMESPACE
|
||||||
|
#ifdef HAVE_CSTDINT
|
||||||
|
#include <cstdint>
|
||||||
|
#else
|
||||||
|
#include <stdint.h>
|
||||||
|
#endif
|
||||||
namespace USE_NIM_NAMESPACE {
|
namespace USE_NIM_NAMESPACE {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -308,33 +321,80 @@ namespace USE_NIM_NAMESPACE {
|
||||||
typedef signed char NI8;
|
typedef signed char NI8;
|
||||||
typedef signed short int NI16;
|
typedef signed short int NI16;
|
||||||
typedef signed int NI32;
|
typedef signed int NI32;
|
||||||
|
typedef __int64 NI64;
|
||||||
/* XXX: Float128? */
|
/* XXX: Float128? */
|
||||||
typedef unsigned char NU8;
|
typedef unsigned char NU8;
|
||||||
typedef unsigned short int NU16;
|
typedef unsigned short int NU16;
|
||||||
typedef unsigned __int64 NU64;
|
|
||||||
typedef __int64 NI64;
|
|
||||||
typedef unsigned int NU32;
|
typedef unsigned int NU32;
|
||||||
|
typedef unsigned __int64 NU64;
|
||||||
#elif defined(HAVE_STDINT_H)
|
#elif defined(HAVE_STDINT_H)
|
||||||
|
#ifndef USE_NIM_NAMESPACE
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
|
#endif
|
||||||
typedef int8_t NI8;
|
typedef int8_t NI8;
|
||||||
typedef int16_t NI16;
|
typedef int16_t NI16;
|
||||||
typedef int32_t NI32;
|
typedef int32_t NI32;
|
||||||
typedef int64_t NI64;
|
typedef int64_t NI64;
|
||||||
typedef uint64_t NU64;
|
|
||||||
typedef uint8_t NU8;
|
typedef uint8_t NU8;
|
||||||
typedef uint16_t NU16;
|
typedef uint16_t NU16;
|
||||||
typedef uint32_t NU32;
|
typedef uint32_t NU32;
|
||||||
|
typedef uint64_t NU64;
|
||||||
|
#elif defined(HAVE_CSTDINT)
|
||||||
|
#ifndef USE_NIM_NAMESPACE
|
||||||
|
# include <cstdint>
|
||||||
|
#endif
|
||||||
|
typedef std::int8_t NI8;
|
||||||
|
typedef std::int16_t NI16;
|
||||||
|
typedef std::int32_t NI32;
|
||||||
|
typedef std::int64_t NI64;
|
||||||
|
typedef std::uint8_t NU8;
|
||||||
|
typedef std::uint16_t NU16;
|
||||||
|
typedef std::uint32_t NU32;
|
||||||
|
typedef std::uint64_t NU64;
|
||||||
|
#else
|
||||||
|
/* Unknown compiler/version, do our best */
|
||||||
|
#ifdef __INT8_TYPE__
|
||||||
|
typedef __INT8_TYPE__ NI8;
|
||||||
#else
|
#else
|
||||||
typedef signed char NI8;
|
typedef signed char NI8;
|
||||||
|
#endif
|
||||||
|
#ifdef __INT16_TYPE__
|
||||||
|
typedef __INT16_TYPE__ NI16;
|
||||||
|
#else
|
||||||
typedef signed short int NI16;
|
typedef signed short int NI16;
|
||||||
|
#endif
|
||||||
|
#ifdef __INT32_TYPE__
|
||||||
|
typedef __INT32_TYPE__ NI32;
|
||||||
|
#else
|
||||||
typedef signed int NI32;
|
typedef signed int NI32;
|
||||||
/* XXX: Float128? */
|
#endif
|
||||||
typedef unsigned char NU8;
|
#ifdef __INT64_TYPE__
|
||||||
typedef unsigned short int NU16;
|
typedef __INT64_TYPE__ NI64;
|
||||||
typedef unsigned long long int NU64;
|
#else
|
||||||
typedef long long int NI64;
|
typedef long long int NI64;
|
||||||
|
#endif
|
||||||
|
/* XXX: Float128? */
|
||||||
|
#ifdef __UINT8_TYPE__
|
||||||
|
typedef __UINT8_TYPE__ NU8;
|
||||||
|
#else
|
||||||
|
typedef unsigned char NU8;
|
||||||
|
#endif
|
||||||
|
#ifdef __UINT16_TYPE__
|
||||||
|
typedef __UINT16_TYPE__ NU16;
|
||||||
|
#else
|
||||||
|
typedef unsigned short int NU16;
|
||||||
|
#endif
|
||||||
|
#ifdef __UINT32_TYPE__
|
||||||
|
typedef __UINT32_TYPE__ NU32;
|
||||||
|
#else
|
||||||
typedef unsigned int NU32;
|
typedef unsigned int NU32;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef __UINT64_TYPE__
|
||||||
|
typedef __UINT64_TYPE__ NU64;
|
||||||
|
#else
|
||||||
|
typedef unsigned long long int NU64;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef NIM_INTBITS
|
#ifdef NIM_INTBITS
|
||||||
# if NIM_INTBITS == 64
|
# if NIM_INTBITS == 64
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue