summaryrefslogtreecommitdiffhomepage
path: root/src/CompilerKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-01-09 02:16:39 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-01-09 02:16:39 +0100
commit693dd621321e3af029d2c8cc8d58af716eb43988 (patch)
tree02d12821dd1a1288e35c98252909dd9cafc9e4ce /src/CompilerKit
parentf8f2153b6b859dee35192f237d292e75c0a4cd76 (diff)
feat: necfront: final refactors and improvements before finishing Netcar implementation.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/CompilerKit')
-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.cc22
-rw-r--r--src/CompilerKit/test/Linkers/DynamicLinker+PEF64.test.cc2
3 files changed, 53 insertions, 48 deletions
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);
}