Better compiler flags detection in CMakeLists.txt\nFixed missing noexcept in StaticRuntime.cpp

This commit is contained in:
kobalicek
2016-05-05 04:08:23 +02:00
parent f7de7b8d35
commit 286bc22f49
12 changed files with 125 additions and 158 deletions

View File

@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.1)
include(CheckCXXCompilerFlag)
# ============================================================================= # =============================================================================
# [AsmJit - Configuration] # [AsmJit - Configuration]
@@ -63,6 +64,22 @@ endif()
message("-- [asmjit] ${ASMJIT_SIGNATURE}") message("-- [asmjit] ${ASMJIT_SIGNATURE}")
message("-- [asmjit] ASMJIT_DIR=${ASMJIT_DIR}") message("-- [asmjit] ASMJIT_DIR=${ASMJIT_DIR}")
# =============================================================================
# [NP-Utilities]
# =============================================================================
function(np_detect_options out)
set(out_array)
foreach(flag ${ARGN})
check_cxx_compiler_flag("${flag}" ok)
if(ok)
list(APPEND out_array "${flag}")
endif()
unset(ok)
endforeach()
set(${out} "${out_array}" PARENT_SCOPE)
endfunction()
# ============================================================================= # =============================================================================
# [AsmJit - Flags / Deps] # [AsmJit - Flags / Deps]
# ============================================================================= # =============================================================================
@@ -95,8 +112,25 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
endif() endif()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(GNU|Clang)$") if("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(GNU|Clang)$")
list(APPEND ASMJIT_PRIVATE_CFLAGS -fno-exceptions) # Keep only the first option detected.
np_detect_options(ASMJIT_CC_OPTIONS
"-std=c++14"
"-std=c++11"
"-std=c++0x")
if(ASMJIT_CC_OPTIONS)
list(GET ASMJIT_CC_OPTIONS 0 ASMJIT_CC_OPTIONS)
list(APPEND ASMJIT_PRIVATE_CFLAGS ${ASMJIT_CC_OPTIONS})
endif()
np_detect_options(ASMJIT_CC_OPTIONS
"-fno-exceptions"
"-fno-tree-vectorize"
"-fvisibility=hidden")
list(APPEND ASMJIT_PRIVATE_CFLAGS ${ASMJIT_CC_OPTIONS})
list(APPEND ASMJIT_PRIVATE_CFLAGS_REL -fmerge-all-constants) list(APPEND ASMJIT_PRIVATE_CFLAGS_REL -fmerge-all-constants)
unset(ASMJIT_CC_OPTIONS)
endif() endif()
if(ASMJIT_EMBED) if(ASMJIT_EMBED)

View File

