mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-17 04:24:37 +03:00
Removed the dependency on a <new> header
This commit is contained in:
@@ -44,7 +44,6 @@
|
|||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <new>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ Error BaseBuilder::newInstNode(InstNode** out, InstId instId, InstOptions instOp
|
|||||||
if (ASMJIT_UNLIKELY(!node))
|
if (ASMJIT_UNLIKELY(!node))
|
||||||
return reportError(DebugUtils::errored(kErrorOutOfMemory));
|
return reportError(DebugUtils::errored(kErrorOutOfMemory));
|
||||||
|
|
||||||
*out = new(node) InstNode(this, instId, instOptions, opCount, opCapacity);
|
*out = new(Support::PlacementNew{node}) InstNode(this, instId, instOptions, opCount, opCapacity);
|
||||||
return kErrorOk;
|
return kErrorOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,7 +621,7 @@ Error BaseBuilder::_emit(InstId instId, const Operand_& o0, const Operand_& o1,
|
|||||||
return reportError(DebugUtils::errored(kErrorOutOfMemory));
|
return reportError(DebugUtils::errored(kErrorOutOfMemory));
|
||||||
}
|
}
|
||||||
|
|
||||||
node = new(node) InstNode(this, instId, options, opCount, opCapacity);
|
node = new(Support::PlacementNew{node}) InstNode(this, instId, options, opCount, opCapacity);
|
||||||
node->setExtraReg(extraReg());
|
node->setExtraReg(extraReg());
|
||||||
node->setOp(0, o0);
|
node->setOp(0, o0);
|
||||||
node->setOp(1, o1);
|
node->setOp(1, o1);
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ Error BaseCompiler::newVirtReg(VirtReg** out, TypeId typeId, OperandSignature si
|
|||||||
uint32_t size = TypeUtils::sizeOf(typeId);
|
uint32_t size = TypeUtils::sizeOf(typeId);
|
||||||
uint32_t alignment = Support::min<uint32_t>(size, 64);
|
uint32_t alignment = Support::min<uint32_t>(size, 64);
|
||||||
|
|
||||||
vReg = new(vReg) VirtReg(signature, Operand::indexToVirtId(index), size, alignment, typeId);
|
vReg = new(Support::PlacementNew{vReg}) VirtReg(signature, Operand::indexToVirtId(index), size, alignment, typeId);
|
||||||
|
|
||||||
#ifndef ASMJIT_NO_LOGGING
|
#ifndef ASMJIT_NO_LOGGING
|
||||||
if (name && name[0] != '\0')
|
if (name && name[0] != '\0')
|
||||||
@@ -490,7 +490,7 @@ Error BaseCompiler::newJumpNode(JumpNode** out, InstId instId, InstOptions instO
|
|||||||
if (ASMJIT_UNLIKELY(!node))
|
if (ASMJIT_UNLIKELY(!node))
|
||||||
return reportError(DebugUtils::errored(kErrorOutOfMemory));
|
return reportError(DebugUtils::errored(kErrorOutOfMemory));
|
||||||
|
|
||||||
node = new(node) JumpNode(this, instId, instOptions, opCount, annotation);
|
node = new(Support::PlacementNew{node}) JumpNode(this, instId, instOptions, opCount, annotation);
|
||||||
node->setOp(0, o0);
|
node->setOp(0, o0);
|
||||||
node->resetOpRange(opCount, JumpNode::kBaseOpCapacity);
|
node->resetOpRange(opCount, JumpNode::kBaseOpCapacity);
|
||||||
|
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ public:
|
|||||||
Node* node = zone->allocT<Node>(sizeof(Node) + size);
|
Node* node = zone->allocT<Node>(sizeof(Node) + size);
|
||||||
if (ASMJIT_UNLIKELY(!node)) return nullptr;
|
if (ASMJIT_UNLIKELY(!node)) return nullptr;
|
||||||
|
|
||||||
node = new(node) Node(offset, shared);
|
node = new(Support::PlacementNew{node}) Node(offset, shared);
|
||||||
memcpy(node->data(), data, size);
|
memcpy(node->data(), data, size);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,17 +25,12 @@ namespace Support {
|
|||||||
ASMJIT_FORCE_INLINE void operatorDelete(void* p) noexcept { if (p) free(p); }
|
ASMJIT_FORCE_INLINE void operatorDelete(void* p) noexcept { if (p) free(p); }
|
||||||
} // {Support}
|
} // {Support}
|
||||||
|
|
||||||
#define ASMJIT_BASE_CLASS(TYPE) \
|
#define ASMJIT_BASE_CLASS(TYPE) \
|
||||||
ASMJIT_FORCE_INLINE void* operator new(size_t n) noexcept { \
|
ASMJIT_FORCE_INLINE void* operator new(size_t n) noexcept { return Support::operatorNew(n); } \
|
||||||
return Support::operatorNew(n); \
|
ASMJIT_FORCE_INLINE void operator delete(void* ptr) noexcept { Support::operatorDelete(ptr); } \
|
||||||
} \
|
\
|
||||||
\
|
ASMJIT_FORCE_INLINE void* operator new(size_t, void* ptr) noexcept { return ptr; } \
|
||||||
ASMJIT_FORCE_INLINE void operator delete(void* p) noexcept { \
|
ASMJIT_FORCE_INLINE void operator delete(void*, void*) noexcept {}
|
||||||
Support::operatorDelete(p); \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
ASMJIT_FORCE_INLINE void* operator new(size_t, void* p) noexcept { return p; } \
|
|
||||||
ASMJIT_FORCE_INLINE void operator delete(void*, void*) noexcept {}
|
|
||||||
#else
|
#else
|
||||||
#define ASMJIT_BASE_CLASS(TYPE)
|
#define ASMJIT_BASE_CLASS(TYPE)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ static inline JitAllocatorPrivateImpl* JitAllocatorImpl_new(const JitAllocator::
|
|||||||
}
|
}
|
||||||
|
|
||||||
JitAllocatorPool* pools = reinterpret_cast<JitAllocatorPool*>((uint8_t*)p + sizeof(JitAllocatorPrivateImpl));
|
JitAllocatorPool* pools = reinterpret_cast<JitAllocatorPool*>((uint8_t*)p + sizeof(JitAllocatorPrivateImpl));
|
||||||
JitAllocatorPrivateImpl* impl = new(p) JitAllocatorPrivateImpl(pools, poolCount);
|
JitAllocatorPrivateImpl* impl = new(Support::PlacementNew{p}) JitAllocatorPrivateImpl(pools, poolCount);
|
||||||
|
|
||||||
impl->options = options;
|
impl->options = options;
|
||||||
impl->blockSize = blockSize;
|
impl->blockSize = blockSize;
|
||||||
@@ -485,7 +485,7 @@ static inline JitAllocatorPrivateImpl* JitAllocatorImpl_new(const JitAllocator::
|
|||||||
impl->pageSize = vmInfo.pageSize;
|
impl->pageSize = vmInfo.pageSize;
|
||||||
|
|
||||||
for (size_t poolId = 0; poolId < poolCount; poolId++)
|
for (size_t poolId = 0; poolId < poolCount; poolId++)
|
||||||
new(&pools[poolId]) JitAllocatorPool(granularity << poolId);
|
new(Support::PlacementNew{&pools[poolId]}) JitAllocatorPool(granularity << poolId);
|
||||||
|
|
||||||
return impl;
|
return impl;
|
||||||
}
|
}
|
||||||
@@ -632,7 +632,7 @@ static Error JitAllocatorImpl_newBlock(JitAllocatorPrivateImpl* impl, JitAllocat
|
|||||||
}
|
}
|
||||||
|
|
||||||
BitWord* bitWords = reinterpret_cast<BitWord*>(blockPtr + sizeof(JitAllocatorBlock));
|
BitWord* bitWords = reinterpret_cast<BitWord*>(blockPtr + sizeof(JitAllocatorBlock));
|
||||||
*dst = new(blockPtr) JitAllocatorBlock(pool, virtMem, blockSize, blockFlags, bitWords, bitWords + numBitWords, areaSize);
|
*dst = new(Support::PlacementNew{blockPtr}) JitAllocatorBlock(pool, virtMem, blockSize, blockFlags, bitWords, bitWords + numBitWords, areaSize);
|
||||||
return kErrorOk;
|
return kErrorOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1165,7 +1165,7 @@ ASMJIT_FAVOR_SPEED Error BaseRAPass::initGlobalLiveSpans() noexcept {
|
|||||||
return DebugUtils::errored(kErrorOutOfMemory);
|
return DebugUtils::errored(kErrorOutOfMemory);
|
||||||
|
|
||||||
for (size_t physId = 0; physId < physCount; physId++)
|
for (size_t physId = 0; physId < physCount; physId++)
|
||||||
new(&liveSpans[physId]) LiveRegSpans();
|
new(Support::PlacementNew{&liveSpans[physId]}) LiveRegSpans();
|
||||||
}
|
}
|
||||||
|
|
||||||
_globalLiveSpans[group] = liveSpans;
|
_globalLiveSpans[group] = liveSpans;
|
||||||
|
|||||||
@@ -882,7 +882,7 @@ public:
|
|||||||
void* p = zone()->alloc(RAInst::sizeOf(tiedRegCount));
|
void* p = zone()->alloc(RAInst::sizeOf(tiedRegCount));
|
||||||
if (ASMJIT_UNLIKELY(!p))
|
if (ASMJIT_UNLIKELY(!p))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return new(p) RAInst(block, instRWFlags, flags, tiedRegCount, clobberedRegs);
|
return new(Support::PlacementNew{p}) RAInst(block, instRWFlags, flags, tiedRegCount, clobberedRegs);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASMJIT_FORCE_INLINE Error assignRAInst(BaseNode* node, RABlock* block, RAInstBuilder& ib) noexcept {
|
ASMJIT_FORCE_INLINE Error assignRAInst(BaseNode* node, RABlock* block, RAInstBuilder& ib) noexcept {
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ ASMJIT_BEGIN_NAMESPACE
|
|||||||
//! here is considered internal and should not be used outside of AsmJit and related projects like AsmTK.
|
//! here is considered internal and should not be used outside of AsmJit and related projects like AsmTK.
|
||||||
namespace Support {
|
namespace Support {
|
||||||
|
|
||||||
|
// Support - Placement New
|
||||||
|
// =======================
|
||||||
|
|
||||||
|
//! Helper to implement placement new/delete without relying on `<new>` header.
|
||||||
|
struct PlacementNew { void* ptr; };
|
||||||
|
|
||||||
// Support - Basic Traits
|
// Support - Basic Traits
|
||||||
// ======================
|
// ======================
|
||||||
|
|
||||||
@@ -1759,4 +1765,14 @@ struct Temporary {
|
|||||||
|
|
||||||
ASMJIT_END_NAMESPACE
|
ASMJIT_END_NAMESPACE
|
||||||
|
|
||||||
|
//! Implementation of a placement new so we don't have to depend on `<new>`.
|
||||||
|
ASMJIT_INLINE_NODEBUG void* operator new(size_t, const asmjit::Support::PlacementNew& p) noexcept {
|
||||||
|
#if defined(_MSC_VER) && !defined(__clang__)
|
||||||
|
__assume(p.ptr != nullptr); // Otherwise MSVC would emit a nullptr check.
|
||||||
|
#endif
|
||||||
|
return p.ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASMJIT_INLINE_NODEBUG void operator delete(void*, const asmjit::Support::PlacementNew&) noexcept {}
|
||||||
|
|
||||||
#endif // ASMJIT_CORE_SUPPORT_H_INCLUDED
|
#endif // ASMJIT_CORE_SUPPORT_H_INCLUDED
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ public:
|
|||||||
void* p = alloc(sizeof(T), alignof(T));
|
void* p = alloc(sizeof(T), alignof(T));
|
||||||
if (ASMJIT_UNLIKELY(!p))
|
if (ASMJIT_UNLIKELY(!p))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return new(p) T();
|
return new(Support::PlacementNew{p}) T();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Like `new(std::nothrow) T(...)`, but allocated by `Zone`.
|
//! Like `new(std::nothrow) T(...)`, but allocated by `Zone`.
|
||||||
@@ -331,7 +331,7 @@ public:
|
|||||||
void* p = alloc(sizeof(T), alignof(T));
|
void* p = alloc(sizeof(T), alignof(T));
|
||||||
if (ASMJIT_UNLIKELY(!p))
|
if (ASMJIT_UNLIKELY(!p))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return new(p) T(std::forward<Args>(args)...);
|
return new(Support::PlacementNew{p}) T(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \cond INTERNAL
|
//! \cond INTERNAL
|
||||||
@@ -573,7 +573,7 @@ public:
|
|||||||
void* p = allocT<T>();
|
void* p = allocT<T>();
|
||||||
if (ASMJIT_UNLIKELY(!p))
|
if (ASMJIT_UNLIKELY(!p))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return new(p) T();
|
return new(Support::PlacementNew{p}) T();
|
||||||
}
|
}
|
||||||
//! Like `new(std::nothrow) T(...)`, but allocated by `Zone`.
|
//! Like `new(std::nothrow) T(...)`, but allocated by `Zone`.
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
@@ -581,7 +581,7 @@ public:
|
|||||||
void* p = allocT<T>();
|
void* p = allocT<T>();
|
||||||
if (ASMJIT_UNLIKELY(!p))
|
if (ASMJIT_UNLIKELY(!p))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return new(p) T(std::forward<Args>(args)...);
|
return new(Support::PlacementNew{p}) T(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Releases the memory previously allocated by `alloc()`. The `size` argument has to be the same as used to call
|
//! Releases the memory previously allocated by `alloc()`. The `size` argument has to be the same as used to call
|
||||||
|
|||||||
Reference in New Issue
Block a user