From 6decb96948f61b9a311467ecdb621a048fbcd3d6 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 5 Dec 2025 16:48:25 -0500 Subject: chore: CompilerKit breaking changes. Signed-off-by: Amlal El Mahrouss --- include/CompilerKit/CodeGenerator.h | 18 ++++---- include/CompilerKit/Ref.h | 2 +- include/CompilerKit/Utilities/Assembler.h | 10 +++-- include/CompilerKit/Utilities/Compiler.h | 2 +- include/LibC++/__abi+unreachable.inl | 16 ------- include/LibC++/__abi.h | 9 +++- src/CompilerKit/src/AssemblyFactory.cc | 51 ---------------------- .../src/CodeGenerator+AssemblyFactory.cc | 51 ++++++++++++++++++++++ .../src/Compilers/CPlusPlusCompiler+AMD64.cc | 6 +-- .../src/DyanmicLinkers/DynamicLinker64+PEF.cc | 2 +- 10 files changed, 80 insertions(+), 87 deletions(-) delete mode 100644 include/LibC++/__abi+unreachable.inl delete mode 100644 src/CompilerKit/src/AssemblyFactory.cc create mode 100644 src/CompilerKit/src/CodeGenerator+AssemblyFactory.cc diff --git a/include/CompilerKit/CodeGenerator.h b/include/CompilerKit/CodeGenerator.h index 383f170..79b185b 100644 --- a/include/CompilerKit/CodeGenerator.h +++ b/include/CompilerKit/CodeGenerator.h @@ -10,12 +10,12 @@ #include #include -#define CK_ASSEMBLY_INTERFACE : public ::CompilerKit::AssemblyInterface +#define CK_ASSEMBLY_INTERFACE : public ::CompilerKit::IAssembly #define CK_ENCODER : public ::CompilerKit::EncoderInterface namespace CompilerKit { class AssemblyFactory; -class AssemblyInterface; +class IAssembly; /// =========================================================== /// /// @brief Simple assembly factory @@ -42,23 +42,23 @@ class AssemblyFactory final { Int32 Compile(std::string sourceFile, const Int32& arch) noexcept; - void Mount(AssemblyInterface* mountPtr) noexcept; - AssemblyInterface* Unmount() noexcept; + void Mount(IAssembly* mountPtr) noexcept; + IAssembly* Unmount() noexcept; private: - AssemblyInterface* fMounted{nullptr}; + IAssembly* fMounted{nullptr}; }; /// =========================================================== /// /// @brief Assembly to binary generator class. /// @note This interface creates according to the CPU target of the child class. /// =========================================================== /// -class AssemblyInterface { +class IAssembly { public: - explicit AssemblyInterface() = default; - virtual ~AssemblyInterface() = default; + explicit IAssembly() = default; + virtual ~IAssembly() = default; - NECTI_COPY_DEFAULT(AssemblyInterface); + NECTI_COPY_DEFAULT(IAssembly); virtual UInt32 Arch() noexcept { return AssemblyFactory::kArchAMD64; } diff --git a/include/CompilerKit/Ref.h b/include/CompilerKit/Ref.h index 863a100..72e9472 100644 --- a/include/CompilerKit/Ref.h +++ b/include/CompilerKit/Ref.h @@ -18,7 +18,7 @@ namespace CompilerKit { template class Ref final { public: - explicit Ref() = default; + Ref() = default; ~Ref() { if (m_Strong) { diff --git a/include/CompilerKit/Utilities/Assembler.h b/include/CompilerKit/Utilities/Assembler.h index fc965f0..afe95d1 100644 --- a/include/CompilerKit/Utilities/Assembler.h +++ b/include/CompilerKit/Utilities/Assembler.h @@ -10,13 +10,14 @@ #include #include -using namespace CompilerKit; - +namespace CompilerKit { /// @brief Get Number from lineBuffer. /// @param lineBuffer the lineBuffer to fetch from. /// @param numberKey where to seek that number. /// @return A numbercast of 32-bit width. -static NumberCast32 GetNumber32(STLString lineBuffer, STLString numberKey) { +inline NumberCast32 GetNumber32(STLString lineBuffer, STLString numberKey) { + if (lineBuffer.empty()) return {}; + auto pos = lineBuffer.find(numberKey) + numberKey.size(); while (lineBuffer[pos] == ' ') { @@ -83,10 +84,11 @@ static NumberCast32 GetNumber32(STLString lineBuffer, STLString numberKey) { NumberCast32 numOffset(strtol(lineBuffer.substr(pos).c_str(), nullptr, 10)); if (kVerbose) { - kStdOut << "asm: found a base 10 number here:" << lineBuffer.substr(pos) << "\n"; + kStdOut << "asm: found a base 10 number here:" << lineBuffer.substr(pos) << kStdEndl; } return numOffset; } } } +} // namespace CompilerKit \ No newline at end of file diff --git a/include/CompilerKit/Utilities/Compiler.h b/include/CompilerKit/Utilities/Compiler.h index bbca020..41b7771 100644 --- a/include/CompilerKit/Utilities/Compiler.h +++ b/include/CompilerKit/Utilities/Compiler.h @@ -28,7 +28,7 @@ #define kStdOut (std::cout << kRed << "drv: " << kWhite) #define kStdErr (std::cerr << kYellow << "drv: " << kWhite) - +#define kStdEndl std::endl #define kPrintF kStdOut #define kPrintErr kStdErr diff --git a/include/LibC++/__abi+unreachable.inl b/include/LibC++/__abi+unreachable.inl deleted file mode 100644 index 5628e7d..0000000 --- a/include/LibC++/__abi+unreachable.inl +++ /dev/null @@ -1,16 +0,0 @@ -/* ======================================== - - Copyright (C) 2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license. - -======================================== */ - -#include -#include - -static const int32_t __unreachable_code = 34; - -extern "C" void __compilerkit_unreachable(void) { - std::base_process::signal(__unreachable_code); - - while (1); -} \ No newline at end of file diff --git a/include/LibC++/__abi.h b/include/LibC++/__abi.h index 206b5ef..6b4b058 100644 --- a/include/LibC++/__abi.h +++ b/include/LibC++/__abi.h @@ -7,9 +7,16 @@ #pragma once #include +#include __init_decl() - extern void __compilerkit_unreachable(void); +static constexpr int32_t __unreachable_code = 34; + +inline void __compilerkit_unreachable(void) { + std::base_process::signal(__unreachable_code); + + while (1); +} __fini_decl() \ No newline at end of file diff --git a/src/CompilerKit/src/AssemblyFactory.cc b/src/CompilerKit/src/AssemblyFactory.cc deleted file mode 100644 index f386083..0000000 --- a/src/CompilerKit/src/AssemblyFactory.cc +++ /dev/null @@ -1,51 +0,0 @@ -/* ======================================== - - Copyright (C) 2024-2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license - -======================================== */ - -#include -#include - -/** - * @file AssemblyFactory.cc - * @author Amlal El Mahrouss (amlal@nekernel.org) - * @brief Assembly API of NeCTI - * @version 0.0.3 - * @copyright Copyright (c) 2024-2025 Amlal El Mahrouss - * - */ - -namespace CompilerKit { -///! @brief Compile for specific format (ELF, PEF, ZBIN) -Int32 AssemblyFactory::Compile(STLString sourceFile, const Int32& arch) noexcept { - if (sourceFile.length() < 1) return NECTI_UNIMPLEMENTED; - - if (!fMounted) return NECTI_UNIMPLEMENTED; - if (arch != fMounted->Arch()) return NECTI_INVALID_ARCH; - - try { - return this->fMounted->CompileToFormat(sourceFile, arch); - } catch (std::exception& e) { - return NECTI_EXEC_ERROR; - } -} - -///! @brief mount assembly backend. -void AssemblyFactory::Mount(AssemblyInterface* mountPtr) noexcept { - if (mountPtr) { - fMounted = mountPtr; - } -} - -///! @brief Unmount assembler. -AssemblyInterface* AssemblyFactory::Unmount() noexcept { - auto mount_prev = fMounted; - - if (fMounted) { - fMounted = nullptr; - } - - return mount_prev; -} -} // namespace CompilerKit diff --git a/src/CompilerKit/src/CodeGenerator+AssemblyFactory.cc b/src/CompilerKit/src/CodeGenerator+AssemblyFactory.cc new file mode 100644 index 0000000..44e2484 --- /dev/null +++ b/src/CompilerKit/src/CodeGenerator+AssemblyFactory.cc @@ -0,0 +1,51 @@ +/* ======================================== + + Copyright (C) 2024-2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license + +======================================== */ + +#include +#include + +/** + * @file AssemblyFactory.cc + * @author Amlal El Mahrouss (amlal@nekernel.org) + * @brief Assembly API of NeCTI + * @version 0.0.3 + * @copyright Copyright (c) 2024-2025 Amlal El Mahrouss + * + */ + +namespace CompilerKit { +///! @brief Compile for specific format (ELF, PEF, ZBIN) +Int32 AssemblyFactory::Compile(STLString sourceFile, const Int32& arch) noexcept { + if (sourceFile.length() < 1) return NECTI_UNIMPLEMENTED; + + if (!fMounted) return NECTI_UNIMPLEMENTED; + if (arch != fMounted->Arch()) return NECTI_INVALID_ARCH; + + try { + return this->fMounted->CompileToFormat(sourceFile, arch); + } catch (...) { + return NECTI_EXEC_ERROR; + } +} + +///! @brief mount assembly backend. +void AssemblyFactory::Mount(IAssembly* mountPtr) noexcept { + if (mountPtr) { + fMounted = mountPtr; + } +} + +///! @brief Unmount assembler. +IAssembly* AssemblyFactory::Unmount() noexcept { + auto mount_prev = fMounted; + + if (fMounted) { + fMounted = nullptr; + } + + return mount_prev; +} +} // namespace CompilerKit diff --git a/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc b/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc index 23e1bd8..d93256d 100644 --- a/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc +++ b/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc @@ -35,7 +35,7 @@ /* (c) Amlal El Mahrouss 2024-2025 */ /// @author Amlal El Mahrouss (amlal@nekernel.org) -/// @file CPlusPlusCompilerAMD64.cxx +/// @file CPlusPlusCompilerAMD64.cc /// @brief Optimized C++ Compiler Driver. ///////////////////////////////////// @@ -146,7 +146,7 @@ static std::size_t kFunctionEmbedLevel = 0UL; /// detail namespaces const char* CompilerFrontendCPlusPlusAMD64::Language() { - return "AMD64 C++"; + return "AMD64 CFront"; } static std::uintptr_t kOrigin = kPefBaseOrigin; @@ -753,7 +753,7 @@ class AssemblyCPlusPlusInterfaceAMD64 final CK_ASSEMBLY_INTERFACE { ///////////////////////////////////////////////////////////////////////////////////////// -#define kExtListCxx {".cpp", ".cxx", ".cc", ".c++", ".cp"} +#define kExtListCxx {".cpp", ".cc", ".cc", ".c++", ".cp"} NECTI_MODULE(CompilerCPlusPlusAMD64) { bool skip = false; diff --git a/src/CompilerKit/src/DyanmicLinkers/DynamicLinker64+PEF.cc b/src/CompilerKit/src/DyanmicLinkers/DynamicLinker64+PEF.cc index 5e8253b..28e12a1 100644 --- a/src/CompilerKit/src/DyanmicLinkers/DynamicLinker64+PEF.cc +++ b/src/CompilerKit/src/DyanmicLinkers/DynamicLinker64+PEF.cc @@ -31,7 +31,7 @@ #define kLinkerId (0x5046FF) #define kLinkerAbiContainer "__PEFContainer:ABI:" -#define kLinkerSplash() kStdOut << kLinkerVersionStr << std::endl +#define kLinkerSplash() kStdOut << kLinkerVersionStr << kStdEndl /// @brief PEF stack size symbol. #define kLinkerStackSizeSymbol "__PEFSizeOfReserveStack" -- cgit v1.2.3