Skip to content

Commit

Permalink
Better compiler flags detection in CMakeLists.txt\nFixed missing noex…
Browse files Browse the repository at this point in the history
…cept in StaticRuntime.cpp
  • Loading branch information
kobalicek committed May 5, 2016
1 parent f7de7b8 commit 286bc22
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 158 deletions.
36 changes: 35 additions & 1 deletion CMakeLists.txt
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.1)
include(CheckCXXCompilerFlag)

# =============================================================================
# [AsmJit - Configuration]
Expand Down Expand Up @@ -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]
# =============================================================================
Expand Down Expand Up @@ -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)
Expand Down
47 changes: 14 additions & 33 deletions src/asmjit/apibegin.h
Expand Up @@ -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

// [GCC]
#if ASMJIT_CC_GCC
# pragma GCC diagnostic push
# pragma GCC diagnostic warning "-Winline"
#endif // ASMJIT_CC_GCC

#if defined(_MSC_VER)
// [MSC]
#if ASMJIT_CC_MSC

# pragma warning(push)
# pragma warning(disable: 4127) // conditional expression is constant
Expand All @@ -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
47 changes: 12 additions & 35 deletions src/asmjit/apiend.h
Expand Up @@ -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

// ============================================================================
// [MSC]
// ============================================================================
// [CLang]
#if ASMJIT_CC_CLANG
# pragma clang diagnostic pop
#endif // ASMJIT_CC_CLANG

#if defined(_MSC_VER)
# pragma warning(pop)
// [GCC]
#if ASMJIT_CC_GCC
# pragma GCC diagnostic pop
#endif // ASMJIT_CC_GCC

// [MSC]
#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
36 changes: 18 additions & 18 deletions src/asmjit/base/compiler.cpp
Expand Up @@ -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 {}

// ============================================================================
Expand Down
25 changes: 9 additions & 16 deletions src/asmjit/base/constpool.h
Expand Up @@ -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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/asmjit/base/cpuinfo.cpp
Expand Up @@ -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';
}
Expand Down
4 changes: 2 additions & 2 deletions src/asmjit/base/hlstream.h
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/asmjit/base/runtime.cpp
Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions src/asmjit/base/vmem.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 286bc22

Please sign in to comment.