diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2026-01-09 02:16:39 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2026-01-09 02:16:39 +0100 |
| commit | 693dd621321e3af029d2c8cc8d58af716eb43988 (patch) | |
| tree | 02d12821dd1a1288e35c98252909dd9cafc9e4ce | |
| parent | f8f2153b6b859dee35192f237d292e75c0a4cd76 (diff) | |
feat: necfront: final refactors and improvements before finishing Netcar implementation.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | src/CommandLine/cppdrv.cc | 4 | ||||
| -rw-r--r-- | src/CommandLine/pef-amd64-necdrv.cc (renamed from src/CommandLine/pef-amd64-cxxdrv.cc) | 2 | ||||
| -rw-r--r-- | src/CommandLine/pef-amd64-necdrv.json (renamed from src/CommandLine/pef-amd64-cxxdrv.json) | 6 | ||||
| -rw-r--r-- | src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc (renamed from src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc) | 77 | ||||
| -rw-r--r-- | src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc | 22 | ||||
| -rw-r--r-- | src/CompilerKit/test/Linkers/DynamicLinker+PEF64.test.cc | 2 | ||||
| -rw-r--r-- | test/test_01_codegen/codegen.test.cc | 10 | ||||
| -rw-r--r-- | test/test_samples/ostream.ncpp | 10 | ||||
| -rw-r--r-- | test/test_samples/sample.ncpp | 8 |
10 files changed, 77 insertions, 65 deletions
@@ -16,6 +16,7 @@ src/*/dbg src/*/cppdrv src/*/kdbg src/*/pef-*-asm +src/*/pef-*-necdrv src/*/pef-*-cxxdrv src/*/pef-*-cdrv diff --git a/src/CommandLine/cppdrv.cc b/src/CommandLine/cppdrv.cc index d5d2cd0..6977923 100644 --- a/src/CommandLine/cppdrv.cc +++ b/src/CommandLine/cppdrv.cc @@ -9,10 +9,10 @@ #include <CompilerKit/Detail/Config.h> #include <CompilerKit/ErrorID.h> -CK_IMPORT_C int CPlusPlusPreprocessorMain(int argc, char const* argv[]); +CK_IMPORT_C int GenericPreprocessorMain(int argc, char const* argv[]); int main(int argc, char const* argv[]) { - if (auto code = CPlusPlusPreprocessorMain(argc, argv); code > 0) { + if (auto code = GenericPreprocessorMain(argc, argv); code > 0) { std::printf("cppdrv: preprocessor exited with code %i.\n", code); return NECTAR_EXEC_ERROR; diff --git a/src/CommandLine/pef-amd64-cxxdrv.cc b/src/CommandLine/pef-amd64-necdrv.cc index 6617d2c..921c674 100644 --- a/src/CommandLine/pef-amd64-cxxdrv.cc +++ b/src/CommandLine/pef-amd64-necdrv.cc @@ -17,7 +17,7 @@ static auto kPath = "/usr/local/lib/libCompilerKit.dylib"; static auto kPath = "/usr/lib/libCompilerKit.so"; #endif -static auto kSymbol = "CompilerCPlusPlusAMD64"; +static auto kSymbol = "CompilerNectarAMD64"; Int32 main(Int32 argc, Char const* argv[]) { CompilerKit::DLLLoader dylib; diff --git a/src/CommandLine/pef-amd64-cxxdrv.json b/src/CommandLine/pef-amd64-necdrv.json index 90295b9..ea2209d 100644 --- a/src/CommandLine/pef-amd64-cxxdrv.json +++ b/src/CommandLine/pef-amd64-necdrv.json @@ -7,13 +7,13 @@ "../include/CompilerKit/src/Detail" ], "sources_path": [ - "pef-amd64-cxxdrv.cc" + "pef-amd64-necdrv.cc" ], - "output_name": "pef-amd64-cxxdrv", + "output_name": "pef-amd64-necdrv", "compiler_flags": [ ], "cpp_macros": [ - "__CXXDRV__=202504", + "__NECDRV__=202504", "kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)" ] } diff --git a/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc b/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc index 18f0931..a7de1b2 100644 --- a/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc +++ b/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc @@ -26,17 +26,17 @@ #include <cstdlib> #include <filesystem> -/* NeKernel C++ Compiler Driver. */ +/* NeKernel NECTAR Compiler Driver. */ /* This is part of the CompilerKit. */ /* (c) Amlal El Mahrouss 2024-2025 */ /// @author Amlal El Mahrouss (amlal@nekernel.org) -/// @file CPlusPlusCompilerAMD64.cc -/// @brief C++ Compiler Driver. +/// @file NectarCompiler+AMD64.cc +/// @brief NECTAR Compiler Driver. ///////////////////////////////////// -// INTERNALS OF THE C++ COMPILER +// INTERNALS OF THE NECTAR COMPILER ///////////////////////////////////// @@ -85,7 +85,7 @@ static Int32 kOnClassScope = 0; ///////////////////////////////////////////////////////////////////////////////////////// -// NEW DATA STRUCTURES FOR C++ SUPPORT +// NEW DATA STRUCTURES FOR NECTAR SUPPORT ///////////////////////////////////////////////////////////////////////////////////////// @@ -206,13 +206,13 @@ static void nectar_process_function_parameters(const std::vector<CompilerKit::ST ///////////////////////////////////////////////////////////////////////////////////////// -/* \brief C++ compiler backend for the NeKernel C++ driver */ -class CompilerFrontendCPlusPlusAMD64 final CK_COMPILER_FRONTEND { +/* \brief NECTAR compiler backend for the NeKernel NECTAR driver */ +class CompilerFrontendNectarAMD64 final CK_COMPILER_FRONTEND { public: - explicit CompilerFrontendCPlusPlusAMD64() = default; - ~CompilerFrontendCPlusPlusAMD64() override = default; + explicit CompilerFrontendNectarAMD64() = default; + ~CompilerFrontendNectarAMD64() override = default; - NECTAR_COPY_DEFAULT(CompilerFrontendCPlusPlusAMD64); + NECTAR_COPY_DEFAULT(CompilerFrontendNectarAMD64); /// \brief Parse C symbols and syntax. CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(CompilerKit::STLString& text, @@ -222,7 +222,7 @@ class CompilerFrontendCPlusPlusAMD64 final CK_COMPILER_FRONTEND { const char* Language() override; public: - /// \brief Parse C++ namespaces and objects. + /// \brief Parse NECTAR namespaces and objects. /// \param CompilerKit::SyntaxLeafList::SyntaxLeaf the leaf to build upon. CompilerKit::SyntaxLeafList::SyntaxLeaf CompilePass2(CompilerKit::STLString& text, const CompilerKit::STLString& file, @@ -231,7 +231,7 @@ class CompilerFrontendCPlusPlusAMD64 final CK_COMPILER_FRONTEND { /// @internal compiler variables -static CompilerFrontendCPlusPlusAMD64* kFrontend = nullptr; +static CompilerFrontendNectarAMD64* kFrontend = nullptr; static std::vector<CompilerKit::STLString> kRegisterMap; @@ -250,7 +250,7 @@ static std::size_t kNamespaceEmbedLevel{}; /// detail namespaces -const char* CompilerFrontendCPlusPlusAMD64::Language() { +const char* CompilerFrontendNectarAMD64::Language() { return "Nectar"; } @@ -260,11 +260,11 @@ static std::vector<std::pair<CompilerKit::STLString, std::uintptr_t>> kOriginMap ///////////////////////////////////////////////////////////////////////////////////////// /// @name Compile -/// @brief Generate assembly from a C++ source. +/// @brief Generate assembly from a NECTAR source. ///////////////////////////////////////////////////////////////////////////////////////// -CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( +CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile( CompilerKit::STLString& text, const CompilerKit::STLString& file) { CompilerKit::SyntaxLeafList::SyntaxLeaf syntax_tree; @@ -733,7 +733,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( constexpr auto kTrueVal = "true"; constexpr auto kFalseVal = "false"; - /// interpet boolean values, since we're on C++ + /// interpet boolean values, since we're on NECTAR if (valueOfVar == kTrueVal) { valueOfVar = "1"; @@ -907,9 +907,9 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( return this->CompilePass2(text, file, syntax_tree); } -/// \brief Parse C++ namespaces and objects. +/// \brief Parse NECTAR namespaces and objects. /// \param CompilerKit::SyntaxLeafList::SyntaxLeaf the leaf to build upon. -CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::CompilePass2( +CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::CompilePass2( CompilerKit::STLString& text, const CompilerKit::STLString& file, CompilerKit::SyntaxLeafList::SyntaxLeaf& syntax_tree) { // Handle namespace entry @@ -1409,17 +1409,19 @@ static void nectar_process_function_parameters(const std::vector<CompilerKit::ST ///////////////////////////////////////////////////////////////////////////////////////// /** - * @brief C++ assembler class. + * @brief NECTAR assembler class. */ ///////////////////////////////////////////////////////////////////////////////////////// -class AssemblyCPlusPlusInterfaceAMD64 final CK_ASSEMBLY_INTERFACE { +#define kExtListCxx {".ncpp"} + +class AssemblyNectarInterfaceAMD64 final CK_ASSEMBLY_INTERFACE { public: - explicit AssemblyCPlusPlusInterfaceAMD64() = default; - ~AssemblyCPlusPlusInterfaceAMD64() override = default; + explicit AssemblyNectarInterfaceAMD64() = default; + ~AssemblyNectarInterfaceAMD64() override = default; - NECTAR_COPY_DEFAULT(AssemblyCPlusPlusInterfaceAMD64); + NECTAR_COPY_DEFAULT(AssemblyNectarInterfaceAMD64); UInt32 Arch() noexcept override { return CompilerKit::AssemblyFactory::kArchAMD64; } @@ -1427,6 +1429,11 @@ class AssemblyCPlusPlusInterfaceAMD64 final CK_ASSEMBLY_INTERFACE { if (kFrontend == nullptr) return EXIT_FAILURE; CompilerKit::STLString dest = src; + + std::vector<CompilerKit::STLString> ext = kExtListCxx; + + dest.erase(dest.find(ext[0])); + dest += ".masm"; std::ofstream out_fp(dest); @@ -1452,9 +1459,7 @@ class AssemblyCPlusPlusInterfaceAMD64 final CK_ASSEMBLY_INTERFACE { ///////////////////////////////////////////////////////////////////////////////////////// -#define kExtListCxx {".ncpp"} - -NECTAR_MODULE(CompilerCPlusPlusAMD64) { +NECTAR_MODULE(CompilerNectarAMD64) { bool skip = false; kKeywords.emplace_back("if", CompilerKit::KeywordKind::kKeywordKindIf); @@ -1492,9 +1497,9 @@ NECTAR_MODULE(CompilerCPlusPlusAMD64) { kKeywords.emplace_back(",", CompilerKit::KeywordKind::kKeywordKindArgSeparator); kKeywords.emplace_back(";", CompilerKit::KeywordKind::kKeywordKindEndInstr); kKeywords.emplace_back(":", CompilerKit::KeywordKind::kKeywordKindSpecifier); - kKeywords.emplace_back("public:", CompilerKit::KeywordKind::kKeywordKindSpecifier); - kKeywords.emplace_back("private:", CompilerKit::KeywordKind::kKeywordKindSpecifier); - kKeywords.emplace_back("protected:", CompilerKit::KeywordKind::kKeywordKindSpecifier); + kKeywords.emplace_back("public", CompilerKit::KeywordKind::kKeywordKindSpecifier); + kKeywords.emplace_back("private", CompilerKit::KeywordKind::kKeywordKindSpecifier); + kKeywords.emplace_back("protected", CompilerKit::KeywordKind::kKeywordKindSpecifier); kKeywords.emplace_back("final", CompilerKit::KeywordKind::kKeywordKindSpecifier); kKeywords.emplace_back("return", CompilerKit::KeywordKind::kKeywordKindReturn); kKeywords.emplace_back("/*", CompilerKit::KeywordKind::kKeywordKindCommentMultiLineStart); @@ -1507,10 +1512,10 @@ NECTAR_MODULE(CompilerCPlusPlusAMD64) { kErrorLimit = 0; - kFrontend = new CompilerFrontendCPlusPlusAMD64(); + kFrontend = new CompilerFrontendNectarAMD64(); - CompilerKit::StrongRef<AssemblyCPlusPlusInterfaceAMD64> mntPnt{ - new AssemblyCPlusPlusInterfaceAMD64()}; + CompilerKit::StrongRef<AssemblyNectarInterfaceAMD64> mntPnt{ + new AssemblyNectarInterfaceAMD64()}; kAssembler.Mount({mntPnt.Leak()}); CompilerKit::install_signal(SIGSEGV, CompilerKit::Detail::drvi_crash_handler); @@ -1530,18 +1535,18 @@ NECTAR_MODULE(CompilerCPlusPlusAMD64) { continue; } - if (strcmp(argv[index], "-cxx-verbose") == 0) { + if (strcmp(argv[index], "-nec-verbose") == 0) { kVerbose = true; continue; } - if (strcmp(argv[index], "-cxx-dialect") == 0) { + if (strcmp(argv[index], "-nec-dialect") == 0) { if (kFrontend) std::cout << kFrontend->Language() << "\n"; return NECTAR_SUCCESS; } - if (strcmp(argv[index], "-cxx-max-err") == 0) { + if (strcmp(argv[index], "-nec-max-err") == 0) { try { kErrorLimit = std::strtol(argv[index + 1], nullptr, 10); } @@ -1558,7 +1563,7 @@ NECTAR_MODULE(CompilerCPlusPlusAMD64) { CompilerKit::STLString err = "Unknown option: "; err += argv[index]; - CompilerKit::Detail::print_error(err, "cxxdrv"); + CompilerKit::Detail::print_error(err, "necfront"); continue; } diff --git a/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc b/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc index d56b9e6..3426ce0 100644 --- a/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc +++ b/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc @@ -758,7 +758,7 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { ///////////////////////////////////////////////////////////////////////////////////////// -NECTAR_MODULE(CPlusPlusPreprocessorMain) { +NECTAR_MODULE(GenericPreprocessorMain) { try { bool skip = false; bool double_skip = false; @@ -791,19 +791,19 @@ NECTAR_MODULE(CPlusPlusPreprocessorMain) { kMacros.push_back(macro_0); - Detail::bpp_macro macro_zka; + Detail::bpp_macro macro_nectar; - macro_zka.fName = "__NECTAR__"; - macro_zka.fValue = "1"; + macro_nectar.fName = "__NECTAR__"; + macro_nectar.fValue = "1"; - kMacros.push_back(macro_zka); + kMacros.push_back(macro_nectar); - Detail::bpp_macro macro_cxx; + Detail::bpp_macro macro_lang; - macro_cxx.fName = "__cplusplus"; - macro_cxx.fValue = "202302L"; + macro_lang.fName = "__ncpp"; + macro_lang.fValue = "202601L"; - kMacros.push_back(macro_cxx); + kMacros.push_back(macro_lang); Detail::bpp_macro macro_size_t; macro_size_t.fName = "__SIZE_TYPE__"; @@ -836,7 +836,7 @@ NECTAR_MODULE(CPlusPlusPreprocessorMain) { if (argv[index][0] == '-') { if (strcmp(argv[index], "-cpp-ver") == 0) { printf("%s\n", - "NeKernel Preprocessor Driver v1.11, (c) Amlal El Mahrouss 2024-2025 all rights " + "Nectar Preprocessor Driver v1.11, (c) Amlal El Mahrouss 2024-2026 all rights " "reserved."); return NECTAR_SUCCESS; @@ -844,7 +844,7 @@ NECTAR_MODULE(CPlusPlusPreprocessorMain) { if (strcmp(argv[index], "-cpp-help") == 0) { printf("%s\n", - "NeKernel Preprocessor Driver v1.11, (c) Amlal El Mahrouss 2024-2025 all rights " + "Nectar Preprocessor Driver v1.11, (c) Amlal El Mahrouss 2024-2026 all rights " "reserved."); printf("%s\n", "-cpp-working-dir <path>: set directory to working path."); printf("%s\n", "-cpp-include-dir <path>: add directory to include path."); diff --git a/src/CompilerKit/test/Linkers/DynamicLinker+PEF64.test.cc b/src/CompilerKit/test/Linkers/DynamicLinker+PEF64.test.cc index fe7130e..1277cae 100644 --- a/src/CompilerKit/test/Linkers/DynamicLinker+PEF64.test.cc +++ b/src/CompilerKit/test/Linkers/DynamicLinker+PEF64.test.cc @@ -24,5 +24,5 @@ Int32 main(Int32 argc, Char** argv) { TEST(LinkerRun, LinkerExitsCorrectly) { EXPECT_TRUE(kArgc > 1); - EXPECT_TRUE(DynamicLinker64PEF(kArgc, kArgv) == 0) << "Linker invocation failed"; + EXPECT_TRUE(DynamicLinker64PEF(kArgc, kArgv) == 0); } diff --git a/test/test_01_codegen/codegen.test.cc b/test/test_01_codegen/codegen.test.cc index 3cee6fb..5115a9b 100644 --- a/test/test_01_codegen/codegen.test.cc +++ b/test/test_01_codegen/codegen.test.cc @@ -10,19 +10,19 @@ TEST(CodegenTest, BasicCodegenTestGrep) { // Compile C++ source to assembly - auto compile_result = std::system("pef-amd64-cxxdrv ../test_samples/sample.cc > /dev/null 2>&1"); + auto compile_result = std::system("pef-amd64-cxxdrv ../test_samples/sample.ncpp > /dev/null 2>&1"); EXPECT_TRUE(compile_result == 0) << "C++ compiler driver failed to compile sample.cc"; // Grep for expected entry point symbol in generated assembly - auto grep_main = std::system("grep -q '__NECTI_main' ../test_samples/sample.cc.pp.masm"); - EXPECT_TRUE(grep_main == 0) << "Generated assembly missing expected entry point __NECTI_main"; + auto grep_main = std::system("grep -q '__NECTI_main' ../test_samples/sample.ncpp.masm"); + EXPECT_TRUE(grep_main == 0) << "Generated assembly missing expected entry point __NECTAR_main"; // Grep for return instruction - auto grep_ret = std::system("grep -q 'ret' ../test_samples/sample.cc.pp.masm"); + auto grep_ret = std::system("grep -q 'ret' ../test_samples/sample.ncpp.masm"); EXPECT_TRUE(grep_ret == 0) << "Generated assembly missing return instruction"; // Grep for 64-bit mode directive - auto grep_bits64 = std::system("grep -q '%bits 64' ../test_samples/sample.cc.pp.masm"); + auto grep_bits64 = std::system("grep -q '%bits 64' ../test_samples/sample.ncpp.masm"); EXPECT_TRUE(grep_bits64 == 0) << "Generated assembly missing 64-bit mode directive"; } diff --git a/test/test_samples/ostream.ncpp b/test/test_samples/ostream.ncpp index 8f0248f..82e9fb4 100644 --- a/test/test_samples/ostream.ncpp +++ b/test/test_samples/ostream.ncpp @@ -2,8 +2,16 @@ struct ostream { - void write(int& val) + void consume(int& val) { printf("%i", val); } + + int read() + { + return getchar(); + } }; + +ostream out; +ostream in; diff --git a/test/test_samples/sample.ncpp b/test/test_samples/sample.ncpp index 241f69e..df857ac 100644 --- a/test/test_samples/sample.ncpp +++ b/test/test_samples/sample.ncpp @@ -2,10 +2,8 @@ int main(void) { - ostream s; - let six_seven = 67; + let six_seven = 100; + out.consume(six_seven); - s.write(six_seven); - - return 0; + return 0; } |
