From 529f053e60fba8d4dde4ca9aa8df18d269a6f839 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 15 Feb 2026 16:03:43 +0100 Subject: [PATCH] File layout --- Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt | 11 ++- .../Bin2CPPLib/GeneratedTemplate.hpp.in | 20 ++++ .../Bin2CPPLib/{touch.cpp => Generator.cpp} | 0 .../Bin2CPPLib/Include/Bin2CPPLib/Assert.hpp} | 0 .../Include/Bin2CPPLib/Generator.hpp | 0 .../Bin2CPPLib/Include/Bin2CPPLib/Log.hpp | 0 Bin2CPP/Sources/Bin2CPPLib/Log.cpp | 0 Bin2CPP/Sources/Bin2CPPLib/MimallocImpl.cpp | 96 +++++++++++++++++++ Bin2CPP/Tests/Bin2CPPLib/Assert.cpp | 0 Bin2CPP/Tests/Bin2CPPLib/Fixture/toto.txt | 1 + Bin2CPP/Tests/Bin2CPPLib/Generator.cpp | 0 Bin2CPP/Tests/Bin2CPPLib/Log.cpp | 0 CMakeLists.txt | 4 + 13 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in rename Bin2CPP/Sources/Bin2CPPLib/{touch.cpp => Generator.cpp} (100%) rename Bin2CPP/{Tests/Bin2CPPLib/touch.cpp => Sources/Bin2CPPLib/Include/Bin2CPPLib/Assert.hpp} (100%) create mode 100644 Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Generator.hpp create mode 100644 Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Log.hpp create mode 100644 Bin2CPP/Sources/Bin2CPPLib/Log.cpp create mode 100644 Bin2CPP/Sources/Bin2CPPLib/MimallocImpl.cpp create mode 100644 Bin2CPP/Tests/Bin2CPPLib/Assert.cpp create mode 100644 Bin2CPP/Tests/Bin2CPPLib/Generator.cpp create mode 100644 Bin2CPP/Tests/Bin2CPPLib/Log.cpp diff --git a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt index 7235b2a..c5f1e6c 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt @@ -12,6 +12,7 @@ file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp.in ) target_sources(${PROJECT_NAME} @@ -19,10 +20,18 @@ target_sources(${PROJECT_NAME} ${SOURCES} ) -target_link_libraries(${PROJECT_NAME} PUBLIC EASTL::EASTL rapidhash::rapidhash mimalloc) +target_link_libraries(${PROJECT_NAME} PUBLIC EASTL::EASTL mimalloc) target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_DL_LIBS}) target_link_libraries(${PROJECT_NAME} PRIVATE $<$:cpptrace::cpptrace> quill::quill) +target_compile_definitions(${PROJECT_NAME} + PUBLIC $<$:QUILL_NO_EXCEPTIONS> + PUBLIC $<$:QUILL_DISABLE_NON_PREFIXED_MACROS> + + PUBLIC MI_SHARED_LIB) + +set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/MimallocImpl.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) + source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX Src FILES ${SOURCES}) set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Bin2CPP/${ParentFolder}) \ No newline at end of file diff --git a/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in b/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in new file mode 100644 index 0000000..0a7caac --- /dev/null +++ b/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in @@ -0,0 +1,20 @@ +#ifndef {{GUARD_NAME}} +#define {{GUARD_NAME}} +/** + * Auto-generated header from: {{FILENAME}} + * Generated by Bin2CPP + * + * DO NOT TOUCH + */ +#include {{ARRAY_TYPE_INCLUDE}} +#include + +namespace {{NAMESPACE}} { + +constexpr {{ARRAY_TYPE}} {{ARRAY_NAME}} = { +{{DATA}} +}; + +} // namespace {{NAMESPACE}} + +#endif // {{GUARD_NAME}} \ No newline at end of file diff --git a/Bin2CPP/Sources/Bin2CPPLib/touch.cpp b/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp similarity index 100% rename from Bin2CPP/Sources/Bin2CPPLib/touch.cpp rename to Bin2CPP/Sources/Bin2CPPLib/Generator.cpp diff --git a/Bin2CPP/Tests/Bin2CPPLib/touch.cpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Assert.hpp similarity index 100% rename from Bin2CPP/Tests/Bin2CPPLib/touch.cpp rename to Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Assert.hpp diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Generator.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Generator.hpp new file mode 100644 index 0000000..e69de29 diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Log.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Log.hpp new file mode 100644 index 0000000..e69de29 diff --git a/Bin2CPP/Sources/Bin2CPPLib/Log.cpp b/Bin2CPP/Sources/Bin2CPPLib/Log.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Bin2CPP/Sources/Bin2CPPLib/MimallocImpl.cpp b/Bin2CPP/Sources/Bin2CPPLib/MimallocImpl.cpp new file mode 100644 index 0000000..bdb5e6a --- /dev/null +++ b/Bin2CPP/Sources/Bin2CPPLib/MimallocImpl.cpp @@ -0,0 +1,96 @@ +/********************************************************************* + * \file MimallocImpl.cpp + * + * \author Romain BOULLARD + * \date February 2026 + *********************************************************************/ +#if defined BIN2CPP_WINDOWS +#pragma comment(linker, "/include:mi_version") +#pragma warning(disable: 4100 4559) +#elif defined BIN2CPP_LINUX +#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#else +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" +#endif +#endif + +// Taken from mimalloc-new-delete.h + +// clang-format off + +// ---------------------------------------------------------------------------- +// This header provides convenient overrides for the new and +// delete operations in C++. +// +// This header should be included in only one source file! +// +// On Windows, or when linking dynamically with mimalloc, these +// can be more performant than the standard new-delete operations. +// See +// --------------------------------------------------------------------------- +#if defined(__cplusplus) + #include + #include + + #if defined(_MSC_VER) && defined(_Ret_notnull_) && defined(_Post_writable_byte_size_) + // stay consistent with VCRT definitions + #define mi_decl_new(n) mi_decl_nodiscard mi_decl_restrict _Ret_notnull_ _Post_writable_byte_size_(n) + #define mi_decl_new_nothrow(n) mi_decl_nodiscard mi_decl_restrict _Ret_maybenull_ _Success_(return != NULL) _Post_writable_byte_size_(n) + #else + #define mi_decl_new(n) mi_decl_nodiscard mi_decl_restrict + #define mi_decl_new_nothrow(n) mi_decl_nodiscard mi_decl_restrict + #endif + + void operator delete(void* p) noexcept { mi_free(p); }; + void operator delete[](void* p) noexcept { mi_free(p); }; + + void operator delete (void* p, const std::nothrow_t&) noexcept { mi_free(p); } + void operator delete[](void* p, const std::nothrow_t&) noexcept { mi_free(p); } + + mi_decl_new(n) void* operator new(std::size_t n) noexcept(false) { return mi_new(n); } + mi_decl_new(n) void* operator new[](std::size_t n) noexcept(false) { return mi_new(n); } + + mi_decl_new_nothrow(n) void* operator new (std::size_t n, const std::nothrow_t& tag) noexcept { (void)(tag); return mi_new_nothrow(n); } + mi_decl_new_nothrow(n) void* operator new[](std::size_t n, const std::nothrow_t& tag) noexcept { (void)(tag); return mi_new_nothrow(n); } + + // Not from mimalloc-new-delete.h, but necessary for EASTL + void* operator new[](size_t size, const char* name, int flags, unsigned debugFlags, const char* file, int line) noexcept(false) { return mi_new(size); } + + #if (__cplusplus >= 201402L || _MSC_VER >= 1916) + void operator delete (void* p, std::size_t n) noexcept { mi_free_size(p,n); }; + void operator delete[](void* p, std::size_t n) noexcept { mi_free_size(p,n); }; + #endif + + #if (__cplusplus > 201402L || defined(__cpp_aligned_new)) + void operator delete (void* p, std::align_val_t al) noexcept { mi_free_aligned(p, static_cast(al)); } + void operator delete[](void* p, std::align_val_t al) noexcept { mi_free_aligned(p, static_cast(al)); } + void operator delete (void* p, std::size_t n, std::align_val_t al) noexcept { mi_free_size_aligned(p, n, static_cast(al)); }; + void operator delete[](void* p, std::size_t n, std::align_val_t al) noexcept { mi_free_size_aligned(p, n, static_cast(al)); }; + void operator delete (void* p, std::align_val_t al, const std::nothrow_t&) noexcept { mi_free_aligned(p, static_cast(al)); } + void operator delete[](void* p, std::align_val_t al, const std::nothrow_t&) noexcept { mi_free_aligned(p, static_cast(al)); } + + void* operator new (std::size_t n, std::align_val_t al) noexcept(false) { return mi_new_aligned(n, static_cast(al)); } + void* operator new[](std::size_t n, std::align_val_t al) noexcept(false) { return mi_new_aligned(n, static_cast(al)); } + void* operator new (std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { return mi_new_aligned_nothrow(n, static_cast(al)); } + void* operator new[](std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { return mi_new_aligned_nothrow(n, static_cast(al)); } + + // Not from mimalloc-new-delete.h, but necessary for EASTL + void* operator new[](size_t size, size_t alignment, size_t alignmentOffset, const char* pName, int flags, unsigned debugFlags, const char* file, int line) noexcept(false) { return mi_new_aligned(size, alignment); } + #endif + +#endif + +// clang-format on + +#if defined BIN2CPP_WINDOWS +#pragma warning(default: 4100 4559) +#elif defined BIN2CPP_LINUX +#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) +#pragma GCC diagnostic pop +#else +#pragma clang diagnostic pop +#endif +#endif diff --git a/Bin2CPP/Tests/Bin2CPPLib/Assert.cpp b/Bin2CPP/Tests/Bin2CPPLib/Assert.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Bin2CPP/Tests/Bin2CPPLib/Fixture/toto.txt b/Bin2CPP/Tests/Bin2CPPLib/Fixture/toto.txt index e69de29..5e1c309 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/Fixture/toto.txt +++ b/Bin2CPP/Tests/Bin2CPPLib/Fixture/toto.txt @@ -0,0 +1 @@ +Hello World \ No newline at end of file diff --git a/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp b/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Bin2CPP/Tests/Bin2CPPLib/Log.cpp b/Bin2CPP/Tests/Bin2CPPLib/Log.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CMakeLists.txt b/CMakeLists.txt index b1e9505..e30b8e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_OPTIMIZE_DEPENDENCIES 1) add_compile_definitions( + $<$:BIN2CPP_OPTIMIZED> + $<$:BIN2CPP_NOT_OPTIMIZED> + $<$:BIN2CPP_WINDOWS> + $<$:BIN2CPP_LINUX> $<$:NOMINMAX> $<$:WIN32_LEAN_AND_MEAN>)