diff options
Diffstat (limited to 'dev/LibCompiler/src')
| -rw-r--r-- | dev/LibCompiler/src/Assembler64x0.cc | 10 | ||||
| -rw-r--r-- | dev/LibCompiler/src/AssemblerAMD64.cc | 14 | ||||
| -rw-r--r-- | dev/LibCompiler/src/AssemblerARM64.cc | 10 | ||||
| -rw-r--r-- | dev/LibCompiler/src/AssemblerPowerPC.cc (renamed from dev/LibCompiler/src/AssemblerPower.cc) | 10 | ||||
| -rw-r--r-- | dev/LibCompiler/src/AssemblyFactory.cc | 2 | ||||
| -rw-r--r-- | dev/LibCompiler/src/CCompiler64x0.cc | 2 | ||||
| -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 | 40 | ||||
| -rw-r--r-- | dev/LibCompiler/src/DynamicLinkerPEF.cc | 19 |
10 files changed, 50 insertions, 61 deletions
diff --git a/dev/LibCompiler/src/Assembler64x0.cc b/dev/LibCompiler/src/Assembler64x0.cc index fe0e8e2..6d4d31a 100644 --- a/dev/LibCompiler/src/Assembler64x0.cc +++ b/dev/LibCompiler/src/Assembler64x0.cc @@ -58,7 +58,7 @@ static const std::string kUndefinedSymbol = ":UndefinedSymbol:"; static const std::string kRelocSymbol = ":RuntimeSymbol:"; // \brief forward decl. -static bool asm_read_attributes(std::string& line); +static bool asm_read_attributes(std::string line); ///////////////////////////////////////////////////////////////////////////////////////// @@ -260,7 +260,7 @@ asm_fail_exit: ///////////////////////////////////////////////////////////////////////////////////////// -static bool asm_read_attributes(std::string& line) { +static bool asm_read_attributes(std::string line) { // extern_segment is the opposite of public_segment, it signals to the ld // that we need this symbol. if (LibCompiler::find_word(line, "extern_segment")) { @@ -395,7 +395,7 @@ static inline bool is_not_alnum_space(char c) { (c == '_') || (c == ':') || (c == '@') || (c == '.')); } -bool is_valid_64x0(const std::string& str) { +bool is_valid_64x0(std::string str) { return std::find_if(str.begin(), str.end(), is_not_alnum_space) == str.end(); } } // namespace Detail::algorithm @@ -406,7 +406,7 @@ bool is_valid_64x0(const std::string& str) { ///////////////////////////////////////////////////////////////////////////////////////// -std::string LibCompiler::Encoder64x0::CheckLine(std::string& line, const std::string& file) { +std::string LibCompiler::Encoder64x0::CheckLine(std::string line, std::string file) { std::string err_str; if (line.empty() || LibCompiler::find_word(line, "extern_segment") || @@ -607,7 +607,7 @@ bool LibCompiler::Encoder64x0::WriteNumber(const std::size_t& pos, std::string& ///////////////////////////////////////////////////////////////////////////////////////// -bool LibCompiler::Encoder64x0::WriteLine(std::string& line, const std::string& file) { +bool LibCompiler::Encoder64x0::WriteLine(std::string line, std::string file) { if (LibCompiler::find_word(line, "public_segment ")) return true; for (auto& opcode64x0 : kOpcodes64x0) { diff --git a/dev/LibCompiler/src/AssemblerAMD64.cc b/dev/LibCompiler/src/AssemblerAMD64.cc index dd6b7be..f8772b8 100644 --- a/dev/LibCompiler/src/AssemblerAMD64.cc +++ b/dev/LibCompiler/src/AssemblerAMD64.cc @@ -75,7 +75,7 @@ static std::vector<std::string> kUndefinedSymbols; static const std::string kUndefinedSymbol = ":UndefinedSymbol:"; // \brief forward decl. -static bool asm_read_attributes(std::string& line); +static bool asm_read_attributes(std::string line); #include <LibCompiler/Detail/AsmUtils.h> @@ -334,7 +334,7 @@ asm_fail_exit: ///////////////////////////////////////////////////////////////////////////////////////// -static bool asm_read_attributes(std::string& line) { +static bool asm_read_attributes(std::string line) { // extern_segment is the opposite of public_segment, it signals to the ld // that we need this symbol. if (LibCompiler::find_word(line, "extern_segment")) { @@ -479,7 +479,7 @@ static inline bool is_not_valid(char c) { return true; } -bool is_valid_amd64(const std::string& str) { +bool is_valid_amd64(std::string str) { return std::find_if(str.begin(), str.end(), is_not_valid) == str.end(); } } // namespace Detail::algorithm @@ -490,7 +490,7 @@ bool is_valid_amd64(const std::string& str) { ///////////////////////////////////////////////////////////////////////////////////////// -std::string LibCompiler::EncoderAMD64::CheckLine(std::string& line, const std::string& file) { +std::string LibCompiler::EncoderAMD64::CheckLine(std::string line, std::string file) { std::string err_str; if (line.empty() || LibCompiler::find_word(line, "extern_segment") || @@ -950,7 +950,7 @@ bool LibCompiler::EncoderAMD64::WriteNumber8(const std::size_t& pos, std::string ///////////////////////////////////////////////////////////////////////////////////////// -bool LibCompiler::EncoderAMD64::WriteLine(std::string& line, const std::string& file) { +bool LibCompiler::EncoderAMD64::WriteLine(std::string line, std::string file) { if (LibCompiler::find_word(line, "public_segment ")) return true; struct RegMapAMD64 { @@ -1135,7 +1135,7 @@ bool LibCompiler::EncoderAMD64::WriteLine(std::string& line, const std::string& if (line[0] == kAssemblerPragmaSym) { if (foundInstruction) { - Detail::print_error("Syntax error: " + line, "LibCompiler"); + Detail::print_error("Syntax error: " + line, file); throw std::runtime_error("syntax_err"); } @@ -1156,7 +1156,7 @@ bool LibCompiler::EncoderAMD64::WriteLine(std::string& line, const std::string& continue; } else { if (kVerbose) { - kStdOut << "AssemblerAMD64: origin set: " << kOrigin << std::endl; + kStdOut << "AssemblerAMD64: Origin Set: " << kOrigin << std::endl; } break; diff --git a/dev/LibCompiler/src/AssemblerARM64.cc b/dev/LibCompiler/src/AssemblerARM64.cc index 6c651aa..eb3e915 100644 --- a/dev/LibCompiler/src/AssemblerARM64.cc +++ b/dev/LibCompiler/src/AssemblerARM64.cc @@ -65,7 +65,7 @@ static const std::string kUndefinedSymbol = ":UndefinedSymbol:"; static const std::string kRelocSymbol = ":RuntimeSymbol:"; // \brief forward decl. -static bool asm_read_attributes(std::string& line); +static bool asm_read_attributes(std::string line); ///////////////////////////////////////////////////////////////////////////////////////// @@ -267,7 +267,7 @@ asm_fail_exit: ///////////////////////////////////////////////////////////////////////////////////////// -static bool asm_read_attributes(std::string& line) { +static bool asm_read_attributes(std::string line) { // extern_segment is the opposite of public_segment, it signals to the li // that we need this symbol. if (LibCompiler::find_word(line, "extern_segment")) { @@ -401,7 +401,7 @@ static inline bool is_not_alnum_space(char c) { (c == '_') || (c == ':') || (c == '@') || (c == '.')); } -bool is_valid_arm64(const std::string& str) { +bool is_valid_arm64(std::string str) { return std::find_if(str.begin(), str.end(), is_not_alnum_space) == str.end(); } } // namespace Detail::algorithm @@ -412,7 +412,7 @@ bool is_valid_arm64(const std::string& str) { ///////////////////////////////////////////////////////////////////////////////////////// -std::string LibCompiler::EncoderARM64::CheckLine(std::string& line, const std::string& file) { +std::string LibCompiler::EncoderARM64::CheckLine(std::string line, std::string file) { std::string err_str; if (line.empty() || LibCompiler::find_word(line, "extern_segment") || @@ -575,7 +575,7 @@ bool LibCompiler::EncoderARM64::WriteNumber(const std::size_t& pos, std::string& ///////////////////////////////////////////////////////////////////////////////////////// -bool LibCompiler::EncoderARM64::WriteLine(std::string& line, const std::string& file) { +bool LibCompiler::EncoderARM64::WriteLine(std::string line, std::string file) { if (LibCompiler::find_word(line, "public_segment")) return false; if (!Detail::algorithm::is_valid_arm64(line)) return false; diff --git a/dev/LibCompiler/src/AssemblerPower.cc b/dev/LibCompiler/src/AssemblerPowerPC.cc index 923008c..ffe5c6a 100644 --- a/dev/LibCompiler/src/AssemblerPower.cc +++ b/dev/LibCompiler/src/AssemblerPowerPC.cc @@ -65,7 +65,7 @@ static const std::string kUndefinedSymbol = ":UndefinedSymbol:"; static const std::string kRelocSymbol = ":RuntimeSymbol:"; // \brief forward decl. -static bool asm_read_attributes(std::string& line); +static bool asm_read_attributes(std::string line); ///////////////////////////////////////////////////////////////////////////////////////// @@ -267,7 +267,7 @@ asm_fail_exit: ///////////////////////////////////////////////////////////////////////////////////////// -static bool asm_read_attributes(std::string& line) { +static bool asm_read_attributes(std::string line) { // extern_segment is the opposite of public_segment, it signals to the li // that we need this symbol. if (LibCompiler::find_word(line, "extern_segment")) { @@ -401,7 +401,7 @@ static inline bool is_not_alnum_space(char c) { (c == '_') || (c == ':') || (c == '@') || (c == '.')); } -bool is_valid_power64(const std::string& str) { +bool is_valid_power64(std::string str) { return std::find_if(str.begin(), str.end(), is_not_alnum_space) == str.end(); } } // namespace Detail::algorithm @@ -412,7 +412,7 @@ bool is_valid_power64(const std::string& str) { ///////////////////////////////////////////////////////////////////////////////////////// -std::string LibCompiler::EncoderPowerPC::CheckLine(std::string& line, const std::string& file) { +std::string LibCompiler::EncoderPowerPC::CheckLine(std::string line, std::string file) { std::string err_str; if (line.empty() || LibCompiler::find_word(line, "extern_segment") || @@ -612,7 +612,7 @@ bool LibCompiler::EncoderPowerPC::WriteNumber(const std::size_t& pos, std::strin ///////////////////////////////////////////////////////////////////////////////////////// -bool LibCompiler::EncoderPowerPC::WriteLine(std::string& line, const std::string& file) { +bool LibCompiler::EncoderPowerPC::WriteLine(std::string line, std::string file) { if (LibCompiler::find_word(line, "public_segment")) return false; if (!Detail::algorithm::is_valid_power64(line)) return false; diff --git a/dev/LibCompiler/src/AssemblyFactory.cc b/dev/LibCompiler/src/AssemblyFactory.cc index 4695c63..8fa12a8 100644 --- a/dev/LibCompiler/src/AssemblyFactory.cc +++ b/dev/LibCompiler/src/AssemblyFactory.cc @@ -25,7 +25,7 @@ namespace LibCompiler { ///! @brief Compile for specific format (ELF, PEF, ZBIN) -Int32 AssemblyFactory::Compile(std::string& sourceFile, const Int32& arch) noexcept { +Int32 AssemblyFactory::Compile(std::string sourceFile, const Int32& arch) noexcept { if (sourceFile.length() < 1 || !fMounted) return LIBCOMPILER_UNIMPLEMENTED; return fMounted->CompileToFormat(sourceFile, arch); diff --git a/dev/LibCompiler/src/CCompiler64x0.cc b/dev/LibCompiler/src/CCompiler64x0.cc index dea3ebd..6fa05fb 100644 --- a/dev/LibCompiler/src/CCompiler64x0.cc +++ b/dev/LibCompiler/src/CCompiler64x0.cc @@ -1054,7 +1054,7 @@ class AssemblyCCInterface final ASSEMBLY_INTERFACE { [[maybe_unused]] static Int32 Arch() noexcept { return LibCompiler::AssemblyFactory::kArch64x0; } - Int32 CompileToFormat(std::string& src, Int32 arch) override { + Int32 CompileToFormat(std::string src, Int32 arch) override { if (arch != AssemblyCCInterface::Arch()) return 1; if (kCompilerFrontend == nullptr) return 1; diff --git a/dev/LibCompiler/src/CCompilerARM64.cc b/dev/LibCompiler/src/CCompilerARM64.cc index 7339840..b2f36e9 100644 --- a/dev/LibCompiler/src/CCompilerARM64.cc +++ b/dev/LibCompiler/src/CCompilerARM64.cc @@ -1054,7 +1054,7 @@ class AssemblyCCInterface final ASSEMBLY_INTERFACE { return LibCompiler::AssemblyFactory::kArchAARCH64; } - Int32 CompileToFormat(std::string& src, Int32 arch) override { + Int32 CompileToFormat(std::string src, Int32 arch) override { if (arch != AssemblyCCInterface::Arch()) return 1; if (kCompilerFrontend == nullptr) return 1; diff --git a/dev/LibCompiler/src/CCompilerPower64.cc b/dev/LibCompiler/src/CCompilerPower64.cc index 42c4a0a..ee9c5a4 100644 --- a/dev/LibCompiler/src/CCompilerPower64.cc +++ b/dev/LibCompiler/src/CCompilerPower64.cc @@ -1074,7 +1074,7 @@ class AssemblyMountpointCLang final ASSEMBLY_INTERFACE { return LibCompiler::AssemblyFactory::kArchPowerPC; } - Int32 CompileToFormat(std::string& src, Int32 arch) override { + Int32 CompileToFormat(std::string src, Int32 arch) override { if (arch != AssemblyMountpointCLang::Arch()) return 1; if (kCompilerFrontend == nullptr) return 1; diff --git a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc index a227f75..e58e4f6 100644 --- a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc +++ b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc @@ -14,11 +14,6 @@ #define kExitOK (EXIT_SUCCESS) #define kExitNO (EXIT_FAILURE) -#define kSplashCxx() \ - kPrintF(kWhite "%s\n", \ - "NeKernel Optimized C++ Compiler Driver, (c) 2024-2025 Amlal El Mahrouss, All rights " \ - "reserved.") - // extern_segment, @autodelete { ... }, fn foo() -> auto { ... } #include <LibCompiler/Backend/Amd64.h> @@ -392,14 +387,15 @@ Boolean CompilerFrontendCPlusPlus::Compile(std::string text, const std::string f if (ch == ' ' || ch == '\t') { if (fnName[indexFnName - 1] != ')') Detail::print_error("Invalid function name: " + fnName, file); - - if ((indexFnName + 1) != fnName.size()) - Detail::print_error("Extra characters after function name: " + fnName, file); } ++indexFnName; } + if (fnName.find("(") != LibCompiler::String::npos) { + fnName.erase(fnName.find("(")); + } + syntax_tree.fUserValue = "public_segment .code64 __LIBCOMPILER_" + fnName + "\n"; ++kFunctionEmbedLevel; @@ -760,7 +756,7 @@ class AssemblyCPlusPlusInterface final ASSEMBLY_INTERFACE { [[maybe_unused]] static Int32 Arch() noexcept { return LibCompiler::AssemblyFactory::kArchAMD64; } - Int32 CompileToFormat(std::string& src, Int32 arch) override { + Int32 CompileToFormat(std::string src, Int32 arch) override { if (arch != AssemblyCPlusPlusInterface::Arch()) return 1; if (kCompilerFrontend == nullptr) return 1; @@ -850,12 +846,6 @@ class AssemblyCPlusPlusInterface final ASSEMBLY_INTERFACE { ///////////////////////////////////////////////////////////////////////////////////////// -static void cxx_print_help() { - kSplashCxx(); - kPrintF("%s", "No help available, see:\n"); - kPrintF("%s", "nekernel.org/docs/cxxdrv\n"); -} - ///////////////////////////////////////////////////////////////////////////////////////// #define kExtListCxx \ @@ -949,30 +939,19 @@ LIBCOMPILER_MODULE(CompilerCPlusPlusAMD64) { continue; } - if (strcmp(argv[index], "-version") == 0) { - kSplashCxx(); - return kExitOK; - } - if (strcmp(argv[index], "-cxx-verbose") == 0) { kState.fVerbose = true; continue; } - if (strcmp(argv[index], "-h") == 0) { - cxx_print_help(); - - return kExitOK; - } - if (strcmp(argv[index], "-cxx-dialect") == 0) { if (kCompilerFrontend) std::cout << kCompilerFrontend->Language() << "\n"; return kExitOK; } - if (strcmp(argv[index], "-max-err") == 0) { + if (strcmp(argv[index], "-cxx-max-err") == 0) { try { kErrorLimit = std::strtol(argv[index + 1], nullptr, 10); } @@ -1016,9 +995,12 @@ LIBCOMPILER_MODULE(CompilerCPlusPlusAMD64) { return 1; } - std::cout << "CPlusPlusCompilerAMD64: Building: " << argv[index] << std::endl; + kStdOut << "CPlusPlusCompilerAMD64: Building: " << argv[index] << std::endl; - if (kFactory.Compile(argv_i, kMachine) != kExitOK) return 1; + if (kFactory.Compile(argv_i, kMachine) != kExitOK) { + kStdOut << "CPlusPlusCompilerAMD64: Failed to build: " << argv[index] << std::endl; + return kExitNO; + } } return kExitOK; diff --git a/dev/LibCompiler/src/DynamicLinkerPEF.cc b/dev/LibCompiler/src/DynamicLinkerPEF.cc index 09e0396..fb2403f 100644 --- a/dev/LibCompiler/src/DynamicLinkerPEF.cc +++ b/dev/LibCompiler/src/DynamicLinkerPEF.cc @@ -15,6 +15,8 @@ //! Toolchain Kit. #include <LibCompiler/Defines.h> + +//! Error ID #include <LibCompiler/ErrorID.h> //! Assembler Kit @@ -22,6 +24,8 @@ //! Preferred Executable Format #include <LibCompiler/PEF.h> + +//! UUID header. #include <LibCompiler/UUID.h> //! Release macros. @@ -30,9 +34,12 @@ //! Advanced Executable Object Format. #include <LibCompiler/AE.h> -#define kLinkerVersionStr \ - "\e[0;97m NeKernel 64-Bit Linker (Preferred Executable Format) %s, (c) Amlal El Mahrouss " \ - "2024-2025, " \ +//! Format header. +#include <format> + +#define kLinkerVersionStr \ + "NeKernel 64-Bit Linker (Preferred Executable Format) {}, (c) Amlal El Mahrouss " \ + "2024-2025 " \ "all rights reserved.\n" #define MemoryCopy(DST, SRC, SZ) memcpy(DST, SRC, SZ) @@ -45,10 +52,10 @@ #define kLinkerDefaultOrigin kPefBaseOrigin #define kLinkerId (0x5046FF) -#define kLinkerAbiContainer "Container:ABI:" +#define kLinkerAbiContainer "__PEFContainer:ABI:" #define kPrintF printf -#define kLinkerSplash() kPrintF(kLinkerVersionStr, kDistVersion) +#define kLinkerSplash() kStdOut << std::format(kLinkerVersionStr, kDistVersion) /// @brief PEF stack size symbol. #define kLinkerStackSizeSymbol "__PEFSizeOfReserveStack" @@ -101,7 +108,7 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { kStdOut << "-version: Show linker version.\n"; kStdOut << "-help: Show linker help.\n"; kStdOut << "-ld-verbose: Enable linker trace.\n"; - kStdOut << "-dylib: Output as a Dyanmic PEF.\n"; + kStdOut << "-dylib: Output as a Dynamic PEF.\n"; kStdOut << "-fat: Output as a FAT PEF.\n"; kStdOut << "-32k: Output as a 32x0 PEF.\n"; kStdOut << "-64k: Output as a 64x0 PEF.\n"; |
