Skip to content

Commit

Permalink
Move mbstring functions into runtime-common
Browse files Browse the repository at this point in the history
  • Loading branch information
apolyakov committed Oct 30, 2024
1 parent eff369e commit a731de3
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 93 deletions.
21 changes: 17 additions & 4 deletions common/unicode/unicode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,21 @@ add_custom_command(
DEPENDS ${UNICODE_DATA_LIST}
COMMENT "unicode-utils-auto.h generation")

vk_add_library(unicode OBJECT
${UNICODE_DIR}/unicode-utils.cpp
${UNICODE_DIR}/utf8-utils.cpp
${AUTO_DIR}/common/unicode-utils-auto.h)
set(UNICODE_SOURCES unicode-utils.cpp utf8-utils.cpp)

if (COMPILE_RUNTIME_LIGHT)
set(UNICODE_SOURCES_FOR_COMP "${UNICODE_SOURCES}")
configure_file(${BASE_DIR}/compiler/unicode_sources.h.in ${AUTO_DIR}/compiler/unicode_sources.h)
endif()

prepend(UNICODE_SOURCES ${UNICODE_DIR}/ ${UNICODE_SOURCES})

if (COMPILE_RUNTIME_LIGHT)
vk_add_library(light_unicode OBJECT ${UNICODE_SOURCES} ${AUTO_DIR}/common/unicode-utils-auto.h)
set_property(TARGET light_unicode PROPERTY POSITION_INDEPENDENT_CODE ON)

target_compile_options(light_unicode PUBLIC -stdlib=libc++)
target_link_options(light_unicode PUBLIC -stdlib=libc++ -static-libstdc++)
endif()

vk_add_library(unicode OBJECT ${UNICODE_SOURCES} ${AUTO_DIR}/common/unicode-utils-auto.h)
20 changes: 19 additions & 1 deletion compiler/compiler-core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

#include "compiler/const-manipulations.h"
#include "compiler/data/composer-json-data.h"
#include "compiler/data/ffi-data.h"
#include "compiler/data/define-data.h"
#include "compiler/data/ffi-data.h"
#include "compiler/data/function-data.h"
#include "compiler/data/lib-data.h"
#include "compiler/data/modulite-data.h"
#include "compiler/data/src-dir.h"
#include "compiler/data/src-file.h"
#include "compiler/index.h"
#include "compiler/name-gen.h"
#include "compiler/runtime_build_info.h"

Expand Down Expand Up @@ -654,6 +655,10 @@ const Index &CompilerCore::get_common_index() {
return common_sources_index;
}

const Index &CompilerCore::get_unicode_index() {
return unicode_sources_index;
}

File *CompilerCore::get_file_info(std::string &&file_name) {
return cpp_index.insert_file(std::move(file_name));
}
Expand Down Expand Up @@ -692,6 +697,14 @@ static std::vector<std::string> get_common_sources() {
#endif
}

static std::vector<std::string> get_unicode_sources() {
#ifdef RUNTIME_LIGHT
return split(UNICODE_SOURCES, ';');
#else
return {};
#endif
}

