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)
include(CheckCXXCompilerFlag)
# =============================================================================
# [AsmJit - Configuration]
@@ -63,6 +64,22 @@ endif()
message("-- [asmjit] ${ASMJIT_SIGNATURE}")
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]
# =============================================================================
@@ -95,8 +112,25 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
endif()
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)
unset(ASMJIT_CC_OPTIONS)
endif()
if(ASMJIT_EMBED)

View File

@@ -16,38 +16,38 @@
# error "[asmjit] Api-Scope is already active, previous scope not closed by apiend.h?"
#endif // ASMJIT_API_SCOPE
// ============================================================================
// [NoExcept]
// ============================================================================
#if !ASMJIT_CC_HAS_NOEXCEPT && !defined(noexcept)
# define noexcept ASMJIT_NOEXCEPT
# define ASMJIT_UNDEF_NOEXCEPT
#endif // !ASMJIT_CC_HAS_NOEXCEPT && !noexcept
// ============================================================================
// [NullPtr]
// ============================================================================
#if !ASMJIT_CC_HAS_NULLPTR && !defined(nullptr)
# define nullptr NULL
# define ASMJIT_UNDEF_NULLPTR
#endif // !ASMJIT_CC_HAS_NULLPTR && !nullptr
// ============================================================================
// [Override]
// ============================================================================
#if !ASMJIT_CC_HAS_OVERRIDE && !defined(override)
# define override
# define ASMJIT_UNDEF_OVERRIDE
#endif // !ASMJIT_CC_HAS_OVERRIDE && !override
// ============================================================================
// [MSC]
// ============================================================================
// [CLang]
#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(disable: 4127) // conditional expression is constant
@@ -73,23 +73,4 @@
# define snprintf _snprintf
# endif // !snprintf
#endif // _MSC_VER
// ============================================================================
// [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__
#endif // ASMJIT_CC_MSC

View File

@@ -11,66 +11,43 @@
# error "[asmjit] Api-Scope not active, forgot to include apibegin.h?"
#endif // ASMJIT_API_SCOPE
// ============================================================================
// [NoExcept]
// ============================================================================
#if defined(ASMJIT_UNDEF_NOEXCEPT)
# undef noexcept
# undef ASMJIT_UNDEF_NOEXCEPT
#endif // ASMJIT_UNDEF_NOEXCEPT
// ============================================================================
// [NullPtr]
// ============================================================================
#if defined(ASMJIT_UNDEF_NULLPTR)
# undef nullptr
# undef ASMJIT_UNDEF_NULLPTR
#endif // ASMJIT_UNDEF_NULLPTR
// ============================================================================
// [Override]
// ============================================================================
#if defined(ASMJIT_UNDEF_OVERRIDE)
# undef override
# undef 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]
// ============================================================================
#if defined(_MSC_VER)
#if ASMJIT_CC_MSC
# pragma warning(pop)
# if defined(ASMJIT_UNDEF_VSNPRINTF)
# undef vsnprintf
# undef ASMJIT_UNDEF_VSNPRINTF
# endif // ASMJIT_UNDEF_VSNPRINTF
# if defined(ASMJIT_UNDEF_SNPRINTF)
# undef snprintf
# undef ASMJIT_UNDEF_SNPRINTF
# endif // ASMJIT_UNDEF_SNPRINTF
#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__
#endif // ASMJIT_CC_MSC

View File

@@ -38,24 +38,24 @@ enum { kCompilerDefaultLookAhead = 64 };
// [asmjit::Compiler - Construction / Destruction]
// ============================================================================
Compiler::Compiler() noexcept :
_features(0),
_maxLookAhead(kCompilerDefaultLookAhead),
_instOptions(0),
_tokenGenerator(0),
_nodeFlowId(0),
_nodeFlags(0),
_targetVarMapping(nullptr),
_firstNode(nullptr),
_lastNode(nullptr),
_cursor(nullptr),
_func(nullptr),
_zoneAllocator(8192 - Zone::kZoneOverhead),
_varAllocator(4096 - Zone::kZoneOverhead),
_stringAllocator(4096 - Zone::kZoneOverhead),
_constAllocator(4096 - Zone::kZoneOverhead),
_localConstPool(&_constAllocator),
_globalConstPool(&_zoneAllocator) {}
Compiler::Compiler() noexcept
: _features(0),
_maxLookAhead(kCompilerDefaultLookAhead),
_instOptions(0),
_tokenGenerator(0),
_nodeFlowId(0),
_nodeFlags(0),
_targetVarMapping(nullptr),
_firstNode(nullptr),
_lastNode(nullptr),
_cursor(nullptr),
_func(nullptr),
_zoneAllocator(8192 - Zone::kZoneOverhead),
_varAllocator(4096 - Zone::kZoneOverhead),
_stringAllocator(4096 - Zone::kZoneOverhead),
_constAllocator(4096 - Zone::kZoneOverhead),
_localConstPool(&_constAllocator),
_globalConstPool(&_zoneAllocator) {}
Compiler::~Compiler() noexcept {}
// ============================================================================