@@ -16,38 +16,38 @@
# error "[asmjit] Api-Scope is already active, previous scope not closed by apiend.h?" # error "[asmjit] Api-Scope is already active, previous scope not closed by apiend.h?"
#endif // ASMJIT_API_SCOPE #endif // ASMJIT_API_SCOPE
// ============================================================================
// [NoExcept] // [NoExcept]
// ============================================================================
#if !ASMJIT_CC_HAS_NOEXCEPT && !defined(noexcept) #if !ASMJIT_CC_HAS_NOEXCEPT && !defined(noexcept)
# define noexcept ASMJIT_NOEXCEPT # define noexcept ASMJIT_NOEXCEPT
# define ASMJIT_UNDEF_NOEXCEPT # define ASMJIT_UNDEF_NOEXCEPT
#endif // !ASMJIT_CC_HAS_NOEXCEPT && !noexcept #endif // !ASMJIT_CC_HAS_NOEXCEPT && !noexcept
// ============================================================================
// [NullPtr] // [NullPtr]
// ============================================================================
#if !ASMJIT_CC_HAS_NULLPTR && !defined(nullptr) #if !ASMJIT_CC_HAS_NULLPTR && !defined(nullptr)
# define nullptr NULL # define nullptr NULL
# define ASMJIT_UNDEF_NULLPTR # define ASMJIT_UNDEF_NULLPTR
#endif // !ASMJIT_CC_HAS_NULLPTR && !nullptr #endif // !ASMJIT_CC_HAS_NULLPTR && !nullptr
// ============================================================================
// [Override] // [Override]
// ============================================================================
#if !ASMJIT_CC_HAS_OVERRIDE && !defined(override) #if !ASMJIT_CC_HAS_OVERRIDE && !defined(override)
# define override # define override
# define ASMJIT_UNDEF_OVERRIDE # define ASMJIT_UNDEF_OVERRIDE
#endif // !ASMJIT_CC_HAS_OVERRIDE && !override #endif // !ASMJIT_CC_HAS_OVERRIDE && !override
// ============================================================================ // [CLang]
// [MSC] #if ASMJIT_CC_CLANG
// ============================================================================ # pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunnamed-type-template-args"
#endif // ASMJIT_CC_CLANG
#if defined(_MSC_VER) // [GCC]
#if ASMJIT_CC_GCC
# pragma GCC diagnostic push
# pragma GCC diagnostic warning "-Winline"
#endif // ASMJIT_CC_GCC
// [MSC]
#if ASMJIT_CC_MSC
# pragma warning(push) # pragma warning(push)
# pragma warning(disable: 4127) // conditional expression is constant # pragma warning(disable: 4127) // conditional expression is constant
@@ -73,23 +73,4 @@
# define snprintf _snprintf # define snprintf _snprintf
# endif // !snprintf # endif // !snprintf
#endif // _MSC_VER #endif // ASMJIT_CC_MSC
// ============================================================================
// [CLang]
// ============================================================================
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunnamed-type-template-args"
#endif // __clang__
// ============================================================================
// [GCC]
// ============================================================================
#if defined(__GNUC__) && !defined(__clang__)
# if __GNUC__ >= 4 && !defined(__MINGW32__)
# pragma GCC visibility push(hidden)
# endif // GCC 4+
#endif // __GNUC__

View File

@@ -11,66 +11,43 @@
# error "[asmjit] Api-Scope not active, forgot to include apibegin.h?" # error "[asmjit] Api-Scope not active, forgot to include apibegin.h?"
#endif // ASMJIT_API_SCOPE #endif // ASMJIT_API_SCOPE
// ============================================================================
// [NoExcept] // [NoExcept]
// ============================================================================
#if defined(ASMJIT_UNDEF_NOEXCEPT) #if defined(ASMJIT_UNDEF_NOEXCEPT)
# undef noexcept # undef noexcept
# undef ASMJIT_UNDEF_NOEXCEPT # undef ASMJIT_UNDEF_NOEXCEPT
#endif // ASMJIT_UNDEF_NOEXCEPT #endif // ASMJIT_UNDEF_NOEXCEPT
// ============================================================================
// [NullPtr] // [NullPtr]
// ============================================================================
#if defined(ASMJIT_UNDEF_NULLPTR) #if defined(ASMJIT_UNDEF_NULLPTR)
# undef nullptr # undef nullptr
# undef ASMJIT_UNDEF_NULLPTR # undef ASMJIT_UNDEF_NULLPTR
#endif // ASMJIT_UNDEF_NULLPTR #endif // ASMJIT_UNDEF_NULLPTR
// ============================================================================
// [Override] // [Override]
// ============================================================================
#if defined(ASMJIT_UNDEF_OVERRIDE) #if defined(ASMJIT_UNDEF_OVERRIDE)
# undef override # undef override
# undef ASMJIT_UNDEF_OVERRIDE # undef ASMJIT_UNDEF_OVERRIDE
#endif // ASMJIT_UNDEF_OVERRIDE #endif // ASMJIT_UNDEF_OVERRIDE
// ============================================================================ // [CLang]
#if ASMJIT_CC_CLANG
# pragma clang diagnostic pop
#endif // ASMJIT_CC_CLANG
// [GCC]
#if ASMJIT_CC_GCC
# pragma GCC diagnostic pop
#endif // ASMJIT_CC_GCC
// [MSC] // [MSC]
// ============================================================================ #if ASMJIT_CC_MSC
#if defined(_MSC_VER)
# pragma warning(pop) # pragma warning(pop)
# if defined(ASMJIT_UNDEF_VSNPRINTF) # if defined(ASMJIT_UNDEF_VSNPRINTF)
# undef vsnprintf # undef vsnprintf
# undef ASMJIT_UNDEF_VSNPRINTF # undef ASMJIT_UNDEF_VSNPRINTF
# endif // ASMJIT_UNDEF_VSNPRINTF # endif // ASMJIT_UNDEF_VSNPRINTF
# if defined(ASMJIT_UNDEF_SNPRINTF) # if defined(ASMJIT_UNDEF_SNPRINTF)
# undef snprintf # undef snprintf
# undef ASMJIT_UNDEF_SNPRINTF # undef ASMJIT_UNDEF_SNPRINTF
# endif // ASMJIT_UNDEF_SNPRINTF # endif // ASMJIT_UNDEF_SNPRINTF
#endif // ASMJIT_CC_MSC
#endif // _MSC_VER
// ============================================================================
// [CLang]
// ============================================================================
#if defined(__clang__)
# pragma clang diagnostic pop
#endif // __clang__
// ============================================================================
// [GCC]
// ============================================================================
#if defined(__GNUC__) && !defined(__clang__)
# if __GNUC__ >= 4 && !defined(__MINGW32__)
# pragma GCC visibility pop
# endif // GCC 4+
#endif // __GNUC__