void CompilerCore::init_runtime_and_common_srcs_dir() {
runtime_common_sources_dir = settings().runtime_and_common_src.get() + "runtime-common/";
runtime_common_sources_index.sync_with_dir(runtime_common_sources_dir);
Expand All @@ -707,6 +720,11 @@ void CompilerCore::init_runtime_and_common_srcs_dir() {
common_sources_index.sync_with_dir(common_sources_dir);
common_sources_dir = common_sources_index.get_dir(); // As in init_dest_dir, IDK what is it for
common_sources_index.filter_with_whitelist(get_common_sources());

unicode_sources_dir = settings().runtime_and_common_src.get() + "common/unicode/";
unicode_sources_index.sync_with_dir(unicode_sources_dir);
unicode_sources_dir = unicode_sources_index.get_dir(); // As in init_dest_dir, IDK what is it for
unicode_sources_index.filter_with_whitelist(get_unicode_sources());
}

bool CompilerCore::try_require_file(SrcFilePtr file) {
Expand Down
3 changes: 3 additions & 0 deletions compiler/compiler-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CompilerCore {
Index runtime_common_sources_index;
Index runtime_sources_index;
Index common_sources_index;
Index unicode_sources_index;
TSHashTable<SrcFilePtr> file_ht;
TSHashTable<SrcDirPtr> dirs_ht;
TSHashTable<FunctionPtr> functions_ht;
Expand Down Expand Up @@ -71,6 +72,7 @@ class CompilerCore {
std::string runtime_common_sources_dir;
std::string runtime_sources_dir;
std::string common_sources_dir;
std::string unicode_sources_dir;

CompilerCore();
void start();
Expand Down Expand Up @@ -144,6 +146,7 @@ class CompilerCore {
const Index &get_runtime_core_index();
const Index &get_runtime_index();
const Index &get_common_index();
const Index &get_unicode_index();
File *get_file_info(std::string &&file_name);
void del_extra_files();
void init_dest_dir();
Expand Down
1 change: 1 addition & 0 deletions compiler/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(KEYWORDS_GPERF ${KPHP_COMPILER_DIR}/keywords.gperf)
if (COMPILE_RUNTIME_LIGHT)
prepend(RUNTIME_BUILD_INFO ${KPHP_COMPILER_AUTO_DIR}/
common_sources.h
unicode_sources.h
runtime_sources.h
runtime_common_sources.h
runtime_compile_flags.h)
Expand Down
10 changes: 6 additions & 4 deletions compiler/make/make.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
#include "common/wrappers/pathname.h"

#include "compiler/compiler-core.h"
#include "compiler/data/lib-data.h"
#include "compiler/data/ffi-data.h"
#include "compiler/data/lib-data.h"
#include "compiler/index.h"
#include "compiler/make/cpp-to-obj-target.h"
#include "compiler/make/runtime-src-to-obj-target.h"
#include "compiler/make/file-target.h"
#include "compiler/make/h-to-pch-target.h"
#include "compiler/make/hardlink-or-copy.h"
#include "compiler/make/make-runner.h"
#include "compiler/make/objs-to-bin-target.h"
#include "compiler/make/objs-to-obj-target.h"
#include "compiler/make/objs-to-k2-component-target.h"
#include "compiler/make/objs-to-obj-target.h"
#include "compiler/make/objs-to-static-lib-target.h"
#include "compiler/make/runtime-src-to-obj-target.h"
#include "compiler/runtime_build_info.h"
#include "compiler/stage.h"
#include "compiler/threading/profiler.h"
Expand Down Expand Up @@ -459,11 +460,12 @@ static std::vector<File *> build_runtime_and_common_from_sources(const std::stri
const Index &runtime_core_dir = G->get_runtime_core_index();
const Index &runtime_dir = G->get_runtime_index();
const Index &common_dir = G->get_common_index();
const Index &unicode_index = G->get_unicode_index();

std::vector<File*> objs;
objs.reserve(runtime_dir.get_files_count() + common_dir.get_files_count());

for (const auto *dir : std::vector<const Index*>{&runtime_core_dir, &runtime_dir, &common_dir}) {
for (const auto *dir : std::vector<const Index*>{&runtime_core_dir, &runtime_dir, &common_dir, &unicode_index}) {
for (File *cpp_file : dir->get_files()) {
File *obj_file = obj_dir.insert_file(static_cast<std::string>(cpp_file->name_without_ext) + ".o");
make.create_cpp_target(cpp_file);
Expand Down
1 change: 1 addition & 0 deletions compiler/runtime_build_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifdef RUNTIME_LIGHT

#include "auto/compiler/common_sources.h"
#include "auto/compiler/unicode_sources.h"
#include "auto/compiler/runtime_compile_flags.h"
#include "auto/compiler/runtime_common_sources.h"
#include "auto/compiler/runtime_sources.h"
Expand Down
3 changes: 3 additions & 0 deletions compiler/unicode_sources.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#define UNICODE_SOURCES "${UNICODE_SOURCES_FOR_COMP}"
3 changes: 2 additions & 1 deletion runtime-common/stdlib/stdlib.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
prepend(STDLIB_STRING stdlib/string/ string-functions.cpp)
prepend(STDLIB_STRING stdlib/string/ string-functions.cpp
mbstring-functions.cpp)

set(STDLIB_SRC "${STDLIB_STRING}")
Loading

0 comments on commit a731de3

Please sign in to comment.