diff options
| author | Amlal <amlal@nekernel.org> | 2025-08-09 19:53:40 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-08-09 19:53:40 +0200 |
| commit | 85a8e5967def8164b90824c9095c3a93d62d96b2 (patch) | |
| tree | 85cf5ab710ba67f25c99eab5e4c81a71aece6892 /dev/CompilerKit/src | |
| parent | 72d1918de80edb8d3a260f6ae3a1613435f2302a (diff) | |
feat: compiler_kit: post PR compiler error fixes.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/CompilerKit/src')
| -rw-r--r-- | dev/CompilerKit/src/Backend/Assembler32x0.cc | 2 | ||||
| -rw-r--r-- | dev/CompilerKit/src/Backend/Assembler64x0.cc | 2 | ||||
| -rw-r--r-- | dev/CompilerKit/src/Backend/AssemblerAMD64.cc | 2 | ||||
| -rw-r--r-- | dev/CompilerKit/src/Backend/AssemblerARM64.cc | 4 | ||||
| -rw-r--r-- | dev/CompilerKit/src/Backend/AssemblerPowerPC.cc | 4 | ||||
| -rw-r--r-- | dev/CompilerKit/src/Frontend/CCompiler64x0.cc | 9 | ||||
| -rw-r--r-- | dev/CompilerKit/src/Frontend/CCompilerARM64.cc | 9 | ||||
| -rw-r--r-- | dev/CompilerKit/src/Frontend/CCompilerPower64.cc | 9 | ||||
| -rw-r--r-- | dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc | 46 | ||||
| -rw-r--r-- | dev/CompilerKit/src/Linker/DynamicLinker64PEF.cc | 17 | ||||
| -rw-r--r-- | dev/CompilerKit/src/StringKit.cc | 20 |
11 files changed, 59 insertions, 65 deletions
diff --git a/dev/CompilerKit/src/Backend/Assembler32x0.cc b/dev/CompilerKit/src/Backend/Assembler32x0.cc index a7cb022..8478930 100644 --- a/dev/CompilerKit/src/Backend/Assembler32x0.cc +++ b/dev/CompilerKit/src/Backend/Assembler32x0.cc @@ -22,9 +22,9 @@ #endif #include <CompilerKit/AE.h> -#include <CompilerKit/detail/32x0.h> #include <CompilerKit/Frontend.h> #include <CompilerKit/PEF.h> +#include <CompilerKit/detail/32x0.h> #include <CompilerKit/utils/CompilerUtils.h> ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/dev/CompilerKit/src/Backend/Assembler64x0.cc b/dev/CompilerKit/src/Backend/Assembler64x0.cc index 6bc8842..c2dd31c 100644 --- a/dev/CompilerKit/src/Backend/Assembler64x0.cc +++ b/dev/CompilerKit/src/Backend/Assembler64x0.cc @@ -22,9 +22,9 @@ #endif #include <CompilerKit/AE.h> -#include <CompilerKit/detail/64x0.h> #include <CompilerKit/Frontend.h> #include <CompilerKit/PEF.h> +#include <CompilerKit/detail/64x0.h> #include <CompilerKit/utils/CompilerUtils.h> #include <algorithm> #include <filesystem> diff --git a/dev/CompilerKit/src/Backend/AssemblerAMD64.cc b/dev/CompilerKit/src/Backend/AssemblerAMD64.cc index b085773..7e21c93 100644 --- a/dev/CompilerKit/src/Backend/AssemblerAMD64.cc +++ b/dev/CompilerKit/src/Backend/AssemblerAMD64.cc @@ -29,9 +29,9 @@ #define kAssemblerPragmaSym '#' #include <CompilerKit/AE.h> -#include <CompilerKit/detail/X64.h> #include <CompilerKit/Frontend.h> #include <CompilerKit/PEF.h> +#include <CompilerKit/detail/X64.h> #include <algorithm> #include <cstdlib> #include <filesystem> diff --git a/dev/CompilerKit/src/Backend/AssemblerARM64.cc b/dev/CompilerKit/src/Backend/AssemblerARM64.cc index 331e708..ec0f16b 100644 --- a/dev/CompilerKit/src/Backend/AssemblerARM64.cc +++ b/dev/CompilerKit/src/Backend/AssemblerARM64.cc @@ -20,12 +20,12 @@ #endif #include <CompilerKit/AE.h> -#include <CompilerKit/detail/Aarch64.h> #include <CompilerKit/ErrorID.h> #include <CompilerKit/Frontend.h> #include <CompilerKit/PEF.h> -#include <CompilerKit/utils/AsmUtils.h> #include <CompilerKit/Version.h> +#include <CompilerKit/detail/Aarch64.h> +#include <CompilerKit/utils/AsmUtils.h> #include <algorithm> #include <filesystem> #include <fstream> diff --git a/dev/CompilerKit/src/Backend/AssemblerPowerPC.cc b/dev/CompilerKit/src/Backend/AssemblerPowerPC.cc index bbb5a8b..3282ccb 100644 --- a/dev/CompilerKit/src/Backend/AssemblerPowerPC.cc +++ b/dev/CompilerKit/src/Backend/AssemblerPowerPC.cc @@ -20,12 +20,12 @@ #endif #include <CompilerKit/AE.h> -#include <CompilerKit/detail/PowerPC.h> #include <CompilerKit/ErrorID.h> #include <CompilerKit/Frontend.h> #include <CompilerKit/PEF.h> -#include <CompilerKit/utils/AsmUtils.h> #include <CompilerKit/Version.h> +#include <CompilerKit/detail/PowerPC.h> +#include <CompilerKit/utils/AsmUtils.h> #include <algorithm> #include <filesystem> #include <fstream> diff --git a/dev/CompilerKit/src/Frontend/CCompiler64x0.cc b/dev/CompilerKit/src/Frontend/CCompiler64x0.cc index 1221521..de76807 100644 --- a/dev/CompilerKit/src/Frontend/CCompiler64x0.cc +++ b/dev/CompilerKit/src/Frontend/CCompiler64x0.cc @@ -10,9 +10,9 @@ /// BUGS: 0 /// TODO: none -#include <CompilerKit/detail/64x0.h> #include <CompilerKit/Frontend.h> #include <CompilerKit/UUID.h> +#include <CompilerKit/detail/64x0.h> #include <CompilerKit/utils/CompilerUtils.h> #include <cstdio> #include <fstream> @@ -141,8 +141,8 @@ class CompilerFrontend64x0 final : public CompilerKit::CompilerFrontendInterface NECTI_COPY_DEFAULT(CompilerFrontend64x0); - std::string Check(const char* text, const char* file); - CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) override; + std::string Check(const char* text, const char* file); + CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) override; const char* Language() override { return "64k C"; } }; @@ -182,7 +182,8 @@ union double_cast final { ///////////////////////////////////////////////////////////////////////////////////////// -CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontend64x0::Compile(std::string text_, std::string file) { +CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontend64x0::Compile(std::string text_, + std::string file) { std::string text = text_; bool typeFound = false; diff --git a/dev/CompilerKit/src/Frontend/CCompilerARM64.cc b/dev/CompilerKit/src/Frontend/CCompilerARM64.cc index 6795c67..9cfc019 100644 --- a/dev/CompilerKit/src/Frontend/CCompilerARM64.cc +++ b/dev/CompilerKit/src/Frontend/CCompilerARM64.cc @@ -10,9 +10,9 @@ /// BUGS: 0 /// TODO: none -#include <CompilerKit/detail/Aarch64.h> #include <CompilerKit/Frontend.h> #include <CompilerKit/UUID.h> +#include <CompilerKit/detail/Aarch64.h> #include <CompilerKit/utils/CompilerUtils.h> #include <cstdio> @@ -142,8 +142,8 @@ class CompilerFrontendARM64 final : public CompilerKit::CompilerFrontendInterfac NECTI_COPY_DEFAULT(CompilerFrontendARM64); - std::string Check(const char* text, const char* file); - CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) override; + std::string Check(const char* text, const char* file); + CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) override; const char* Language() override { return "64k C"; } }; @@ -183,7 +183,8 @@ union double_cast final { ///////////////////////////////////////////////////////////////////////////////////////// -CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendARM64::Compile(std::string text, std::string file) { +CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendARM64::Compile(std::string text, + std::string file) { bool typeFound = false; bool fnFound = false; diff --git a/dev/CompilerKit/src/Frontend/CCompilerPower64.cc b/dev/CompilerKit/src/Frontend/CCompilerPower64.cc index 1999f48..1888ed0 100644 --- a/dev/CompilerKit/src/Frontend/CCompilerPower64.cc +++ b/dev/CompilerKit/src/Frontend/CCompilerPower64.cc @@ -7,9 +7,9 @@ * ======================================================== */ -#include <CompilerKit/detail/PowerPC.h> #include <CompilerKit/Frontend.h> #include <CompilerKit/UUID.h> +#include <CompilerKit/detail/PowerPC.h> #include <CompilerKit/utils/CompilerUtils.h> #include <cstdio> #include <fstream> @@ -132,8 +132,8 @@ class CompilerFrontendPower64 final : public CompilerKit::CompilerFrontendInterf NECTI_COPY_DEFAULT(CompilerFrontendPower64); - std::string Check(const char* text, const char* file); - CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) override; + std::string Check(const char* text, const char* file); + CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) override; const char* Language() override { return "POWER C"; } }; @@ -173,7 +173,8 @@ union double_cast final { ///////////////////////////////////////////////////////////////////////////////////////// -CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendPower64::Compile(std::string text_, std::string file) { +CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendPower64::Compile(std::string text_, + std::string file) { std::string text = text_; bool typeFound = false; diff --git a/dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc b/dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc index ad2b8e1..c92f2e2 100644 --- a/dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc +++ b/dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc @@ -15,10 +15,10 @@ #define kExitOK (EXIT_SUCCESS) #define kExitNO (EXIT_FAILURE) -#include <CompilerKit/detail/X64.h> #include <CompilerKit/Frontend.h> #include <CompilerKit/PEF.h> #include <CompilerKit/UUID.h> +#include <CompilerKit/detail/X64.h> #include <CompilerKit/utils/CompilerUtils.h> #include <csignal> #include <cstdlib> @@ -48,7 +48,6 @@ ///////////////////////////////////// /// @internal -namespace Detail { // Avoids relative_path which could discard parts of the original. std::filesystem::path expand_home(const std::filesystem::path& input) { const std::string& raw = input.string(); @@ -57,14 +56,12 @@ std::filesystem::path expand_home(const std::filesystem::path& input) { const char* home = std::getenv("HOME"); if (!home) home = std::getenv("USERPROFILE"); - if (!home) - throw std::runtime_error("Home directory not found in environment variables"); + if (!home) throw std::runtime_error("Home directory not found in environment variables"); return std::filesystem::path(home) / raw.substr(1); } return input; - } } struct CompilerRegisterMap final { @@ -90,16 +87,14 @@ struct CompilerState final { /// @brief prints an error into stdout. /// @param reason the reason of the error. /// @param file where does it originate from? -void print_error(const CompilerKit::STLString& reason, const CompilerKit::STLString& file) noexcept { +void print_error(const CompilerKit::STLString& reason, + const CompilerKit::STLString& file) noexcept { kPrintErr << kRed << "Error in " << file << ": " << reason << kWhite << std::endl; } -} // namespace Detail -static Detail::CompilerState kState; +static CompilerState kState; static Int32 kOnClassScope = 0; -static Boolean kVerbose = false; -static Int32 kErrorLimit = 0; ///////////////////////////////////////////////////////////////////////////////////////// @@ -245,7 +240,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( expr.find("<=") + strlen("<=")); auto right = text.substr(expr.find(">=") + strlen(">="), text.find(")") - 1); - // Trim whitespace + // Trim whitespace while (!right.empty() && (right.back() == ' ' || right.back() == '\t')) { right.pop_back(); } @@ -323,8 +318,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( break; accept: - CompilerKit::STLString symbol_name_fn = text; - size_t indexFnName = 0; + CompilerKit::STLString symbol_name_fn = text; + size_t indexFnName = 0; // this one is for the type. for (auto& ch : text) { @@ -369,11 +364,11 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( break; lc_write_assembly: - auto it = - std::find_if(kOriginMap.begin(), kOriginMap.end(), - [&symbol_name_fn](std::pair<CompilerKit::STLString, std::uintptr_t> pair) -> bool { - return symbol_name_fn == pair.first; - }); + auto it = std::find_if( + kOriginMap.begin(), kOriginMap.end(), + [&symbol_name_fn](std::pair<CompilerKit::STLString, std::uintptr_t> pair) -> bool { + return symbol_name_fn == pair.first; + }); if (it != kOriginMap.end()) { std::stringstream ss; @@ -490,8 +485,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( if (pairRight != valueOfVar) { if (valueOfVar[0] == '\"') { - syntax_tree.fUserValue = "segment .data64 __NECTI_LOCAL_VAR_" + varName + - ": db " + valueOfVar + ", 0\n\n"; + syntax_tree.fUserValue = "segment .data64 __NECTI_LOCAL_VAR_" + varName + ": db " + + valueOfVar + ", 0\n\n"; syntax_tree.fUserValue += instr + kRegisterList[kRegisterMap.size() - 1] + ", " + "__NECTI_LOCAL_VAR_" + varName + "\n"; kOrigin += 1UL; @@ -507,8 +502,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( if (((int) indexRight - 1) < 0) { if (valueOfVar[0] == '\"') { - syntax_tree.fUserValue = "segment .data64 __NECTI_LOCAL_VAR_" + varName + - ": db " + valueOfVar + ", 0\n"; + syntax_tree.fUserValue = + "segment .data64 __NECTI_LOCAL_VAR_" + varName + ": db " + valueOfVar + ", 0\n"; syntax_tree.fUserValue += instr + kRegisterList[kRegisterMap.size()] + ", " + "__NECTI_LOCAL_VAR_" + varName + "\n"; kOrigin += 1UL; @@ -521,7 +516,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( goto done; } - if (!valueOfVar.empty() && valueOfVar[0] != '\"' && valueOfVar[0] != '\'' && !isdigit(valueOfVar[0])) { + if (!valueOfVar.empty() && valueOfVar[0] != '\"' && valueOfVar[0] != '\'' && + !isdigit(valueOfVar[0])) { for (auto pair : kRegisterMap) { if (pair == valueOfVar) goto done; } @@ -819,14 +815,13 @@ NECTI_MODULE(CompilerCPlusPlusAMD64) { kFactory.Mount(new AssemblyCPlusPlusInterfaceAMD64()); CompilerKit::install_signal(SIGSEGV, Detail::drvi_crash_handler); - + // Ensure cleanup on exit std::atexit([]() { delete kCompilerFrontend; kCompilerFrontend = nullptr; }); - for (auto index = 1UL; index < argc; ++index) { if (!argv[index]) break; @@ -835,7 +830,6 @@ NECTI_MODULE(CompilerCPlusPlusAMD64) { skip = false; continue; } - if (strcmp(argv[index], "-cxx-verbose") == 0) { kVerbose = true; diff --git a/dev/CompilerKit/src/Linker/DynamicLinker64PEF.cc b/dev/CompilerKit/src/Linker/DynamicLinker64PEF.cc index 394014c..2d149df 100644 --- a/dev/CompilerKit/src/Linker/DynamicLinker64PEF.cc +++ b/dev/CompilerKit/src/Linker/DynamicLinker64PEF.cc @@ -13,19 +13,19 @@ /// @note Do not look up for anything with .code64/.data64/.zero64! /// It will be loaded when the program loader will start the image. - +#include <CompilerKit/AE.h> +#include <CompilerKit/Compiler.h> #include <CompilerKit/Defines.h> #include <CompilerKit/ErrorID.h> -#include <CompilerKit/Compiler.h> #include <CompilerKit/PEF.h> #include <CompilerKit/UUID.h> #include <CompilerKit/Version.h> -#include <CompilerKit/AE.h> #include <CompilerKit/utils/CompilerUtils.h> -#define kLinkerVersionStr \ - "NeKernel.org 64-Bit Linker (Preferred Executable Format) %s, (c) Amlal El Mahrouss, and NeKernel Contributors " \ - "2024-2025 " \ +#define kLinkerVersionStr \ + "NeKernel.org 64-Bit Linker (Preferred Executable Format) %s, (c) Amlal El Mahrouss, and " \ + "NeKernel Contributors " \ + "2024-2025 " \ "all rights reserved.\n" #define MemoryCopy(DST, SRC, SZ) memcpy(DST, SRC, SZ) @@ -44,10 +44,7 @@ /// @brief PEF stack size symbol. #define kLinkerStackSizeSymbol "__PEFSizeOfReserveStack" -#define kConsoleOut \ - (std::cout << "\e[0;31m" \ - << "ld64: " \ - << "\e[0;97m") +#define kConsoleOut (std::cout << "\e[0;31m" << "ld64: " << "\e[0;97m") enum { kABITypeNull = 0, diff --git a/dev/CompilerKit/src/StringKit.cc b/dev/CompilerKit/src/StringKit.cc index 13142a6..67f2f55 100644 --- a/dev/CompilerKit/src/StringKit.cc +++ b/dev/CompilerKit/src/StringKit.cc @@ -42,7 +42,7 @@ bool BasicString::operator==(const BasicString& rhs) const { bool BasicString::operator==(const Char* rhs) const { const SizeType rhs_len = string_length(rhs); - const SizeType len = Length(); + const SizeType len = Length(); if (rhs_len != len) return false; return memcmp(m_Data, rhs, len) == 0; } @@ -74,7 +74,7 @@ BasicString StringBuilder::FromInt(const char* fmt, int i) { const SizeType res_len = string_length(result); BasicString output(fmt_len + res_len); - bool inserted = false; + bool inserted = false; for (SizeType idx = 0; idx < fmt_len; ++idx) { if (!inserted && fmt[idx] == '%') { @@ -91,12 +91,12 @@ BasicString StringBuilder::FromInt(const char* fmt, int i) { BasicString StringBuilder::FromBool(const char* fmt, bool val) { if (!fmt) return BasicString(0); - const Char* boolean_expr = val ? "true" : "false"; - const SizeType fmt_len = string_length(fmt); - const SizeType res_len = string_length(boolean_expr); + const Char* boolean_expr = val ? "true" : "false"; + const SizeType fmt_len = string_length(fmt); + const SizeType res_len = string_length(boolean_expr); BasicString output(fmt_len + res_len); - bool inserted = false; + bool inserted = false; for (SizeType idx = 0; idx < fmt_len; ++idx) { if (!inserted && fmt[idx] == '%') { @@ -125,7 +125,7 @@ BasicString StringBuilder::Format(const char* fmt, const char* fmtRight) { const SizeType rhs_len = string_length(fmtRight); BasicString output(fmt_len + rhs_len); - bool inserted = false; + bool inserted = false; for (SizeType idx = 0; idx < fmt_len; ++idx) { if (!inserted && fmt[idx] == '%') { @@ -146,7 +146,7 @@ BasicString& BasicString::operator+=(const Char* rhs) { } memcpy(this->m_Data + this->m_Cur, rhs, rhs_len); - + this->m_Cur += rhs_len; this->m_Data[this->m_Cur] = '\0'; @@ -171,9 +171,9 @@ BasicString& BasicString::operator+=(const Char ch) { } this->m_Data[this->m_Cur++] = ch; - this->m_Data[this->m_Cur] = '\0'; + this->m_Data[this->m_Cur] = '\0'; return *this; } -} // namespace CompilerKit +} // namespace CompilerKit |