View File

@@ -38,8 +38,8 @@ enum { kCompilerDefaultLookAhead = 64 };
// [asmjit::Compiler - Construction / Destruction] // [asmjit::Compiler - Construction / Destruction]
// ============================================================================ // ============================================================================
Compiler::Compiler() noexcept : Compiler::Compiler() noexcept
_features(0), : _features(0),
_maxLookAhead(kCompilerDefaultLookAhead), _maxLookAhead(kCompilerDefaultLookAhead),
_instOptions(0), _instOptions(0),
_tokenGenerator(0), _tokenGenerator(0),

View File

@@ -141,40 +141,33 @@ struct ConstPool {
template<typename Visitor> template<typename Visitor>
ASMJIT_INLINE void iterate(Visitor& visitor) const noexcept { ASMJIT_INLINE void iterate(Visitor& visitor) const noexcept {
Node* node = const_cast<Node*>(_root); Node* node = const_cast<Node*>(_root);
Node* link;
Node* stack[kHeightLimit];
if (node == nullptr) if (node == nullptr)
return; return;
Node* stack[kHeightLimit];
size_t top = 0; size_t top = 0;
for (;;) { for (;;) {
link = node->_link[0]; Node* left = node->_link[0];
if (left != nullptr) {
if (link != nullptr) {
ASMJIT_ASSERT(top != kHeightLimit); ASMJIT_ASSERT(top != kHeightLimit);
stack[top++] = node; stack[top++] = node;
node = link; node = left;
continue; continue;
} }
_Visit: L_Visit:
visitor.visit(node); visitor.visit(node);
link = node->_link[1]; node = node->_link[1];
if (node != nullptr)
if (link != nullptr) {
node = link;
continue; continue;
}
if (top == 0) if (top == 0)
break; return;
node = stack[--top]; node = stack[--top];
goto _Visit; goto L_Visit;
} }
} }

View File

@@ -357,14 +357,14 @@ static ASMJIT_INLINE void x86SimplifyBrandString(char* s) noexcept {
if (curr == ' ') { if (curr == ' ') {
if (prev == '@' || s[1] == ' ' || s[1] == '@') if (prev == '@' || s[1] == ' ' || s[1] == '@')
goto _Skip; goto L_Skip;
} }
d[0] = curr; d[0] = curr;
d++; d++;
prev = curr; prev = curr;
_Skip: L_Skip:
curr = *++s; curr = *++s;
s[0] = '\0'; s[0] = '\0';
} }

View File

@@ -418,10 +418,10 @@ struct HLInst : public HLNode {
uint32_t i; uint32_t i;
for (i = 0; i < opCount; i++) for (i = 0; i < opCount; i++)
if (opList[i].isMem()) if (opList[i].isMem())
goto _Update; goto L_Update;
i = 0xFF; i = 0xFF;
_Update: L_Update:
setMemOpIndex(i); setMemOpIndex(i);
} }

