Skip to content

Commit

Permalink
generate compiled code in subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Coulom committed Oct 12, 2024
1 parent 7b7c297 commit 0e6e69d
Show file tree
Hide file tree
Showing 26 changed files with 82 additions and 94 deletions.
7 changes: 1 addition & 6 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
benchmarkdb.h
benchmarkdb.cpp
benchmarkdb_readonly.h
benchmarkdb_readonly.cpp
benchmarkdb_interpreted.h
benchmarkdb_interpreted.cpp
benchmarkdb/*.*
*.joedb
*.sqlite3
2 changes: 1 addition & 1 deletion benchmark/joedbc_insert.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "benchmarkdb.h"
#include "benchmarkdb/writable.h"
#include <cstdio>

int main(int argc, char **argv)
Expand Down
33 changes: 18 additions & 15 deletions compcmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ if(GTest_FOUND)
endif()

joedb_add_executable(joedb_test
../doc/source/tutorial/settings.cpp
../doc/source/tutorial/settings/readonly.cpp
../doc/source/tutorial/settings/writable.cpp
../test/Async_Test.cpp
../test/Buffer_Test.cpp
../test/endianness_Test.cpp
Expand Down Expand Up @@ -272,12 +273,14 @@ endforeach(mode)
# Targets below require databases to be compiled
#############################################################################
joedb_add_executable(tutorial
../doc/source/tutorial/tutorial.cpp
../doc/source/tutorial/tutorial/readonly.cpp
../doc/source/tutorial/tutorial/writable.cpp
../doc/source/tutorial/tutorial_main.cpp
)

add_executable(minimal_tutorial
../doc/source/tutorial/tutorial.cpp
../doc/source/tutorial/tutorial/readonly.cpp
../doc/source/tutorial/tutorial/writable.cpp
../doc/source/tutorial/tutorial_main.cpp
../src/joedb/compiler/minimal_runtime.cpp
../src/joedb/io/main_exception_catcher.cpp
Expand All @@ -286,44 +289,44 @@ add_executable(minimal_tutorial

if (NOT JOEDB_PORTABLE)
joedb_add_executable(local_concurrency
../doc/source/tutorial/tutorial.cpp
../doc/source/tutorial/tutorial/readonly.cpp
../doc/source/tutorial/tutorial/writable.cpp
../doc/source/tutorial/local_concurrency.cpp
)
endif()

joedb_add_executable(concurrency_tutorial
../doc/source/tutorial/tutorial.cpp
../doc/source/tutorial/tutorial/readonly.cpp
../doc/source/tutorial/tutorial/writable.cpp
../doc/source/tutorial/concurrency_tutorial.cpp
)

joedb_add_executable(step_by_step_replay
../doc/source/tutorial/tutorial.cpp
../doc/source/tutorial/tutorial/readonly.cpp
../doc/source/tutorial/tutorial/writable.cpp
../doc/source/tutorial/step_by_step_replay.cpp
)

joedb_add_executable(file_tutorial
../doc/source/tutorial/tutorial.cpp
../doc/source/tutorial/tutorial/readonly.cpp
../doc/source/tutorial/tutorial/writable.cpp
../doc/source/tutorial/file_tutorial.cpp
)

joedb_add_executable(index_tutorial
../doc/source/tutorial/tutorial.cpp
../doc/source/tutorial/tutorial/readonly.cpp
../doc/source/tutorial/tutorial/writable.cpp
../doc/source/tutorial/index_tutorial.cpp
)

#joedb_add_executable(wrapper_tutorial
# ../doc/source/tutorial/tutorial.cpp
# ../doc/source/tutorial/tutorial_wrapper.cpp
# ../doc/source/tutorial/tutorial_main.c
#)

joedb_add_executable(joedb_generate_translation_header
../test/compiler/db/test.cpp
../test/compiler/generate_translation_header.cpp
)

joedb_add_executable(joedbc_insert
../benchmark/benchmarkdb.cpp
../benchmark/benchmarkdb/readonly.cpp
../benchmark/benchmarkdb/writable.cpp
../benchmark/joedbc_insert.cpp
)

Expand Down
14 changes: 8 additions & 6 deletions compcmake/joedbc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ function(joedbc_build_absolute dir namespace)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
add_custom_command(
OUTPUT
${dir}/${namespace}_readonly.cpp
${dir}/${namespace}_readonly.h
${dir}/${namespace}.cpp
${dir}/${namespace}.h
${dir}/${namespace}/readonly.cpp
${dir}/${namespace}/readonly.h
${dir}/${namespace}/writable.cpp
${dir}/${namespace}/writable.h
COMMAND joedbc ${namespace}.joedbi ${namespace}.joedbc
DEPENDS
joedbc
Expand All @@ -101,8 +101,10 @@ function(joedbc_build_absolute dir namespace)
)
add_custom_target(compile_${namespace}_with_joedbc
DEPENDS
${dir}/${namespace}.cpp
${dir}/${namespace}.h
${dir}/${namespace}/readonly.cpp
${dir}/${namespace}/readonly.h
${dir}/${namespace}/writable.cpp
${dir}/${namespace}/writable.h
)
add_dependencies(all_joedbc compile_${namespace}_with_joedbc)
endfunction()
Expand Down
5 changes: 3 additions & 2 deletions compcmake/libjoedb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ set(JOEDB_SOURCES
)

set(JOEDB_DATABASES
${JOEDB_SRC_DIR}/joedb/db/encoded_file.cpp
${JOEDB_SRC_DIR}/joedb/db/multi_server_readonly.cpp
${JOEDB_SRC_DIR}/joedb/db/encoded_file/readonly.cpp
${JOEDB_SRC_DIR}/joedb/db/encoded_file/writable.cpp
${JOEDB_SRC_DIR}/joedb/db/multi_server/readonly.cpp
${JOEDB_SRC_DIR}/joedb/journal/Encoded_File.cpp
${JOEDB_SRC_DIR}/joedb/journal/Readonly_Encoded_File.cpp
${JOEDB_SRC_DIR}/joedb/io/File_Parser.cpp
Expand Down
18 changes: 2 additions & 16 deletions doc/source/tutorial/.gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
tutorial.h
tutorial.cpp
tutorial_interpreted.h
tutorial_interpreted.cpp
tutorial_readonly.h
tutorial_readonly.cpp
tutorial_wrapper.h
tutorial_wrapper.cpp
settings.h
settings.cpp
settings_interpreted.h
settings_interpreted.cpp
settings_readonly.h
settings_readonly.cpp
settings_wrapper.h
settings_wrapper.cpp
tutorial/*.*
settings/*.*
edited_tutorial.h
tutorial.joedb
tutorial.out
Expand Down
2 changes: 1 addition & 1 deletion doc/source/tutorial/concurrency_tutorial.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "tutorial.h"
#include "tutorial/writable.h"
#include "joedb/concurrency/File_Connection.h"
#include "joedb/journal/Memory_File.h"

Expand Down
2 changes: 1 addition & 1 deletion doc/source/tutorial/file_tutorial.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "tutorial.h"
#include "tutorial/writable.h"

#include "joedb/io/main_exception_catcher.h"

Expand Down
2 changes: 1 addition & 1 deletion doc/source/tutorial/index_tutorial.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "tutorial.h"
#include "tutorial/writable.h"

#include <iostream>

Expand Down
2 changes: 1 addition & 1 deletion doc/source/tutorial/local_concurrency.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "tutorial.h"
#include "tutorial/writable.h"

#include "joedb/io/main_exception_catcher.h"

Expand Down
2 changes: 1 addition & 1 deletion doc/source/tutorial/settings_main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "settings.h"
#include "settings/writable.h"
#include "joedb/journal/Interpreted_File.h"

#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion doc/source/tutorial/step_by_step_replay.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "tutorial.h"
#include "tutorial/writable.h"

#include <iostream>
#include <iomanip>
Expand Down
2 changes: 1 addition & 1 deletion doc/source/tutorial/tutorial_main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "tutorial.h"
#include "tutorial/writable.h"

#include "joedb/io/main_exception_catcher.h"

Expand Down
31 changes: 16 additions & 15 deletions src/joedb/compiler/joedbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <fstream>
#include <set>
#include <filesystem>

using namespace joedb;

Expand Down Expand Up @@ -157,12 +158,12 @@ static void generate_h(std::ostream &out, const Compiler_Options &options)

namespace_include_guard(out, "Database", options.get_name_space());

out << '\n';
out << "#include \"" << options.get_name_space().back() << "_readonly.h\"\n";
out << "#include \"joedb/concurrency/Client.h\"\n";
out << "#include \"joedb/concurrency/Connection.h\"\n";
out << "#include \"joedb/Span.h\"\n";
out << '\n';
out << R"RRR(
#include "readonly.h"
#include "joedb/concurrency/Client.h"
#include "joedb/concurrency/Connection.h"
#include "joedb/Span.h"
)RRR";

namespace_open(out, options.get_name_space());

Expand Down Expand Up @@ -2039,8 +2040,7 @@ static void generate_readonly_cpp
const std::vector<char> &schema
)
{
const std::vector<std::string> &ns = options.get_name_space();
out << "#include \"" << ns.back() << "_readonly.h\"\n";
out << "#include \"readonly.h\"\n";

namespace_open(out, options.get_name_space());

Expand All @@ -2063,10 +2063,8 @@ static void generate_cpp
{
const auto &db = options.get_db();
const auto &tables = db.get_tables();
const std::string &file_name = options.get_name_space().back();

out << "#include \"" << file_name << "_readonly.cpp\"\n";
out << "#include \"" << file_name << ".h\"\n";
out << "#include \"writable.h\"\n";
out << "#include \"joedb/Writable.h\"\n";
out << "#include \"joedb/journal/Readonly_Memory_File.h\"\n";
out << '\n';
Expand Down Expand Up @@ -2388,10 +2386,13 @@ static int joedbc_main(int argc, char **argv)
//
// Generate code
//
const std::string dir_name = compiler_options.get_name_space().back();
std::filesystem::create_directory(dir_name);

{
std::ofstream h_file
(
compiler_options.get_name_space().back() + "_readonly.h",
compiler_options.get_name_space().back() + "/readonly.h",
std::ios::trunc
);
write_initial_comment(h_file, compiler_options, exe_path);
Expand All @@ -2400,7 +2401,7 @@ static int joedbc_main(int argc, char **argv)
{
std::ofstream cpp_file
(
compiler_options.get_name_space().back() + "_readonly.cpp",
compiler_options.get_name_space().back() + "/readonly.cpp",
std::ios::trunc
);
write_initial_comment(cpp_file, compiler_options, exe_path);
Expand All @@ -2409,7 +2410,7 @@ static int joedbc_main(int argc, char **argv)
{
std::ofstream h_file
(
compiler_options.get_name_space().back() + ".h",
compiler_options.get_name_space().back() + "/writable.h",
std::ios::trunc
);
write_initial_comment(h_file, compiler_options, exe_path);
Expand All @@ -2418,7 +2419,7 @@ static int joedbc_main(int argc, char **argv)
{
std::ofstream cpp_file
(
compiler_options.get_name_space().back() + ".cpp",
compiler_options.get_name_space().back() + "/writable.cpp",
std::ios::trunc
);
write_initial_comment(cpp_file, compiler_options, exe_path);
Expand Down
2 changes: 1 addition & 1 deletion src/joedb/db/encoded_file.joedbc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
namespace joedb::encoded_file
namespace joedb::db::encoded_file
2 changes: 1 addition & 1 deletion src/joedb/db/multi_server.joedbc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
namespace joedb::multi_server
namespace joedb::db::multi_server
4 changes: 2 additions & 2 deletions src/joedb/io/joedb_multi_server.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "joedb/io/main_exception_catcher.h"
#include "joedb/db/multi_server_readonly.h"
#include "joedb/db/multi_server/readonly.h"
#include "joedb/journal/Readonly_Interpreted_File.h"
#include "joedb/concurrency/Server.h"
#include "joedb/concurrency/Writable_Journal_Client_Data.h"
Expand Down Expand Up @@ -58,7 +58,7 @@ namespace joedb
}

const char * const config_file_name = argv[1];
multi_server::Generic_Readonly_Database db
db::multi_server::Generic_Readonly_Database db
(
Readonly_Interpreted_File{config_file_name}
);
Expand Down
4 changes: 2 additions & 2 deletions src/joedb/journal/Brotli_File.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace joedb
{
protected:
Brotli_Codec codec;
encoded_file::File_Database db;
db::encoded_file::File_Database db;

public:
Brotli_File_Data(const char *file_name);
Expand All @@ -35,7 +35,7 @@ namespace joedb
protected:
Brotli_Codec codec;
File file;
encoded_file::Readonly_Database db;
db::encoded_file::Readonly_Database db;

public:
Readonly_Brotli_File_Data(const char *file_name);
Expand Down
2 changes: 1 addition & 1 deletion src/joedb/journal/Encoded_File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace joedb
//////////////////////////////////////////////////////////////////////////
(
Codec &codec,
encoded_file::Generic_File_Database &db
db::encoded_file::Generic_File_Database &db
):
Readonly_Encoded_File(codec, db, db, Open_Mode::write_existing_or_create_new),
db(db),
Expand Down
6 changes: 3 additions & 3 deletions src/joedb/journal/Encoded_File.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define joedb_Encoded_File_declared

#include "joedb/journal/Readonly_Encoded_File.h"
#include "joedb/db/encoded_file.h"
#include "joedb/db/encoded_file/writable.h"

namespace joedb
{
Expand All @@ -11,7 +11,7 @@ namespace joedb
////////////////////////////////////////////////////////////////////////////
{
private:
encoded_file::Generic_File_Database &db;
db::encoded_file::Generic_File_Database &db;

static constexpr size_t write_buffer_total_size = 1 << 20;
std::vector<char> write_buffer;
Expand All @@ -38,7 +38,7 @@ namespace joedb
Encoded_File
(
Codec &codec,
encoded_file::Generic_File_Database &db
db::encoded_file::Generic_File_Database &db
);

int64_t get_size() const override;
Expand Down
4 changes: 2 additions & 2 deletions src/joedb/journal/Readonly_Encoded_File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace joedb
//////////////////////////////////////////////////////////////////////////
(
Codec &codec,
encoded_file::Database &db,
db::encoded_file::Database &db,
Blob_Reader &blob_reader,
Open_Mode mode
):
Expand All @@ -79,7 +79,7 @@ namespace joedb
//////////////////////////////////////////////////////////////////////////
(
Codec &codec,
encoded_file::Database &db,
db::encoded_file::Database &db,
Blob_Reader &blob_reader
):
Readonly_Encoded_File(codec, db, blob_reader, Open_Mode::read_existing)
Expand Down
Loading

0 comments on commit 0e6e69d

Please sign in to comment.