src: add boost-pfr

This commit is contained in:
Markus F.X.J. Oberhumer 2023-01-05 00:57:05 +01:00
parent d9657e9831
commit cd686cb1d9
5 changed files with 67 additions and 1 deletions

View File

@ -180,7 +180,7 @@ else()
endif()
set(t upx)
target_include_directories(${t} PRIVATE vendor)
target_include_directories(${t} PRIVATE vendor vendor/boost-pfr/include)
target_compile_definitions(${t} PRIVATE $<$<CONFIG:Debug>:DEBUG=1>)
if(GITREV_SHORT)
target_compile_definitions(${t} PRIVATE UPX_VERSION_GITREV="${GITREV_SHORT}${GITREV_PLUS}")

View File

@ -120,6 +120,9 @@ build/extra/cross-windows-mingw64/%: UPX_CMAKE_CONFIG_FLAGS += -DUPX_CONFIG_DISA
# check git submodules
#***********************************************************************
ifeq ($(wildcard ./vendor/boost-pfr/include/.),)
$(error ERROR: missing git submodule; run 'git submodule update --init')
endif
ifeq ($(wildcard ./vendor/doctest/doctest/.),)
$(error ERROR: missing git submodule; run 'git submodule update --init')
endif

View File

@ -1,5 +1,6 @@
-std=gnu++17
-Ivendor
-Ivendor/boost-pfr/include
-fno-strict-aliasing
-fno-strict-overflow
-funsigned-char

View File

@ -778,6 +778,34 @@ unsigned membuffer_get_size(MemBuffer &mb);
//#define DOCTEST_CONFIG_DISABLE 1
#include <doctest/doctest/parts/doctest_fwd.h>
#if WITH_BOOST_PFR
#include <boost/pfr/io.hpp>
template <class A>
__acc_noinline std::string pfr_str(const A &a) {
std::ostringstream ss;
ss << boost::pfr::io(a);
return ss.str();
}
template <class A, class B>
__acc_noinline std::string pfr_str(const A &a, const B &b) {
std::ostringstream ss;
ss << boost::pfr::io(a);
ss << ' ';
ss << boost::pfr::io(b);
return ss.str();
}
template <class A, class B, class C>
__acc_noinline std::string pfr_str(const A &a, const B &b, const C &c) {
std::ostringstream ss;
ss << boost::pfr::io(a);
ss << ' ';
ss << boost::pfr::io(b);
ss << ' ';
ss << boost::pfr::io(c);
return ss.str();
}
#endif // WITH_BOOST_PFR
// util/dt_check.cpp
void upx_compiler_sanity_check();
int upx_doctest_check();

View File

@ -25,6 +25,11 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#if DEBUG || 1
#ifndef WITH_BOOST_PFR
#define WITH_BOOST_PFR 1
#endif
#endif
#include "../conf.h"
/*************************************************************************
@ -448,4 +453,33 @@ TEST_CASE("libc snprintf") {
CHECK_EQ(strcmp(buf, "-7.0.0.0.0.0.0.0.7.0xffffffffffffffff"), 0);
}
#if WITH_BOOST_PFR
TEST_CASE("Boost.PFR") {
int i = -1;
CHECK_EQ(strcmp(pfr_str(i).c_str(), "-1"), 0);
BE32 b32;
b32 = 1;
LE32 l32;
l32 = 2;
CHECK_EQ(strcmp(pfr_str(b32).c_str(), "1"), 0);
CHECK_EQ(strcmp(pfr_str(l32).c_str(), "2"), 0);
struct Foo {
BE16 b16;
BE32 b32;
BE64 b64;
LE16 l16;
LE32 l32;
LE64 l64;
};
Foo foo;
foo.b16 = 1;
foo.b32 = 2;
foo.b64 = 3;
foo.l16 = 4;
foo.l32 = 5;
foo.l64 = 6;
CHECK_EQ(strcmp(pfr_str("foo", "=", foo).c_str(), "foo = {1, 2, 3, 4, 5, 6}"), 0);
}
#endif // WITH_BOOST_PFR
/* vim:set ts=4 sw=4 et: */