View File

@@ -115,7 +115,7 @@ StaticRuntime::StaticRuntime(void* baseAddress, size_t sizeLimit) noexcept {
_sizeLimit = sizeLimit; _sizeLimit = sizeLimit;
_baseAddress = static_cast<Ptr>((uintptr_t)baseAddress); _baseAddress = static_cast<Ptr>((uintptr_t)baseAddress);
} }
StaticRuntime::~StaticRuntime() {} StaticRuntime::~StaticRuntime() noexcept {}
// ============================================================================ // ============================================================================
// [asmjit::StaticRuntime - Interface] // [asmjit::StaticRuntime - Interface]

View File

@@ -825,7 +825,7 @@ static void* vMemMgrAllocFreeable(VMemMgr* self, size_t vSize) noexcept {
if (++cont == need) { if (++cont == need) {
i += j; i += j;
i -= cont; i -= cont;
goto _Found; goto L_Found;
} }
continue; continue;
@@ -868,7 +868,7 @@ static void* vMemMgrAllocFreeable(VMemMgr* self, size_t vSize) noexcept {
self->_allocatedBytes += node->size; self->_allocatedBytes += node->size;
} }
_Found: L_Found:
// Update bits. // Update bits.
_SetBits(node->baUsed, i, need); _SetBits(node->baUsed, i, need);
_SetBits(node->baCont, i, need - 1); _SetBits(node->baCont, i, need - 1);
@@ -923,8 +923,8 @@ static void vMemMgrReset(VMemMgr* self, bool keepVirtualMemory) noexcept {
#if !ASMJIT_OS_WINDOWS #if !ASMJIT_OS_WINDOWS
VMemMgr::VMemMgr() noexcept VMemMgr::VMemMgr() noexcept
#else #else
VMemMgr::VMemMgr(HANDLE hProcess) noexcept : VMemMgr::VMemMgr(HANDLE hProcess) noexcept
_hProcess(vMemGet().getSafeProcessHandle(hProcess)) : _hProcess(vMemGet().getSafeProcessHandle(hProcess))
#endif // ASMJIT_OS_WINDOWS #endif // ASMJIT_OS_WINDOWS
{ {
_blockSize = VMemUtil::getPageGranularity(); _blockSize = VMemUtil::getPageGranularity();

View File

@@ -34,11 +34,8 @@ namespace asmjit {
//! data used by `Assembler` and `Compiler` has a very short lifetime, thus, is //! data used by `Assembler` and `Compiler` has a very short lifetime, thus, is
//! allocated by `Zone`. The advantage is that `Zone` can free all of the data //! allocated by `Zone`. The advantage is that `Zone` can free all of the data
//! allocated at once by calling `reset()` or by `Zone` destructor. //! allocated at once by calling `reset()` or by `Zone` destructor.
struct Zone { class Zone {
// -------------------------------------------------------------------------- public:
// [Block]
// --------------------------------------------------------------------------
//! \internal //! \internal
//! //!
//! A single block of memory. //! A single block of memory.
@@ -75,13 +72,11 @@ struct Zone {
uint8_t data[sizeof(void*)]; uint8_t data[sizeof(void*)];
}; };
// --------------------------------------------------------------------------
// [Enums]
// --------------------------------------------------------------------------
enum { enum {
//! Zone allocator overhead. //! Zone allocator overhead.
kZoneOverhead = static_cast<int>(sizeof(Block) - sizeof(void*)) + kMemAllocOverhead kZoneOverhead =
kMemAllocOverhead
+ static_cast<int>(sizeof(Block) - sizeof(void*))
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@@ -137,19 +132,19 @@ struct Zone {
//! ~~~ //! ~~~
//! using namespace asmjit; //! using namespace asmjit;
//! //!
//! class SomeObject { ... }; //! class Object { ... };
//! //!
//! // Create Zone with default block size of 65536 bytes. //! // Create Zone with default block size of approximately 65536 bytes.
//! Zone zone(65536); //! Zone zone(65536 - Zone::kZoneOverhead);
//! //!
//! // Create your objects using zone object allocating, for example: //! // Create your objects using zone object allocating, for example:
//! Object* obj = static_cast<Object*>( zone.alloc(sizeof(SomeClass)) ); //! Object* obj = static_cast<Object*>( zone.alloc(sizeof(Object)) );
// //
//! if (obj == nullptr) { //! if (obj == nullptr) {
//! // Handle out of memory error. //! // Handle out of memory error.
//! } //! }
//! //!
//! // To instantiate class placement `new` and `delete` operators can be used. //! // Placement `new` and `delete` operators can be used to instantiate it.
//! new(obj) Object(); //! new(obj) Object();
//! //!
//! // ... lifetime of your objects ... //! // ... lifetime of your objects ...
@@ -157,7 +152,7 @@ struct Zone {
//! // To destroy the instance (if required). //! // To destroy the instance (if required).
//! obj->~Object(); //! obj->~Object();
//! //!
//! // Reset of destroy `Zone`. //! // Reset or destroy `Zone`.
//! zone.reset(); //! zone.reset();
//! ~~~ //! ~~~
ASMJIT_INLINE void* alloc(size_t size) noexcept { ASMJIT_INLINE void* alloc(size_t size) noexcept {

View File

@@ -607,9 +607,7 @@
// [@CC_INLINE{@] // [@CC_INLINE{@]
// \def ASMJIT_INLINE // \def ASMJIT_INLINE
// Always inline the decorated function. // Always inline the decorated function.
#if ASMJIT_CC_HAS_ATTRIBUTE_ALWAYS_INLINE && ASMJIT_CC_CLANG #if ASMJIT_CC_HAS_ATTRIBUTE_ALWAYS_INLINE
# define ASMJIT_INLINE inline __attribute__((__always_inline__, __visibility__("hidden")))
#elif ASMJIT_CC_HAS_ATTRIBUTE_ALWAYS_INLINE
# define ASMJIT_INLINE inline __attribute__((__always_inline__)) # define ASMJIT_INLINE inline __attribute__((__always_inline__))
#elif ASMJIT_CC_HAS_DECLSPEC_FORCEINLINE #elif ASMJIT_CC_HAS_DECLSPEC_FORCEINLINE
# define ASMJIT_INLINE __forceinline # define ASMJIT_INLINE __forceinline

View File

@@ -1980,19 +1980,12 @@ ASMJIT_ENUM(X86VCmp) {
//! X86/X64 round encoding used by ROUND[PD/PS/SD/SS] family instructions. //! X86/X64 round encoding used by ROUND[PD/PS/SD/SS] family instructions.
ASMJIT_ENUM(X86Round) { ASMJIT_ENUM(X86Round) {
//! Round control - round to nearest (even). kX86RoundNearest = 0x00, //!< Round to nearest (even).
kX86RoundNearest = 0x0, kX86RoundDown = 0x01, //!< Round to down toward -INF (floor),
//! Round control - round to down toward -INF (floor), kX86RoundUp = 0x02, //!< Round to up toward +INF (ceil).
kX86RoundDown = 0x1, kX86RoundTrunc = 0x03, //!< Round toward zero (truncate).
//! Round control - round to up toward +INF (ceil). kX86RoundCurrent = 0x04, //!< Round to the current rounding mode set (ignores other RC bits).
kX86RoundUp = 0x2, kX86RoundInexact = 0x08 //!< Avoid the inexact exception, if set.
//! Round control - round toward zero (truncate).
kX86RoundTrunc = 0x3,
//! Rounding select - if set it will use the the current rounding mode
//! according to MXCS and ignore the round control (RC) bits.
kX86RoundCurrent = 0x4,
//! Precision mask - if set it avoids an inexact exception.
kX86RoundInexact = 0x8
}; };
// ============================================================================ // ============================================================================
@@ -2001,14 +1994,10 @@ ASMJIT_ENUM(X86Round) {
//! X86/X64 Prefetch hints. //! X86/X64 Prefetch hints.
ASMJIT_ENUM(X86Prefetch) { ASMJIT_ENUM(X86Prefetch) {
//! Prefetch using NT hint. kX86PrefetchNTA = 0, //!< Prefetch using NT hint.
kX86PrefetchNTA = 0, kX86PrefetchT0 = 1, //!< Prefetch to L0 cache.
//! Prefetch to L0 cache. kX86PrefetchT1 = 2, //!< Prefetch to L1 cache.
kX86PrefetchT0 = 1, kX86PrefetchT2 = 3 //!< Prefetch to L2 cache.
//! Prefetch to L1 cache.
kX86PrefetchT1 = 2,
//! Prefetch to L2 cache.
kX86PrefetchT2 = 3
}; };
// ============================================================================ // ============================================================================
@@ -2045,7 +2034,7 @@ struct X86InstExtendedInfo {
return _instFlags; return _instFlags;
} }
//! Get whether the instruction is a control-flow intruction. //! Get whether the instruction is a control-flow instruction.
//! //!
//! Control flow instruction is instruction that can perform a branch, //! Control flow instruction is instruction that can perform a branch,
//! typically `jmp`, `jcc`, `call`, or `ret`. //! typically `jmp`, `jcc`, `call`, or `ret`.
@@ -2053,7 +2042,7 @@ struct X86InstExtendedInfo {
return (getInstFlags() & kX86InstFlagFlow) != 0; return (getInstFlags() & kX86InstFlagFlow) != 0;
} }
//! Get whether the instruction is a compare/test like intruction. //! Get whether the instruction is a compare/test like instruction.
ASMJIT_INLINE bool isTest() const { ASMJIT_INLINE bool isTest() const {
return (getInstFlags() & kX86InstFlagTest) != 0; return (getInstFlags() & kX86InstFlagTest) != 0;
} }
@@ -2073,7 +2062,7 @@ struct X86InstExtendedInfo {
//! Get whether the instruction is a typical Exchange instruction. //! Get whether the instruction is a typical Exchange instruction.
//! //!
//! Exchange instructios are 'xchg' and 'xadd'. //! Exchange instructions are 'xchg' and 'xadd'.
ASMJIT_INLINE bool isXchg() const { ASMJIT_INLINE bool isXchg() const {
return (getInstFlags() & kX86InstFlagXchg) != 0; return (getInstFlags() & kX86InstFlagXchg) != 0;
} }
@@ -2177,7 +2166,7 @@ struct X86InstExtendedInfo {
//! this is the size of the register (and of Ymm/Zmm registers). This means //! this is the size of the register (and of Ymm/Zmm registers). This means
//! that 16-bytes of the register are changed, the rest remains unchanged. //! that 16-bytes of the register are changed, the rest remains unchanged.
//! However, AVX instructions should use the size of Zmm register as every //! However, AVX instructions should use the size of Zmm register as every
//! AVX instruction zeroes the rest of the register (AVX/AVX2 instructions //! AVX instruction clears the rest of the register (AVX/AVX2 instructions
//! zero the HI part of Zmm if available). //! zero the HI part of Zmm if available).
uint8_t _writeSize; uint8_t _writeSize;
@@ -2391,7 +2380,7 @@ struct X86Util {
// [Shuffle (SIMD)] // [Shuffle (SIMD)]
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
//! Pack a shuffle constant to be used with multimedia instrutions (2 values). //! Pack a shuffle constant to be used with multimedia instructions (2 values).
//! //!
//! \param a Position of the first component [0, 1], inclusive. //! \param a Position of the first component [0, 1], inclusive.
//! \param b Position of the second component [0, 1], inclusive. //! \param b Position of the second component [0, 1], inclusive.
@@ -2404,7 +2393,7 @@ struct X86Util {
return static_cast<int>(result); return static_cast<int>(result);
} }
//! Pack a shuffle constant to be used with multimedia instrutions (4 values). //! Pack a shuffle constant to be used with multimedia instructions (4 values).
//! //!
//! \param a Position of the first component [0, 3], inclusive. //! \param a Position of the first component [0, 3], inclusive.
//! \param b Position of the second component [0, 3], inclusive. //! \param b Position of the second component [0, 3], inclusive.