diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-05-23 03:48:06 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-05-23 03:48:06 +0200 |
| commit | 2eed4954c762bb8050e40798c3d9f1d3998324d1 (patch) | |
| tree | 8848d4345fca4d62c23d1e7136eeff2978c9e6c5 | |
| parent | 8ad58a91a11380203c4a81fe4dc93e7734631b32 (diff) | |
feat!(LibCompiler): Codebase and diagram has been improved.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | dev/LibCompiler/Backend/32x0.h | 24 | ||||
| -rw-r--r-- | dev/LibCompiler/Backend/64x0.h | 42 | ||||
| -rw-r--r-- | dev/LibCompiler/Backend/Aarch64.h | 2 | ||||
| -rw-r--r-- | dev/LibCompiler/Backend/X64.h (renamed from dev/LibCompiler/Backend/Amd64.h) | 18 | ||||
| -rw-r--r-- | dev/LibCompiler/CodeGen.h (renamed from dev/LibCompiler/AssemblyInterface.h) | 5 | ||||
| -rw-r--r-- | dev/LibCompiler/Defines.h | 15 | ||||
| -rw-r--r-- | dev/LibCompiler/ErrorID.h | 1 | ||||
| -rw-r--r-- | dev/LibCompiler/ErrorOr.h | 5 | ||||
| -rw-r--r-- | dev/LibCompiler/Frontend.h (renamed from dev/LibCompiler/CompilerFrontend.h) | 38 | ||||
| -rw-r--r-- | dev/LibCompiler/Macros.h | 2 | ||||
| -rw-r--r-- | dev/LibCompiler/PEF.h | 2 | ||||
| -rw-r--r-- | dev/LibCompiler/PString.h (renamed from dev/LibCompiler/StringView.h) | 29 | ||||
| -rw-r--r-- | dev/LibCompiler/Ref.h | 5 | ||||
| -rw-r--r-- | dev/LibCompiler/Util/LCAsmUtils.h (renamed from dev/LibCompiler/Detail/AsmUtils.h) | 8 | ||||
| -rw-r--r-- | dev/LibCompiler/Util/LCClUtils.h (renamed from dev/LibCompiler/Detail/ClUtils.h) | 6 | ||||
| -rw-r--r-- | dev/LibCompiler/Version.h | 4 | ||||
| -rw-r--r-- | dev/LibCompiler/XCOFF.h | 2 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Asm/Assembler32x0.cc (renamed from dev/LibCompiler/src/Assembler32x0.cc) | 4 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Asm/Assembler64x0.cc (renamed from dev/LibCompiler/src/Assembler64x0.cc) | 6 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Asm/AssemblerAMD64.cc (renamed from dev/LibCompiler/src/AssemblerAMD64.cc) | 8 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Asm/AssemblerARM64.cc (renamed from dev/LibCompiler/src/AssemblerARM64.cc) | 6 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Asm/AssemblerPowerPC.cc (renamed from dev/LibCompiler/src/AssemblerPowerPC.cc) | 6 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Cl/CCompiler64x0.cc (renamed from dev/LibCompiler/src/CCompiler64x0.cc) | 4 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Cl/CCompilerARM64.cc (renamed from dev/LibCompiler/src/CCompilerARM64.cc) | 4 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Cl/CCompilerPower64.cc (renamed from dev/LibCompiler/src/CCompilerPower64.cc) | 4 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Cl/CPlusPlusCompilerAMD64.cc (renamed from dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc) | 10 | ||||
| -rw-r--r-- | dev/LibCompiler/src/CodeGen.cc (renamed from dev/LibCompiler/src/AssemblyFactory+AssemblyInterface.cc) | 10 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Frontend.cc | 51 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Linker/DynamicLinkerPEF.cc (renamed from dev/LibCompiler/src/DynamicLinkerPEF.cc) | 109 | ||||
| -rw-r--r-- | dev/LibCompiler/src/PP/CPlusPlusCompilerPreProcessor.cc (renamed from dev/LibCompiler/src/CPlusPlusCompilerPreProcessor.cc) | 139 | ||||
| -rw-r--r-- | dev/LibCompiler/src/PString.cc (renamed from dev/LibCompiler/src/StringView.cc) | 32 | ||||
| -rw-r--r-- | dev/LibDebugger/Version.h | 15 | ||||
| -rw-r--r-- | docs/drawio/LIBCOMPILER_DESIGN.drawio | 38 | ||||
| -rw-r--r-- | lc-osx-san.json | 3 | ||||
| -rw-r--r-- | lc-osx.json | 3 | ||||
| -rw-r--r-- | lc-posix.json | 3 | ||||
| -rw-r--r-- | tools/asm.cc | 2 | ||||
| -rw-r--r-- | tools/cppdrv.cc | 2 | ||||
| -rw-r--r-- | tools/cxxdrv.cc | 2 | ||||
| -rw-r--r-- | tools/dbg.cc | 2 | ||||
| -rw-r--r-- | tools/kdbg.cc | 2 | ||||
| -rw-r--r-- | tools/ld64.cc | 2 |
42 files changed, 363 insertions, 312 deletions
diff --git a/dev/LibCompiler/Backend/32x0.h b/dev/LibCompiler/Backend/32x0.h index 49bb978..240d885 100644 --- a/dev/LibCompiler/Backend/32x0.h +++ b/dev/LibCompiler/Backend/32x0.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ @@ -11,7 +11,7 @@ // @brief 32x0 support. // @file Backend/32x0.h -#define kAsmOpcodeDecl(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \ +#define LC_ASM_OPCODE(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \ {.fName = __NAME, .fOpcode = __OPCODE, .fFunct3 = __FUNCT3, .fFunct7 = __FUNCT7}, #define kAsmImmediate 0x01 @@ -37,18 +37,18 @@ struct CpuCode32x0 { #define kAsmByteStr ".byte" /* 8-bit */ inline std::vector<CpuCode32x0> kOpcodes32x0 = { - kAsmOpcodeDecl("nop", 0b0100011, 0b000, kAsmNoArgs) // nothing to do. (1C) - kAsmOpcodeDecl("jmp", 0b1110011, 0b001, kAsmJump) // jump to branch (2C) - kAsmOpcodeDecl("mov", 0b0100011, 0b101, kAsmImmediate) // move registers (3C) - kAsmOpcodeDecl("psh", 0b0111011, 0b000, kAsmImmediate) // push to sp (2C) - kAsmOpcodeDecl("pop", 0b0111011, 0b001, kAsmImmediate) // pop from sp. (1C) - kAsmOpcodeDecl("lea", 0b0111011, 0b010, + LC_ASM_OPCODE("nop", 0b0100011, 0b000, kAsmNoArgs) // nothing to do. (1C) + LC_ASM_OPCODE("jmp", 0b1110011, 0b001, kAsmJump) // jump to branch (2C) + LC_ASM_OPCODE("mov", 0b0100011, 0b101, kAsmImmediate) // move registers (3C) + LC_ASM_OPCODE("psh", 0b0111011, 0b000, kAsmImmediate) // push to sp (2C) + LC_ASM_OPCODE("pop", 0b0111011, 0b001, kAsmImmediate) // pop from sp. (1C) + LC_ASM_OPCODE("lea", 0b0111011, 0b010, kAsmImmediate) // setup stack and call, store address to CR (1C). - kAsmOpcodeDecl("ret", 0b0111011, 0b110, + LC_ASM_OPCODE("ret", 0b0111011, 0b110, kAsmImmediate) // return from procedure (2C). - kAsmOpcodeDecl("uc", 0b0111111, 0b000, kAsmSyscall) // user call (1C) - kAsmOpcodeDecl("kc", 0b0111111, 0b001, kAsmSyscall) // kernel call (1C) - kAsmOpcodeDecl("int", 0b0111111, 0b010, kAsmSyscall) // raise interrupt (1C) + LC_ASM_OPCODE("uc", 0b0111111, 0b000, kAsmSyscall) // user call (1C) + LC_ASM_OPCODE("kc", 0b0111111, 0b001, kAsmSyscall) // kernel call (1C) + LC_ASM_OPCODE("int", 0b0111111, 0b010, kAsmSyscall) // raise interrupt (1C) }; // \brief 64x0 register prefix diff --git a/dev/LibCompiler/Backend/64x0.h b/dev/LibCompiler/Backend/64x0.h index f929995..f7f0332 100644 --- a/dev/LibCompiler/Backend/64x0.h +++ b/dev/LibCompiler/Backend/64x0.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ @@ -12,7 +12,7 @@ // @brief 64x0 support. // @file Backend/64x0.h -#define kAsmOpcodeDecl(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \ +#define LC_ASM_OPCODE(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \ {.fName = __NAME, .fOpcode = __OPCODE, .fFunct3 = __FUNCT3, .fFunct7 = __FUNCT7}, #define kAsmImmediate 0x01 @@ -32,29 +32,29 @@ struct CpuOpcode64x0 { }; inline std::vector<CpuOpcode64x0> kOpcodes64x0 = { - kAsmOpcodeDecl("nop", 0b0000000, 0b0000000, kAsmNoArgs) // no-operation. - kAsmOpcodeDecl("np", 0b0000000, 0b0000000, kAsmNoArgs) // no-operation. - kAsmOpcodeDecl("jlr", 0b1110011, 0b0000111, + LC_ASM_OPCODE("nop", 0b0000000, 0b0000000, kAsmNoArgs) // no-operation. + LC_ASM_OPCODE("np", 0b0000000, 0b0000000, kAsmNoArgs) // no-operation. + LC_ASM_OPCODE("jlr", 0b1110011, 0b0000111, kAsmJump) // jump to linked return register - kAsmOpcodeDecl("jrl", 0b1110011, 0b0001111, + LC_ASM_OPCODE("jrl", 0b1110011, 0b0001111, kAsmJump) // jump from return register. - kAsmOpcodeDecl("mv", 0b0100011, 0b101, kAsmRegToReg) kAsmOpcodeDecl( - "bg", 0b1100111, 0b111, kAsmRegToReg) kAsmOpcodeDecl("bl", 0b1100111, 0b011, kAsmRegToReg) - kAsmOpcodeDecl("beq", 0b1100111, 0b000, kAsmRegToReg) - kAsmOpcodeDecl("bne", 0b1100111, 0b001, kAsmRegToReg) - kAsmOpcodeDecl("bge", 0b1100111, 0b101, kAsmRegToReg) - kAsmOpcodeDecl("ble", 0b1100111, 0b100, kAsmRegToReg) - kAsmOpcodeDecl("stw", 0b0001111, 0b100, kAsmImmediate) - kAsmOpcodeDecl("ldw", 0b0001111, 0b100, kAsmImmediate) - kAsmOpcodeDecl("lda", 0b0001111, 0b101, kAsmImmediate) - kAsmOpcodeDecl("sta", 0b0001111, 0b001, kAsmImmediate) + LC_ASM_OPCODE("mv", 0b0100011, 0b101, kAsmRegToReg) LC_ASM_OPCODE( + "bg", 0b1100111, 0b111, kAsmRegToReg) LC_ASM_OPCODE("bl", 0b1100111, 0b011, kAsmRegToReg) + LC_ASM_OPCODE("beq", 0b1100111, 0b000, kAsmRegToReg) + LC_ASM_OPCODE("bne", 0b1100111, 0b001, kAsmRegToReg) + LC_ASM_OPCODE("bge", 0b1100111, 0b101, kAsmRegToReg) + LC_ASM_OPCODE("ble", 0b1100111, 0b100, kAsmRegToReg) + LC_ASM_OPCODE("stw", 0b0001111, 0b100, kAsmImmediate) + LC_ASM_OPCODE("ldw", 0b0001111, 0b100, kAsmImmediate) + LC_ASM_OPCODE("lda", 0b0001111, 0b101, kAsmImmediate) + LC_ASM_OPCODE("sta", 0b0001111, 0b001, kAsmImmediate) // add/sub without carry flag - kAsmOpcodeDecl("add", 0b0101011, 0b100, kAsmImmediate) - kAsmOpcodeDecl("sub", 0b0101011, 0b101, kAsmImmediate) + LC_ASM_OPCODE("add", 0b0101011, 0b100, kAsmImmediate) + LC_ASM_OPCODE("sub", 0b0101011, 0b101, kAsmImmediate) // add/sub with carry flag - kAsmOpcodeDecl("addc", 0b0101011, 0b110, kAsmImmediate) - kAsmOpcodeDecl("subc", 0b0101011, 0b111, kAsmImmediate) - kAsmOpcodeDecl("sc", 0b1110011, 0b00, kAsmSyscall)}; + LC_ASM_OPCODE("addc", 0b0101011, 0b110, kAsmImmediate) + LC_ASM_OPCODE("subc", 0b0101011, 0b111, kAsmImmediate) + LC_ASM_OPCODE("sc", 0b1110011, 0b00, kAsmSyscall)}; // \brief 64x0 register prefix // example: r32, r0 diff --git a/dev/LibCompiler/Backend/Aarch64.h b/dev/LibCompiler/Backend/Aarch64.h index dcafa0a..2676306 100644 --- a/dev/LibCompiler/Backend/Aarch64.h +++ b/dev/LibCompiler/Backend/Aarch64.h @@ -1,6 +1,6 @@ /* ------------------------------------------- -Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved +Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ diff --git a/dev/LibCompiler/Backend/Amd64.h b/dev/LibCompiler/Backend/X64.h index ae8458f..f489515 100644 --- a/dev/LibCompiler/Backend/Amd64.h +++ b/dev/LibCompiler/Backend/X64.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ @@ -9,9 +9,9 @@ #include <LibCompiler/Defines.h> // @brief AMD64 support. -// @file Backend/Amd64.h +// @file Backend/X64.h -#define kAsmOpcodeDecl(__NAME, __OPCODE) {.fName = __NAME, .fOpcode = __OPCODE}, +#define LC_ASM_OPCODE(__NAME, __OPCODE) {.fName = __NAME, .fOpcode = __OPCODE}, typedef char i64_character_t; typedef uint8_t i64_byte_t; @@ -39,11 +39,11 @@ struct CpuOpcodeAMD64 { #define kJumpLimitStandardLimit 0xEB inline std::vector<CpuOpcodeAMD64> kOpcodesAMD64 = { - kAsmOpcodeDecl("int", 0xCD) kAsmOpcodeDecl("into", 0xCE) kAsmOpcodeDecl("intd", 0xF1) - kAsmOpcodeDecl("int3", 0xC3) kAsmOpcodeDecl("iret", 0xCF) kAsmOpcodeDecl("retf", 0xCB) - kAsmOpcodeDecl("retn", 0xC3) kAsmOpcodeDecl("ret", 0xC3) kAsmOpcodeDecl("sti", 0xfb) - kAsmOpcodeDecl("cli", 0xfa) kAsmOpcodeDecl("hlt", 0xf4) kAsmOpcodeDecl("nop", 0x90) - kAsmOpcodeDecl("mov", 0x48) kAsmOpcodeDecl("call", 0xFF) - kAsmOpcodeDecl("syscall", 0x0F) kAsmOpcodeDecl("xor", 0x48)}; + LC_ASM_OPCODE("int", 0xCD) LC_ASM_OPCODE("into", 0xCE) LC_ASM_OPCODE("intd", 0xF1) + LC_ASM_OPCODE("int3", 0xC3) LC_ASM_OPCODE("iret", 0xCF) LC_ASM_OPCODE("retf", 0xCB) + LC_ASM_OPCODE("retn", 0xC3) LC_ASM_OPCODE("ret", 0xC3) LC_ASM_OPCODE("sti", 0xfb) + LC_ASM_OPCODE("cli", 0xfa) LC_ASM_OPCODE("hlt", 0xf4) LC_ASM_OPCODE("nop", 0x90) + LC_ASM_OPCODE("mov", 0x48) LC_ASM_OPCODE("call", 0xFF) + LC_ASM_OPCODE("syscall", 0x0F) LC_ASM_OPCODE("xor", 0x48)}; #define kAsmRegisterLimit 16 diff --git a/dev/LibCompiler/AssemblyInterface.h b/dev/LibCompiler/CodeGen.h index 5206005..1e955d8 100644 --- a/dev/LibCompiler/AssemblyInterface.h +++ b/dev/LibCompiler/CodeGen.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ @@ -8,7 +8,7 @@ #include <LibCompiler/Defines.h> #include <LibCompiler/Macros.h> -#include <LibCompiler/StringView.h> +#include <LibCompiler/PString.h> #define LC_ASSEMBLY_INTERFACE : public LibCompiler::AssemblyInterface #define LC_ENCODER : public LibCompiler::EncoderInterface @@ -35,6 +35,7 @@ class AssemblyFactory final { kArchPowerPC, kArchAARCH64, kArchUnknown, + kArchCount = kArchUnknown - kArchAMD64, }; Int32 Compile(std::string sourceFile, const Int32& arch) noexcept; diff --git a/dev/LibCompiler/Defines.h b/dev/LibCompiler/Defines.h index eacf9c0..1735606 100644 --- a/dev/LibCompiler/Defines.h +++ b/dev/LibCompiler/Defines.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ @@ -99,22 +99,16 @@ #define LC_IMPORT_C extern "C" #define LC_IMPORT extern - -#include <ctime> -#include <fstream> -#include <string> -#include <vector> - namespace LibCompiler { inline constexpr int kBaseYear = 1900; -typedef std::string String; +typedef std::string STLString; -inline String current_date() noexcept { +inline STLString current_date() noexcept { auto time_data = time(nullptr); auto time_struct = gmtime(&time_data); - String fmt = std::to_string(kBaseYear + time_struct->tm_year); + STLString fmt = std::to_string(kBaseYear + time_struct->tm_year); fmt += "-"; fmt += std::to_string(time_struct->tm_mon + 1); @@ -144,7 +138,6 @@ inline bool to_str(CharType* str, Int32 limit, Int32 base) noexcept { return true; } -using String = std::basic_string<CharType>; } // namespace LibCompiler #define PACKED __attribute__((packed)) diff --git a/dev/LibCompiler/ErrorID.h b/dev/LibCompiler/ErrorID.h index 45bb393..c82fb16 100644 --- a/dev/LibCompiler/ErrorID.h +++ b/dev/LibCompiler/ErrorID.h @@ -10,7 +10,6 @@ #pragma once #include <LibCompiler/Defines.h> -#include <LibCompiler/ErrorOr.h> #define LIBCOMPILER_SUCCESS 0 #define LIBCOMPILER_EXEC_ERROR -30 diff --git a/dev/LibCompiler/ErrorOr.h b/dev/LibCompiler/ErrorOr.h index ca93dd2..77015b1 100644 --- a/dev/LibCompiler/ErrorOr.h +++ b/dev/LibCompiler/ErrorOr.h @@ -10,6 +10,7 @@ #pragma once #include <LibCompiler/Defines.h> +#include <LibCompiler/ErrorID.h> #include <LibCompiler/Ref.h> namespace LibCompiler { @@ -33,6 +34,10 @@ class ErrorOr final { Ref<T> Leak() { return mRef; } + Int32 Error() { return mId; } + + BOOL HasError() { return mId != LIBCOMPILER_SUCCESS; } + operator bool() { return mRef; } private: diff --git a/dev/LibCompiler/CompilerFrontend.h b/dev/LibCompiler/Frontend.h index d9dd7a4..119b9fe 100644 --- a/dev/LibCompiler/CompilerFrontend.h +++ b/dev/LibCompiler/Frontend.h @@ -1,12 +1,12 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ #pragma once -#include <LibCompiler/AssemblyInterface.h> +#include <LibCompiler/CodeGen.h> #define LC_COMPILER_FRONTEND : public LibCompiler::CompilerFrontendInterface @@ -111,41 +111,11 @@ struct SyntaxLeafList final { /// \param haystack base string /// \param needle the string we search for. /// \return if we found it or not. -inline bool find_word(std::string haystack, std::string needle) noexcept { - auto index = haystack.find(needle); - - // check for needle validity. - if (index == std::string::npos) return false; - - // declare lambda - auto not_part_of_word = [&](int index) { - if (std::isspace(haystack[index]) || std::ispunct(haystack[index])) return true; - - if (index <= 0 || index >= haystack.size()) return true; - - return false; - }; - - return not_part_of_word(index - 1) && not_part_of_word(index + needle.size()); -} +bool find_word(std::string haystack, std::string needle) noexcept; /// find a word within strict conditions and returns a range of it. /// \param haystack /// \param needle /// \return position of needle. -inline std::size_t find_word_range(std::string haystack, std::string needle) noexcept { - auto index = haystack.find(needle); - - // check for needle validity. - if (index == std::string::npos) return false; - - if (!isalnum((haystack[index + needle.size() + 1])) && - !isdigit(haystack[index + needle.size() + 1]) && - !isalnum((haystack[index - needle.size() - 1])) && - !isdigit(haystack[index - needle.size() - 1])) { - return index; - } - - return std::string::npos; -} +std::size_t find_word_range(std::string haystack, std::string needle) noexcept; } // namespace LibCompiler diff --git a/dev/LibCompiler/Macros.h b/dev/LibCompiler/Macros.h index cce89d6..5027ffa 100644 --- a/dev/LibCompiler/Macros.h +++ b/dev/LibCompiler/Macros.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ diff --git a/dev/LibCompiler/PEF.h b/dev/LibCompiler/PEF.h index fe6cfe1..f2662c8 100644 --- a/dev/LibCompiler/PEF.h +++ b/dev/LibCompiler/PEF.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ diff --git a/dev/LibCompiler/StringView.h b/dev/LibCompiler/PString.h index 18003a3..a54be06 100644 --- a/dev/LibCompiler/StringView.h +++ b/dev/LibCompiler/PString.h @@ -13,21 +13,24 @@ #include <LibCompiler/ErrorOr.h> namespace LibCompiler { +class StringBuilder; +class PString; + /** - * @brief StringView class, contains a C string and manages it. + * @brief PString class, contains a C string and manages it. * @note No need to manage it it's getting deleted by default. */ -class StringView final { +class PString final { public: - explicit StringView() = delete; + explicit PString() = delete; - explicit StringView(SizeType Sz) noexcept : m_Sz(Sz) { + explicit PString(SizeType Sz) noexcept : m_Sz(Sz) { m_Data = new CharType[Sz]; assert(m_Data); } - ~StringView() noexcept { + ~PString() noexcept { if (m_Data) { memset(m_Data, 0, m_Sz); delete[] m_Data; @@ -36,7 +39,7 @@ class StringView final { } } - LIBCOMPILER_COPY_DEFAULT(StringView); + LIBCOMPILER_COPY_DEFAULT(PString); CharType* Data(); const CharType* CData() const; @@ -45,11 +48,11 @@ class StringView final { bool operator==(const CharType* rhs) const; bool operator!=(const CharType* rhs) const; - bool operator==(const StringView& rhs) const; - bool operator!=(const StringView& rhs) const; + bool operator==(const PString& rhs) const; + bool operator!=(const PString& rhs) const; - StringView& operator+=(const CharType* rhs); - StringView& operator+=(const StringView& rhs); + PString& operator+=(const CharType* rhs); + PString& operator+=(const PString& rhs); operator bool() { return m_Data && m_Data[0] != 0; } @@ -65,13 +68,15 @@ class StringView final { /** * @brief StringBuilder class - * @note These results shall call delete[] after they're used. + * @note These results shall call be delete[] after they're used. */ struct StringBuilder final { - static StringView Construct(const CharType* data); + static PString Construct(const CharType* data); static const char* FromInt(const char* fmt, int n); static const char* FromBool(const char* fmt, bool n); static const char* Format(const char* fmt, const char* from); static bool Equals(const char* lhs, const char* rhs); }; + +using PStringOr = ErrorOr<PString>; } // namespace LibCompiler diff --git a/dev/LibCompiler/Ref.h b/dev/LibCompiler/Ref.h index c5188b5..ffc11c0 100644 --- a/dev/LibCompiler/Ref.h +++ b/dev/LibCompiler/Ref.h @@ -22,14 +22,15 @@ class Ref final { ~Ref() { if (m_Strong) { - (*m_Class).~T(); + delete m_Class; + m_Class = nullptr; } } LIBCOMPILER_COPY_DEFAULT(Ref); public: - explicit Ref(T cls, const Bool& strong = false) : m_Class(&cls), m_Strong(strong) {} + explicit Ref(T* cls, const Bool& strong = false) : m_Class(cls), m_Strong(strong) {} Ref& operator=(T ref) { *m_Class = ref; diff --git a/dev/LibCompiler/Detail/AsmUtils.h b/dev/LibCompiler/Util/LCAsmUtils.h index 77805c1..7728444 100644 --- a/dev/LibCompiler/Detail/AsmUtils.h +++ b/dev/LibCompiler/Util/LCAsmUtils.h @@ -1,15 +1,15 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ #pragma once -#include <LibCompiler/AssemblyInterface.h> -#include <LibCompiler/CompilerFrontend.h> +#include <LibCompiler/CodeGen.h> +#include <LibCompiler/Frontend.h> -#include <LibCompiler/Detail/ClUtils.h> +#include <LibCompiler/Util/LCClUtils.h> using namespace LibCompiler; diff --git a/dev/LibCompiler/Detail/ClUtils.h b/dev/LibCompiler/Util/LCClUtils.h index b33f66b..c88339d 100644 --- a/dev/LibCompiler/Detail/ClUtils.h +++ b/dev/LibCompiler/Util/LCClUtils.h @@ -1,14 +1,14 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ #pragma once -#include <LibCompiler/AssemblyInterface.h> -#include <LibCompiler/CompilerFrontend.h> +#include <LibCompiler/CodeGen.h> #include <LibCompiler/ErrorID.h> +#include <LibCompiler/Frontend.h> #include <Vendor/Dialogs.h> #define kZero64Section ".zero64" diff --git a/dev/LibCompiler/Version.h b/dev/LibCompiler/Version.h index 601bb28..b94be42 100644 --- a/dev/LibCompiler/Version.h +++ b/dev/LibCompiler/Version.h @@ -1,12 +1,12 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ #pragma once -#define kDistVersion "v0.0.1" +#define kDistVersion "v0.0.1-libcompiler" #define kDistVersionBCD 0x0001 #define ToString(X) Stringify(X) diff --git a/dev/LibCompiler/XCOFF.h b/dev/LibCompiler/XCOFF.h index 047a20f..7aa13d6 100644 --- a/dev/LibCompiler/XCOFF.h +++ b/dev/LibCompiler/XCOFF.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved File: XCOFF.hpp Purpose: XCOFF for NeKernel. diff --git a/dev/LibCompiler/src/Assembler32x0.cc b/dev/LibCompiler/src/Asm/Assembler32x0.cc index 44850f6..683b866 100644 --- a/dev/LibCompiler/src/Assembler32x0.cc +++ b/dev/LibCompiler/src/Asm/Assembler32x0.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ @@ -21,7 +21,7 @@ #include <LibCompiler/AE.h> #include <LibCompiler/Backend/32x0.h> -#include <LibCompiler/CompilerFrontend.h> +#include <LibCompiler/Frontend.h> #include <LibCompiler/PEF.h> ///////////////////// diff --git a/dev/LibCompiler/src/Assembler64x0.cc b/dev/LibCompiler/src/Asm/Assembler64x0.cc index eb5b4dd..9d07d99 100644 --- a/dev/LibCompiler/src/Assembler64x0.cc +++ b/dev/LibCompiler/src/Asm/Assembler64x0.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ @@ -21,8 +21,8 @@ #include <LibCompiler/AE.h> #include <LibCompiler/Backend/64x0.h> -#include <LibCompiler/CompilerFrontend.h> -#include <LibCompiler/Detail/ClUtils.h> +#include <LibCompiler/Util/LCClUtils.h> +#include <LibCompiler/Frontend.h> #include <LibCompiler/PEF.h> #include <algorithm> #include <filesystem> diff --git a/dev/LibCompiler/src/AssemblerAMD64.cc b/dev/LibCompiler/src/Asm/AssemblerAMD64.cc index f017f0d..4a4ca41 100644 --- a/dev/LibCompiler/src/AssemblerAMD64.cc +++ b/dev/LibCompiler/src/Asm/AssemblerAMD64.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ @@ -27,8 +27,8 @@ #define kAssemblerPragmaSym '#' #include <LibCompiler/AE.h> -#include <LibCompiler/Backend/Amd64.h> -#include <LibCompiler/CompilerFrontend.h> +#include <LibCompiler/Backend/X64.h> +#include <LibCompiler/Frontend.h> #include <LibCompiler/PEF.h> #include <algorithm> #include <cstdlib> @@ -74,7 +74,7 @@ static const std::string kUndefinedSymbol = ":UndefinedSymbol:"; // \brief forward decl. static bool asm_read_attributes(std::string line); -#include <LibCompiler/Detail/AsmUtils.h> +#include <LibCompiler/Util/LCAsmUtils.h> ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/dev/LibCompiler/src/AssemblerARM64.cc b/dev/LibCompiler/src/Asm/AssemblerARM64.cc index bad974e..5014a73 100644 --- a/dev/LibCompiler/src/AssemblerARM64.cc +++ b/dev/LibCompiler/src/Asm/AssemblerARM64.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ @@ -19,9 +19,9 @@ #include <LibCompiler/AE.h> #include <LibCompiler/Backend/Aarch64.h> -#include <LibCompiler/CompilerFrontend.h> -#include <LibCompiler/Detail/AsmUtils.h> +#include <LibCompiler/Util/LCAsmUtils.h> #include <LibCompiler/ErrorID.h> +#include <LibCompiler/Frontend.h> #include <LibCompiler/PEF.h> #include <LibCompiler/Version.h> #include <algorithm> diff --git a/dev/LibCompiler/src/AssemblerPowerPC.cc b/dev/LibCompiler/src/Asm/AssemblerPowerPC.cc index c0a7172..1502205 100644 --- a/dev/LibCompiler/src/AssemblerPowerPC.cc +++ b/dev/LibCompiler/src/Asm/AssemblerPowerPC.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ @@ -19,9 +19,9 @@ #include <LibCompiler/AE.h> #include <LibCompiler/Backend/PowerPC.h> -#include <LibCompiler/CompilerFrontend.h> -#include <LibCompiler/Detail/AsmUtils.h> +#include <LibCompiler/Util/LCAsmUtils.h> #include <LibCompiler/ErrorID.h> +#include <LibCompiler/Frontend.h> #include <LibCompiler/PEF.h> #include <LibCompiler/Version.h> #include <algorithm> diff --git a/dev/LibCompiler/src/CCompiler64x0.cc b/dev/LibCompiler/src/Cl/CCompiler64x0.cc index 55adc75..6ca680b 100644 --- a/dev/LibCompiler/src/CCompiler64x0.cc +++ b/dev/LibCompiler/src/Cl/CCompiler64x0.cc @@ -11,8 +11,8 @@ /// TODO: none #include <LibCompiler/Backend/64x0.h> -#include <LibCompiler/CompilerFrontend.h> -#include <LibCompiler/Detail/ClUtils.h> +#include <LibCompiler/Util/LCClUtils.h> +#include <LibCompiler/Frontend.h> #include <LibCompiler/UUID.h> #include <cstdio> #include <fstream> diff --git a/dev/LibCompiler/src/CCompilerARM64.cc b/dev/LibCompiler/src/Cl/CCompilerARM64.cc index 7a342ae..9abdc8c 100644 --- a/dev/LibCompiler/src/CCompilerARM64.cc +++ b/dev/LibCompiler/src/Cl/CCompilerARM64.cc @@ -11,8 +11,8 @@ /// TODO: none #include <LibCompiler/Backend/Aarch64.h> -#include <LibCompiler/CompilerFrontend.h> -#include <LibCompiler/Detail/ClUtils.h> +#include <LibCompiler/Util/LCClUtils.h> +#include <LibCompiler/Frontend.h> #include <LibCompiler/UUID.h> #include <cstdio> #include <fstream> diff --git a/dev/LibCompiler/src/CCompilerPower64.cc b/dev/LibCompiler/src/Cl/CCompilerPower64.cc index 91cd32f..d3dd81e 100644 --- a/dev/LibCompiler/src/CCompilerPower64.cc +++ b/dev/LibCompiler/src/Cl/CCompilerPower64.cc @@ -8,8 +8,8 @@ */ #include <LibCompiler/Backend/PowerPC.h> -#include <LibCompiler/CompilerFrontend.h> -#include <LibCompiler/Detail/ClUtils.h> +#include <LibCompiler/Util/LCClUtils.h> +#include <LibCompiler/Frontend.h> #include <LibCompiler/UUID.h> #include <cstdio> #include <fstream> diff --git a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc b/dev/LibCompiler/src/Cl/CPlusPlusCompilerAMD64.cc index cc6fa67..c99508c 100644 --- a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc +++ b/dev/LibCompiler/src/Cl/CPlusPlusCompilerAMD64.cc @@ -16,9 +16,9 @@ // extern_segment, @autodelete { ... }, fn foo() -> auto { ... } -#include <LibCompiler/Backend/Amd64.h> -#include <LibCompiler/CompilerFrontend.h> -#include <LibCompiler/Detail/ClUtils.h> +#include <LibCompiler/Backend/X64.h> +#include <LibCompiler/Util/LCClUtils.h> +#include <LibCompiler/Frontend.h> #include <LibCompiler/UUID.h> /* NeKernel C++ Compiler Driver */ @@ -358,7 +358,7 @@ Boolean CompilerFrontendCPlusPlus::Compile(std::string text, std::string file) { ++indexFnName; } - if (fnName.find("(") != LibCompiler::String::npos) { + if (fnName.find("(") != LibCompiler::STLString::npos) { fnName.erase(fnName.find("(")); } @@ -884,7 +884,7 @@ LIBCOMPILER_MODULE(CompilerCPlusPlusAMD64) { std::string argv_i = argv[index]; std::vector<std::string> exts = kExtListCxx; - BOOL found = false; + BOOL found = false; for (std::string ext : exts) { if (argv_i.ends_with(ext)) { diff --git a/dev/LibCompiler/src/AssemblyFactory+AssemblyInterface.cc b/dev/LibCompiler/src/CodeGen.cc index e6072d9..31a809b 100644 --- a/dev/LibCompiler/src/AssemblyFactory+AssemblyInterface.cc +++ b/dev/LibCompiler/src/CodeGen.cc @@ -1,10 +1,10 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ -#include <LibCompiler/AssemblyInterface.h> +#include <LibCompiler/CodeGen.h> #include <LibCompiler/ErrorID.h> /** @@ -23,13 +23,15 @@ namespace LibCompiler { ///! @brief Compile for specific format (ELF, PEF, ZBIN) -Int32 AssemblyFactory::Compile(std::string sourceFile, const Int32& arch) noexcept { +Int32 AssemblyFactory::Compile(STLString sourceFile, const Int32& arch) noexcept { if (sourceFile.length() < 1 || !fMounted) return LIBCOMPILER_UNIMPLEMENTED; + if (!fMounted) return LIBCOMPILER_UNIMPLEMENTED; + if (arch != fMounted->Arch()) return LIBCOMPILER_INVALID_ARCH; try { - return fMounted->CompileToFormat(sourceFile, arch); + return this->fMounted->CompileToFormat(sourceFile, arch); } catch (std::exception& e) { return LIBCOMPILER_EXEC_ERROR; } diff --git a/dev/LibCompiler/src/Frontend.cc b/dev/LibCompiler/src/Frontend.cc new file mode 100644 index 0000000..69ff6fd --- /dev/null +++ b/dev/LibCompiler/src/Frontend.cc @@ -0,0 +1,51 @@ +/* ------------------------------------------- + + Copyright (C) 2025 Amlal EL Mahrouss, all rights reserved + +------------------------------------------- */ + +#include <LibCompiler/Frontend.h> + +namespace LibCompiler { +/// find the perfect matching word in a haystack. +/// \param haystack base string +/// \param needle the string we search for. +/// \return if we found it or not. +bool find_word(std::string haystack, std::string needle) noexcept { + auto index = haystack.find(needle); + + // check for needle validity. + if (index == std::string::npos) return false; + + // declare lambda + auto not_part_of_word = [&](int index) { + if (std::isspace(haystack[index]) || std::ispunct(haystack[index])) return true; + + if (index <= 0 || index >= haystack.size()) return true; + + return false; + }; + + return not_part_of_word(index - 1) && not_part_of_word(index + needle.size()); +} + +/// find a word within strict conditions and returns a range of it. +/// \param haystack +/// \param needle +/// \return position of needle. +std::size_t find_word_range(std::string haystack, std::string needle) noexcept { + auto index = haystack.find(needle); + + // check for needle validity. + if (index == std::string::npos) return false; + + if (!isalnum((haystack[index + needle.size() + 1])) && + !isdigit(haystack[index + needle.size() + 1]) && + !isalnum((haystack[index - needle.size() - 1])) && + !isdigit(haystack[index - needle.size() - 1])) { + return index; + } + + return std::string::npos; +} +} // namespace LibCompiler
\ No newline at end of file diff --git a/dev/LibCompiler/src/DynamicLinkerPEF.cc b/dev/LibCompiler/src/Linker/DynamicLinkerPEF.cc index 6421171..0c6f3bf 100644 --- a/dev/LibCompiler/src/DynamicLinkerPEF.cc +++ b/dev/LibCompiler/src/Linker/DynamicLinkerPEF.cc @@ -20,7 +20,7 @@ #include <LibCompiler/ErrorID.h> //! Assembler Kit -#include <LibCompiler/AssemblyInterface.h> +#include <LibCompiler/CodeGen.h> //! Preferred Executable Format #include <LibCompiler/PEF.h> @@ -35,7 +35,7 @@ #include <LibCompiler/AE.h> //! LibCompiler utils. -#include <LibCompiler/Detail/ClUtils.h> +#include <LibCompiler/Util/LCClUtils.h> //! I/O stream from std c++ #include <iostream> @@ -80,20 +80,20 @@ enum { kABITypeInvalid = 0xFFFF, }; -static LibCompiler::String kOutput = "a" kPefExt; -static Int32 kAbi = kABITypeNE; -static Int32 kSubArch = kPefNoSubCpu; -static Int32 kArch = LibCompiler::kPefArchInvalid; -static Bool kFatBinaryEnable = false; -static Bool kStartFound = false; -static Bool kDuplicateSymbols = false; +static LibCompiler::STLString kOutput = "a" kPefExt; +static Int32 kAbi = kABITypeNE; +static Int32 kSubArch = kPefNoSubCpu; +static Int32 kArch = LibCompiler::kPefArchInvalid; +static Bool kFatBinaryEnable = false; +static Bool kStartFound = false; +static Bool kDuplicateSymbols = false; /* ld64 is to be found, mld is to be found at runtime. */ static const CharType* kLdDefineSymbol = ":UndefinedSymbol:"; static const CharType* kLdDynamicSym = ":RuntimeSymbol:"; /* object code and list. */ -static std::vector<LibCompiler::String> kObjectList; +static std::vector<LibCompiler::STLString> kObjectList; static std::vector<Detail::DynamicLinkerBlob> kObjectBytes; /// @brief NE 64-bit Linker. @@ -165,7 +165,7 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { continue; } - if (kOutput.find(kPefExt) != LibCompiler::String::npos) + if (kOutput.find(kPefExt) != LibCompiler::STLString::npos) kOutput.erase(kOutput.find(kPefExt), strlen(kPefExt)); kOutput += kPefDylibExt; @@ -308,15 +308,15 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { MemoryCopy(command_header.Name, ae_records[ae_record_index].fName, kPefNameLen); - LibCompiler::String cmd_hdr_name(command_header.Name); + LibCompiler::STLString cmd_hdr_name(command_header.Name); // check this header if it's any valid. - if (cmd_hdr_name.find(kPefCode64) == LibCompiler::String::npos && - cmd_hdr_name.find(kPefData64) == LibCompiler::String::npos && - cmd_hdr_name.find(kPefZero64) == LibCompiler::String::npos) { - if (cmd_hdr_name.find(kPefStart) == LibCompiler::String::npos && + if (cmd_hdr_name.find(kPefCode64) == LibCompiler::STLString::npos && + cmd_hdr_name.find(kPefData64) == LibCompiler::STLString::npos && + cmd_hdr_name.find(kPefZero64) == LibCompiler::STLString::npos) { + if (cmd_hdr_name.find(kPefStart) == LibCompiler::STLString::npos && *command_header.Name == 0) { - if (cmd_hdr_name.find(kLdDefineSymbol) != LibCompiler::String::npos) { + if (cmd_hdr_name.find(kLdDefineSymbol) != LibCompiler::STLString::npos) { goto ld_mark_header; } else { continue; @@ -324,8 +324,8 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { } } - if (cmd_hdr_name.find(kPefStart) != LibCompiler::String::npos && - cmd_hdr_name.find(kPefCode64) != LibCompiler::String::npos) { + if (cmd_hdr_name.find(kPefStart) != LibCompiler::STLString::npos && + cmd_hdr_name.find(kPefCode64) != LibCompiler::STLString::npos) { kStartFound = true; } @@ -381,19 +381,21 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { output_fc.seekp(std::streamsize(pef_container.HdrSz)); - std::vector<LibCompiler::String> not_found; - std::vector<LibCompiler::String> symbols; + std::vector<LibCompiler::STLString> not_found; + std::vector<LibCompiler::STLString> symbols; // step 2: check for errors (multiple symbols, undefined ones) for (auto& command_hdr : command_headers) { // check if this symbol needs to be resolved. - if (LibCompiler::String(command_hdr.Name).find(kLdDefineSymbol) != LibCompiler::String::npos && - LibCompiler::String(command_hdr.Name).find(kLdDynamicSym) == LibCompiler::String::npos) { + if (LibCompiler::STLString(command_hdr.Name).find(kLdDefineSymbol) != + LibCompiler::STLString::npos && + LibCompiler::STLString(command_hdr.Name).find(kLdDynamicSym) == + LibCompiler::STLString::npos) { if (kVerbose) kConsoleOut << "Found undefined symbol: " << command_hdr.Name << "\n"; - if (auto it = - std::find(not_found.begin(), not_found.end(), LibCompiler::String(command_hdr.Name)); + if (auto it = std::find(not_found.begin(), not_found.end(), + LibCompiler::STLString(command_hdr.Name)); it == not_found.end()) { not_found.emplace_back(command_hdr.Name); } @@ -406,26 +408,27 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { for (size_t not_found_idx = 0; not_found_idx < command_headers.size(); ++not_found_idx) { if (const auto it = std::find(not_found.begin(), not_found.end(), - LibCompiler::String(command_headers[not_found_idx].Name)); + LibCompiler::STLString(command_headers[not_found_idx].Name)); it != not_found.end()) { - LibCompiler::String symbol_imp = *it; + LibCompiler::STLString symbol_imp = *it; - if (symbol_imp.find(kLdDefineSymbol) == LibCompiler::String::npos) continue; + if (symbol_imp.find(kLdDefineSymbol) == LibCompiler::STLString::npos) continue; // erase the lookup prefix. symbol_imp.erase(0, symbol_imp.find(kLdDefineSymbol) + strlen(kLdDefineSymbol)); // demangle everything. - while (symbol_imp.find('$') != LibCompiler::String::npos) + while (symbol_imp.find('$') != LibCompiler::STLString::npos) symbol_imp.erase(symbol_imp.find('$'), 1); // the reason we do is because, this may not match the symbol, and we need // to look for other matching symbols. for (auto& command_hdr : command_headers) { - if (LibCompiler::String(command_hdr.Name).find(symbol_imp) != LibCompiler::String::npos && - LibCompiler::String(command_hdr.Name).find(kLdDefineSymbol) == - LibCompiler::String::npos) { - LibCompiler::String undefined_symbol = command_hdr.Name; + if (LibCompiler::STLString(command_hdr.Name).find(symbol_imp) != + LibCompiler::STLString::npos && + LibCompiler::STLString(command_hdr.Name).find(kLdDefineSymbol) == + LibCompiler::STLString::npos) { + LibCompiler::STLString undefined_symbol = command_hdr.Name; auto result_of_sym = undefined_symbol.substr(undefined_symbol.find(symbol_imp)); for (int i = 0; result_of_sym[i] != 0; ++i) { @@ -462,7 +465,7 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { time_t timestamp = time(nullptr); - LibCompiler::String timeStampStr = "Container:BuildEpoch:"; + LibCompiler::STLString timeStampStr = "Container:BuildEpoch:"; timeStampStr += std::to_string(timestamp); strncpy(date_cmd_hdr.Name, timeStampStr.c_str(), timeStampStr.size()); @@ -476,7 +479,7 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { LibCompiler::PEFCommandHeader abi_cmd_hdr{}; - LibCompiler::String abi = kLinkerAbiContainer; + LibCompiler::STLString abi = kLinkerAbiContainer; switch (kArch) { case LibCompiler::kPefArchAMD64: { @@ -542,9 +545,9 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { command_headers.push_back(uuid_cmd_hdr); // prepare a symbol vector. - std::vector<LibCompiler::String> undef_symbols; - std::vector<LibCompiler::String> dupl_symbols; - std::vector<LibCompiler::String> resolve_symbols; + std::vector<LibCompiler::STLString> undef_symbols; + std::vector<LibCompiler::STLString> dupl_symbols; + std::vector<LibCompiler::STLString> resolve_symbols; constexpr Int32 kPaddingOffset = 16; @@ -567,15 +570,15 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { // And check for any duplications for (size_t commandHeaderIndex = 0UL; commandHeaderIndex < command_headers.size(); ++commandHeaderIndex) { - if (LibCompiler::String(command_headers[commandHeaderIndex].Name).find(kLdDefineSymbol) != - LibCompiler::String::npos && - LibCompiler::String(command_headers[commandHeaderIndex].Name).find(kLdDynamicSym) == - LibCompiler::String::npos) { + if (LibCompiler::STLString(command_headers[commandHeaderIndex].Name).find(kLdDefineSymbol) != + LibCompiler::STLString::npos && + LibCompiler::STLString(command_headers[commandHeaderIndex].Name).find(kLdDynamicSym) == + LibCompiler::STLString::npos) { // ignore :UndefinedSymbol: headers, they do not contain code. continue; } - LibCompiler::String symbol_name = command_headers[commandHeaderIndex].Name; + LibCompiler::STLString symbol_name = command_headers[commandHeaderIndex].Name; if (!symbol_name.empty()) { undef_symbols.emplace_back(symbol_name); @@ -584,13 +587,13 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { command_headers[commandHeaderIndex].Offset += previous_offset; previous_offset += command_headers[commandHeaderIndex].Size; - LibCompiler::String name = command_headers[commandHeaderIndex].Name; + LibCompiler::STLString name = command_headers[commandHeaderIndex].Name; /// so this is valid when we get to the entrypoint. /// it is always a code64 container. And should equal to kPefStart as well. /// this chunk of code updates the pef_container.Start with the updated offset. - if (name.find(kPefStart) != LibCompiler::String::npos && - name.find(kPefCode64) != LibCompiler::String::npos) { + if (name.find(kPefStart) != LibCompiler::STLString::npos && + name.find(kPefCode64) != LibCompiler::STLString::npos) { pef_container.Start = command_headers[commandHeaderIndex].Offset; auto tellCurPos = output_fc.tellp(); @@ -612,10 +615,10 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { ++sub_command_header_index) { if (sub_command_header_index == commandHeaderIndex) continue; - if (LibCompiler::String(command_headers[sub_command_header_index].Name) - .find(kLdDefineSymbol) != LibCompiler::String::npos && - LibCompiler::String(command_headers[sub_command_header_index].Name).find(kLdDynamicSym) == - LibCompiler::String::npos) { + if (LibCompiler::STLString(command_headers[sub_command_header_index].Name) + .find(kLdDefineSymbol) != LibCompiler::STLString::npos && + LibCompiler::STLString(command_headers[sub_command_header_index].Name) + .find(kLdDynamicSym) == LibCompiler::STLString::npos) { if (kVerbose) { kConsoleOut << "Ignoring :UndefinedSymbol: headers...\n"; } @@ -626,7 +629,7 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { auto& command_hdr = command_headers[sub_command_header_index]; - if (command_hdr.Name == LibCompiler::String(command_headers[commandHeaderIndex].Name)) { + if (command_hdr.Name == LibCompiler::STLString(command_headers[commandHeaderIndex].Name)) { if (std::find(dupl_symbols.cbegin(), dupl_symbols.cend(), command_hdr.Name) == dupl_symbols.cend()) { dupl_symbols.emplace_back(command_hdr.Name); @@ -659,11 +662,11 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { // step 3: check if we have those symbols - std::vector<LibCompiler::String> unreferenced_symbols; + std::vector<LibCompiler::STLString> unreferenced_symbols; for (auto& command_hdr : command_headers) { if (auto it = - std::find(not_found.begin(), not_found.end(), LibCompiler::String(command_hdr.Name)); + std::find(not_found.begin(), not_found.end(), LibCompiler::STLString(command_hdr.Name)); it != not_found.end()) { unreferenced_symbols.emplace_back(command_hdr.Name); } diff --git a/dev/LibCompiler/src/CPlusPlusCompilerPreProcessor.cc b/dev/LibCompiler/src/PP/CPlusPlusCompilerPreProcessor.cc index 9981f37..2c7c551 100644 --- a/dev/LibCompiler/src/CPlusPlusCompilerPreProcessor.cc +++ b/dev/LibCompiler/src/PP/CPlusPlusCompilerPreProcessor.cc @@ -9,8 +9,8 @@ /// BUGS: 0 -#include <LibCompiler/CompilerFrontend.h> #include <LibCompiler/ErrorID.h> +#include <LibCompiler/Frontend.h> #include <algorithm> #include <filesystem> #include <fstream> @@ -24,7 +24,7 @@ /// @file bpp.cxx /// @brief Preprocessor. -typedef Int32 (*bpp_parser_fn_t)(LibCompiler::String& line, std::ifstream& hdr_file, +typedef Int32 (*bpp_parser_fn_t)(LibCompiler::STLString& line, std::ifstream& hdr_file, std::ofstream& pp_out); ///////////////////////////////////////////////////////////////////////////////////////// @@ -46,8 +46,8 @@ enum { }; struct bpp_macro_condition final { - int32_t fType; - LibCompiler::String fTypeName; + int32_t fType; + LibCompiler::STLString fTypeName; void Print() { std::cout << "type: " << fType << "\n"; @@ -56,9 +56,9 @@ struct bpp_macro_condition final { }; struct bpp_macro final { - std::vector<LibCompiler::String> fArgs; - LibCompiler::String fName; - LibCompiler::String fValue; + std::vector<LibCompiler::STLString> fArgs; + LibCompiler::STLString fName; + LibCompiler::STLString fValue; void Print() { std::cout << "name: " << fName << "\n"; @@ -71,11 +71,11 @@ struct bpp_macro final { }; } // namespace Detail -static std::vector<LibCompiler::String> kFiles; -static std::vector<Detail::bpp_macro> kMacros; -static std::vector<LibCompiler::String> kIncludes; +static std::vector<LibCompiler::STLString> kFiles; +static std::vector<Detail::bpp_macro> kMacros; +static std::vector<LibCompiler::STLString> kIncludes; -static LibCompiler::String kWorkingDir = ""; +static LibCompiler::STLString kWorkingDir = ""; ///////////////////////////////////////////////////////////////////////////////////////// @@ -85,11 +85,12 @@ static LibCompiler::String kWorkingDir = ""; ///////////////////////////////////////////////////////////////////////////////////////// int32_t bpp_parse_if_condition(Detail::bpp_macro_condition& cond, Detail::bpp_macro& macro, - bool& inactive_code, bool& defined, LibCompiler::String& macro_str) { + bool& inactive_code, bool& defined, + LibCompiler::STLString& macro_str) { if (cond.fType == Detail::kEqual) { auto substr_macro = macro_str.substr(macro_str.find(macro.fName) + macro.fName.size()); - if (substr_macro.find(macro.fValue) != LibCompiler::String::npos) { + if (substr_macro.find(macro.fValue) != LibCompiler::STLString::npos) { if (macro.fValue == "0") { defined = false; inactive_code = true; @@ -105,8 +106,8 @@ int32_t bpp_parse_if_condition(Detail::bpp_macro_condition& cond, Detail::bpp_ma } else if (cond.fType == Detail::kNotEqual) { auto substr_macro = macro_str.substr(macro_str.find(macro.fName) + macro.fName.size()); - if (substr_macro.find(macro.fName) != LibCompiler::String::npos) { - if (substr_macro.find(macro.fValue) != LibCompiler::String::npos) { + if (substr_macro.find(macro.fName) != LibCompiler::STLString::npos) { + if (substr_macro.find(macro.fValue) != LibCompiler::STLString::npos) { defined = false; inactive_code = true; @@ -124,10 +125,10 @@ int32_t bpp_parse_if_condition(Detail::bpp_macro_condition& cond, Detail::bpp_ma auto substr_macro = macro_str.substr(macro_str.find(macro.fName) + macro.fName.size()); - LibCompiler::String number; + LibCompiler::STLString number; for (auto& macro_num : kMacros) { - if (substr_macro.find(macro_num.fName) != LibCompiler::String::npos) { + if (substr_macro.find(macro_num.fName) != LibCompiler::STLString::npos) { for (size_t i = 0; i < macro_num.fName.size(); ++i) { if (isdigit(macro_num.fValue[i])) { number += macro_num.fValue[i]; @@ -231,7 +232,7 @@ int32_t bpp_parse_if_condition(Detail::bpp_macro_condition& cond, Detail::bpp_ma ///////////////////////////////////////////////////////////////////////////////////////// -std::vector<LibCompiler::String> kAllIncludes; +std::vector<LibCompiler::STLString> kAllIncludes; ///////////////////////////////////////////////////////////////////////////////////////// @@ -241,8 +242,8 @@ std::vector<LibCompiler::String> kAllIncludes; ///////////////////////////////////////////////////////////////////////////////////////// void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { - LibCompiler::String hdr_line; - LibCompiler::String line_after_include; + LibCompiler::STLString hdr_line; + LibCompiler::STLString line_after_include; bool inactive_code = false; bool defined = false; @@ -250,36 +251,36 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { try { while (std::getline(hdr_file, hdr_line)) { if (inactive_code) { - if (hdr_line.find("#endif") == LibCompiler::String::npos) { + if (hdr_line.find("#endif") == LibCompiler::STLString::npos) { continue; } else if (hdr_line[0] == kMacroPrefix && - hdr_line.find("#endif") != LibCompiler::String::npos) { + hdr_line.find("#endif") != LibCompiler::STLString::npos) { inactive_code = false; } - if (hdr_line.find("*/") != LibCompiler::String::npos) { + if (hdr_line.find("*/") != LibCompiler::STLString::npos) { continue; } } - if (hdr_line.find("--/") != LibCompiler::String::npos) { + if (hdr_line.find("--/") != LibCompiler::STLString::npos) { hdr_line.erase(hdr_line.find("--/")); } - if (hdr_line.find("--*") != LibCompiler::String::npos) { + if (hdr_line.find("--*") != LibCompiler::STLString::npos) { inactive_code = true; // get rid of comment. hdr_line.erase(hdr_line.find("--*")); } /// BPP 'brief' documentation. - if (hdr_line.find("@brief") != LibCompiler::String::npos) { + if (hdr_line.find("@brief") != LibCompiler::STLString::npos) { hdr_line.erase(hdr_line.find("@brief")); // TODO: Write an <file_name>.html or append to it. } - if (hdr_line[0] == kMacroPrefix && hdr_line.find("endif") != LibCompiler::String::npos) { + if (hdr_line[0] == kMacroPrefix && hdr_line.find("endif") != LibCompiler::STLString::npos) { if (!defined && inactive_code) { inactive_code = false; defined = false; @@ -301,17 +302,17 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { for (auto macro : kMacros) { if (LibCompiler::find_word(hdr_line, macro.fName)) { if (hdr_line.substr(hdr_line.find(macro.fName)).find(macro.fName + '(') != - LibCompiler::String::npos) { + LibCompiler::STLString::npos) { if (!macro.fArgs.empty()) { - LibCompiler::String symbol_val = macro.fValue; - std::vector<LibCompiler::String> args; + LibCompiler::STLString symbol_val = macro.fValue; + std::vector<LibCompiler::STLString> args; size_t x_arg_indx = 0; - LibCompiler::String line_after_define = hdr_line; - LibCompiler::String str_arg; + LibCompiler::STLString line_after_define = hdr_line; + LibCompiler::STLString str_arg; - if (line_after_define.find("(") != LibCompiler::String::npos) { + if (line_after_define.find("(") != LibCompiler::STLString::npos) { line_after_define.erase(0, line_after_define.find("(") + 1); for (auto& subc : line_after_define) { @@ -332,7 +333,7 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { } for (auto arg : macro.fArgs) { - if (symbol_val.find(macro.fArgs[x_arg_indx]) != LibCompiler::String::npos) { + if (symbol_val.find(macro.fArgs[x_arg_indx]) != LibCompiler::STLString::npos) { symbol_val.replace(symbol_val.find(macro.fArgs[x_arg_indx]), macro.fArgs[x_arg_indx].size(), args[x_arg_indx]); ++x_arg_indx; @@ -358,16 +359,16 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { } } - if (hdr_line[0] == kMacroPrefix && hdr_line.find("define ") != LibCompiler::String::npos) { + if (hdr_line[0] == kMacroPrefix && hdr_line.find("define ") != LibCompiler::STLString::npos) { auto line_after_define = hdr_line.substr(hdr_line.find("define ") + strlen("define ")); - LibCompiler::String macro_value; - LibCompiler::String macro_key; + LibCompiler::STLString macro_value; + LibCompiler::STLString macro_key; std::size_t pos = 0UL; - std::vector<LibCompiler::String> args; - bool on_args = false; + std::vector<LibCompiler::STLString> args; + bool on_args = false; for (auto& ch : line_after_define) { ++pos; @@ -397,9 +398,9 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { macro_key += ch; } - LibCompiler::String str; + LibCompiler::STLString str; - if (line_after_define.find("(") != LibCompiler::String::npos) { + if (line_after_define.find("(") != LibCompiler::STLString::npos) { line_after_define.erase(0, line_after_define.find("(") + 1); for (auto& subc : line_after_define) { @@ -438,9 +439,9 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { continue; } - if (hdr_line[0] == kMacroPrefix && hdr_line.find("ifndef") != LibCompiler::String::npos) { + if (hdr_line[0] == kMacroPrefix && hdr_line.find("ifndef") != LibCompiler::STLString::npos) { auto line_after_ifndef = hdr_line.substr(hdr_line.find("ifndef") + strlen("ifndef") + 1); - LibCompiler::String macro; + LibCompiler::STLString macro; for (auto& ch : line_after_ifndef) { if (ch == ' ') { @@ -469,7 +470,7 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { inactive_code = false; for (auto& macro_ref : kMacros) { - if (hdr_line.find(macro_ref.fName) != LibCompiler::String::npos) { + if (hdr_line.find(macro_ref.fName) != LibCompiler::STLString::npos) { found = true; break; } @@ -482,7 +483,7 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { continue; } } else if (hdr_line[0] == kMacroPrefix && - hdr_line.find("else") != LibCompiler::String::npos) { + hdr_line.find("else") != LibCompiler::STLString::npos) { if (!defined && inactive_code) { inactive_code = false; defined = true; @@ -495,9 +496,9 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { continue; } } else if (hdr_line[0] == kMacroPrefix && - hdr_line.find("ifdef") != LibCompiler::String::npos) { + hdr_line.find("ifdef") != LibCompiler::STLString::npos) { auto line_after_ifdef = hdr_line.substr(hdr_line.find("ifdef") + strlen("ifdef") + 1); - LibCompiler::String macro; + LibCompiler::STLString macro; for (auto& ch : line_after_ifdef) { if (ch == ' ') { @@ -525,14 +526,15 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { inactive_code = true; for (auto& macro_ref : kMacros) { - if (hdr_line.find(macro_ref.fName) != LibCompiler::String::npos) { + if (hdr_line.find(macro_ref.fName) != LibCompiler::STLString::npos) { defined = true; inactive_code = false; break; } } - } else if (hdr_line[0] == kMacroPrefix && hdr_line.find("if") != LibCompiler::String::npos) { + } else if (hdr_line[0] == kMacroPrefix && + hdr_line.find("if") != LibCompiler::STLString::npos) { inactive_code = true; std::vector<Detail::bpp_macro_condition> bpp_macro_condition_list = { @@ -565,9 +567,9 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { int32_t good_to_go = 0; for (auto& macro_condition : bpp_macro_condition_list) { - if (hdr_line.find(macro_condition.fTypeName) != LibCompiler::String::npos) { + if (hdr_line.find(macro_condition.fTypeName) != LibCompiler::STLString::npos) { for (auto& found_macro : kMacros) { - if (hdr_line.find(found_macro.fName) != LibCompiler::String::npos) { + if (hdr_line.find(found_macro.fName) != LibCompiler::STLString::npos) { good_to_go = bpp_parse_if_condition(macro_condition, found_macro, inactive_code, defined, hdr_line); @@ -579,8 +581,8 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { if (good_to_go) continue; - auto line_after_if = hdr_line.substr(hdr_line.find("if") + strlen("if") + 1); - LibCompiler::String macro; + auto line_after_if = hdr_line.substr(hdr_line.find("if") + strlen("if") + 1); + LibCompiler::STLString macro; for (auto& ch : line_after_if) { if (ch == ' ') { @@ -605,7 +607,8 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { // last try, is it defined to be one? for (auto& macro_ref : kMacros) { - if (macro_ref.fName.find(macro) != LibCompiler::String::npos && macro_ref.fValue == "1") { + if (macro_ref.fName.find(macro) != LibCompiler::STLString::npos && + macro_ref.fValue == "1") { inactive_code = false; defined = true; @@ -613,9 +616,9 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { } } } else if (hdr_line[0] == kMacroPrefix && - hdr_line.find("warning") != LibCompiler::String::npos) { + hdr_line.find("warning") != LibCompiler::STLString::npos) { auto line_after_warning = hdr_line.substr(hdr_line.find("warning") + strlen("warning") + 1); - LibCompiler::String message; + LibCompiler::STLString message; for (auto& ch : line_after_warning) { if (ch == '\r' || ch == '\n') { @@ -627,9 +630,9 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { std::cout << "warn: " << message << std::endl; } else if (hdr_line[0] == kMacroPrefix && - hdr_line.find("error") != LibCompiler::String::npos) { + hdr_line.find("error") != LibCompiler::STLString::npos) { auto line_after_warning = hdr_line.substr(hdr_line.find("error") + strlen("error") + 1); - LibCompiler::String message; + LibCompiler::STLString message; for (auto& ch : line_after_warning) { if (ch == '\r' || ch == '\n') { @@ -641,7 +644,7 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { throw std::runtime_error("error: " + message); } else if (hdr_line[0] == kMacroPrefix && - hdr_line.find("include ") != LibCompiler::String::npos) { + hdr_line.find("include ") != LibCompiler::STLString::npos) { line_after_include = hdr_line.substr(hdr_line.find("include ") + strlen("include ")); kIncludeFile: @@ -651,7 +654,7 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { continue; } - LibCompiler::String path; + LibCompiler::STLString path; kAllIncludes.push_back(line_after_include); @@ -691,7 +694,7 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { } for (auto& include : kIncludes) { - LibCompiler::String header_path = include; + LibCompiler::STLString header_path = include; header_path.push_back('/'); header_path += path; @@ -830,7 +833,7 @@ LIBCOMPILER_MODULE(CPlusPlusPreprocessorMain) { } if (strcmp(argv[index], "--cppdrv:include-dir") == 0) { - LibCompiler::String inc = argv[index + 1]; + LibCompiler::STLString inc = argv[index + 1]; skip = true; @@ -838,17 +841,17 @@ LIBCOMPILER_MODULE(CPlusPlusPreprocessorMain) { } if (strcmp(argv[index], "--cppdrv:working-dir") == 0) { - LibCompiler::String inc = argv[index + 1]; - skip = true; - kWorkingDir = inc; + LibCompiler::STLString inc = argv[index + 1]; + skip = true; + kWorkingDir = inc; } if (strcmp(argv[index], "--cppdrv:def") == 0 && argv[index + 1] != nullptr && argv[index + 2] != nullptr) { - LibCompiler::String macro_key = argv[index + 1]; + LibCompiler::STLString macro_key = argv[index + 1]; - LibCompiler::String macro_value; - bool is_string = false; + LibCompiler::STLString macro_value; + bool is_string = false; for (int argv_find_len = 0; argv_find_len < strlen(argv[index]); ++argv_find_len) { if (!isdigit(argv[index][argv_find_len])) { diff --git a/dev/LibCompiler/src/StringView.cc b/dev/LibCompiler/src/PString.cc index 41ee636..c8c060b 100644 --- a/dev/LibCompiler/src/StringView.cc +++ b/dev/LibCompiler/src/PString.cc @@ -8,7 +8,7 @@ */ /** - * @file String.cxx + * @file PString.cxx * @author Amlal (amlal@el-mahrouss-logic.com) * @brief C++ string manipulation API. * @version 0.2 @@ -18,22 +18,22 @@ * */ -#include <LibCompiler/StringView.h> +#include <LibCompiler/PString.h> namespace LibCompiler { -CharType* StringView::Data() { +CharType* PString::Data() { return m_Data; } -const CharType* StringView::CData() const { +const CharType* PString::CData() const { return m_Data; } -SizeType StringView::Length() const { +SizeType PString::Length() const { return strlen(m_Data); } -bool StringView::operator==(const StringView& rhs) const { +bool PString::operator==(const PString& rhs) const { if (rhs.Length() != Length()) return false; for (SizeType index = 0; index < Length(); ++index) { @@ -43,7 +43,7 @@ bool StringView::operator==(const StringView& rhs) const { return true; } -bool StringView::operator==(const CharType* rhs) const { +bool PString::operator==(const CharType* rhs) const { if (string_length(rhs) != Length()) return false; for (SizeType index = 0; index < string_length(rhs); ++index) { @@ -53,7 +53,7 @@ bool StringView::operator==(const CharType* rhs) const { return true; } -bool StringView::operator!=(const StringView& rhs) const { +bool PString::operator!=(const PString& rhs) const { if (rhs.Length() != Length()) return false; for (SizeType index = 0; index < rhs.Length(); ++index) { @@ -63,7 +63,7 @@ bool StringView::operator!=(const StringView& rhs) const { return true; } -bool StringView::operator!=(const CharType* rhs) const { +bool PString::operator!=(const CharType* rhs) const { if (string_length(rhs) != Length()) return false; for (SizeType index = 0; index < string_length(rhs); ++index) { @@ -73,10 +73,10 @@ bool StringView::operator!=(const CharType* rhs) const { return true; } -StringView StringBuilder::Construct(const CharType* data) { - if (!data || *data == 0) return StringView(0); +PString StringBuilder::Construct(const CharType* data) { + if (!data || *data == 0) return PString(0); - StringView view(strlen(data)); + PString view(strlen(data)); view += data; return view; @@ -183,9 +183,9 @@ const char* StringBuilder::Format(const char* fmt, const char* fmtRight) { return ret; } -StringView& StringView::operator+=(const CharType* rhs) { +PString& PString::operator+=(const CharType* rhs) { if (strlen(rhs) > this->m_Sz) { - throw std::runtime_error("out_of_bounds: StringView"); + throw std::runtime_error("out_of_bounds: PString"); } memcpy(this->m_Data + this->m_Cur, rhs, strlen(rhs)); @@ -194,9 +194,9 @@ StringView& StringView::operator+=(const CharType* rhs) { return *this; } -StringView& StringView::operator+=(const StringView& rhs) { +PString& PString::operator+=(const PString& rhs) { if (rhs.m_Cur > this->m_Sz) { - throw std::runtime_error("out_of_bounds: StringView"); + throw std::runtime_error("out_of_bounds: PString"); } memcpy(this->m_Data + this->m_Cur, rhs.CData(), strlen(rhs.CData())); diff --git a/dev/LibDebugger/Version.h b/dev/LibDebugger/Version.h new file mode 100644 index 0000000..4159191 --- /dev/null +++ b/dev/LibDebugger/Version.h @@ -0,0 +1,15 @@ +/* ------------------------------------------- + + Copyright (C) 2025 Amlal EL Mahrouss, all rights reserved + +------------------------------------------- */ + +#pragma once + +#define kDistVersion "v0.0.1-libdebugger" +#define kDistVersionBCD 0x0001 + +#define ToString(X) Stringify(X) +#define Stringify(X) #X + +#define kDistRelease ToString(kDistReleaseBranch) diff --git a/docs/drawio/LIBCOMPILER_DESIGN.drawio b/docs/drawio/LIBCOMPILER_DESIGN.drawio index 3c81ecc..89cb7d1 100644 --- a/docs/drawio/LIBCOMPILER_DESIGN.drawio +++ b/docs/drawio/LIBCOMPILER_DESIGN.drawio @@ -1,61 +1,61 @@ <mxfile host="65bd71144e"> <diagram id="Hvu3NLRsK3fSdSTnrkoh" name="Page-1"> - <mxGraphModel dx="1142" dy="550" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0"> + <mxGraphModel dx="960" dy="709" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0"> <root> <mxCell id="0"/> <mxCell id="1" parent="0"/> - <mxCell id="4" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="2" target="3"> + <mxCell id="4" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="2" target="3" edge="1"> <mxGeometry relative="1" as="geometry"/> </mxCell> - <mxCell id="2" value="CompilerFrontend" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxCell id="2" value="Frontend" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> <mxGeometry x="130" y="580" width="120" height="60" as="geometry"/> </mxCell> - <mxCell id="6" style="edgeStyle=none;html=1;" edge="1" parent="1" source="3" target="5"> + <mxCell id="6" style="edgeStyle=none;html=1;" parent="1" source="3" target="5" edge="1"> <mxGeometry relative="1" as="geometry"/> </mxCell> - <mxCell id="3" value="AssemblyInterface" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxCell id="3" value="CodeGen Stage 1<div>(Assembler)</div>" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> <mxGeometry x="285" y="580" width="120" height="60" as="geometry"/> </mxCell> - <mxCell id="8" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="5" target="7"> + <mxCell id="8" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="5" target="7" edge="1"> <mxGeometry relative="1" as="geometry"/> </mxCell> - <mxCell id="5" value="Assembler" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxCell id="5" value="CodeGen Stage 2<div>(AE encoding)</div>" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> <mxGeometry x="440" y="580" width="120" height="60" as="geometry"/> </mxCell> - <mxCell id="7" value="64-bit Linker Driver" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxCell id="7" value="64-bit Linker Driver" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> <mxGeometry x="600" y="580" width="120" height="60" as="geometry"/> </mxCell> - <mxCell id="10" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9" target="2"> + <mxCell id="10" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="9" target="2" edge="1"> <mxGeometry relative="1" as="geometry"/> </mxCell> - <mxCell id="14" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="9" target="11"> + <mxCell id="14" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="9" target="11" edge="1"> <mxGeometry relative="1" as="geometry"/> </mxCell> - <mxCell id="9" value="Cl Driver Tool" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxCell id="9" value="Cl Driver Tool" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> <mxGeometry x="130" y="410" width="120" height="60" as="geometry"/> </mxCell> - <mxCell id="12" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="7"> + <mxCell id="12" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="11" target="7" edge="1"> <mxGeometry relative="1" as="geometry"/> </mxCell> - <mxCell id="13" style="edgeStyle=none;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="9"> + <mxCell id="13" style="edgeStyle=none;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="11" target="9" edge="1"> <mxGeometry relative="1" as="geometry"/> </mxCell> - <mxCell id="11" value="Linker Tool" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxCell id="11" value="Linker Tool" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> <mxGeometry x="600" y="410" width="120" height="60" as="geometry"/> </mxCell> - <mxCell id="15" value="High Level CLI" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxCell id="15" value="High Level CLI" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> <mxGeometry x="130" y="290" width="590" height="60" as="geometry"/> </mxCell> - <mxCell id="17" style="edgeStyle=none;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.102;entryY=1;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" source="9" target="15"> + <mxCell id="17" style="edgeStyle=none;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.102;entryY=1;entryDx=0;entryDy=0;entryPerimeter=0;" parent="1" source="9" target="15" edge="1"> <mxGeometry relative="1" as="geometry"/> </mxCell> - <mxCell id="18" style="edgeStyle=none;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.898;entryY=1.05;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" source="11" target="15"> + <mxCell id="18" style="edgeStyle=none;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.898;entryY=1.05;entryDx=0;entryDy=0;entryPerimeter=0;" parent="1" source="11" target="15" edge="1"> <mxGeometry relative="1" as="geometry"/> </mxCell> - <mxCell id="19" value="LibCompiler Architecture" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1"> + <mxCell id="19" value="LibCompiler Architecture" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1"> <mxGeometry x="338" y="210" width="175" height="30" as="geometry"/> </mxCell> - <mxCell id="20" value="LibCompiler.so" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1"> + <mxCell id="20" value="LibCompiler.so" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1"> <mxGeometry x="338" y="510" width="175" height="30" as="geometry"/> </mxCell> </root> diff --git a/lc-osx-san.json b/lc-osx-san.json index 9b2d1c6..4e8f5c8 100644 --- a/lc-osx-san.json +++ b/lc-osx-san.json @@ -8,7 +8,8 @@ "./dev/LibCompiler/src/Detail" ], "sources_path": [ - "dev/LibCompiler/src/*.cc" + "dev/LibCompiler/src/*.cc", + "dev/LibCompiler/src/*/*.cc" ], "output_name": "/usr/local/lib/libCompiler.dylib", "compiler_flags": [ diff --git a/lc-osx.json b/lc-osx.json index 38a4c10..b331cbc 100644 --- a/lc-osx.json +++ b/lc-osx.json @@ -8,7 +8,8 @@ "./dev/LibCompiler/src/Detail" ], "sources_path": [ - "dev/LibCompiler/src/*.cc" + "dev/LibCompiler/src/*.cc", + "dev/LibCompiler/src/*/*.cc" ], "output_name": "/usr/local/lib/libCompiler.dylib", "compiler_flags": [ diff --git a/lc-posix.json b/lc-posix.json index 297d35b..6717707 100644 --- a/lc-posix.json +++ b/lc-posix.json @@ -8,7 +8,8 @@ "./dev/LibCompiler/src/Detail" ], "sources_path": [ - "dev/LibCompiler/src/*.cc" + "dev/LibCompiler/src/*.cc", + "dev/LibCompiler/src/*/*.cc" ], "output_name": "/usr/lib/libCompiler.so", "compiler_flags": [ diff --git a/tools/asm.cc b/tools/asm.cc index 8f98543..6f83c81 100644 --- a/tools/asm.cc +++ b/tools/asm.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ diff --git a/tools/cppdrv.cc b/tools/cppdrv.cc index 7adfd0b..e479222 100644 --- a/tools/cppdrv.cc +++ b/tools/cppdrv.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ diff --git a/tools/cxxdrv.cc b/tools/cxxdrv.cc index d500101..1f58692 100644 --- a/tools/cxxdrv.cc +++ b/tools/cxxdrv.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ diff --git a/tools/dbg.cc b/tools/dbg.cc index b9be862..1d89c21 100644 --- a/tools/dbg.cc +++ b/tools/dbg.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ diff --git a/tools/kdbg.cc b/tools/kdbg.cc index 11901e3..08a0465 100644 --- a/tools/kdbg.cc +++ b/tools/kdbg.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ diff --git a/tools/ld64.cc b/tools/ld64.cc index ebb7376..ebdcb47 100644 --- a/tools/ld64.cc +++ b/tools/ld64.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved ------------------------------------------- */ |
