From f6b400b80efc64b918c03352e93ec9de4e2369a1 Mon Sep 17 00:00:00 2001 From: Amlal Date: Fri, 25 Apr 2025 19:21:22 +0200 Subject: dev, general: codebase needed refactors and tweaks, for NeKernel's 0.0.2 release. details: - things needed to be cleared off, short sighted decisions fixed. - the inconsistency of certain files have been fixed too. Signed-off-by: Amlal --- dev/LibCompiler/src/Assembler64x0.cc | 46 ++----------- dev/LibCompiler/src/AssemblerAMD64.cc | 12 +--- dev/LibCompiler/src/AssemblerARM64.cc | 14 +--- dev/LibCompiler/src/AssemblerPower.cc | 12 +--- dev/LibCompiler/src/CCompilerARM64.cc | 2 +- dev/LibCompiler/src/CCompilerPower64.cc | 2 +- dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc | 9 +-- dev/LibCompiler/src/Detail/AsmUtils.h | 96 --------------------------- dev/LibCompiler/src/Detail/ClUtils.h | 18 ----- 9 files changed, 19 insertions(+), 192 deletions(-) delete mode 100644 dev/LibCompiler/src/Detail/AsmUtils.h delete mode 100644 dev/LibCompiler/src/Detail/ClUtils.h (limited to 'dev/LibCompiler/src') diff --git a/dev/LibCompiler/src/Assembler64x0.cc b/dev/LibCompiler/src/Assembler64x0.cc index 7701982..9dc8e52 100644 --- a/dev/LibCompiler/src/Assembler64x0.cc +++ b/dev/LibCompiler/src/Assembler64x0.cc @@ -28,6 +28,7 @@ #include #include #include +#include ///////////////////// @@ -35,29 +36,16 @@ ///////////////////// -#define kBlank "\e[0;30m" -#define kRed "\e[0;31m" -#define kWhite "\e[0;97m" -#define kYellow "\e[0;33m" - -#define kStdOut (std::cout << kWhite) -#define kStdErr (std::cout << kRed) - static char kOutputArch = LibCompiler::kPefArch64000; -static Boolean kOutputAsBinary = false; -static UInt32 kErrorLimit = 10; -static UInt32 kAcceptableErrors = 0; - -constexpr auto c64x0IPAlignment = 0x4U; +/// @note The 64x0 is VLSIW, so we need to jump to 4 bytes. +constexpr auto k64x0IPAlignment = 0x4U; static std::size_t kCounter = 1UL; static std::uintptr_t kOrigin = kPefBaseOrigin; static std::vector> kOriginLabel; -static bool kVerbose = false; - static std::vector kBytes; static LibCompiler::AERecordHeader kCurrentRecord{ @@ -72,32 +60,6 @@ static const std::string kRelocSymbol = ":RuntimeSymbol:"; // \brief forward decl. static bool asm_read_attributes(std::string& line); -namespace Detail { -void print_error(std::string reason, std::string file) noexcept { - if (reason[0] == '\n') reason.erase(0, 1); - - kStdErr << kRed << "[ asm ] " << kWhite - << ((file == "LibCompiler") ? "InternalErrorException: " - : ("FileException{ " + file + " }: ")) - << kBlank << std::endl; - kStdErr << kRed << "[ asm ] " << kWhite << reason << kBlank << std::endl; - - if (kAcceptableErrors > kErrorLimit) std::exit(3); - - ++kAcceptableErrors; -} - -void print_warning(std::string reason, std::string file) noexcept { - if (reason[0] == '\n') reason.erase(0, 1); - - if (!file.empty()) { - kStdOut << kYellow << "[ asm ] " << kWhite << file << kBlank << std::endl; - } - - kStdOut << kYellow << "[ asm ] " << kWhite << reason << kBlank << std::endl; -} -} // namespace Detail - ///////////////////////////////////////////////////////////////////////////////////////// // @brief 64x0 assembler entrypoint, the program/module starts here. @@ -897,7 +859,7 @@ bool LibCompiler::Encoder64x0::WriteLine(std::string& line, const std::string& f } asm_end_label_cpy: - kOrigin += c64x0IPAlignment; + kOrigin += k64x0IPAlignment; break; } diff --git a/dev/LibCompiler/src/AssemblerAMD64.cc b/dev/LibCompiler/src/AssemblerAMD64.cc index a5a7ee5..7dfa36a 100644 --- a/dev/LibCompiler/src/AssemblerAMD64.cc +++ b/dev/LibCompiler/src/AssemblerAMD64.cc @@ -27,7 +27,7 @@ #define kAssemblerPragmaSym '#' #include -#include +#include #include #include #include @@ -52,12 +52,8 @@ #define kStdErr (std::cout << kRed) static char kOutputArch = LibCompiler::kPefArchAMD64; -static Boolean kOutputAsBinary = false; -static UInt32 kErrorLimit = 10; -static UInt32 kAcceptableErrors = 0; - -constexpr auto kIPAlignement = 0x4U; +constexpr auto kIPAlignement = 0x1U; static std::size_t kCounter = 1UL; @@ -67,8 +63,6 @@ static std::vector> kOriginLabel; /// @brief keep it simple by default. static std::int32_t kRegisterBitWidth = 16U; -static bool kVerbose = false; - static std::vector kAppBytes; static LibCompiler::AERecordHeader kCurrentRecord{ @@ -83,7 +77,7 @@ static const std::string kUndefinedSymbol = ":UndefinedSymbol:"; // \brief forward decl. static bool asm_read_attributes(std::string& line); -#include +#include ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/dev/LibCompiler/src/AssemblerARM64.cc b/dev/LibCompiler/src/AssemblerARM64.cc index d984845..98f12b8 100644 --- a/dev/LibCompiler/src/AssemblerARM64.cc +++ b/dev/LibCompiler/src/AssemblerARM64.cc @@ -18,11 +18,12 @@ #define __ASM_NEED_ARM64__ 1 #include -#include +#include #include #include #include #include +#include #include #include #include @@ -43,21 +44,15 @@ #define kStdOut (std::cout << kWhite) #define kStdErr (std::cout << kRed) -constexpr auto cPowerIPAlignment = 0x4U; +constexpr auto cPowerIPAlignment = 0x1U; static CharType kOutputArch = LibCompiler::kPefArchARM64; -static Boolean kOutputAsBinary = false; - -static UInt32 kErrorLimit = 10; -static UInt32 kAcceptableErrors = 0; static std::size_t kCounter = 1UL; static std::uintptr_t kOrigin = kPefBaseOrigin; static std::vector> kOriginLabel; -static bool kVerbose = false; - static std::vector kBytes; static LibCompiler::AERecordHeader kCurrentRecord{ @@ -72,9 +67,6 @@ static const std::string kRelocSymbol = ":RuntimeSymbol:"; // \brief forward decl. static bool asm_read_attributes(std::string& line); -/// Do not move it on top! it uses the assembler detail namespace! -#include - ///////////////////////////////////////////////////////////////////////////////////////// /// @brief POWER assembler entrypoint, the program/module starts here. diff --git a/dev/LibCompiler/src/AssemblerPower.cc b/dev/LibCompiler/src/AssemblerPower.cc index 30b6d68..d3b3b6d 100644 --- a/dev/LibCompiler/src/AssemblerPower.cc +++ b/dev/LibCompiler/src/AssemblerPower.cc @@ -18,7 +18,7 @@ #define __ASM_NEED_PPC__ 1 #include -#include +#include #include #include #include @@ -28,6 +28,7 @@ #include #include #include +#include ///////////////////// @@ -46,18 +47,12 @@ constexpr auto cPowerIPAlignment = 0x4U; static CharType kOutputArch = LibCompiler::kPefArchPowerPC; -static Boolean kOutputAsBinary = false; - -static UInt32 kErrorLimit = 10; -static UInt32 kAcceptableErrors = 0; static std::size_t kCounter = 1UL; static std::uintptr_t kOrigin = kPefBaseOrigin; static std::vector> kOriginLabel; -static bool kVerbose = false; - static std::vector kBytes; static LibCompiler::AERecordHeader kCurrentRecord{ @@ -72,9 +67,6 @@ static const std::string kRelocSymbol = ":RuntimeSymbol:"; // \brief forward decl. static bool asm_read_attributes(std::string& line); -/// Do not move it on top! it uses the assembler detail namespace! -#include - ///////////////////////////////////////////////////////////////////////////////////////// /// @brief POWER assembler entrypoint, the program/module starts here. diff --git a/dev/LibCompiler/src/CCompilerARM64.cc b/dev/LibCompiler/src/CCompilerARM64.cc index accd9f9..7339840 100644 --- a/dev/LibCompiler/src/CCompilerARM64.cc +++ b/dev/LibCompiler/src/CCompilerARM64.cc @@ -10,7 +10,7 @@ /// BUGS: 0 /// TODO: none -#include +#include #include #include #include diff --git a/dev/LibCompiler/src/CCompilerPower64.cc b/dev/LibCompiler/src/CCompilerPower64.cc index 90031a0..42c4a0a 100644 --- a/dev/LibCompiler/src/CCompilerPower64.cc +++ b/dev/LibCompiler/src/CCompilerPower64.cc @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include #include #include diff --git a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc index 66cf859..558a94d 100644 --- a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc +++ b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc @@ -21,10 +21,12 @@ // extern_segment, @autodelete { ... }, fn foo() -> auto { ... } -#include +#include #include #include +#include + #include /* NE C++ Compiler */ @@ -99,12 +101,9 @@ struct CompilerState final { } // namespace Detail static Detail::CompilerState kState; -static SizeType kErrorLimit = 100; static Int32 kOnClassScope = 0; -static Int32 kAcceptableErrors = 0; - namespace Detail { /// @brief prints an error into stdout. /// @param reason the reason of the error. @@ -939,6 +938,8 @@ LIBCOMPILER_MODULE(CompilerCPlusPlusAMD64) { kKeywords.push_back({.keyword_name = ">=", .keyword_kind = LibCompiler::kKeywordKindGreaterEq}); kKeywords.push_back({.keyword_name = "<=", .keyword_kind = LibCompiler::kKeywordKindLessEq}); + kErrorLimit = 100; + kFactory.Mount(new AssemblyCPlusPlusInterface()); kCompilerFrontend = new CompilerFrontendCPlusPlus(); diff --git a/dev/LibCompiler/src/Detail/AsmUtils.h b/dev/LibCompiler/src/Detail/AsmUtils.h deleted file mode 100644 index 358700a..0000000 --- a/dev/LibCompiler/src/Detail/AsmUtils.h +++ /dev/null @@ -1,96 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved - -------------------------------------------- */ - -#pragma once - -#include -#include - -using namespace LibCompiler; - -namespace Detail { -extern void print_error(std::string reason, std::string file) noexcept; -extern void print_warning(std::string reason, std::string file) noexcept; -} // namespace Detail - -/// @brief Get Number from lineBuffer. -/// @param lineBuffer the lineBuffer to fetch from. -/// @param numberKey where to seek that number. -/// @return -static NumberCast32 GetNumber32(std::string lineBuffer, std::string numberKey) { - auto pos = lineBuffer.find(numberKey) + numberKey.size(); - - while (lineBuffer[pos] == ' ') { - ++pos; - } - - switch (lineBuffer[pos + 1]) { - case 'x': { - if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 16); !res) { - if (errno != 0) { - Detail::print_error("invalid hex number: " + lineBuffer, "LibCompiler"); - throw std::runtime_error("invalid_hex"); - } - } - - NumberCast32 numOffset(strtol(lineBuffer.substr(pos).c_str(), nullptr, 16)); - - if (kVerbose) { - kStdOut << "asm: found a base 16 number here: " << lineBuffer.substr(pos) << "\n"; - } - - return numOffset; - } - case 'b': { - if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 2); !res) { - if (errno != 0) { - Detail::print_error("invalid binary number:" + lineBuffer, "LibCompiler"); - throw std::runtime_error("invalid_bin"); - } - } - - NumberCast32 numOffset(strtol(lineBuffer.substr(pos).c_str(), nullptr, 2)); - - if (kVerbose) { - kStdOut << "asm: found a base 2 number here:" << lineBuffer.substr(pos) << "\n"; - } - - return numOffset; - } - case 'o': { - if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 7); !res) { - if (errno != 0) { - Detail::print_error("invalid octal number: " + lineBuffer, "LibCompiler"); - throw std::runtime_error("invalid_octal"); - } - } - - NumberCast32 numOffset(strtol(lineBuffer.substr(pos).c_str(), nullptr, 7)); - - if (kVerbose) { - kStdOut << "asm: found a base 8 number here:" << lineBuffer.substr(pos) << "\n"; - } - - return numOffset; - } - default: { - if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 10); !res) { - if (errno != 0) { - Detail::print_error("invalid hex number: " + lineBuffer, "LibCompiler"); - throw std::runtime_error("invalid_hex"); - } - } - - NumberCast32 numOffset(strtol(lineBuffer.substr(pos).c_str(), nullptr, 10)); - - if (kVerbose) { - kStdOut << "asm: found a base 10 number here:" << lineBuffer.substr(pos) << "\n"; - } - - return numOffset; - } - } -} diff --git a/dev/LibCompiler/src/Detail/ClUtils.h b/dev/LibCompiler/src/Detail/ClUtils.h deleted file mode 100644 index 024d0d2..0000000 --- a/dev/LibCompiler/src/Detail/ClUtils.h +++ /dev/null @@ -1,18 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved - -------------------------------------------- */ - -#pragma once - -#include -#include - -#define kZero64Section ".zero64" -#define kCode64Section ".code64" -#define kData64Section ".data64" - -#define kZero128Section ".zero128" -#define kCode128Section ".code128" -#define kData128Section ".data128" -- cgit v1.2.3