-
-
Notifications
You must be signed in to change notification settings - Fork 18
Turn PCRE2's SLJIT dependency into its own CMake library #2877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| if(NOT SLJIT_FOUND) | ||
| set(SLJIT_DIR "${PROJECT_SOURCE_DIR}/vendor/sljit") | ||
| set(SLJIT_SOURCE_DIR "${SLJIT_DIR}/sljit_src") | ||
|
|
||
| # This library ships one source that includes every backend and allocator | ||
| # that the target architecture and platform select | ||
| # Merged into the library that uses it, so that no archive, no header and | ||
| # no CMake package of our own build of it reaches an installed consumer | ||
| add_library(sljit OBJECT "${SLJIT_SOURCE_DIR}/sljitLir.c") | ||
| sourcemeta_add_default_options(PRIVATE sljit) | ||
|
|
||
| # The compiler structure that this library hands out grows extra members | ||
| # under any of the tracing, argument checking, or debugging options, so | ||
| # every translation unit that reaches for the header has to be told the | ||
| # same configuration that the library itself was built with | ||
| target_compile_definitions(sljit PUBLIC SLJIT_CONFIG_AUTO=1) | ||
| target_compile_definitions(sljit PUBLIC SLJIT_VERBOSE=0) | ||
| target_compile_definitions(sljit PUBLIC SLJIT_DEBUG=0) | ||
|
|
||
| if(SOURCEMETA_COMPILER_LLVM OR SOURCEMETA_COMPILER_GCC) | ||
| # Generated code accumulates into a trailing single-element array that is | ||
| # over-allocated and written well past its first element, so the strictest | ||
| # interpretation of what counts as a trailing flexible array would treat | ||
| # every byte this library emits as running off the end of the object | ||
| target_compile_options(sljit PRIVATE -fstrict-flex-arrays=0) | ||
| endif() | ||
|
|
||
| if(SOURCEMETA_COMPILER_LLVM) | ||
| # The immediate byte of a vector lane instruction is only read back on the | ||
| # paths that set it, which the compiler cannot correlate | ||
| target_compile_options(sljit PRIVATE -Wno-conditional-uninitialized) | ||
| endif() | ||
|
|
||
| if(SOURCEMETA_COMPILER_MSVC) | ||
| target_compile_options(sljit PRIVATE /wd4701) | ||
| endif() | ||
|
|
||
| target_include_directories(sljit PUBLIC | ||
| "$<BUILD_INTERFACE:${SLJIT_SOURCE_DIR}>") | ||
|
|
||
| add_library(SLJIT::sljit ALIAS sljit) | ||
|
|
||
| set(SLJIT_FOUND ON) | ||
| endif() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: Juan Cruz Viotti <jviotti@sourcemeta.com> | ||
| Date: Wed, 24 Sep 2026 12:00:00 -0300 | ||
| Subject: [PATCH] Link the JIT code generator instead of including its source | ||
|
|
||
| This file textually included the whole of sljitLir.c, which compiled the | ||
| code generator into this translation unit with internal linkage and routed | ||
| its allocations through the pcre2 general context. That makes it impossible | ||
| to treat the code generator as a dependency of its own, or to reuse it from | ||
| anywhere else in the tree. | ||
|
|
||
| Include the public header instead and let the build system compile and link | ||
| the code generator separately. The configuration macros that change the | ||
| layout of struct sljit_compiler now come from the build system, so that both | ||
| sides of the interface agree on them, and the code generator falls back to | ||
| its own malloc and free rather than the pcre2 general context allocator. | ||
|
|
||
| SSIZE_OF is the one name this file needs that the code generator keeps in | ||
| its implementation rather than its header. It takes a parameter, so the | ||
| build system cannot carry it as a definition, and it is reproduced here. | ||
| --- | ||
| src/pcre2_jit_compile.c | 35 ++++++++--------------------------- | ||
| 1 file changed, 8 insertions(+), 27 deletions(-) | ||
|
|
||
| diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c | ||
| index 105a1dd35..de3f03133 100644 | ||
| --- a/src/pcre2_jit_compile.c | ||
| +++ b/src/pcre2_jit_compile.c | ||
| @@ -49,36 +49,17 @@ POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
| #ifdef SUPPORT_JIT | ||
|
|
||
| -/* All-in-one: Since we use the JIT compiler only from here, | ||
| -we just include it. This way we don't need to touch the build | ||
| -system files. */ | ||
| +/* The JIT code generator is built as a library of its own, and the build | ||
| +system sets its configuration on both sides of the interface, so that this | ||
| +translation unit and that library agree on the layout of the structures they | ||
| +pass between them. */ | ||
|
|
||
| -#define SLJIT_CONFIG_AUTO 1 | ||
| -#define SLJIT_CONFIG_STATIC 1 | ||
| -#define SLJIT_VERBOSE 0 | ||
| +#include "sljitLir.h" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Including Prompt for AI agents |
||
|
|
||
| -#ifdef PCRE2_DEBUG | ||
| -#define SLJIT_DEBUG 1 | ||
| -#else | ||
| -#define SLJIT_DEBUG 0 | ||
| -#endif | ||
| +/* A convenience that the code generator keeps private to its implementation, | ||
| +reproduced here in terms of the types that its header does publish. */ | ||
|
|
||
| -#define SLJIT_MALLOC(size, allocator_data) pcre2_jit_malloc(size, allocator_data) | ||
| -#define SLJIT_FREE(ptr, allocator_data) pcre2_jit_free(ptr, allocator_data) | ||
| - | ||
| -static void * pcre2_jit_malloc(size_t size, void *allocator_data) | ||
| -{ | ||
| -pcre2_memctl *allocator = ((pcre2_memctl*)allocator_data); | ||
| -return allocator->malloc(size, allocator->memory_data); | ||
| -} | ||
| - | ||
| -static void pcre2_jit_free(void *ptr, void *allocator_data) | ||
| -{ | ||
| -pcre2_memctl *allocator = ((pcre2_memctl*)allocator_data); | ||
| -allocator->free(ptr, allocator->memory_data); | ||
| -} | ||
| - | ||
| -#include "../deps/sljit/sljit_src/sljitLir.c" | ||
| +#define SSIZE_OF(type) ((sljit_s32)sizeof(sljit_ ## type)) | ||
|
|
||
| #if defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED | ||
| #error Unsupported architecture | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.