From 9f82f316b44a2c2549797bfced171cd366fd1354 Mon Sep 17 00:00:00 2001 From: muit Date: Sat, 27 Aug 2022 21:26:09 +0200 Subject: [PATCH 1/7] Progress on parsing of include files --- Libs/Bindings/Native/Include/NativeBinding.h | 2 + Libs/Bindings/Native/Src/NativeBinding.cpp | 65 +++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/Libs/Bindings/Native/Include/NativeBinding.h b/Libs/Bindings/Native/Include/NativeBinding.h index 40e29d05..47f8c699 100644 --- a/Libs/Bindings/Native/Include/NativeBinding.h +++ b/Libs/Bindings/Native/Include/NativeBinding.h @@ -15,4 +15,6 @@ namespace rift public: void Register(TPtr rift) override {} }; + + void Sync(); } // namespace rift diff --git a/Libs/Bindings/Native/Src/NativeBinding.cpp b/Libs/Bindings/Native/Src/NativeBinding.cpp index 456744c9..470920fb 100644 --- a/Libs/Bindings/Native/Src/NativeBinding.cpp +++ b/Libs/Bindings/Native/Src/NativeBinding.cpp @@ -2,4 +2,67 @@ #include "NativeBinding.h" -#include +#include +#include +#include + + +namespace rift::NativeBinding +{ + struct ParsedModule + { + AST::Id moduleId; + CXIndex index = clang_createIndex(0, 0); + TArray includes; + TArray units; + + ~ParsedModule() + { + for (auto unit : units) + { + clang_disposeTranslationUnit(unit); + } + clang_disposeIndex(index); + } + }; + + void ResolveIncludes(TSpan parsedModules) {} + + void ParseIncludes(TSpan parsedModules) + { + for (auto& module : parsedModules) + { + for (i32 i = 0; i < module.includes.Size(); ++i) + { + const StringView include = module.includes[i]; + const CXTranslationUnit unit = clang_parseTranslationUnit( + module.index, include.data(), nullptr, 0, nullptr, 0, CXTranslationUnit_None); + if (!unit) + { + module.includes.RemoveAt(i, false); + --i; + Log::Error("Unable to parse module header '{}'", include); + continue; + } + module.units.Add(unit); + } + } + } + + void Sync() + { + TArray moduleIds; + // TODO: Find dirty native modules + + TArray parsedModules; + parsedModules.Reserve(moduleIds.Size()); + for (i32 i = 0; i < moduleIds.Size(); ++i) + { + auto& parsed = parsedModules.AddDefaultedRef(); + parsed.moduleId = moduleIds[i]; + } + ResolveIncludes(parsedModules); + ParseIncludes(parsedModules); + // TODO: Generate Rift interface + } +} // namespace rift::NativeBinding From 8d039438e67386513ac302f55aa889497d0dcc70 Mon Sep 17 00:00:00 2001 From: muit Date: Sun, 28 Aug 2022 21:50:44 +0200 Subject: [PATCH 2/7] Removed Cpp backend --- Apps/CLI/CMakeLists.txt | 1 - Apps/CLI/Src/main.cpp | 2 - Apps/Editor/CMakeLists.txt | 1 - Apps/Editor/Src/main.cpp | 2 - Libs/Backends/Cpp/CMakeLists.txt | 22 -- Libs/Backends/Cpp/Include/CppBackend.h | 36 --- .../Cpp/Include/CppBackend/CMakeGen.h | 13 - .../Components/CCppCodeGenFragment.h | 15 - .../CppBackend/Components/CCppNativeName.h | 17 - .../Cpp/Include/CppBackend/CppGeneration.h | 16 - Libs/Backends/Cpp/Src/CppBackend.cpp | 128 -------- Libs/Backends/Cpp/Src/CppBackend/CMakeGen.cpp | 99 ------ .../Cpp/Src/CppBackend/CppGeneration.cpp | 293 ------------------ Libs/Backends/Cpp/Src/CppModule.cpp | 4 - Libs/CMakeLists.txt | 1 - Libs/Editor/CMakeLists.txt | 1 - Libs/Editor/Src/Systems/EditorSystem.cpp | 1 - 17 files changed, 652 deletions(-) delete mode 100644 Libs/Backends/Cpp/CMakeLists.txt delete mode 100644 Libs/Backends/Cpp/Include/CppBackend.h delete mode 100644 Libs/Backends/Cpp/Include/CppBackend/CMakeGen.h delete mode 100644 Libs/Backends/Cpp/Include/CppBackend/Components/CCppCodeGenFragment.h delete mode 100644 Libs/Backends/Cpp/Include/CppBackend/Components/CCppNativeName.h delete mode 100644 Libs/Backends/Cpp/Include/CppBackend/CppGeneration.h delete mode 100644 Libs/Backends/Cpp/Src/CppBackend.cpp delete mode 100644 Libs/Backends/Cpp/Src/CppBackend/CMakeGen.cpp delete mode 100644 Libs/Backends/Cpp/Src/CppBackend/CppGeneration.cpp delete mode 100644 Libs/Backends/Cpp/Src/CppModule.cpp diff --git a/Apps/CLI/CMakeLists.txt b/Apps/CLI/CMakeLists.txt index 93a5b380..9837b3d0 100644 --- a/Apps/CLI/CMakeLists.txt +++ b/Apps/CLI/CMakeLists.txt @@ -11,7 +11,6 @@ set_target_properties (RiftCLIExe PROPERTIES FOLDER Rift/Executables) target_link_libraries(RiftCLIExe PUBLIC rift::Rift rift::Backend::LLVM - rift::Backend::Cpp rift::View::Graph CLI11 ) diff --git a/Apps/CLI/Src/main.cpp b/Apps/CLI/Src/main.cpp index 1a81072e..3cabc349 100644 --- a/Apps/CLI/Src/main.cpp +++ b/Apps/CLI/Src/main.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -64,7 +63,6 @@ int main(int argc, char** argv) p::Log::Init("Saved/Logs"); TOwnPtr rift = MakeOwned(); rift->AddPlugin(); - rift->AddPlugin(); rift->AddPlugin(); diff --git a/Apps/Editor/CMakeLists.txt b/Apps/Editor/CMakeLists.txt index f8a4f897..040694f2 100644 --- a/Apps/Editor/CMakeLists.txt +++ b/Apps/Editor/CMakeLists.txt @@ -11,7 +11,6 @@ set_target_properties (RiftEditorExe PROPERTIES FOLDER Rift/Executables) target_link_libraries(RiftEditorExe PUBLIC rift::Editor rift::Backend::LLVM - rift::Backend::Cpp rift::View::Graph ) pipe_target_define_platform(RiftEditorExe) diff --git a/Apps/Editor/Src/main.cpp b/Apps/Editor/Src/main.cpp index 62725587..ae70ba01 100644 --- a/Apps/Editor/Src/main.cpp +++ b/Apps/Editor/Src/main.cpp @@ -1,6 +1,5 @@ // Copyright 2015-2022 Piperift - All rights reserved -#include #include #include #include @@ -20,7 +19,6 @@ int RunEditor(StringView projectPath) p::Log::Init("Saved/Logs"); TOwnPtr rift = MakeOwned(); rift->AddPlugin(); - rift->AddPlugin(); rift->AddPlugin(); diff --git a/Libs/Backends/Cpp/CMakeLists.txt b/Libs/Backends/Cpp/CMakeLists.txt deleted file mode 100644 index 08281ba6..00000000 --- a/Libs/Backends/Cpp/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ - -file(GLOB_RECURSE BACKEND_CPP_SOURCE_FILES CONFIGURE_DEPENDS Src/*.cpp Src/*.h) - -add_library(RiftBackendCpp STATIC) -add_library(rift::Backend::Cpp ALIAS RiftBackendCpp) -target_include_directories(RiftBackendCpp PUBLIC Include) -target_sources(RiftBackendCpp PRIVATE ${BACKEND_CPP_SOURCE_FILES}) -pipe_target_enable_CPP20(RiftBackendCpp) -set_target_properties (RiftBackendCpp PROPERTIES FOLDER Rift) -pipe_target_define_platform(RiftBackendCpp) -pipe_target_shared_output_directory(RiftBackendCpp) -target_link_libraries(RiftBackendCpp PUBLIC - rift::Rift -) - -install(TARGETS RiftBackendCpp - EXPORT RiftTargets - LIBRARY DESTINATION Lib - ARCHIVE DESTINATION Lib - RUNTIME DESTINATION Bin - INCLUDES DESTINATION Include -) diff --git a/Libs/Backends/Cpp/Include/CppBackend.h b/Libs/Backends/Cpp/Include/CppBackend.h deleted file mode 100644 index 199c3881..00000000 --- a/Libs/Backends/Cpp/Include/CppBackend.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015-2022 Piperift - All rights reserved - -#pragma once - -#include -#include -#include - - -namespace rift -{ - class CPPBackendPlugin : public Plugin - { - CLASS(CPPBackendPlugin, Plugin) - - public: - void Register(TPtr rift) override {} - }; - - - namespace compiler - { - class CppBackend : public Backend - { - CLASS(CppBackend, Backend) - - public: - Name GetName() override - { - return "Cpp"; - } - - void Build(Compiler& compiler) override; - }; - } // namespace compiler -} // namespace rift diff --git a/Libs/Backends/Cpp/Include/CppBackend/CMakeGen.h b/Libs/Backends/Cpp/Include/CppBackend/CMakeGen.h deleted file mode 100644 index a2b7ab6b..00000000 --- a/Libs/Backends/Cpp/Include/CppBackend/CMakeGen.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2015-2022 Piperift - All rights reserved - -#pragma once - -#include -#include -#include - - -namespace rift::compiler::Cpp -{ - void GenerateCMake(Compiler& compiler, const p::Path& codePath); -} // namespace rift::compiler::Cpp diff --git a/Libs/Backends/Cpp/Include/CppBackend/Components/CCppCodeGenFragment.h b/Libs/Backends/Cpp/Include/CppBackend/Components/CCppCodeGenFragment.h deleted file mode 100644 index d1429c6e..00000000 --- a/Libs/Backends/Cpp/Include/CppBackend/Components/CCppCodeGenFragment.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2015-2022 Piperift - All rights reserved -#pragma once - -#include - - -namespace rift -{ - struct CCppCodeGenFragment : public p::Struct - { - STRUCT(CCppCodeGenFragment, p::Struct) - - String code; - }; -} // namespace rift diff --git a/Libs/Backends/Cpp/Include/CppBackend/Components/CCppNativeName.h b/Libs/Backends/Cpp/Include/CppBackend/Components/CCppNativeName.h deleted file mode 100644 index 9bf2ea62..00000000 --- a/Libs/Backends/Cpp/Include/CppBackend/Components/CCppNativeName.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015-2022 Piperift - All rights reserved -#pragma once - -#include - - -namespace rift -{ - struct CCppNativeName : public p::Struct - { - STRUCT(CCppNativeName, p::Struct) - - String codeName; - - CCppNativeName(String codeName) : codeName(codeName) {} - }; -} // namespace rift diff --git a/Libs/Backends/Cpp/Include/CppBackend/CppGeneration.h b/Libs/Backends/Cpp/Include/CppBackend/CppGeneration.h deleted file mode 100644 index dc403cc1..00000000 --- a/Libs/Backends/Cpp/Include/CppBackend/CppGeneration.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015-2022 Piperift - All rights reserved - -#pragma once - -#include - - -namespace rift::compiler -{ - struct Compiler; -} - -namespace rift::compiler::Cpp -{ - void GenerateCode(Compiler& compiler, const p::Path& generatePath); -} // namespace rift::compiler::Cpp diff --git a/Libs/Backends/Cpp/Src/CppBackend.cpp b/Libs/Backends/Cpp/Src/CppBackend.cpp deleted file mode 100644 index 841cc24a..00000000 --- a/Libs/Backends/Cpp/Src/CppBackend.cpp +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2015-2022 Piperift - All rights reserved - -#include "CppBackend.h" - -#include "CppBackend/CMakeGen.h" -#include "CppBackend/Components/CCppNativeName.h" -#include "CppBackend/CppGeneration.h" - -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace rift::compiler -{ - namespace Cpp - { - void AssignNativeTypeNames(AST::Tree& ast) - { - const auto& nativeTypes = ast.GetNativeTypes(); - ast.Add(nativeTypes.boolId, "bool"); - ast.Add(nativeTypes.floatId, "float"); - ast.Add(nativeTypes.doubleId, "double"); - ast.Add(nativeTypes.u8Id, "std::uint_8"); - ast.Add(nativeTypes.i8Id, "std::int_8"); - ast.Add(nativeTypes.u16Id, "std::uint_16"); - ast.Add(nativeTypes.i16Id, "std::int_16"); - ast.Add(nativeTypes.u32Id, "std::uint_32"); - ast.Add(nativeTypes.i32Id, "std::int_32"); - ast.Add(nativeTypes.u64Id, "std::uint_64"); - ast.Add(nativeTypes.i64Id, "std::int_64"); - ast.Add(nativeTypes.stringId, "std::string"); - } - - void BuildCode(Compiler& compiler, const p::Path& codePath, const p::Path& cmakePath) - { - ZoneScoped; - files::CreateFolder(cmakePath, true); - - - Log::Info("Generating"); - const String generate = - Strings::Format("cmake -S {} -B {}", p::ToString(codePath), p::ToString(cmakePath)); - - if (std::system(generate.c_str()) > 0) - { - compiler.AddError("Failed to generate cmake code"); - return; - } - - Log::Info("Building"); - const String build = Strings::Format( - "cmake --build {} --config {}", p::ToString(cmakePath), compiler.config.buildMode); - if (std::system(build.c_str()) > 0) - { - compiler.AddError("C++ build failed"); - return; - } - } - } // namespace Cpp - - void CppBackend::Build(Compiler& compiler) - { - ZoneScopedN("Backend: Cpp"); - - DateTime startTime = DateTime::Now(); - - const p::Path& codePath = compiler.config.intermediatesPath / "Code"; - files::Delete(codePath, true, false); - files::CreateFolder(codePath, true); - - Cpp::AssignNativeTypeNames(compiler.ast); - - Log::Info("Generating C++"); - Cpp::GenerateCode(compiler, codePath); - if (compiler.HasErrors()) - { - compiler.AddError("Failed to generate C++ code"); - return; - } - - - Log::Info("Generating CMake"); - Cpp::GenerateCMake(compiler, codePath); - if (compiler.HasErrors()) - { - compiler.AddError("Failed to generate cmake files"); - return; - } - - - Log::Info("Building C++"); - const p::Path cmakePath = compiler.config.intermediatesPath / "CMake"; - Cpp::BuildCode(compiler, codePath, cmakePath); - if (compiler.HasErrors()) - { - compiler.AddError("Compilation failed while building C++ code"); - return; - } - - - // Copy code & binaries - if (!files::Copy(codePath, compiler.config.binariesPath)) - { - compiler.AddError("Failed to copy code"); - return; - } - - TAccess modules{compiler.ast}; - for (AST::Id moduleId : ecs::ListAll(modules)) - { - Name name = Modules::GetModuleName(compiler.ast, moduleId); - if (!files::Copy(cmakePath / name.ToString() / compiler.config.buildMode, - compiler.config.binariesPath / name.ToString() / "Bin")) - { - compiler.AddError("Failed to copy binaries"); - } - } - - const float duration = (DateTime::Now() - startTime).GetTotalSeconds(); - Log::Info("Build complete ({:.2f}s)", duration); - } -} // namespace rift::compiler diff --git a/Libs/Backends/Cpp/Src/CppBackend/CMakeGen.cpp b/Libs/Backends/Cpp/Src/CppBackend/CMakeGen.cpp deleted file mode 100644 index 066983a5..00000000 --- a/Libs/Backends/Cpp/Src/CppBackend/CMakeGen.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2015-2022 Piperift - All rights reserved - -#include "CppBackend/CMakeGen.h" - -#include "CppBackend.h" - -#include -#include -#include -#include - - -namespace rift::compiler::Cpp -{ - void SetProject(String& code, Compiler& compiler, Name name, StringView version) - { - Strings::FormatTo(code, - "cmake_minimum_required (VERSION 3.12)\n" - "project({ProjectName} VERSION {Version} LANGUAGES CXX)\n", - fmt::arg("ProjectName", name), fmt::arg("Version", version)); - } - - void AddSubdirectory(String& code, StringView path) - { - Strings::FormatTo(code, "add_subdirectory({})\n", path); - } - - void AddLibrary( - String& code, Compiler& compiler, ModuleTarget type, Name name, StringView cppVersion) - { - StringView targetType; - switch (type) - { - case ModuleTarget::Shared: targetType = "SHARED"; break; - case ModuleTarget::Static: targetType = "STATIC"; break; - // case ModuleTarget::Interface: - // targetType = "INTERFACE"; - // break; - default: compiler.AddError("Failed to add CMake library. Invalid ModuleTarget"); return; - } - - Strings::FormatTo(code, - "add_library({ModuleName} {TargetType})\n" - "set_target_properties ({ModuleName} PROPERTIES CXX_STANDARD {CppVersion})\n" - "target_include_directories({ModuleName} PUBLIC Include)\n", - fmt::arg("ModuleName", name), fmt::arg("TargetType", targetType), - fmt::arg("CppVersion", cppVersion)); - - - Strings::FormatTo(code, "target_sources({ModuleName} PRIVATE Src/code.cpp)\n", - fmt::arg("ModuleName", name)); - } - - void AddExecutable(String& code, Compiler& compiler, Name name, StringView cppVersion) - { - Strings::FormatTo(code, - "add_executable({ModuleName})\n" - "set_target_properties ({ModuleName} PROPERTIES CXX_STANDARD {CppVersion})\n" - "target_include_directories({ModuleName} PUBLIC Include)\n", - fmt::arg("ModuleName", name), fmt::arg("CppVersion", cppVersion)); - - Strings::FormatTo(code, "target_sources({ModuleName} PRIVATE Src/code.cpp)\n", - fmt::arg("ModuleName", name)); - } - - void GenerateCMakeModule( - Compiler& compiler, AST::Id moduleId, CModule& module, const p::Path& codePath, Name name) - { - String code; - ModuleTarget target = module.target; - if (target == ModuleTarget::Executable) - { - AddExecutable(code, compiler, name, "20"); - } - else - { - AddLibrary(code, compiler, target, name, "20"); - } - files::SaveStringFile(codePath / name.ToString() / "CMakelists.txt", code); - } - - void GenerateCMake(Compiler& compiler, const p::Path& codePath) - { - String code; - Name projectName = Modules::GetProjectName(compiler.ast); - SetProject(code, compiler, projectName, "0.1"); - - TAccess> modules{compiler.ast}; - for (AST::Id moduleId : ecs::ListAll(modules)) - { - Name name = Modules::GetModuleName(compiler.ast, moduleId); - GenerateCMakeModule(compiler, moduleId, modules.Get(moduleId), codePath, name); - - AddSubdirectory(code, name.ToString()); - } - - files::SaveStringFile(codePath / "CMakelists.txt", code); - } -} // namespace rift::compiler::Cpp diff --git a/Libs/Backends/Cpp/Src/CppBackend/CppGeneration.cpp b/Libs/Backends/Cpp/Src/CppBackend/CppGeneration.cpp deleted file mode 100644 index 7cd335d7..00000000 --- a/Libs/Backends/Cpp/Src/CppBackend/CppGeneration.cpp +++ /dev/null @@ -1,293 +0,0 @@ -// Copyright 2015-2022 Piperift - All rights reserved - -#include "CppBackend/CppGeneration.h" - -#include "AST/Utils/Namespaces.h" -#include "CppBackend.h" -#include "CppBackend/Components/CCppCodeGenFragment.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace rift::compiler::Cpp -{ - void Spacing(String& code) - { - Strings::FormatTo(code, "\n"); - } - - void Comment(String& code, StringView text) - { - Strings::FormatTo(code, "// {}\n", text); - } - - void AddInclude(String& code, StringView name) - { - Strings::FormatTo(code, "#include <{}>\n", name); - } - - void ForwardDeclareStruct(String& code, StringView name) - { - Strings::FormatTo(code, "struct {};\n", name); - } - void DeclareStruct(String& code, StringView name, StringView super = {}, - TFunction buildContent = {}) - { - String innerCode; - if (buildContent) - { - buildContent(innerCode); - } - - if (!super.empty()) - { - Strings::FormatTo(code, - "struct {} : public {}\n" - "{{\n" - "{}" - "}};\n", - name, super, innerCode); - } - else - { - Strings::FormatTo(code, - "struct {}\n" - "{{\n" - "{}" - "}};\n", - name, innerCode); - } - } - - void AddVariable(String& code, StringView type, StringView name, StringView defaultValue) - { - if (defaultValue.empty()) - { - Strings::FormatTo(code, "{} {};\n", type, name); - } - else - { - Strings::FormatTo(code, "{} {} {{ {} }};\n", type, name, defaultValue); - } - } - - void DeclareFunction(String& code, StringView name) - { - Strings::FormatTo(code, "void {}();\n", name); - } - - void DefineFunction(String& code, StringView name, StringView owner = {}, - TFunction buildContent = {}) - { - String innerCode; - if (buildContent) - { - buildContent(innerCode); - } - - if (owner.empty()) - { - Strings::FormatTo(code, - "inline void {}()\n" - "{{\n" - "{}" - "}};\n", - name, innerCode); - } - else - { - Strings::FormatTo(code, - "inline void {}_{}({}& self)\n" - "{{\n" - "{}" - "}};\n", - owner, name, owner, innerCode); - } - } - - void ForwardDeclareTypes(String& code, TAccessRef access, AST::Id moduleId, - const TArray& structs, const TArray& classes) - { - for (AST::Id entity : structs) - { - const auto& ns = access.Get(entity); - ForwardDeclareStruct(code, ns.name.ToString()); - } - - for (AST::Id entity : classes) - { - const auto& ns = access.Get(entity); - ForwardDeclareStruct(code, ns.name.ToString()); - } - } - - void AddTypeVariables( - String& code, TAccessRef access, AST::Id owner) - { - if (const auto* parent = access.TryGet(owner)) - { - for (AST::Id entity : parent->children) - { - if (access.Has(entity)) - { - auto& ns = access.Get(entity); - AddVariable(code, "bool", ns.name.ToString(), "false"); - } - } - } - } - - void DeclareTypes(String& code, TAccessRef access, - AST::Id moduleId, const TArray& structs, const TArray& classes) - { - for (AST::Id entity : structs) - { - const auto& ns = access.Get(entity); - DeclareStruct(code, ns.name.ToString(), {}, [&access, entity](String& innerCode) { - AddTypeVariables(innerCode, access, entity); - }); - } - - for (AST::Id entity : classes) - { - const auto& ns = access.Get(entity); - DeclareStruct(code, ns.name.ToString(), {}, [&access, entity](String& innerCode) { - AddTypeVariables(innerCode, access, entity); - }); - } - } - - - void DeclareFunctions(String& code, - TAccessRef access, AST::Id moduleId, - const TArray& functions) - { - for (AST::Id entity : functions) - { - DeclareFunction(code, AST::GetNamespace(access, entity).ToString()); - } - } - - - void DefineFunctions(String& code, TAccessRef access, - AST::Id moduleId, const TArray& functions) - { - for (AST::Id entity : functions) - { - StringView ownerName; - AST::Id parentId = AST::Hierarchy::GetParent(access, entity); - if (!IsNone(parentId)) - { - if (const auto* ns = access.TryGet(parentId)) - { - ownerName = ns->name.ToString(); - } - } - - const auto& ns = access.Get(entity); - DefineFunction(code, ns.name.ToString(), ownerName); - } - } - - void GenParameters(TAccessRef> access) {} - - - void GenerateModuleCode(Compiler& compiler, AST::Id moduleId, const p::Path& codePath) - { - ZoneScopedC(0x459bd1); - - auto& ast = compiler.ast; - - const Name name = Modules::GetModuleName(ast, moduleId); - const p::Path modulePath = codePath / name.ToString(); - const p::Path includePath = modulePath / "Include"; - const p::Path sourcePath = modulePath / "Src"; - files::CreateFolder(includePath, true); - files::CreateFolder(sourcePath, true); - - - String code; - Strings::FormatTo(code, "#pragma once\n"); - Spacing(code); - - // Includes - AddInclude(code, "stdint.h"); - - TArray classes, structs; - AST::Hierarchy::GetChildren(ast, moduleId, classes); - ecs::ExcludeIfNot(ast, classes); - structs = classes; - - ecs::ExcludeIfNot(ast, classes); - ecs::ExcludeIfNot(ast, structs); - - Spacing(code); - Comment(code, "Forward declarations"); - ForwardDeclareTypes(code, ast, moduleId, structs, classes); - - Spacing(code); - Comment(code, "Declarations"); - DeclareTypes(code, ast, moduleId, structs, classes); - - - TArray functions; - // Module -> Types -> Functions = depth 2 - AST::Hierarchy::GetChildrenDeep(ast, moduleId, functions, 2); - ecs::ExcludeIfNot(ast, functions); - - Spacing(code); - Comment(code, "Function Declarations"); - DeclareFunctions(code, ast, moduleId, functions); - - Spacing(code); - Comment(code, "Function Definitions"); - DefineFunctions(code, ast, moduleId, functions); - - const p::Path headerFile = includePath / "code.h"; - if (!files::SaveStringFile(headerFile, code)) - { - compiler.AddError( - Strings::Format("Couldn't save generated header at '{}'", p::ToString(headerFile))); - } - - code = {}; - AddInclude(code, "code.h"); - Strings::FormatTo(code, "int main() {{ return 0; }}\n"); - Spacing(code); - - Path sourceFile = sourcePath / "code.cpp"; - if (!files::SaveStringFile(sourceFile, code)) - { - compiler.AddError( - Strings::Format("Couldn't save generated source at '{}'", p::ToString(sourceFile))); - } - } - - void GenerateCode(Compiler& compiler, const p::Path& generatePath) - { - ZoneScopedC(0x459bd1); - - GenParameters(compiler.ast); - - for (AST::Id moduleId : ecs::ListAll(compiler.ast)) - { - GenerateModuleCode(compiler, moduleId, generatePath); - } - } -} // namespace rift::compiler::Cpp diff --git a/Libs/Backends/Cpp/Src/CppModule.cpp b/Libs/Backends/Cpp/Src/CppModule.cpp deleted file mode 100644 index cdc5c143..00000000 --- a/Libs/Backends/Cpp/Src/CppModule.cpp +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright 2015-2022 Piperift - All rights reserved - -#include -// PIPE_OVERRIDE_NEW_DELETE diff --git a/Libs/CMakeLists.txt b/Libs/CMakeLists.txt index c23c55c2..fa07b57b 100644 --- a/Libs/CMakeLists.txt +++ b/Libs/CMakeLists.txt @@ -4,7 +4,6 @@ add_subdirectory(Pipe) add_subdirectory(Framework) add_subdirectory(Backends/LLVM) -add_subdirectory(Backends/Cpp) add_subdirectory(Bindings/Native) add_subdirectory(UI) diff --git a/Libs/Editor/CMakeLists.txt b/Libs/Editor/CMakeLists.txt index 6803c697..26213442 100644 --- a/Libs/Editor/CMakeLists.txt +++ b/Libs/Editor/CMakeLists.txt @@ -9,7 +9,6 @@ set_target_properties (RiftEditor PROPERTIES FOLDER Rift) target_link_libraries(RiftEditor PUBLIC rift::Rift rift::Backend::LLVM - rift::Backend::Cpp rift::UI CLI11 ) diff --git a/Libs/Editor/Src/Systems/EditorSystem.cpp b/Libs/Editor/Src/Systems/EditorSystem.cpp index 3ed4d52f..fd610537 100644 --- a/Libs/Editor/Src/Systems/EditorSystem.cpp +++ b/Libs/Editor/Src/Systems/EditorSystem.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include From 443578dc2716b43f65b364a785d8e0bd0e7c0bbc Mon Sep 17 00:00:00 2001 From: muit Date: Sun, 28 Aug 2022 22:04:02 +0200 Subject: [PATCH 3/7] Progress improving module types --- .../LLVM/Src/LLVMBackend/IRGeneration.cpp | 5 ++- Libs/Backends/LLVM/Src/LLVMBackend/Linker.cpp | 25 +++++++------ .../Native/Include/Components/CNativeModule.h | 17 +++++++++ Libs/Bindings/Native/Include/NativeBinding.h | 5 ++- .../Include/AST/Components/CModule.h | 37 +------------------ .../Include/AST/Components/CRiftModule.h | 29 +++++++++++++++ Libs/Framework/Src/AST/Utils/ModuleUtils.cpp | 10 +++++ 7 files changed, 77 insertions(+), 51 deletions(-) create mode 100644 Libs/Bindings/Native/Include/Components/CNativeModule.h create mode 100644 Libs/Framework/Include/AST/Components/CRiftModule.h diff --git a/Libs/Backends/LLVM/Src/LLVMBackend/IRGeneration.cpp b/Libs/Backends/LLVM/Src/LLVMBackend/IRGeneration.cpp index 02723f1b..a4ac5a76 100644 --- a/Libs/Backends/LLVM/Src/LLVMBackend/IRGeneration.cpp +++ b/Libs/Backends/LLVM/Src/LLVMBackend/IRGeneration.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -389,8 +390,8 @@ namespace rift::compiler::LLVM DefineFunctions(gen, ast, functionIds); - const auto& mod = compiler.ast.Get(moduleId); - if (mod.target == ModuleTarget::Executable) + const auto* riftMod = compiler.ast.TryGet(moduleId); + if (riftMod && riftMod->target == RiftModuleTarget::Executable) { CreateMain(gen); } diff --git a/Libs/Backends/LLVM/Src/LLVMBackend/Linker.cpp b/Libs/Backends/LLVM/Src/LLVMBackend/Linker.cpp index 1230753d..1e64b26e 100644 --- a/Libs/Backends/LLVM/Src/LLVMBackend/Linker.cpp +++ b/Libs/Backends/LLVM/Src/LLVMBackend/Linker.cpp @@ -6,8 +6,8 @@ #include "Pipe/Core/PlatformProcess.h" #include "Pipe/Core/String.h" -#include #include +#include #include #include #include @@ -20,32 +20,33 @@ namespace rift::compiler::LLVM { void Link(Compiler& compiler) { - for (AST::Id moduleId : ecs::ListAll(compiler.ast)) + String linkerPath{PlatformProcess::GetExecutablePath()}; + linkerPath.append("/"); + linkerPath.append(RIFT_LLVM_LINKER_PATH); + + for (AST::Id moduleId : ecs::ListAll(compiler.ast)) { - p::Name moduleName = Modules::GetModuleName(compiler.ast, moduleId); - const auto& module = compiler.ast.Get(moduleId); - auto& irModule = compiler.ast.Get(moduleId); + p::Name moduleName = Modules::GetModuleName(compiler.ast, moduleId); + const auto& riftModule = compiler.ast.Get(moduleId); + auto& irModule = compiler.ast.Get(moduleId); if (p::files::Exists(irModule.objectFile)) { TArray command; - String linkerPath{PlatformProcess::GetExecutablePath()}; - linkerPath.append("/"); - linkerPath.append(RIFT_LLVM_LINKER_PATH); command.Add(linkerPath.c_str()); const char* extension = nullptr; - switch (module.target) + switch (riftModule.target) { - case ModuleTarget::Executable: + case RiftModuleTarget::Executable: command.Add("/entry:main"); extension = "exe"; break; - case ModuleTarget::Shared: + case RiftModuleTarget::Shared: command.Add("/dll"); extension = "dll"; break; - case ModuleTarget::Static: + case RiftModuleTarget::Static: command.Add("/lib"); extension = "lib"; break; diff --git a/Libs/Bindings/Native/Include/Components/CNativeModule.h b/Libs/Bindings/Native/Include/Components/CNativeModule.h new file mode 100644 index 00000000..3d1d1db1 --- /dev/null +++ b/Libs/Bindings/Native/Include/Components/CNativeModule.h @@ -0,0 +1,17 @@ +// Copyright 2015-2022 Piperift - All rights reserved +#pragma once + +#include +#include + + +namespace rift +{ + struct CNativeModule : public p::Struct + { + STRUCT(CNativeModule, p::Struct) + + PROP(includePaths) + p::TArray includePaths; + }; +} // namespace rift diff --git a/Libs/Bindings/Native/Include/NativeBinding.h b/Libs/Bindings/Native/Include/NativeBinding.h index 47f8c699..f92ef039 100644 --- a/Libs/Bindings/Native/Include/NativeBinding.h +++ b/Libs/Bindings/Native/Include/NativeBinding.h @@ -13,7 +13,10 @@ namespace rift CLASS(NativeBindingPlugin, Plugin) public: - void Register(TPtr rift) override {} + void Register(TPtr rift) override + { + // Register module type + } }; void Sync(); diff --git a/Libs/Framework/Include/AST/Components/CModule.h b/Libs/Framework/Include/AST/Components/CModule.h index e38eb390..41c2a67d 100644 --- a/Libs/Framework/Include/AST/Components/CModule.h +++ b/Libs/Framework/Include/AST/Components/CModule.h @@ -5,48 +5,13 @@ #include -namespace rift -{ - using namespace p; - - enum class ModuleTarget : u8 - { - Executable, - Shared, - Static - }; - // TODO: Simplify enum reflection so that ENUM() is not needed - - enum class ModuleType : u8 - { - Rift, - Native - }; -} // namespace rift -// TODO: Simplify enum reflection so that ENUM() is not needed -ENUM(rift::ModuleTarget) -ENUM(rift::ModuleType) - - namespace rift { struct CModule : public p::Struct { STRUCT(CModule, p::Struct) - PROP(target) - ModuleTarget target = ModuleTarget::Executable; - - PROP(type) - ModuleType type = ModuleType::Rift; - PROP(dependencies) - TArray dependencies; - - PROP(libraryFiles) - TArray libraryFiles; - - - CModule() {} + p::TArray dependencies; }; } // namespace rift diff --git a/Libs/Framework/Include/AST/Components/CRiftModule.h b/Libs/Framework/Include/AST/Components/CRiftModule.h new file mode 100644 index 00000000..61fc0843 --- /dev/null +++ b/Libs/Framework/Include/AST/Components/CRiftModule.h @@ -0,0 +1,29 @@ +// Copyright 2015-2022 Piperift - All rights reserved +#pragma once + +#include +#include + + +namespace rift +{ + enum class RiftModuleTarget : p::u8 + { + Executable, + Shared, + Static + }; +} // namespace rift +ENUM(rift::RiftModuleTarget) + + +namespace rift +{ + struct CRiftModule : public p::Struct + { + STRUCT(CRiftModule, p::Struct) + + PROP(target) + RiftModuleTarget target = RiftModuleTarget::Executable; + }; +} // namespace rift diff --git a/Libs/Framework/Src/AST/Utils/ModuleUtils.cpp b/Libs/Framework/Src/AST/Utils/ModuleUtils.cpp index d1d877c0..73c83c3d 100644 --- a/Libs/Framework/Src/AST/Utils/ModuleUtils.cpp +++ b/Libs/Framework/Src/AST/Utils/ModuleUtils.cpp @@ -213,5 +213,15 @@ namespace rift::Modules p::ReadWriter common{ct}; ast.GetOrAdd(id).SerializeReflection(common); ast.GetOrAdd(id).SerializeReflection(common); + + // Extract module type data + p::Type* type = nullptr; + // ct.Next("type", type); + if (type) + { + // Add from type: + // typeComp = ...; + // typeComp.SerializeReflection(common); + } } } // namespace rift::Modules From c116d4444d9ad040bfbf57b99be15a87cd416071 Mon Sep 17 00:00:00 2001 From: muit Date: Mon, 29 Aug 2022 23:20:54 +0200 Subject: [PATCH 4/7] Updated Pipe --- Libs/Pipe | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libs/Pipe b/Libs/Pipe index 968df317..de6ec17b 160000 --- a/Libs/Pipe +++ b/Libs/Pipe @@ -1 +1 @@ -Subproject commit 968df317e79ec1cf2cde682ae65c19caa830f0ac +Subproject commit de6ec17b0f78de3c0151df452042ea2eeff0c77a From 4efd297510712f20a4d0831901fadfcecc50d43a Mon Sep 17 00:00:00 2001 From: muit Date: Tue, 30 Aug 2022 22:36:07 +0200 Subject: [PATCH 5/7] Updated Pipe, simplified namespace serialization --- Examples/Project/TestClass.rf | 4 +--- Examples/Project/TestStruct.rf | 4 +--- Examples/Project/Welcome.rf | 16 ++++---------- Libs/Editor/Src/Tools/ASTDebugger.cpp | 4 ++-- Libs/Editor/Src/Tools/ReflectionDebugger.cpp | 4 ++-- .../Include/AST/Components/CNamespace.h | 9 ++++++++ Libs/Framework/Src/AST/Utils/ModuleUtils.cpp | 21 +++++++++---------- Libs/Pipe | 2 +- 8 files changed, 30 insertions(+), 34 deletions(-) diff --git a/Examples/Project/TestClass.rf b/Examples/Project/TestClass.rf index 8ce08352..5d7306f2 100644 --- a/Examples/Project/TestClass.rf +++ b/Examples/Project/TestClass.rf @@ -6,9 +6,7 @@ ], "components": { "CNamespace": { - "0": { - "name": "TestClass" - } + "0": "TestClass" } } } \ No newline at end of file diff --git a/Examples/Project/TestStruct.rf b/Examples/Project/TestStruct.rf index c5ffc756..46464437 100644 --- a/Examples/Project/TestStruct.rf +++ b/Examples/Project/TestStruct.rf @@ -9,9 +9,7 @@ "0": -1 }, "CNamespace": { - "0": { - "name": "TestStruct" - } + "0": "TestStruct" } } } \ No newline at end of file diff --git a/Examples/Project/Welcome.rf b/Examples/Project/Welcome.rf index f3de1c82..d063240f 100644 --- a/Examples/Project/Welcome.rf +++ b/Examples/Project/Welcome.rf @@ -169,18 +169,10 @@ } }, "CNamespace": { - "0": { - "name": "Welcome" - }, - "1": { - "name": "Print" - }, - "10": { - "name": "class" - }, - "11": { - "name": "struct" - } + "0": "Welcome", + "1": "Print", + "10": "class", + "11": "struct" }, "CParent": { "0": [ diff --git a/Libs/Editor/Src/Tools/ASTDebugger.cpp b/Libs/Editor/Src/Tools/ASTDebugger.cpp index 6f131178..8da03306 100644 --- a/Libs/Editor/Src/Tools/ASTDebugger.cpp +++ b/Libs/Editor/Src/Tools/ASTDebugger.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include @@ -31,7 +31,7 @@ namespace rift return; } - const auto& registry = ReflectionRegistry::Get(); + const auto& registry = TypeRegistry::Get(); for (const auto& poolInstance : ast.GetPools()) { Type* type = registry.FindType(poolInstance.componentId); diff --git a/Libs/Editor/Src/Tools/ReflectionDebugger.cpp b/Libs/Editor/Src/Tools/ReflectionDebugger.cpp index 5856bf88..4623340a 100644 --- a/Libs/Editor/Src/Tools/ReflectionDebugger.cpp +++ b/Libs/Editor/Src/Tools/ReflectionDebugger.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include @@ -26,7 +26,7 @@ namespace rift return; } - const auto& registry = ReflectionRegistry::Get(); + const auto& registry = TypeRegistry::Get(); UI::Begin("Reflection", &open); diff --git a/Libs/Framework/Include/AST/Components/CNamespace.h b/Libs/Framework/Include/AST/Components/CNamespace.h index 4b94552f..29050e74 100644 --- a/Libs/Framework/Include/AST/Components/CNamespace.h +++ b/Libs/Framework/Include/AST/Components/CNamespace.h @@ -27,4 +27,13 @@ namespace rift return name == other; } }; + + inline void Read(p::Reader& r, CNamespace& val) + { + r.Serialize(val.name); + } + inline void Write(p::Writer& w, const CNamespace& val) + { + w.Serialize(val.name); + } } // namespace rift diff --git a/Libs/Framework/Src/AST/Utils/ModuleUtils.cpp b/Libs/Framework/Src/AST/Utils/ModuleUtils.cpp index 73c83c3d..1e6dbab7 100644 --- a/Libs/Framework/Src/AST/Utils/ModuleUtils.cpp +++ b/Libs/Framework/Src/AST/Utils/ModuleUtils.cpp @@ -202,26 +202,25 @@ namespace rift::Modules { ZoneScoped; - JsonFormatReader reader{data}; - if (!reader.IsValid()) + JsonFormatReader formatReader{data}; + if (!formatReader.IsValid()) { return; } - AST::Reader ct{reader, ast}; - ct.BeginObject(); - p::ReadWriter common{ct}; - ast.GetOrAdd(id).SerializeReflection(common); - ast.GetOrAdd(id).SerializeReflection(common); + AST::Reader r{formatReader, ast}; + r.BeginObject(); + p::ReadWriter rw{r}; + ast.GetOrAdd(id).SerializeReflection(rw); + ast.GetOrAdd(id).SerializeReflection(rw); // Extract module type data p::Type* type = nullptr; - // ct.Next("type", type); + r.Next("type", type); if (type) { - // Add from type: - // typeComp = ...; - // typeComp.SerializeReflection(common); + // void* instance = nullptr; // Add by type + // type->Read(r, instance); } } } // namespace rift::Modules diff --git a/Libs/Pipe b/Libs/Pipe index de6ec17b..a84a63c7 160000 --- a/Libs/Pipe +++ b/Libs/Pipe @@ -1 +1 @@ -Subproject commit de6ec17b0f78de3c0151df452042ea2eeff0c77a +Subproject commit a84a63c7a9f8bd6445fcb60b2a9b1f69329f6e58 From 0ecb2b3980f998e319ee665f34cd312a5e6a56ee Mon Sep 17 00:00:00 2001 From: muit Date: Tue, 30 Aug 2022 23:20:21 +0200 Subject: [PATCH 6/7] Updated Pipe --- Libs/Editor/Src/Systems/EditorSystem.cpp | 3 +-- Libs/Framework/Include/Compiler/Compiler.h | 1 + Libs/Pipe | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Libs/Editor/Src/Systems/EditorSystem.cpp b/Libs/Editor/Src/Systems/EditorSystem.cpp index fd610537..8a0b7332 100644 --- a/Libs/Editor/Src/Systems/EditorSystem.cpp +++ b/Libs/Editor/Src/Systems/EditorSystem.cpp @@ -7,8 +7,7 @@ #include "Components/CTypeEditor.h" #include "DockSpaceLayout.h" #include "Editor.h" -#include "imgui.h" -#include "imgui_internal.h" +#include "Pipe/Files/Files.h" #include "Statics/SEditor.h" #include "Utils/DetailsPanel.h" #include "Utils/ElementsPanel.h" diff --git a/Libs/Framework/Include/Compiler/Compiler.h b/Libs/Framework/Include/Compiler/Compiler.h index b1f9138f..87c88f85 100644 --- a/Libs/Framework/Include/Compiler/Compiler.h +++ b/Libs/Framework/Include/Compiler/Compiler.h @@ -5,6 +5,7 @@ #include "Compiler/CompilerConfig.h" #include +#include #include #include diff --git a/Libs/Pipe b/Libs/Pipe index a84a63c7..1ab378a2 160000 --- a/Libs/Pipe +++ b/Libs/Pipe @@ -1 +1 @@ -Subproject commit a84a63c7a9f8bd6445fcb60b2a9b1f69329f6e58 +Subproject commit 1ab378a2f45663bfb72732f10397193db9a4e83e From 989f58e1b41bfa5c5d96c5c128b332fd3ec6df1d Mon Sep 17 00:00:00 2001 From: muit Date: Tue, 30 Aug 2022 23:49:22 +0200 Subject: [PATCH 7/7] Updated Pipe --- Libs/Pipe | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libs/Pipe b/Libs/Pipe index 1ab378a2..68cdad90 160000 --- a/Libs/Pipe +++ b/Libs/Pipe @@ -1 +1 @@ -Subproject commit 1ab378a2f45663bfb72732f10397193db9a4e83e +Subproject commit 68cdad90ae3e60b943ac8b7203ab0de1585dbf34