View File

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

View File

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

View File

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

View File

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

View File

@@ -34,11 +34,8 @@ namespace asmjit {
//! 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 at once by calling `reset()` or by `Zone` destructor.
struct Zone {
// --------------------------------------------------------------------------
// [Block]
// --------------------------------------------------------------------------
class Zone {
public:
//! \internal
//!
//! A single block of memory.
@@ -75,13 +72,11 @@ struct Zone {
uint8_t data[sizeof(void*)];
};
// --------------------------------------------------------------------------
// [Enums]
// --------------------------------------------------------------------------
enum {
//! 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;
//!
//! class SomeObject { ... };
//! class Object { ... };
//!
//! // Create Zone with default block size of 65536 bytes.
//! Zone zone(65536);
//! // Create Zone with default block size of approximately 65536 bytes.
//! Zone zone(65536 - Zone::kZoneOverhead);
//!
//! // 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) {
//! // 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();
//!
//! // ... lifetime of your objects ...
@@ -157,7 +152,7 @@ struct Zone {
//! // To destroy the instance (if required).
//! obj->~Object();
//!
//! // Reset of destroy `Zone`.
//! // Reset or destroy `Zone`.
//! zone.reset();
//! ~~~
ASMJIT_INLINE void* alloc(size_t size) noexcept {

View File

@@ -607,9 +607,7 @@
// [@CC_INLINE{@]
// \def ASMJIT_INLINE
// Always inline the decorated function.
#if ASMJIT_CC_HAS_ATTRIBUTE_ALWAYS_INLINE && ASMJIT_CC_CLANG
# define ASMJIT_INLINE inline __attribute__((__always_inline__, __visibility__("hidden")))
#elif ASMJIT_CC_HAS_ATTRIBUTE_ALWAYS_INLINE
#if ASMJIT_CC_HAS_ATTRIBUTE_ALWAYS_INLINE
# define ASMJIT_INLINE inline __attribute__((__always_inline__))
#elif ASMJIT_CC_HAS_DECLSPEC_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.
ASMJIT_ENUM(X86Round) {
//! Round control - round to nearest (even).
kX86RoundNearest = 0x0,
//! Round control - round to down toward -INF (floor),
kX86RoundDown = 0x1,
//! Round control - round to up toward +INF (ceil).
kX86RoundUp = 0x2,
//! 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
kX86RoundNearest = 0x00, //!< Round to nearest (even).
kX86RoundDown = 0x01, //!< Round to down toward -INF (floor),
kX86RoundUp = 0x02, //!< Round to up toward +INF (ceil).
kX86RoundTrunc = 0x03, //!< Round toward zero (truncate).
kX86RoundCurrent = 0x04, //!< Round to the current rounding mode set (ignores other RC bits).
kX86RoundInexact = 0x08 //!< Avoid the inexact exception, if set.
};
// ============================================================================
@@ -2001,14 +1994,10 @@ ASMJIT_ENUM(X86Round) {
//! X86/X64 Prefetch hints.
ASMJIT_ENUM(X86Prefetch) {
//! Prefetch using NT hint.
kX86PrefetchNTA = 0,
//! Prefetch to L0 cache.
kX86PrefetchT0 = 1,
//! Prefetch to L1 cache.
kX86PrefetchT1 = 2,
//! Prefetch to L2 cache.
kX86PrefetchT2 = 3
kX86PrefetchNTA = 0, //!< Prefetch using NT hint.
kX86PrefetchT0 = 1, //!< Prefetch to L0 cache.
kX86PrefetchT1 = 2, //!< Prefetch to L1 cache.
kX86PrefetchT2 = 3 //!< Prefetch to L2 cache.
};
// ============================================================================
@@ -2045,7 +2034,7 @@ struct X86InstExtendedInfo {
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,
//! typically `jmp`, `jcc`, `call`, or `ret`.
@@ -2053,7 +2042,7 @@ struct X86InstExtendedInfo {
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 {
return (getInstFlags() & kX86InstFlagTest) != 0;
}
@@ -2073,7 +2062,7 @@ struct X86InstExtendedInfo {
//! 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 {
return (getInstFlags() & kX86InstFlagXchg) != 0;
}
@@ -2177,7 +2166,7 @@ struct X86InstExtendedInfo {
//! 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.
//! 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).
uint8_t _writeSize;
@@ -2391,7 +2380,7 @@ struct X86Util {
// [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 b Position of the second component [0, 1], inclusive.
@@ -2404,7 +2393,7 @@ struct X86Util {
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 b Position of the second component [0, 3], inclusive.