summaryrefslogtreecommitdiffhomepage
path: root/dev/LibCompiler
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-22 08:25:35 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-05-22 08:26:57 +0200
commit96ea259e3e3a3b1be7d0e3b589063340fc48cd2e (patch)
treeeee3788889ee7c9f7e5d538604920acef05a8bba /dev/LibCompiler
parent385178a1ecb41a7a529d219d80e2ed1232831abd (diff)
feat(LibCompiler): Update AssemblyInterface's Arch method.
also: - Figured out the segfault, currently working on a patch. - Better CLI output, with each library having it's prefix. - LibCompiler: `drv` - LibDebugger: `dbg` Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/LibCompiler')
-rw-r--r--dev/LibCompiler/AssemblyInterface.h2
-rw-r--r--dev/LibCompiler/Detail/ClUtils.h14
-rw-r--r--dev/LibCompiler/src/AssemblerAMD64.cc3
-rw-r--r--dev/LibCompiler/src/AssemblerARM64.cc3
-rw-r--r--dev/LibCompiler/src/AssemblerPowerPC.cc3
-rw-r--r--dev/LibCompiler/src/CCompiler64x0.cc4
-rw-r--r--dev/LibCompiler/src/CCompilerARM64.cc4
-rw-r--r--dev/LibCompiler/src/CCompilerPower64.cc4
-rw-r--r--dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc29
9 files changed, 25 insertions, 41 deletions
diff --git a/dev/LibCompiler/AssemblyInterface.h b/dev/LibCompiler/AssemblyInterface.h
index b612962..81440ce 100644
--- a/dev/LibCompiler/AssemblyInterface.h
+++ b/dev/LibCompiler/AssemblyInterface.h
@@ -54,7 +54,7 @@ class AssemblyInterface {
LIBCOMPILER_COPY_DEFAULT(AssemblyInterface);
- [[maybe_unused]] virtual Int32 Arch() noexcept { return AssemblyFactory::kArchAMD64; }
+ virtual UInt32 Arch() noexcept { return AssemblyFactory::kArchAMD64; }
/// @brief compile to object file.
/// @note Example C++ -> MASM -> AE object.
diff --git a/dev/LibCompiler/Detail/ClUtils.h b/dev/LibCompiler/Detail/ClUtils.h
index 5277a6b..7a400b4 100644
--- a/dev/LibCompiler/Detail/ClUtils.h
+++ b/dev/LibCompiler/Detail/ClUtils.h
@@ -24,8 +24,8 @@
#define kWhite "\e[0;97m"
#define kYellow "\e[0;33m"
-#define kStdOut (std::cout << kWhite)
-#define kStdErr (std::cout << kRed)
+#define kStdOut (std::cout << kRed << "drv: " << kWhite)
+#define kStdErr (std::cout << kYellow << "drv: " << kWhite)
inline static UInt32 kErrorLimit = 10;
inline static UInt32 kAcceptableErrors = 0;
@@ -36,7 +36,7 @@ namespace Detail {
inline void print_error(std::string reason, std::string file) noexcept {
if (reason[0] == '\n') reason.erase(0, 1);
- kStdErr << kRed << "drv: " << kWhite << reason << kBlank << std::endl;
+ kStdErr << kRed << reason << kBlank << std::endl;
if (kAcceptableErrors > kErrorLimit) std::exit(LIBCOMPILER_EXEC_ERROR);
@@ -46,7 +46,7 @@ inline void print_error(std::string reason, std::string file) noexcept {
inline void print_warning(std::string reason, std::string file) noexcept {
if (reason[0] == '\n') reason.erase(0, 1);
- kStdOut << kYellow << "drv: " << kWhite << reason << kBlank << std::endl;
+ kStdOut << kYellow << reason << kBlank << std::endl;
}
/// @internal
@@ -54,14 +54,12 @@ inline void print_warning(std::string reason, std::string file) noexcept {
inline void drv_segfault_handler(std::int32_t id) {
switch (id) {
case SIGSEGV: {
- kStdErr << kRed << "drv: " << kWhite
- << "Segmentation fault. Please report this on the GitHub issues page." << kBlank
+ kStdErr << "SIGSEGV: Please report this on the GitHub issues page." << kBlank
<< std::endl;
break;
}
case SIGABRT: {
- kStdErr << kRed << "drv: " << kWhite
- << "Aborted. Please report this on the GitHub issues page." << kBlank << std::endl;
+ kStdErr << "SIGABRT: Please report this on the GitHub issues page." << kBlank << std::endl;
break;
}
}
diff --git a/dev/LibCompiler/src/AssemblerAMD64.cc b/dev/LibCompiler/src/AssemblerAMD64.cc
index eb767cc..f017f0d 100644
--- a/dev/LibCompiler/src/AssemblerAMD64.cc
+++ b/dev/LibCompiler/src/AssemblerAMD64.cc
@@ -48,9 +48,6 @@
#define kWhite "\e[0;97m"
#define kYellow "\e[0;33m"
-#define kStdOut (std::cout << kWhite)
-#define kStdErr (std::cout << kRed)
-
static char kOutputArch = LibCompiler::kPefArchAMD64;
constexpr auto kIPAlignement = 0x1U;
diff --git a/dev/LibCompiler/src/AssemblerARM64.cc b/dev/LibCompiler/src/AssemblerARM64.cc
index 19c7401..bad974e 100644
--- a/dev/LibCompiler/src/AssemblerARM64.cc
+++ b/dev/LibCompiler/src/AssemblerARM64.cc
@@ -41,9 +41,6 @@
#define kWhite "\e[0;97m"
#define kYellow "\e[0;33m"
-#define kStdOut (std::cout << kWhite)
-#define kStdErr (std::cout << kRed)
-
constexpr auto cPowerIPAlignment = 0x1U;
static CharType kOutputArch = LibCompiler::kPefArchARM64;
diff --git a/dev/LibCompiler/src/AssemblerPowerPC.cc b/dev/LibCompiler/src/AssemblerPowerPC.cc
index ddd0b4e..c0a7172 100644
--- a/dev/LibCompiler/src/AssemblerPowerPC.cc
+++ b/dev/LibCompiler/src/AssemblerPowerPC.cc
@@ -41,9 +41,6 @@
#define kWhite "\e[0;97m"
#define kYellow "\e[0;33m"
-#define kStdOut (std::cout << kWhite)
-#define kStdErr (std::cout << kRed)
-
constexpr auto cPowerIPAlignment = 0x4U;
static CharType kOutputArch = LibCompiler::kPefArchPowerPC;
diff --git a/dev/LibCompiler/src/CCompiler64x0.cc b/dev/LibCompiler/src/CCompiler64x0.cc
index 7bd8e8b..17de065 100644
--- a/dev/LibCompiler/src/CCompiler64x0.cc
+++ b/dev/LibCompiler/src/CCompiler64x0.cc
@@ -1051,9 +1051,7 @@ class AssemblyCCInterface final ASSEMBLY_INTERFACE {
LIBCOMPILER_COPY_DEFAULT(AssemblyCCInterface);
- [[maybe_unused]] Int32 Arch() noexcept override {
- return LibCompiler::AssemblyFactory::kArch64x0;
- }
+ UInt32 Arch() noexcept override { return LibCompiler::AssemblyFactory::kArch64x0; }
Int32 CompileToFormat(std::string src, Int32 arch) override {
if (kCompilerFrontend == nullptr) return 1;
diff --git a/dev/LibCompiler/src/CCompilerARM64.cc b/dev/LibCompiler/src/CCompilerARM64.cc
index 542f45f..3aaab5f 100644
--- a/dev/LibCompiler/src/CCompilerARM64.cc
+++ b/dev/LibCompiler/src/CCompilerARM64.cc
@@ -1049,9 +1049,7 @@ class AssemblyCCInterface final ASSEMBLY_INTERFACE {
LIBCOMPILER_COPY_DEFAULT(AssemblyCCInterface);
- [[maybe_unused]] Int32 Arch() noexcept override {
- return LibCompiler::AssemblyFactory::kArchAARCH64;
- }
+ UInt32 Arch() noexcept override { return LibCompiler::AssemblyFactory::kArchAARCH64; }
Int32 CompileToFormat(std::string src, Int32 arch) override {
if (kCompilerFrontend == nullptr) return 1;
diff --git a/dev/LibCompiler/src/CCompilerPower64.cc b/dev/LibCompiler/src/CCompilerPower64.cc
index e5b25a5..aa49768 100644
--- a/dev/LibCompiler/src/CCompilerPower64.cc
+++ b/dev/LibCompiler/src/CCompilerPower64.cc
@@ -1069,9 +1069,7 @@ class AssemblyMountpointCLang final ASSEMBLY_INTERFACE {
LIBCOMPILER_COPY_DEFAULT(AssemblyMountpointCLang);
- [[maybe_unused]] Int32 Arch() noexcept override {
- return LibCompiler::AssemblyFactory::kArchPowerPC;
- }
+ UInt32 Arch() noexcept override { return LibCompiler::AssemblyFactory::kArchPowerPC; }
Int32 CompileToFormat(std::string src, Int32 arch) override {
if (kCompilerFrontend == nullptr) return 1;
diff --git a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc
index 29cdee7..517a2f2 100644
--- a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc
+++ b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc
@@ -21,8 +21,6 @@
#include <LibCompiler/Detail/ClUtils.h>
#include <LibCompiler/UUID.h>
-#include <cstdio>
-
/* NeKernel C++ Compiler Driver */
/* This is part of the LibCompiler. */
/* (c) Amlal El Mahrouss */
@@ -188,7 +186,7 @@ static std::vector<std::pair<std::string, std::uintptr_t>> kOriginMap;
/////////////////////////////////////////////////////////////////////////////////////////
Boolean CompilerFrontendCPlusPlus::Compile(std::string text, std::string file) {
- if (text.empty()) return false;
+ if (text.length() < 1) return false;
std::size_t index = 0UL;
std::vector<std::pair<LibCompiler::CompilerKeyword, std::size_t>> keywords_list;
@@ -717,9 +715,7 @@ class AssemblyCPlusPlusInterface final ASSEMBLY_INTERFACE {
LIBCOMPILER_COPY_DEFAULT(AssemblyCPlusPlusInterface);
- [[maybe_unused]] Int32 Arch() noexcept override {
- return LibCompiler::AssemblyFactory::kArchAMD64;
- }
+ UInt32 Arch() noexcept override { return LibCompiler::AssemblyFactory::kArchAMD64; }
Int32 CompileToFormat(std::string src, Int32 arch) override {
if (kCompilerFrontend == nullptr) return kExitNO;
@@ -727,21 +723,26 @@ class AssemblyCPlusPlusInterface final ASSEMBLY_INTERFACE {
std::string dest = src;
dest += ".masm";
- std::string line_source;
-
std::ofstream out_fp(dest);
std::ifstream src_fp = std::ifstream(src);
+ std::string line_source;
+
while (std::getline(src_fp, line_source)) {
if (kVerbose) {
- std::cout << kWhite << line_source << std::endl;
+ kStdOut << line_source << std::endl;
+ kStdOut << line_source.length() << " bytes\n";
}
kCompilerFrontend->Compile(line_source, src);
out_fp << kState.fOutputValue;
}
+ if (kVerbose) {
+ kStdOut << "Done compiling " << src << " to " << dest << "\n";
+ }
+
return kExitOK;
}
};
@@ -851,7 +852,7 @@ LIBCOMPILER_MODULE(CompilerCPlusPlusAMD64) {
if (strcmp(argv[index], "-cxx-dialect") == 0) {
if (kCompilerFrontend) std::cout << kCompilerFrontend->Language() << "\n";
- return kExitOK;
+ return LIBCOMPILER_SUCCESS;
}
if (strcmp(argv[index], "-cxx-max-err") == 0) {
@@ -879,14 +880,14 @@ LIBCOMPILER_MODULE(CompilerCPlusPlusAMD64) {
std::string argv_i = argv[index];
std::vector exts = kExtListCxx;
- Boolean found = false;
+ BOOL found = false;
for (std::string ext : exts) {
if (argv_i.find(ext) != std::string::npos) {
found = true;
if (kFactory.Compile(argv_i, kMachine) != kExitOK) {
- return kExitNO;
+ return LIBCOMPILER_INVALID_DATA;
}
}
}
@@ -896,13 +897,13 @@ LIBCOMPILER_MODULE(CompilerCPlusPlusAMD64) {
Detail::print_error(argv_i + " is not a valid C++ source.\n", "cxxdrv");
}
- return kExitNO;
+ return LIBCOMPILER_INVALID_DATA;
}
}
kFactory.Unmount();
- return kExitOK;
+ return LIBCOMPILER_SUCCESS;
}
// Last rev 8-1-24