diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-25 19:21:22 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-25 19:21:51 +0200 |
| commit | f6b400b80efc64b918c03352e93ec9de4e2369a1 (patch) | |
| tree | 251a82ee3653568ef33ffdc48c83b7f54e370bc1 /dev/LibCompiler/src | |
| parent | 20042235d1f53ae428aa154e64afdbae5d8d91ad (diff) | |
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 <amlal@nekernel.org>
Diffstat (limited to 'dev/LibCompiler/src')
| -rw-r--r-- | dev/LibCompiler/src/Assembler64x0.cc | 46 | ||||
| -rw-r--r-- | dev/LibCompiler/src/AssemblerAMD64.cc | 12 | ||||
| -rw-r--r-- | dev/LibCompiler/src/AssemblerARM64.cc | 14 | ||||
| -rw-r--r-- | dev/LibCompiler/src/AssemblerPower.cc | 12 | ||||
| -rw-r--r-- | dev/LibCompiler/src/CCompilerARM64.cc | 2 | ||||
| -rw-r--r-- | dev/LibCompiler/src/CCompilerPower64.cc | 2 | ||||
| -rw-r--r-- | dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc | 9 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Detail/AsmUtils.h | 96 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Detail/ClUtils.h | 18 |
9 files changed, 19 insertions, 192 deletions
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 <fstream> #include <iostream> #include <vector> +#include <LibCompiler/Detail/ClUtils.h> ///////////////////// @@ -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<std::pair<std::string, std::uintptr_t>> kOriginLabel; -static bool kVerbose = false; - static std::vector<e64k_num_t> 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 <LibCompiler/AE.h> -#include <LibCompiler/Backend/amd64.h> +#include <LibCompiler/Backend/Amd64.h> #include <LibCompiler/PEF.h> #include <LibCompiler/Parser.h> #include <algorithm> @@ -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<std::pair<std::string, std::uintptr_t>> kOriginLabel; /// @brief keep it simple by default. static std::int32_t kRegisterBitWidth = 16U; -static bool kVerbose = false; - static std::vector<i64_byte_t> 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 <AsmUtils.h> +#include <LibCompiler/Detail/AsmUtils.h> ///////////////////////////////////////////////////////////////////////////////////////// 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 <LibCompiler/AE.h> -#include <LibCompiler/Backend/arm64.h> +#include <LibCompiler/Backend/Aarch64.h> #include <LibCompiler/ErrorID.h> #include <LibCompiler/PEF.h> #include <LibCompiler/Parser.h> #include <LibCompiler/Version.h> +#include <LibCompiler/Detail/AsmUtils.h> #include <algorithm> #include <filesystem> #include <fstream> @@ -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<std::pair<std::string, std::uintptr_t>> kOriginLabel; -static bool kVerbose = false; - static std::vector<uint8_t> 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 <Detail/AsmUtils.h> - ///////////////////////////////////////////////////////////////////////////////////////// /// @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 <LibCompiler/AE.h> -#include <LibCompiler/Backend/power64.h> +#include <LibCompiler/Backend/PowerPC.h> #include <LibCompiler/ErrorID.h> #include <LibCompiler/PEF.h> #include <LibCompiler/Parser.h> @@ -28,6 +28,7 @@ #include <fstream> #include <iostream> #include <vector> +#include <LibCompiler/Detail/AsmUtils.h> ///////////////////// @@ -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<std::pair<std::string, std::uintptr_t>> kOriginLabel; -static bool kVerbose = false; - static std::vector<uint8_t> 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 <AsmUtils.h> - ///////////////////////////////////////////////////////////////////////////////////////// /// @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 <LibCompiler/Backend/arm64.h> +#include <LibCompiler/Backend/Aarch64.h> #include <LibCompiler/Parser.h> #include <LibCompiler/UUID.h> #include <cstdio> 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 <LibCompiler/Backend/power64.h> +#include <LibCompiler/Backend/PowerPC.h> #include <LibCompiler/Parser.h> #include <LibCompiler/UUID.h> #include <cstdio> 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 <LibCompiler/Backend/amd64.h> +#include <LibCompiler/Backend/Amd64.h> #include <LibCompiler/Parser.h> #include <LibCompiler/UUID.h> +#include <LibCompiler/Detail/ClUtils.h> + #include <cstdio> /* 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 <LibCompiler/AssemblyInterface.h> -#include <LibCompiler/Parser.h> - -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 <LibCompiler/AssemblyInterface.h> -#include <LibCompiler/Parser.h> - -#define kZero64Section ".zero64" -#define kCode64Section ".code64" -#define kData64Section ".data64" - -#define kZero128Section ".zero128" -#define kCode128Section ".code128" -#define kData128Section ".data128" |
