From 5a8b86ade94d3e6f853b8d68030457143f8b1543 Mon Sep 17 00:00:00 2001 From: Reece Date: Tue, 14 Sep 2021 14:30:08 +0100 Subject: [PATCH] [+] Added family-type macros [+] Attempt to resolve endianness and bsd --- AuroraEnvironment.h | 99 +++++++++++++++++- AuroraEnvironment.hpp | 229 ++++++++++++++++++++++++++++-------------- 2 files changed, 250 insertions(+), 78 deletions(-) diff --git a/AuroraEnvironment.h b/AuroraEnvironment.h index df023c9..4ab9100 100644 --- a/AuroraEnvironment.h +++ b/AuroraEnvironment.h @@ -13,7 +13,7 @@ #define AURORA_COMPILER_CLANG #elif defined(_MSC_VER) #define AURORA_COMPILER_MSVC -#elif __GNUC__ > 8 || __GNUC__ == 8 +#elif __GNUC__ > 8 || __GNUC__ == 8 // minimum *might* be boosted to 10 soon #define AURORA_COMPILER_GCC #elif __GNUC__ #error GCC outdated @@ -35,6 +35,8 @@ #define AURORA_PLATFORM_APPLE #elif (defined(__APPLE__) && defined(TARGET_OS_IPHONE)) || defined(_APPLE_MOBILE_AURORA_PREPROCESSOR) #define AURORA_PLATFORM_IOS +#elif defined(__FreeBSD__) + #define AURORA_PLATFORM_BSD #elif defined(_SWITCH_AURORA_PREPROCESSOR) #define AURORA_PLATFORM_SWITCH #elif defined(_PS4_AURORA_PREPROCESSOR) || defined(__ORBIS__) @@ -63,23 +65,46 @@ #define VENDOR_UNKNOWN #endif +#if defined(AURORA_PLATFORM_BSD) || defined(AURORA_PLATFORM_IOS) || defined(AURORA_PLATFORM_APPLE) || defined(VENDOR_CONSOLE_SONY) + #define AURORA_IS_BSD_DERIVED +#endif + +#if defined(AURORA_PLATFORM_LINUX) || defined(AURORA_PLATFORM_ANDROID) + #define AURORA_IS_LINUX_DERIVED +#endif + +#if defined(VENDOR_GENERIC_APPLE) + #define AURORA_IS_XNU_DERIVED +#endif + +#if defined(AURORA_IS_BSD_DERIVED) || defined(AURORA_IS_LINUX_DERIVED) || defined(VENDOR_GENERIC_APPLE) + #define AURORA_IS_POSIX_DERIVED +#endif + +#if defined(VENDOR_CONSOLE_MICROSOFT) || defined(AURORA_PLATFORM_WIN32) + #define AURORA_IS_MODERNNT_DERIVED +#endif + #if defined(AURORA_COMPILER_MSVC) #if defined(_M_X64) #define AURORA_ABI_MSFT_64 #define AURORA_ARCH_X64 + #define AURORA_IS_64BIT #elif defined(__aarch64__) #define AURORA_ARCH_ARM #define AURORA_ABI_MS_ARM + #define AURORA_IS_64BIT #else #define AURORA_ARCH_X86 #define AURORA_ABI_CDECL + #define AURORA_IS_32BIT #endif #define AURORA_SYMBOL_IMPORT __declspec(dllimport) #define AURORA_SYMBOL_EXPORT __declspec(dllexport) -#elif defined(AURORA_COMPILER_COMMUNISM) || defined(AURORA_COMPILER_CLANG) +#elif defined(AURORA_COMPILER_GCC) || defined(AURORA_COMPILER_CLANG) #if defined(__x86_64__) #define AURORA_ARCH_X64 @@ -88,6 +113,7 @@ #else #define AURORA_ABI_SYSV #endif + #define AURORA_IS_64BIT #elif defined(__aarch64__) #define AURORA_ARCH_ARM #if defined(__APPLE__) @@ -95,12 +121,81 @@ #else #define AURORA_ABI_LLVM_ARM #endif + #define AURORA_IS_64BIT #else #define AURORA_ARCH_X86 #define AURORA_ABI_CDECL + #define AURORA_IS_32BIT #endif #define AURORA_SYMBOL_IMPORT #define AURORA_SYMBOL_EXPORT __attribute__((visibility("default"))) #endif + +#if defined(__cplusplus) + #if defined(_AURORA_DONT_QUESTION_ME_17) + #define AU_LANG_CPP_17 + #elif defined(_AURORA_DONT_QUESTION_ME_14) + #define AU_LANG_CPP_14 + #elif __cplusplus > 201703L + #define AU_LANG_CPP_20 + #elif __cplusplus >= 201703L + #define AU_LANG_CPP_17 + #elif __cplusplus >= 201400L + #define AU_LANG_CPP_14 + #else + #define AU_LANG_C + #endif +#endif + +#if (defined(_CPU_BIG_AURORA_PREPROCESSOR) || defined(_CPU_LITTLE_AURORA_PREPROCESSOR)) + #if defined(_CPU_LITTLE_AURORA_PREPROCESSOR) + #define AU_CPU_ENDIAN_LITTLE + #elif defined(_CPU_BIG_AURORA_PREPROCESSOR) + #define AU_CPU_ENDIAN_BIG + #endif +#else + + // Could we please ignore this? + #if defined(__has_include) + #if __has_include() + #include + #elif __has_include() + #include + #endif + #endif + + #if (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN) || \ + (defined(__BYTE_ORDER) && __BYTE_ORDER == __ORDER_BIG_ENDIAN__) || \ + defined(__BIG_ENDIAN__) || \ + defined(__ARMEB__) || \ + defined(__THUMBEB__) || \ + defined(__AARCH64EB__) || \ + defined(_M_PPC) || \ + (defined(__sun) && defined(__SVR4) && defined(_BIG_ENDIAN)) || \ + defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__) + + #define AU_CPU_ENDIAN_BIG + + #elif (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \ + (defined(__BYTE_ORDER) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN__) || \ + defined(__LITTLE_ENDIAN__) || \ + defined(__ARMEL__) || \ + defined(__THUMBEL__) || \ + defined(__AARCH64EL__) || \ + defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || \ + defined(_M_IX86) || defined(_M_X64) + + #define AU_CPU_ENDIAN_LITTLE + + #else + + #if defined(AURORA_PLATFORM_WIN32) + #define AU_CPU_ENDIAN_LITTLE + #else + #define AU_CPU_ENDIAN_LITTLE + #endif + + #endif +#endif \ No newline at end of file diff --git a/AuroraEnvironment.hpp b/AuroraEnvironment.hpp index 3e21b74..232aba0 100644 --- a/AuroraEnvironment.hpp +++ b/AuroraEnvironment.hpp @@ -18,149 +18,226 @@ namespace Aurora::Build { enum class ECompiler { - kInvaild = -1, - kMSVC, - kClang, - kGCC + eInvaild = -1, + eMSVC, + eClang, + eGCC }; #if defined(AURORA_COMPILER_CLANG) - static const ECompiler kCurrentECompiler = ECompiler::kClang; + static const ECompiler kCurrentECompiler = ECompiler::eClang; #elif defined(AURORA_COMPILER_MSVC) - static const ECompiler kCurrentECompiler = ECompiler::kMSVC; + static const ECompiler kCurrentECompiler = ECompiler::eMSVC; #elif defined(AURORA_COMPILER_GCC) - static const ECompiler kCurrentECompiler = ECompiler::kGCC; + static const ECompiler kCurrentECompiler = ECompiler::eGCC; #else - static const ECompiler kCurrentECompiler = ECompiler::kInvaild; + static const ECompiler kCurrentECompiler = ECompiler::eInvaild; #endif enum class EPlatform { - kInvalid = -1, + eInvalid = -1, - kKernelLinux, - kKernelNtos, + eeernelLinux, + eeernelNtos, - kPlatformWin32, - kPlatformAndroid, - kPlatformLinux, - kPlatformApple, - kPlatformIos, - kPlatformSwitch, - kPlatformPS4, - kPlatformPS5, - kPlatformXbone, - kPlatformWii, - kPlatformWiiU + ePlatformWin32, + ePlatformAndroid, + ePlatformLinux, + ePlatformApple, + ePlatformIos, + ePlatformSwitch, + ePlatformPS4, + ePlatformPS5, + ePlatformXbone, + ePlatformWii, + ePlatformWiiU }; - #if defined(AURORA_PLATFORM_KERNEL_LINUX) - static const EPlatform kCurrentPlatform = EPlatform::kKernelLinux; + #if defined(AURORA_PLATFORM_eERNEL_LINUX) + static const EPlatform kCurrentPlatform = EPlatform::eeernelLinux; #elif defined(AURORA_PLATFORM_NTOS) - static const EPlatform kCurrentPlatform = EPlatform::kKernelNtos; + static const EPlatform kCurrentPlatform = EPlatform::eeernelNtos; #elif defined(AURORA_PLATFORM_WIN32) - static const EPlatform kCurrentPlatform = EPlatform::kPlatformWin32; + static const EPlatform kCurrentPlatform = EPlatform::ePlatformWin32; #elif defined(AURORA_PLATFORM_ANDROID) - static const EPlatform kCurrentPlatform = EPlatform::kPlatformAndroid; + static const EPlatform kCurrentPlatform = EPlatform::ePlatformAndroid; #elif defined(AURORA_PLATFORM_LINUX) - static const EPlatform kCurrentPlatform = EPlatform::kPlatformLinux; + static const EPlatform kCurrentPlatform = EPlatform::ePlatformLinux; #elif defined(AURORA_PLATFORM_APPLE) - static const EPlatform kCurrentPlatform = EPlatform::kPlatformApple; + static const EPlatform kCurrentPlatform = EPlatform::ePlatformApple; #elif defined(AURORA_PLATFORM_IOS) - static const EPlatform kCurrentPlatform = EPlatform::kPlatformIos; + static const EPlatform kCurrentPlatform = EPlatform::ePlatformIos; #elif defined(AURORA_PLATFORM_SWITCH) - static const EPlatform kCurrentPlatform = EPlatform::kPlatformSwitch; + static const EPlatform kCurrentPlatform = EPlatform::ePlatformSwitch; #elif defined(AURORA_PLATFORM_PS4) - static const EPlatform kCurrentPlatform = EPlatform::kPlatformPS4; + static const EPlatform kCurrentPlatform = EPlatform::ePlatformPS4; #elif defined(AURORA_PLATFORM_PS5) - static const EPlatform kCurrentPlatform = EPlatform::kPlatformPS5; + static const EPlatform kCurrentPlatform = EPlatform::ePlatformPS5; #elif defined(AURORA_PLATFORM_XBONE) - static const EPlatform kCurrentPlatform = EPlatform::kPlatformXbone; + static const EPlatform kCurrentPlatform = EPlatform::ePlatformXbone; #elif defined(AURORA_PLATFORM_WII) - static const EPlatform kCurrentPlatform = EPlatform::kPlatformWii; + static const EPlatform kCurrentPlatform = EPlatform::ePlatformWii; #elif defined(AURORA_PLATFORM_WII_U) - static const EPlatform kCurrentPlatform = EPlatform::kPlatformWiiU; + static const EPlatform kCurrentPlatform = EPlatform::ePlatformWiiU; #else - static const EPlatform kCurrentPlatform = EPlatform::kInvalid; + static const EPlatform kCurrentPlatform = EPlatform::eInvalid; #endif enum class EVendor { - kInvalid = -1, - kUnknown = 0, + eInvalid = -1, + eUnenown = 0, - kConsoleMicrosft, - kConsoleSony, - kConsoleNintendo, + eConsoleMicrosft, + eConsoleSony, + eConsoleNintendo, - kGenericApple, - kGenericMicrosoft, + eGenericApple, + eGenericMicrosoft, }; #if defined(VENDOR_CONSOLE_MICROSOFT) - static const EVendor kCurrentVendor = EVendor::kConsoleMicrosft; + static const EVendor kCurrentVendor = EVendor::eConsoleMicrosft; #elif defined(VENDOR_GENERIC_APPLE) - static const EVendor kCurrentVendor = EVendor::kGenericApple; + static const EVendor kCurrentVendor = EVendor::eGenericApple; #elif defined(VENDOR_CONSOLE_SONY) - static const EVendor kCurrentVendor = EVendor::kConsoleSony; + static const EVendor kCurrentVendor = EVendor::eConsoleSony; #elif defined(VENDOR_CONSOLE_NINTENDO) - static const EVendor kCurrentVendor = EVendor::kConsoleNintendo; + static const EVendor kCurrentVendor = EVendor::eConsoleNintendo; #elif defined(VENDOR_GENERIC_MICROSOFT) - static const EVendor kCurrentVendor = EVendor::kGenericMicrosoft; - #elif defined(VENDOR_UNKNOWN) - static const EVendor kCurrentVendor = EVendor::kUnknown; + static const EVendor kCurrentVendor = EVendor::eGenericMicrosoft; + #elif defined(VENDOR_UNeNOWN) + static const EVendor kCurrentVendor = EVendor::eUnenown; #else - static const EVendor kCurrentVendor = EVendor::kInvalid; + static const EVendor kCurrentVendor = EVendor::eInvalid; #endif enum class EArchitecture { - kInvalid = -1, - kX86_32, - kX86_64, - kAArch64 + eInvalid = -1, + eX86_32, + eX86_64, + eAArch64 }; - + #if defined(AURORA_ARCH_X86) - static const EArchitecture kCurrentArchitecture = EArchitecture::kX86_32; + static const EArchitecture kCurrentArchitecture = EArchitecture::eX86_32; #elif defined(AURORA_ARCH_X64) - static const EArchitecture kCurrentArchitecture = EArchitecture::kX86_64; + static const EArchitecture kCurrentArchitecture = EArchitecture::eX86_64; #elif defined(AURORA_ARCH_ARM) - static const EArchitecture kCurrentArchitecture = EArchitecture::kAArch64; + static const EArchitecture kCurrentArchitecture = EArchitecture::eAArch64; #else - static const EArchitecture kCurrentArchitecture = EArchitecture::kInvalid; + static const EArchitecture kCurrentArchitecture = EArchitecture::eInvalid; #endif + + static bool constexpr IsPlatformX32() + { + return kCurrentArchitecture == EArchitecture::eX86_32; + } + enum class EABI { - kInvalid = -1, + eInvalid = -1, // MSFTs in house amd64 abi - kMSFT64, + eMSFT64, // MSFTs in house aarch64 abi - kMSFTArm, + eMSFTArm, // x86 sysv and microsoft only deviate with fastcall and thiscall :( - kCdeclIntel, + eCdeclIntel, // x86_64 others - kSysV, - // tim apple is special - kAppleArm, + eSysV, + // M1 + eAppleArm, + // Microsoft made a new aarch ABI that makes it easier for them to JIT x86 + eMSFTAArchIntelBridge, // other arm EPlatforms... - kLLVMArm + eLLVMArm }; #if defined(AURORA_ABI_MSFT_64) - static const EABI kCurrentABI = EABI::kMSFT64; + static const EABI kCurrentABI = EABI::eMSFT64; #elif defined(AURORA_ABI_MS_ARM) - static const EABI kCurrentABI = EABI::kMSFTArm; + static const EABI kCurrentABI = EABI::eMSFTArm; #elif defined(AURORA_ABI_LLVM_ARM) - static const EABI kCurrentABI = EABI::kLLVMArm; + static const EABI kCurrentABI = EABI::eLLVMArm; #elif defined(AURORA_ABI_CDECL) - static const EABI kCurrentABI = EABI::kCdeclIntel; + static const EABI kCurrentABI = EABI::eCdeclIntel; #elif defined(AURORA_ABI_SYSV) - static const EABI kCurrentABI = EABI::kSysV; + static const EABI kCurrentABI = EABI::eSysV; #elif defined(AURORA_ABI_APPLE) - static const EABI kCurrentABI = EABI::kAppleArm; + static const EABI kCurrentABI = EABI::eAppleArm; #else - static const EABI kCurrentABI = EABI::kInvalid; + static const EABI kCurrentABI = EABI::eInvalid; #endif + + enum class ECPUEndian + { + eCPUBig, + eCPULittle + }; + + #if defined (AU_CPU_ENDIAN_LITTLE) + static const ECPUEndian kCurrentEndian = ECPUEndian::eCPULittle; + #else + static const ECPUEndian kCurrentEndian = ECPUEndian::eCPUBig; + #endif + + enum class ELanguage + { + eCpp20, + eCpp17, + eCpp14, + eC + }; + + #if defined (AU_LANG_CPP_20) + static const ELanguage kCurrentLanguage = ELanguage::eCpp20; + #elif defined (AU_LANG_CPP_17) + static const ELanguage kCurrentLanguage = ELanguage::eCpp17; + #elif defined (AU_LANG_CPP_14) + static const ELanguage kCurrentLanguage = ELanguage::eCpp14; + #elif defined (AU_LANG_C) + static const ELanguage kCurrentLanguage = ELanguage::eC; + #else + static const ELanguage kCurrentLanguage = ELanguage::eC; + #endif + + #if defined(AURORA_IS_BSD_DERIVED) + static const bool kCurrentBSDDerived = true; + #else + static const bool kCurrentBSDDerived = false; + #endif + + #if defined(AURORA_IS_POSIX_DERIVED) + static const bool kCurrentPosixDerived = true; + #else + static const bool kCurrentPosixDerived = false; + #endif + + #if defined(AURORA_IS_BSD_DERIVED) + static const bool kCurrentBsdDerived = true; + #else + static const bool kCurrentBsdDerived = false; + #endif + + #if defined(AURORA_IS_XNU_DERIVED) + static const bool kCurrentXnuDerived = true; + #else + static const bool kCurrentXnuDerived = false; + #endif + + #if defined(AURORA_IS_LINUX_DERIVED) + static const bool kCurrentLinuxDerived = true; + #else + static const bool kCurrentLinuxDerived = false; + #endif + + #if defined(AURORA_IS_MODERNNT_DERIVED) + static const bool kCurrentNtDerived = true; + #else + static const bool kCurrentNtDerived = false; + #endif + } \ No newline at end of file