summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-04 16:22:22 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-04 16:25:57 +0100
commit654c31b94d547e8d83be378eb5d5ab16a820dcdd (patch)
tree96b33b2722401bf556de941617b085905b371789 /src
parentcd3092186eb698a9ed175dacb6884f0404e7c062 (diff)
chore:: breaking structural changes of CompilerKit.
The Kit has been redesigned to be expandable to new language frontends. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src')
-rw-r--r--src/CompilerKit/AST.h2
-rw-r--r--src/CompilerKit/AST.inl (renamed from src/CompilerKit/src/AST.cc)20
-rw-r--r--src/CompilerKit/CodeGenerator.h1
-rw-r--r--src/CompilerKit/StringKit.h95
-rw-r--r--src/CompilerKit/Utilities/Assembler.h8
-rw-r--r--src/CompilerKit/Utilities/Compiler.h14
-rw-r--r--src/CompilerKit/Utilities/DLL.h4
-rw-r--r--src/CompilerKit/src/Assemblers/Assembler+32x0.cc (renamed from src/CompilerKit/src/Backend/Assembler32x0.cc)2
-rw-r--r--src/CompilerKit/src/Assemblers/Assembler+64x0.cc (renamed from src/CompilerKit/src/Backend/Assembler64x0.cc)52
-rw-r--r--src/CompilerKit/src/Assemblers/Assembler+AMD64.cc (renamed from src/CompilerKit/src/Backend/AssemblerAMD64.cc)60
-rw-r--r--src/CompilerKit/src/Assemblers/Assembler+ARM64.cc (renamed from src/CompilerKit/src/Backend/AssemblerARM64.cc)28
-rw-r--r--src/CompilerKit/src/Assemblers/Assembler+PowerPC.cc (renamed from src/CompilerKit/src/Backend/AssemblerPowerPC.cc)46
-rw-r--r--src/CompilerKit/src/Compilers/CCompiler+64x0.cc (renamed from src/CompilerKit/src/Frontend/CCompiler64x0.cc)16
-rw-r--r--src/CompilerKit/src/Compilers/CCompiler+ARM64.cc (renamed from src/CompilerKit/src/Frontend/CCompilerARM64.cc)15
-rw-r--r--src/CompilerKit/src/Compilers/CCompiler+Power64.cc (renamed from src/CompilerKit/src/Frontend/CCompilerPower64.cc)10
-rw-r--r--src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc (renamed from src/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc)16
-rw-r--r--src/CompilerKit/src/DyanmicLinkers/DynamicLinker64+PEF.cc (renamed from src/CompilerKit/src/Linker/DynamicLinker64PEF.cc)4
-rw-r--r--src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc (renamed from src/CompilerKit/src/Macro/CPlusPlusPreprocessor.cc)0
-rw-r--r--src/CompilerKit/src/StringKit.cc180
19 files changed, 148 insertions, 425 deletions
diff --git a/src/CompilerKit/AST.h b/src/CompilerKit/AST.h
index 2489176..3987f13 100644
--- a/src/CompilerKit/AST.h
+++ b/src/CompilerKit/AST.h
@@ -139,3 +139,5 @@ class CompilerFrontendInterface {
virtual bool IsValid();
};
} // namespace CompilerKit
+
+#include <CompilerKit/AST.inl> \ No newline at end of file
diff --git a/src/CompilerKit/src/AST.cc b/src/CompilerKit/AST.inl
index 764fa71..3dc9456 100644
--- a/src/CompilerKit/src/AST.cc
+++ b/src/CompilerKit/AST.inl
@@ -4,24 +4,12 @@
======================================== */
-#include <CompilerKit/AST.h>
-
-/**
- * @file Frontend.cc
- * @author Amlal El Mahrouss (amlal@nekernel.org)
- * @brief AST of NeCTI
- * @version 0.0.3
- *
- * @copyright Copyright (c) 2025 Amlal El Mahrouss and NeKernel.org Contributors
- *
- */
-
namespace CompilerKit {
/// find the perfect matching word in a haystack.
/// \param haystack base string
/// \param needle the string we search for.
/// \return if we found it or not.
-bool find_word(STLString haystack, STLString needle) noexcept {
+inline bool find_word(STLString haystack, STLString needle) noexcept {
auto index = haystack.find(needle);
// check for needle validity.
@@ -43,7 +31,7 @@ bool find_word(STLString haystack, STLString needle) noexcept {
/// \param haystack
/// \param needle
/// \return position of needle.
-SizeType find_word_range(STLString haystack, STLString needle) noexcept {
+inline SizeType find_word_range(STLString haystack, STLString needle) noexcept {
auto index = haystack.find(needle);
// check for needle validity.
@@ -62,14 +50,14 @@ SizeType find_word_range(STLString haystack, STLString needle) noexcept {
/// =========================================================== ///
//! @brief What language are we dealing with?
/// =========================================================== ///
-const char* CompilerFrontendInterface::Language() {
+inline const char* CompilerFrontendInterface::Language() {
return kInvalidFrontend;
}
/// =========================================================== ///
/// @brief Checks if language is a valid frontend.
/// =========================================================== ///
-bool CompilerFrontendInterface::IsValid() {
+inline bool CompilerFrontendInterface::IsValid() {
return strcmp(this->Language(), kInvalidFrontend) > 0;
}
} // namespace CompilerKit \ No newline at end of file
diff --git a/src/CompilerKit/CodeGenerator.h b/src/CompilerKit/CodeGenerator.h
index 3a18803..383f170 100644
--- a/src/CompilerKit/CodeGenerator.h
+++ b/src/CompilerKit/CodeGenerator.h
@@ -8,7 +8,6 @@
#include <CompilerKit/Detail/Config.h>
#include <CompilerKit/Macros.h>
-#include <CompilerKit/StringKit.h>
#include <cstring>
#define CK_ASSEMBLY_INTERFACE : public ::CompilerKit::AssemblyInterface
diff --git a/src/CompilerKit/StringKit.h b/src/CompilerKit/StringKit.h
deleted file mode 100644
index d3eb3ad..0000000
--- a/src/CompilerKit/StringKit.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * ========================================================
- *
- * CompilerKit
- * Copyright (C) 2024-2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license.
- *
- * ========================================================
- */
-
-#ifndef __NECTI_STRINGKIT__
-#define __NECTI_STRINGKIT__
-
-#include <CompilerKit/Detail/Config.h>
-#include <CompilerKit/ErrorOr.h>
-#include <cstring>
-
-/// =========================================================== ///
-/// @file StringKit.h
-/// @author Amlal El Mahrouss
-/// @brief StringKit for CompilerKit.
-/// =========================================================== ///
-
-namespace CompilerKit {
-class NEStringBuilder;
-class NEString;
-
-/**
- * @brief NEString class, contains a C string and manages it.
- * @note No need to manage it it's getting deleted by default.
- */
-
-class NEString final {
- public:
- explicit NEString() = delete;
-
- explicit NEString(SizeType Sz) noexcept : m_Sz(Sz) {
- m_Data = new Char[Sz];
- assert(m_Data);
- }
-
- ~NEString() noexcept {
- if (m_Data) {
- memset(m_Data, 0, m_Sz);
- delete[] m_Data;
-
- m_Data = nullptr;
- }
- }
-
- NECTI_COPY_DEFAULT(NEString);
-
- Char* Data();
- const Char* CData() const;
- SizeType Length() const;
-
- bool operator==(const Char* rhs) const;
- bool operator!=(const Char* rhs) const;
-
- bool operator==(const NEString& rhs) const;
- bool operator!=(const NEString& rhs) const;
-
- NEString& operator+=(const Char* rhs);
- NEString& operator+=(const Char rhs);
- NEString& operator+=(const NEString& rhs);
-
- explicit operator bool() { return m_Data && m_Data[0] != 0; }
-
- bool operator!() { return !m_Data || m_Data[0] == 0; }
-
- private:
- Char* m_Data{nullptr};
- SizeType m_Sz{0};
- SizeType m_Cur{0};
-
- friend class NEStringBuilder;
-};
-
-/**
- * @brief NEStringBuilder class
- * @note These results shall call be delete[] after they're used.
- */
-struct NEStringBuilder final {
- static NEString Construct(const Char* data);
- static NEString FromInt(const char* fmt, int n);
- static NEString FromBool(const char* fmt, bool n);
- static NEString Format(const char* fmt, const char* from);
- static bool Equals(const char* lhs, const char* rhs);
-};
-
-using NEStringOr = ErrorOr<NEString>;
-using NEStringPtr = NEString*;
-using NEStringRef = Ref<NEString>;
-} // namespace CompilerKit
-
-#endif /* ifndef __NECTI_STRINGKIT__ */
diff --git a/src/CompilerKit/Utilities/Assembler.h b/src/CompilerKit/Utilities/Assembler.h
index 3da48cc..fc965f0 100644
--- a/src/CompilerKit/Utilities/Assembler.h
+++ b/src/CompilerKit/Utilities/Assembler.h
@@ -27,7 +27,7 @@ static NumberCast32 GetNumber32(STLString lineBuffer, STLString numberKey) {
case 'x': {
if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 16); !res) {
if (errno != 0) {
- Detail::print_error("invalid hex number: " + lineBuffer, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid hex number: " + lineBuffer, "CompilerKit");
throw std::runtime_error("invalid_hex");
}
}
@@ -43,7 +43,7 @@ static NumberCast32 GetNumber32(STLString lineBuffer, STLString numberKey) {
case 'b': {
if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 2); !res) {
if (errno != 0) {
- Detail::print_error("invalid binary number:" + lineBuffer, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid binary number:" + lineBuffer, "CompilerKit");
throw std::runtime_error("invalid_bin");
}
}
@@ -59,7 +59,7 @@ static NumberCast32 GetNumber32(STLString lineBuffer, STLString numberKey) {
case 'o': {
if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 7); !res) {
if (errno != 0) {
- Detail::print_error("invalid octal number: " + lineBuffer, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid octal number: " + lineBuffer, "CompilerKit");
throw std::runtime_error("invalid_octal");
}
}
@@ -75,7 +75,7 @@ static NumberCast32 GetNumber32(STLString lineBuffer, STLString numberKey) {
default: {
if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 10); !res) {
if (errno != 0) {
- Detail::print_error("invalid hex number: " + lineBuffer, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid hex number: " + lineBuffer, "CompilerKit");
throw std::runtime_error("invalid_hex");
}
}
diff --git a/src/CompilerKit/Utilities/Compiler.h b/src/CompilerKit/Utilities/Compiler.h
index 165ab53..bbca020 100644
--- a/src/CompilerKit/Utilities/Compiler.h
+++ b/src/CompilerKit/Utilities/Compiler.h
@@ -37,14 +37,18 @@ inline static UInt32 kAcceptableErrors = 0;
inline static bool kVerbose = false;
inline static bool kOutputAsBinary = false;
-namespace Detail {
-/// @brief Linker specific blob metadata structure
-struct DynamicLinkerBlob final {
+namespace CompilerKit::Detail {
+/// @brief Blob structure
+struct Blob final {
std::vector<Char> mBlob{}; // PEF code/bss/data blob.
UIntPtr mOffset{0UL}; // the offset of the PEF container header...
+
+ explicit operator bool() {
+ return mBlob.empty() && mOffset > 0UL;
+ }
};
-inline void print_error(std::string reason, std::string file) noexcept {
+inline void print_error(STLString reason, STLString file) noexcept {
if (reason[0] == '\n') reason.erase(0, 1);
kStdErr << reason << kBlank << std::endl;
@@ -54,7 +58,7 @@ inline void print_error(std::string reason, std::string file) noexcept {
++kAcceptableErrors;
}
-inline void print_warning(std::string reason, std::string file) noexcept {
+inline void print_warning(STLString reason, STLString file) noexcept {
if (reason[0] == '\n') reason.erase(0, 1);
kStdOut << kYellow << reason << kBlank << std::endl;
diff --git a/src/CompilerKit/Utilities/DLL.h b/src/CompilerKit/Utilities/DLL.h
index 58e0cc7..5bfe032 100644
--- a/src/CompilerKit/Utilities/DLL.h
+++ b/src/CompilerKit/Utilities/DLL.h
@@ -20,6 +20,10 @@ struct CompilerKitDylibTraits final {
CompilerKitEntrypoint fEntrypoint{nullptr};
std::mutex fMutex;
+ explicit operator bool() {
+ return fDylib && fEntrypoint;
+ }
+
CompilerKitDylibTraits& operator()(const Char* path, const Char* fEntrypoint) {
std::lock_guard<std::mutex> lock(this->fMutex);
diff --git a/src/CompilerKit/src/Backend/Assembler32x0.cc b/src/CompilerKit/src/Assemblers/Assembler+32x0.cc
index fd44ffa..9229cf1 100644
--- a/src/CompilerKit/src/Backend/Assembler32x0.cc
+++ b/src/CompilerKit/src/Assemblers/Assembler+32x0.cc
@@ -34,6 +34,6 @@
/////////////////////////////////////////////////////////////////////////////////////////
NECTI_MODULE(NEAssemblerMain32000) {
- CompilerKit::install_signal(SIGSEGV, Detail::drvi_crash_handler);
+ CompilerKit::install_signal(SIGSEGV, CompilerKit::Detail::drvi_crash_handler);
return EXIT_SUCCESS;
}
diff --git a/src/CompilerKit/src/Backend/Assembler64x0.cc b/src/CompilerKit/src/Assemblers/Assembler+64x0.cc
index f84ee46..3fd588a 100644
--- a/src/CompilerKit/src/Backend/Assembler64x0.cc
+++ b/src/CompilerKit/src/Assemblers/Assembler+64x0.cc
@@ -68,7 +68,7 @@ static bool asm_read_attributes(std::string line);
/////////////////////////////////////////////////////////////////////////////////////////
NECTI_MODULE(AssemblerMain64x0) {
- CompilerKit::install_signal(SIGSEGV, Detail::drvi_crash_handler);
+ CompilerKit::install_signal(SIGSEGV, CompilerKit::Detail::drvi_crash_handler);
for (size_t i = 1; i < argc; ++i) {
if (argv[i][0] == '-') {
@@ -144,7 +144,7 @@ NECTI_MODULE(AssemblerMain64x0) {
while (std::getline(file_ptr, line)) {
if (auto ln = asm64.CheckLine(line, argv[i]); !ln.empty()) {
- Detail::print_error(ln, argv[i]);
+ CompilerKit::Detail::print_error(ln, argv[i]);
continue;
}
@@ -154,7 +154,7 @@ NECTI_MODULE(AssemblerMain64x0) {
} catch (const std::exception& e) {
if (kVerbose) {
std::string what = e.what();
- Detail::print_warning("exit because of: " + what, "CompilerKit");
+ CompilerKit::Detail::print_warning("exit because of: " + what, "CompilerKit");
}
std::filesystem::remove(object_output);
@@ -269,7 +269,7 @@ static bool asm_read_attributes(std::string line) {
// that we need this symbol.
if (CompilerKit::find_word(line, "extern_segment")) {
if (kOutputAsBinary) {
- Detail::print_error("Invalid extern_segment directive in flat binary mode.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid extern_segment directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_extern_segment_bin");
}
@@ -277,7 +277,7 @@ static bool asm_read_attributes(std::string line) {
/// sanity check to avoid stupid linker errors.
if (name.size() == 0) {
- Detail::print_error("Invalid extern_segment", "power-as");
+ CompilerKit::Detail::print_error("Invalid extern_segment", "power-as");
throw std::runtime_error("invalid_extern_segment");
}
@@ -329,7 +329,7 @@ static bool asm_read_attributes(std::string line) {
// .zero64
else if (CompilerKit::find_word(line, "public_segment")) {
if (kOutputAsBinary) {
- Detail::print_error("Invalid public_segment directive in flat binary mode.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid public_segment directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_public_segment_bin");
}
@@ -391,7 +391,7 @@ static bool asm_read_attributes(std::string line) {
// \brief algorithms and helpers.
-namespace Detail::algorithm {
+namespace CompilerKit::Detail::algorithm {
// \brief authorize a brief set of characters.
static inline bool is_not_alnum_space(char c) {
return !(isalpha(c) || isdigit(c) || (c == ' ') || (c == '\t') || (c == ',') || (c == '(') ||
@@ -402,7 +402,7 @@ static inline bool is_not_alnum_space(char c) {
bool is_valid_64x0(std::string str) {
return std::find_if(str.begin(), str.end(), is_not_alnum_space) == str.end();
}
-} // namespace Detail::algorithm
+} // namespace CompilerKit::Detail::algorithm
/////////////////////////////////////////////////////////////////////////////////////////
@@ -422,7 +422,7 @@ std::string CompilerKit::Encoder64x0::CheckLine(std::string line, std::string fi
line.erase(line.find(';'));
} else {
// now check the line for validity
- if (!Detail::algorithm::is_valid_64x0(line)) {
+ if (!CompilerKit::Detail::algorithm::is_valid_64x0(line)) {
err_str = "Line contains non alphanumeric characters.\nhere -> ";
err_str += line;
}
@@ -431,7 +431,7 @@ std::string CompilerKit::Encoder64x0::CheckLine(std::string line, std::string fi
return err_str;
}
- if (!Detail::algorithm::is_valid_64x0(line)) {
+ if (!CompilerKit::Detail::algorithm::is_valid_64x0(line)) {
err_str = "Line contains non alphanumeric characters.\nhere -> ";
err_str += line;
@@ -523,7 +523,7 @@ bool CompilerKit::Encoder64x0::WriteNumber(const std::size_t& pos, std::string&
case 'x': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 16); !res) {
if (errno != 0) {
- Detail::print_error("invalid hex number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid hex number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_hex_number");
}
}
@@ -543,7 +543,7 @@ bool CompilerKit::Encoder64x0::WriteNumber(const std::size_t& pos, std::string&
case 'b': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 2); !res) {
if (errno != 0) {
- Detail::print_error("invalid binary number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid binary number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_bin");
}
}
@@ -563,7 +563,7 @@ bool CompilerKit::Encoder64x0::WriteNumber(const std::size_t& pos, std::string&
case 'o': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 7); !res) {
if (errno != 0) {
- Detail::print_error("invalid octal number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid octal number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_octal");
}
}
@@ -616,7 +616,7 @@ bool CompilerKit::Encoder64x0::WriteLine(std::string line, std::string file) {
for (auto& opcode64x0 : kOpcodes64x0) {
// strict check here
- if (CompilerKit::find_word(line, opcode64x0.fName) && Detail::algorithm::is_valid_64x0(line)) {
+ if (CompilerKit::find_word(line, opcode64x0.fName) && CompilerKit::Detail::algorithm::is_valid_64x0(line)) {
std::string name(opcode64x0.fName);
std::string jump_label, cpy_jump_label;
@@ -649,7 +649,7 @@ bool CompilerKit::Encoder64x0::WriteLine(std::string line, std::string file) {
if (kOutputArch == CompilerKit::kPefArch64000) {
if (isdigit(line[line_index + 3]) && isdigit(line[line_index + 2])) {
reg_str += line[line_index + 3];
- Detail::print_error("invalid register index, r" + reg_str +
+ CompilerKit::Detail::print_error("invalid register index, r" + reg_str +
"\nnote: The 64x0 accepts registers from r0 to r20.",
file);
throw std::runtime_error("invalid_register_index");
@@ -660,7 +660,7 @@ bool CompilerKit::Encoder64x0::WriteLine(std::string line, std::string file) {
std::size_t reg_index = strtol(reg_str.c_str(), nullptr, 10);
if (reg_index > kAsmRegisterLimit) {
- Detail::print_error("invalid register index, r" + reg_str, file);
+ CompilerKit::Detail::print_error("invalid register index, r" + reg_str, file);
throw std::runtime_error("invalid_register_index");
}
@@ -678,7 +678,7 @@ bool CompilerKit::Encoder64x0::WriteLine(std::string line, std::string file) {
if (opcode64x0.fFunct7 != kAsmImmediate) {
// remember! register to register!
if (found_some == 1) {
- Detail::print_error(
+ CompilerKit::Detail::print_error(
"Too few registers.\ntip: each Assembler64x0 register "
"starts with 'r'.\nline: " +
line,
@@ -688,21 +688,21 @@ bool CompilerKit::Encoder64x0::WriteLine(std::string line, std::string file) {
}
if (found_some < 1 && name != "ldw" && name != "lda" && name != "stw") {
- Detail::print_error("invalid combination of opcode and registers.\nline: " + line,
+ CompilerKit::Detail::print_error("invalid combination of opcode and registers.\nline: " + line,
file);
throw std::runtime_error("invalid_comb_op_reg");
} else if (found_some == 1 && name == "add") {
- Detail::print_error("invalid combination of opcode and registers.\nline: " + line,
+ CompilerKit::Detail::print_error("invalid combination of opcode and registers.\nline: " + line,
file);
throw std::runtime_error("invalid_comb_op_reg");
} else if (found_some == 1 && name == "sub") {
- Detail::print_error("invalid combination of opcode and registers.\nline: " + line,
+ CompilerKit::Detail::print_error("invalid combination of opcode and registers.\nline: " + line,
file);
throw std::runtime_error("invalid_comb_op_reg");
}
if (found_some > 0 && name == "pop") {
- Detail::print_error(
+ CompilerKit::Detail::print_error(
"invalid combination for opcode 'pop'.\ntip: it expects "
"nothing.\nline: " +
line,
@@ -735,7 +735,7 @@ bool CompilerKit::Encoder64x0::WriteLine(std::string line, std::string file) {
if (jump_label[0] != kAsmRegisterPrefix[0] && !isdigit(jump_label[1])) {
if (found_sym) {
- Detail::print_error(
+ CompilerKit::Detail::print_error(
"invalid combination of opcode and operands.\nhere -> " + jump_label, file);
throw std::runtime_error("invalid_comb_op_ops");
} else {
@@ -759,13 +759,13 @@ bool CompilerKit::Encoder64x0::WriteLine(std::string line, std::string file) {
if (!this->WriteNumber(0, jump_label)) {
// sta expects this: sta 0x000000, r0
if (name == "sta") {
- Detail::print_error("invalid combination of opcode and operands.\nHere ->" + line,
+ CompilerKit::Detail::print_error("invalid combination of opcode and operands.\nHere ->" + line,
file);
throw std::runtime_error("invalid_comb_op_ops");
}
} else {
if (name == "sta" && cpy_jump_label.find("extern_segment ") != std::string::npos) {
- Detail::print_error("invalid usage extern_segment on 'sta', here: " + line, file);
+ CompilerKit::Detail::print_error("invalid usage extern_segment on 'sta', here: " + line, file);
throw std::runtime_error("invalid_sta_usage");
}
}
@@ -783,7 +783,7 @@ bool CompilerKit::Encoder64x0::WriteLine(std::string line, std::string file) {
cpy_jump_label.erase(cpy_jump_label.find("extern_segment"), strlen("extern_segment"));
if (name == "sta") {
- Detail::print_error("extern_segment is not allowed on a sta operation.", file);
+ CompilerKit::Detail::print_error("extern_segment is not allowed on a sta operation.", file);
throw std::runtime_error("extern_segment_sta_op");
} else {
goto asm_end_label_cpy;
@@ -829,7 +829,7 @@ bool CompilerKit::Encoder64x0::WriteLine(std::string line, std::string file) {
}
if (cpy_jump_label.size() < 1) {
- Detail::print_error("label is empty, can't jump on it.", file);
+ CompilerKit::Detail::print_error("label is empty, can't jump on it.", file);
throw std::runtime_error("label_empty");
}
diff --git a/src/CompilerKit/src/Backend/AssemblerAMD64.cc b/src/CompilerKit/src/Assemblers/Assembler+AMD64.cc
index ba1dd77..5b3d665 100644
--- a/src/CompilerKit/src/Backend/AssemblerAMD64.cc
+++ b/src/CompilerKit/src/Assemblers/Assembler+AMD64.cc
@@ -86,7 +86,7 @@ static bool asm_read_attributes(std::string line);
NECTI_MODULE(AssemblerMainAMD64) {
//////////////// CPU OPCODES BEGIN ////////////////
- CompilerKit::install_signal(SIGSEGV, Detail::drvi_crash_handler);
+ CompilerKit::install_signal(SIGSEGV, CompilerKit::Detail::drvi_crash_handler);
std::string opcodes_jump[kJumpLimit] = {"ja", "jae", "jb", "jbe", "jc", "je", "jg", "jge",
"jl", "jle", "jna", "jnae", "jnb", "jnbe", "jnc", "jne",
@@ -205,7 +205,7 @@ NECTI_MODULE(AssemblerMainAMD64) {
while (std::getline(file_ptr, line)) {
if (auto ln = asm64.CheckLine(line, argv[i]); !ln.empty()) {
- Detail::print_error(ln, argv[i]);
+ CompilerKit::Detail::print_error(ln, argv[i]);
continue;
}
@@ -215,7 +215,7 @@ NECTI_MODULE(AssemblerMainAMD64) {
} catch (const std::exception& e) {
if (kVerbose) {
std::string what = e.what();
- Detail::print_warning("exit because of: " + what, "CompilerKit");
+ CompilerKit::Detail::print_warning("exit because of: " + what, "CompilerKit");
}
try {
@@ -340,14 +340,14 @@ static bool asm_read_attributes(std::string line) {
// that we need this symbol.
if (CompilerKit::find_word(line, "extern_segment")) {
if (kOutputAsBinary) {
- Detail::print_error("Invalid directive in flat binary mode.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_extern_segment_bin");
}
auto name = line.substr(line.find("extern_segment") + strlen("extern_segment") + 1);
if (name.size() == 0) {
- Detail::print_error("Invalid extern_segment", "power-as");
+ CompilerKit::Detail::print_error("Invalid extern_segment", "power-as");
throw std::runtime_error("invalid_extern_segment");
}
@@ -399,7 +399,7 @@ static bool asm_read_attributes(std::string line) {
// .zero64.
else if (CompilerKit::find_word(line, "public_segment")) {
if (kOutputAsBinary) {
- Detail::print_error("Invalid directive in flat binary mode.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_public_segment_bin");
}
@@ -412,7 +412,7 @@ static bool asm_read_attributes(std::string line) {
}
if (std::find(kDefinedSymbols.begin(), kDefinedSymbols.end(), name) != kDefinedSymbols.end()) {
- Detail::print_error("Symbol already defined.", "CompilerKit");
+ CompilerKit::Detail::print_error("Symbol already defined.", "CompilerKit");
throw std::runtime_error("invalid_public_segment_bin");
}
@@ -468,7 +468,7 @@ static bool asm_read_attributes(std::string line) {
// \brief algorithms and helpers.
-namespace Detail::algorithm {
+namespace CompilerKit::Detail::algorithm {
// \brief authorize a brief set of characters.
static inline bool is_not_valid(char c) {
if ((isalpha(c) || isdigit(c)) ||
@@ -483,7 +483,7 @@ static inline bool is_not_valid(char c) {
bool is_valid_amd64(std::string str) {
return std::find_if(str.begin(), str.end(), is_not_valid) == str.end();
}
-} // namespace Detail::algorithm
+} // namespace CompilerKit::Detail::algorithm
/////////////////////////////////////////////////////////////////////////////////////////
@@ -502,7 +502,7 @@ std::string CompilerKit::EncoderAMD64::CheckLine(std::string line, std::string f
line.erase(line.find(';'));
} else {
// now check the line for validity
- if (!Detail::algorithm::is_valid_amd64(line)) {
+ if (!CompilerKit::Detail::algorithm::is_valid_amd64(line)) {
err_str = "Line contains non valid characters.\nhere -> ";
err_str += line;
}
@@ -564,7 +564,7 @@ bool CompilerKit::EncoderAMD64::WriteNumber(const std::size_t& pos, std::string&
case 'x': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 16); !res) {
if (errno != 0) {
- Detail::print_error("invalid hex number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid hex number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_hex");
}
}
@@ -588,7 +588,7 @@ bool CompilerKit::EncoderAMD64::WriteNumber(const std::size_t& pos, std::string&
case 'b': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 2); !res) {
if (errno != 0) {
- Detail::print_error("invalid binary number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid binary number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_bin");
}
}
@@ -611,7 +611,7 @@ bool CompilerKit::EncoderAMD64::WriteNumber(const std::size_t& pos, std::string&
case 'o': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 7); !res) {
if (errno != 0) {
- Detail::print_error("invalid octal number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid octal number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_octal");
}
}
@@ -764,7 +764,7 @@ bool CompilerKit::EncoderAMD64::WriteNumber16(const std::size_t& pos, std::strin
case 'x': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 16); !res) {
if (errno != 0) {
- Detail::print_error("invalid hex number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid hex number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_hex");
}
}
@@ -788,7 +788,7 @@ bool CompilerKit::EncoderAMD64::WriteNumber16(const std::size_t& pos, std::strin
case 'b': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 2); !res) {
if (errno != 0) {
- Detail::print_error("invalid binary number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid binary number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_bin");
}
}
@@ -811,7 +811,7 @@ bool CompilerKit::EncoderAMD64::WriteNumber16(const std::size_t& pos, std::strin
case 'o': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 7); !res) {
if (errno != 0) {
- Detail::print_error("invalid octal number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid octal number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_octal");
}
}
@@ -866,7 +866,7 @@ bool CompilerKit::EncoderAMD64::WriteNumber8(const std::size_t& pos, std::string
case 'x': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 16); !res) {
if (errno != 0) {
- Detail::print_error("invalid hex number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid hex number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_hex");
}
}
@@ -886,7 +886,7 @@ bool CompilerKit::EncoderAMD64::WriteNumber8(const std::size_t& pos, std::string
case 'b': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 2); !res) {
if (errno != 0) {
- Detail::print_error("invalid binary number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid binary number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_bin");
}
}
@@ -905,7 +905,7 @@ bool CompilerKit::EncoderAMD64::WriteNumber8(const std::size_t& pos, std::string
case 'o': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 7); !res) {
if (errno != 0) {
- Detail::print_error("invalid octal number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid octal number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_octal");
}
}
@@ -971,7 +971,7 @@ bool CompilerKit::EncoderAMD64::WriteLine(std::string line, std::string file) {
for (auto& opcodeAMD64 : kOpcodesAMD64) {
// strict check here
if (CompilerKit::find_word(line, opcodeAMD64.fName) &&
- Detail::algorithm::is_valid_amd64(line)) {
+ CompilerKit::Detail::algorithm::is_valid_amd64(line)) {
foundInstruction = true;
std::string name(opcodeAMD64.fName);
@@ -983,7 +983,7 @@ bool CompilerKit::EncoderAMD64::WriteLine(std::string line, std::string file) {
uint64_t bits = kRegisterBitWidth;
if (substr.find(",") == std::string::npos) {
- Detail::print_error("Syntax error: missing right operand.", "CompilerKit");
+ CompilerKit::Detail::print_error("Syntax error: missing right operand.", "CompilerKit");
throw std::runtime_error("syntax_err");
}
@@ -1006,7 +1006,7 @@ bool CompilerKit::EncoderAMD64::WriteLine(std::string line, std::string file) {
if (bits == 16) {
if (registerName[0] == 'r') {
- Detail::print_error("invalid size for register, current bit width is: " +
+ CompilerKit::Detail::print_error("invalid size for register, current bit width is: " +
std::to_string(kRegisterBitWidth),
file);
throw std::runtime_error("invalid_reg_size");
@@ -1046,7 +1046,7 @@ bool CompilerKit::EncoderAMD64::WriteLine(std::string line, std::string file) {
if (!onlyOneReg) kAppBytes.emplace_back(0x89);
} else if (bits == 16) {
if (hasRBasedRegs) {
- Detail::print_error("Invalid combination of operands and registers.",
+ CompilerKit::Detail::print_error("Invalid combination of operands and registers.",
"CompilerKit");
throw std::runtime_error("comb_op_reg");
} else {
@@ -1085,33 +1085,33 @@ bool CompilerKit::EncoderAMD64::WriteLine(std::string line, std::string file) {
}
if (currentRegList[1].fName[0] == 'r' && currentRegList[0].fName[0] == 'e') {
- Detail::print_error("Invalid combination of operands and registers.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid combination of operands and registers.", "CompilerKit");
throw std::runtime_error("comb_op_reg");
}
if (currentRegList[0].fName[0] == 'r' && currentRegList[1].fName[0] == 'e') {
- Detail::print_error("Invalid combination of operands and registers.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid combination of operands and registers.", "CompilerKit");
throw std::runtime_error("comb_op_reg");
}
if (bits == 16) {
if (currentRegList[0].fName[0] == 'r' || currentRegList[0].fName[0] == 'e') {
- Detail::print_error("Invalid combination of operands and registers.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid combination of operands and registers.", "CompilerKit");
throw std::runtime_error("comb_op_reg");
}
if (currentRegList[1].fName[0] == 'r' || currentRegList[1].fName[0] == 'e') {
- Detail::print_error("Invalid combination of operands and registers.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid combination of operands and registers.", "CompilerKit");
throw std::runtime_error("comb_op_reg");
}
} else {
if (currentRegList[0].fName[0] != 'r' || currentRegList[0].fName[0] == 'e') {
- Detail::print_error("Invalid combination of operands and registers.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid combination of operands and registers.", "CompilerKit");
throw std::runtime_error("comb_op_reg");
}
if (currentRegList[1].fName[0] != 'r' || currentRegList[1].fName[0] == 'e') {
- Detail::print_error("Invalid combination of operands and registers.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid combination of operands and registers.", "CompilerKit");
throw std::runtime_error("comb_op_reg");
}
}
@@ -1154,7 +1154,7 @@ bool CompilerKit::EncoderAMD64::WriteLine(std::string line, std::string file) {
if (line[0] == kAssemblerPragmaSym) {
if (foundInstruction) {
- Detail::print_error("Syntax error: " + line, file);
+ CompilerKit::Detail::print_error("Syntax error: " + line, file);
throw std::runtime_error("syntax_err");
}
diff --git a/src/CompilerKit/src/Backend/AssemblerARM64.cc b/src/CompilerKit/src/Assemblers/Assembler+ARM64.cc
index abc7d13..3bce0ff 100644
--- a/src/CompilerKit/src/Backend/AssemblerARM64.cc
+++ b/src/CompilerKit/src/Assemblers/Assembler+ARM64.cc
@@ -73,7 +73,7 @@ static bool asm_read_attributes(std::string line);
/////////////////////////////////////////////////////////////////////////////////////////
NECTI_MODULE(AssemblerMainARM64) {
- CompilerKit::install_signal(SIGSEGV, Detail::drvi_crash_handler);
+ CompilerKit::install_signal(SIGSEGV, CompilerKit::Detail::drvi_crash_handler);
for (size_t i = 1; i < argc; ++i) {
if (argv[i][0] == '-') {
@@ -149,7 +149,7 @@ NECTI_MODULE(AssemblerMainARM64) {
while (std::getline(file_ptr, line)) {
if (auto ln = asm64.CheckLine(line, argv[i]); !ln.empty()) {
- Detail::print_error(ln, argv[i]);
+ CompilerKit::Detail::print_error(ln, argv[i]);
continue;
}
@@ -159,7 +159,7 @@ NECTI_MODULE(AssemblerMainARM64) {
} catch (const std::exception& e) {
if (kVerbose) {
std::string what = e.what();
- Detail::print_warning("exit because of: " + what, "CompilerKit");
+ CompilerKit::Detail::print_warning("exit because of: " + what, "CompilerKit");
}
std::filesystem::remove(object_output);
@@ -274,14 +274,14 @@ static bool asm_read_attributes(std::string line) {
// that we need this symbol.
if (CompilerKit::find_word(line, "extern_segment")) {
if (kOutputAsBinary) {
- Detail::print_error("Invalid extern_segment directive in flat binary mode.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid extern_segment directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_extern_segment_bin");
}
auto name = line.substr(line.find("extern_segment") + strlen("extern_segment") + 1);
if (name.size() == 0) {
- Detail::print_error("Invalid extern_segment", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid extern_segment", "CompilerKit");
throw std::runtime_error("invalid_extern_segment");
}
@@ -333,7 +333,7 @@ static bool asm_read_attributes(std::string line) {
// .zero64
else if (CompilerKit::find_word(line, "public_segment")) {
if (kOutputAsBinary) {
- Detail::print_error("Invalid public_segment directive in flat binary mode.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid public_segment directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_public_segment_bin");
}
@@ -395,7 +395,7 @@ static bool asm_read_attributes(std::string line) {
// \brief algorithms and helpers.
-namespace Detail::algorithm {
+namespace CompilerKit::Detail::algorithm {
// \brief authorize a brief set of characters.
static inline bool is_not_alnum_space(char c) {
return !(isalpha(c) || isdigit(c) || (c == ' ') || (c == '\t') || (c == ',') || (c == '(') ||
@@ -406,7 +406,7 @@ static inline bool is_not_alnum_space(char c) {
bool is_valid_arm64(std::string str) {
return std::find_if(str.begin(), str.end(), is_not_alnum_space) == str.end();
}
-} // namespace Detail::algorithm
+} // namespace CompilerKit::Detail::algorithm
/////////////////////////////////////////////////////////////////////////////////////////
@@ -426,7 +426,7 @@ std::string CompilerKit::EncoderARM64::CheckLine(std::string line, std::string f
line.erase(line.find(';'));
} else {
/// does the line contains valid input?
- if (!Detail::algorithm::is_valid_arm64(line)) {
+ if (!CompilerKit::Detail::algorithm::is_valid_arm64(line)) {
err_str = "Line contains non alphanumeric characters.\nhere -> ";
err_str += line;
}
@@ -435,7 +435,7 @@ std::string CompilerKit::EncoderARM64::CheckLine(std::string line, std::string f
return err_str;
}
- if (!Detail::algorithm::is_valid_arm64(line)) {
+ if (!CompilerKit::Detail::algorithm::is_valid_arm64(line)) {
err_str = "Line contains non alphanumeric characters.\nhere -> ";
err_str += line;
@@ -488,7 +488,7 @@ bool CompilerKit::EncoderARM64::WriteNumber(const std::size_t& pos, std::string&
case 'x': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 16); !res) {
if (errno != 0) {
- Detail::print_error("invalid hex number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid hex number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_hex");
}
}
@@ -509,7 +509,7 @@ bool CompilerKit::EncoderARM64::WriteNumber(const std::size_t& pos, std::string&
case 'b': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 2); !res) {
if (errno != 0) {
- Detail::print_error("invalid binary number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid binary number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_bin");
}
}
@@ -529,7 +529,7 @@ bool CompilerKit::EncoderARM64::WriteNumber(const std::size_t& pos, std::string&
case 'o': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 7); !res) {
if (errno != 0) {
- Detail::print_error("invalid octal number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid octal number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_octal");
}
}
@@ -580,7 +580,7 @@ bool CompilerKit::EncoderARM64::WriteNumber(const std::size_t& pos, std::string&
bool CompilerKit::EncoderARM64::WriteLine(std::string line, std::string file) {
if (CompilerKit::find_word(line, "public_segment")) return false;
- if (!Detail::algorithm::is_valid_arm64(line)) return false;
+ if (!CompilerKit::Detail::algorithm::is_valid_arm64(line)) return false;
return true;
}
diff --git a/src/CompilerKit/src/Backend/AssemblerPowerPC.cc b/src/CompilerKit/src/Assemblers/Assembler+PowerPC.cc
index c7d57e3..4bb9876 100644
--- a/src/CompilerKit/src/Backend/AssemblerPowerPC.cc
+++ b/src/CompilerKit/src/Assemblers/Assembler+PowerPC.cc
@@ -73,7 +73,7 @@ static bool asm_read_attributes(std::string line);
/////////////////////////////////////////////////////////////////////////////////////////
NECTI_MODULE(AssemblerMainPower64) {
- CompilerKit::install_signal(SIGSEGV, Detail::drvi_crash_handler);
+ CompilerKit::install_signal(SIGSEGV, CompilerKit::Detail::drvi_crash_handler);
for (size_t i = 1; i < argc; ++i) {
if (argv[i][0] == '-') {
@@ -149,7 +149,7 @@ NECTI_MODULE(AssemblerMainPower64) {
while (std::getline(file_ptr, line)) {
if (auto ln = asm64.CheckLine(line, argv[i]); !ln.empty()) {
- Detail::print_error(ln, argv[i]);
+ CompilerKit::Detail::print_error(ln, argv[i]);
continue;
}
@@ -159,7 +159,7 @@ NECTI_MODULE(AssemblerMainPower64) {
} catch (const std::exception& e) {
if (kVerbose) {
std::string what = e.what();
- Detail::print_warning("exit because of: " + what, "CompilerKit");
+ CompilerKit::Detail::print_warning("exit because of: " + what, "CompilerKit");
}
std::filesystem::remove(object_output);
@@ -274,14 +274,14 @@ static bool asm_read_attributes(std::string line) {
// that we need this symbol.
if (CompilerKit::find_word(line, "extern_segment")) {
if (kOutputAsBinary) {
- Detail::print_error("Invalid extern_segment directive in flat binary mode.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid extern_segment directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_extern_segment_bin");
}
auto name = line.substr(line.find("extern_segment") + strlen("extern_segment") + 1);
if (name.size() == 0) {
- Detail::print_error("Invalid extern_segment", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid extern_segment", "CompilerKit");
throw std::runtime_error("invalid_extern_segment");
}
@@ -333,7 +333,7 @@ static bool asm_read_attributes(std::string line) {
// .zero64
else if (CompilerKit::find_word(line, "public_segment")) {
if (kOutputAsBinary) {
- Detail::print_error("Invalid public_segment directive in flat binary mode.", "CompilerKit");
+ CompilerKit::Detail::print_error("Invalid public_segment directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_public_segment_bin");
}
@@ -395,7 +395,7 @@ static bool asm_read_attributes(std::string line) {
// \brief algorithms and helpers.
-namespace Detail::algorithm {
+namespace CompilerKit::Detail::algorithm {
// \brief authorize a brief set of characters.
static inline bool is_not_alnum_space(char c) {
return !(isalpha(c) || isdigit(c) || (c == ' ') || (c == '\t') || (c == ',') || (c == '(') ||
@@ -406,7 +406,7 @@ static inline bool is_not_alnum_space(char c) {
bool is_valid_power64(std::string str) {
return std::find_if(str.begin(), str.end(), is_not_alnum_space) == str.end();
}
-} // namespace Detail::algorithm
+} // namespace CompilerKit::Detail::algorithm
/////////////////////////////////////////////////////////////////////////////////////////
@@ -426,7 +426,7 @@ std::string CompilerKit::EncoderPowerPC::CheckLine(std::string line, std::string
line.erase(line.find(';'));
} else {
/// does the line contains valid input?
- if (!Detail::algorithm::is_valid_power64(line)) {
+ if (!CompilerKit::Detail::algorithm::is_valid_power64(line)) {
err_str = "Line contains non alphanumeric characters.\nhere -> ";
err_str += line;
}
@@ -435,7 +435,7 @@ std::string CompilerKit::EncoderPowerPC::CheckLine(std::string line, std::string
return err_str;
}
- if (!Detail::algorithm::is_valid_power64(line)) {
+ if (!CompilerKit::Detail::algorithm::is_valid_power64(line)) {
err_str = "Line contains non alphanumeric characters.\nhere -> ";
err_str += line;
@@ -525,7 +525,7 @@ bool CompilerKit::EncoderPowerPC::WriteNumber(const std::size_t& pos, std::strin
case 'x': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 16); !res) {
if (errno != 0) {
- Detail::print_error("invalid hex number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid hex number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_hex");
}
}
@@ -546,7 +546,7 @@ bool CompilerKit::EncoderPowerPC::WriteNumber(const std::size_t& pos, std::strin
case 'b': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 2); !res) {
if (errno != 0) {
- Detail::print_error("invalid binary number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid binary number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_bin");
}
}
@@ -566,7 +566,7 @@ bool CompilerKit::EncoderPowerPC::WriteNumber(const std::size_t& pos, std::strin
case 'o': {
if (auto res = strtol(jump_label.substr(pos + 2).c_str(), nullptr, 7); !res) {
if (errno != 0) {
- Detail::print_error("invalid octal number: " + jump_label, "CompilerKit");
+ CompilerKit::Detail::print_error("invalid octal number: " + jump_label, "CompilerKit");
throw std::runtime_error("invalid_octal");
}
}
@@ -616,7 +616,7 @@ bool CompilerKit::EncoderPowerPC::WriteNumber(const std::size_t& pos, std::strin
bool CompilerKit::EncoderPowerPC::WriteLine(std::string line, std::string file) {
if (CompilerKit::find_word(line, "public_segment")) return false;
- if (!Detail::algorithm::is_valid_power64(line)) return false;
+ if (!CompilerKit::Detail::algorithm::is_valid_power64(line)) return false;
for (auto& opcode_risc : kOpcodesPowerPC) {
// strict check here
@@ -676,7 +676,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string line, std::string file)
// something like r190 doesn't exist in the instruction set.
if (isdigit(line[line_index + 3]) && isdigit(line[line_index + 2])) {
reg_str += line[line_index + 3];
- Detail::print_error("invalid register index, r" + reg_str +
+ CompilerKit::Detail::print_error("invalid register index, r" + reg_str +
"\nnote: The POWER accepts registers from r0 to r32.",
file);
throw std::runtime_error("invalid_register_index");
@@ -686,7 +686,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string line, std::string file)
std::size_t reg_index = strtol(reg_str.c_str(), nullptr, 10);
if (reg_index > kAsmRegisterLimit) {
- Detail::print_error("invalid register index, r" + reg_str, file);
+ CompilerKit::Detail::print_error("invalid register index, r" + reg_str, file);
throw std::runtime_error("invalid_register_index");
}
@@ -707,7 +707,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string line, std::string file)
// check if bigger than two.
for (size_t i = 2; i < 4; i++) {
if (num.number[i] > 0) {
- Detail::print_warning("number overflow on li operation.", file);
+ CompilerKit::Detail::print_warning("number overflow on li operation.", file);
break;
}
}
@@ -783,7 +783,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string line, std::string file)
++found_some_count;
if (found_some_count > 3) {
- Detail::print_error("Too much registers. -> " + line, file);
+ CompilerKit::Detail::print_error("Too much registers. -> " + line, file);
throw std::runtime_error("too_much_regs");
}
}
@@ -792,7 +792,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string line, std::string file)
++found_some_count;
if (found_some_count > 3) {
- Detail::print_error("Too much registers. -> " + line, file);
+ CompilerKit::Detail::print_error("Too much registers. -> " + line, file);
throw std::runtime_error("too_much_regs");
}
}
@@ -810,7 +810,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string line, std::string file)
++found_some_count;
if (found_some_count > 1) {
- Detail::print_error("Too much registers. -> " + line, file);
+ CompilerKit::Detail::print_error("Too much registers. -> " + line, file);
throw std::runtime_error("too_much_regs");
}
@@ -872,7 +872,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string line, std::string file)
if (opcodeName == "mr") {
if (register_count == 1) {
- Detail::print_error("Too few registers. -> " + line, file);
+ CompilerKit::Detail::print_error("Too few registers. -> " + line, file);
throw std::runtime_error("too_few_registers");
}
}
@@ -881,7 +881,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string line, std::string file)
if (opcode_risc.ops->type != GREG) {
// remember! register to register!
if (found_some_count == 1) {
- Detail::print_error(
+ CompilerKit::Detail::print_error(
"Unrecognized register found.\ntip: each AssemblerPower register "
"starts with 'r'.\nline: " +
line,
@@ -892,7 +892,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string line, std::string file)
}
if (found_some_count < 1 && name[0] != 'l' && name[0] != 's') {
- Detail::print_error("invalid combination of opcode and registers.\nline: " + line,
+ CompilerKit::Detail::print_error("invalid combination of opcode and registers.\nline: " + line,
file);
throw std::runtime_error("invalid_comb_op_reg");
}
diff --git a/src/CompilerKit/src/Frontend/CCompiler64x0.cc b/src/CompilerKit/src/Compilers/CCompiler+64x0.cc
index e0aed61..8437722 100644
--- a/src/CompilerKit/src/Frontend/CCompiler64x0.cc
+++ b/src/CompilerKit/src/Compilers/CCompiler+64x0.cc
@@ -23,6 +23,8 @@
#include <utility>
#include <vector>
+#define kSourceExt ".c"
+
/* C driver */
/* This is part of the CompilerKit. */
/* (c) Amlal El Mahrouss */
@@ -39,8 +41,6 @@
/////////////////////
-#define kFrontendExt ".c"
-
/////////////////////////////////////
// INTERNAL STUFF OF THE C COMPILER
@@ -346,7 +346,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontend64x0::Compile(std::strin
if (text.find("typedef ") != std::string::npos) continue;
if (text[text_index] == '=' && kInStruct) {
- Detail::print_error("assignement of value in struct " + text, file);
+ CompilerKit::Detail::print_error("assignement of value in struct " + text, file);
continue;
}
@@ -1089,7 +1089,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE {
if (auto err = kCompilerFrontend->Check(line_src.c_str(), src.data()); err.empty()) {
kCompilerFrontend->Compile(line_src, src.data());
} else {
- Detail::print_error(err, src.data());
+ CompilerKit::Detail::print_error(err, src.data());
}
}
@@ -1180,7 +1180,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE {
};
NECTI_MODULE(CompilerCLang64x0) {
- ::signal(SIGSEGV, Detail::drvi_crash_handler);
+ ::signal(SIGSEGV, CompilerKit::Detail::drvi_crash_handler);
kCompilerTypes.push_back({.fName = "void", .fValue = "void"});
kCompilerTypes.push_back({.fName = "char", .fValue = "byte"});
@@ -1239,7 +1239,7 @@ NECTI_MODULE(CompilerCLang64x0) {
std::string err = "Unknown command: ";
err += argv[index];
- Detail::print_error(err, "cc");
+ CompilerKit::Detail::print_error(err, "cc");
continue;
}
@@ -1248,9 +1248,9 @@ NECTI_MODULE(CompilerCLang64x0) {
std::string srcFile = argv[index];
- if (strstr(argv[index], kFrontendExt) == nullptr) {
+ if (strstr(argv[index], kSourceExt) == nullptr) {
if (kState.fVerbose) {
- Detail::print_error(srcFile + " is not a valid C source.\n", "cc");
+ CompilerKit::Detail::print_error(srcFile + " is not a valid C source.\n", "cc");
}
return 1;
diff --git a/src/CompilerKit/src/Frontend/CCompilerARM64.cc b/src/CompilerKit/src/Compilers/CCompiler+ARM64.cc
index 811f4ea..45ec9a3 100644
--- a/src/CompilerKit/src/Frontend/CCompilerARM64.cc
+++ b/src/CompilerKit/src/Compilers/CCompiler+ARM64.cc
@@ -24,6 +24,8 @@
#include <utility>
#include <vector>
+#define kSourceExt ".c"
+
/* C driver */
/* This is part of the CompilerKit. */
/* (c) Amlal El Mahrouss */
@@ -40,7 +42,6 @@
/////////////////////
-#define kCExtension ".c"
/////////////////////////////////////
@@ -345,7 +346,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendARM64::Compile(std::stri
if (text.find("typedef ") != std::string::npos) continue;
if (text[text_index] == '=' && kInStruct) {
- Detail::print_error("assignement of value in struct " + text, file);
+ CompilerKit::Detail::print_error("assignement of value in struct " + text, file);
continue;
}
@@ -1088,7 +1089,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE {
if (auto err = kCompilerFrontend->Check(line_src.c_str(), src.data()); err.empty()) {
kCompilerFrontend->Compile(line_src, src.data());
} else {
- Detail::print_error(err, src.data());
+ CompilerKit::Detail::print_error(err, src.data());
}
}
@@ -1179,7 +1180,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE {
};
NECTI_MODULE(CompilerCLangARM64) {
- ::signal(SIGSEGV, Detail::drvi_crash_handler);
+ CompilerKit::install_signal(SIGSEGV, CompilerKit::Detail::drvi_crash_handler);
kCompilerTypes.push_back({.fName = "void", .fValue = "void"});
kCompilerTypes.push_back({.fName = "char", .fValue = "byte"});
@@ -1238,7 +1239,7 @@ NECTI_MODULE(CompilerCLangARM64) {
std::string err = "Unknown command: ";
err += argv[index];
- Detail::print_error(err, "cc");
+ CompilerKit::Detail::print_error(err, "cc");
continue;
}
@@ -1247,9 +1248,9 @@ NECTI_MODULE(CompilerCLangARM64) {
std::string srcFile = argv[index];
- if (strstr(argv[index], kCExtension) == nullptr) {
+ if (strstr(argv[index], kSourceExt) == nullptr) {
if (kState.fVerbose) {
- Detail::print_error(srcFile + " is not a valid C source.\n", "cc");
+ CompilerKit::Detail::print_error(srcFile + " is not a valid C source.\n", "cc");
}
return 1;
diff --git a/src/CompilerKit/src/Frontend/CCompilerPower64.cc b/src/CompilerKit/src/Compilers/CCompiler+Power64.cc
index 03c4d66..7d5dc74 100644
--- a/src/CompilerKit/src/Frontend/CCompilerPower64.cc
+++ b/src/CompilerKit/src/Compilers/CCompiler+Power64.cc
@@ -348,7 +348,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendPower64::Compile(std::st
if (text.find("typedef ") != std::string::npos) continue;
if (text[text_index] == '=' && kInStruct) {
- Detail::print_error("assignement of value inside a struct " + text, file);
+ CompilerKit::Detail::print_error("assignement of value inside a struct " + text, file);
continue;
}
@@ -1101,7 +1101,7 @@ class AssemblyMountpointCLang final CK_ASSEMBLY_INTERFACE {
if (auto err = kCompilerFrontend->Check(line_src.c_str(), src.data()); err.empty()) {
kCompilerFrontend->Compile(line_src, src.data());
} else {
- Detail::print_error(err, src.data());
+ CompilerKit::Detail::print_error(err, src.data());
}
}
@@ -1191,7 +1191,7 @@ class AssemblyMountpointCLang final CK_ASSEMBLY_INTERFACE {
};
NECTI_MODULE(CompilerCLangPowerPC) {
- ::signal(SIGSEGV, Detail::drvi_crash_handler);
+ CompilerKit::install_signal(SIGSEGV, CompilerKit::Detail::drvi_crash_handler);
kCompilerTypes.push_back({.fName = "void", .fValue = "void"});
kCompilerTypes.push_back({.fName = "char", .fValue = "byte"});
@@ -1252,7 +1252,7 @@ NECTI_MODULE(CompilerCLangPowerPC) {
std::string err = "Unknown command: ";
err += argv[index];
- Detail::print_error(err, "cc");
+ CompilerKit::Detail::print_error(err, "cc");
continue;
}
@@ -1263,7 +1263,7 @@ NECTI_MODULE(CompilerCLangPowerPC) {
if (strstr(argv[index], kSourceExt) == nullptr) {
if (kState.fVerbose) {
- Detail::print_error(srcFile + " is not a valid C source.\n", "cc");
+ CompilerKit::Detail::print_error(srcFile + " is not a valid C source.\n", "cc");
}
return 1;
diff --git a/src/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc b/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc
index 87de974..23e1bd8 100644
--- a/src/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc
+++ b/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc
@@ -217,7 +217,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
if (keywordPos == CompilerKit::STLString::npos ||
openParen == CompilerKit::STLString::npos ||
closeParen == CompilerKit::STLString::npos || closeParen <= openParen) {
- Detail::print_error("Malformed if expression: " + text, file);
+ CompilerKit::Detail::print_error("Malformed if expression: " + text, file);
break;
}
@@ -328,14 +328,14 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
if (text.ends_with(";") && text.find("return") == CompilerKit::STLString::npos)
goto lc_write_assembly;
else if (text.size() <= indexFnName)
- Detail::print_error("Invalid function name: " + symbol_name_fn, file);
+ CompilerKit::Detail::print_error("Invalid function name: " + symbol_name_fn, file);
indexFnName = 0;
for (auto& ch : symbol_name_fn) {
if (ch == ' ' || ch == '\t') {
if (symbol_name_fn[indexFnName - 1] != ')')
- Detail::print_error("Invalid function name: " + symbol_name_fn, file);
+ CompilerKit::Detail::print_error("Invalid function name: " + symbol_name_fn, file);
}
++indexFnName;
@@ -525,7 +525,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
if (pair == valueOfVar) goto done;
}
- Detail::print_error("Variable not declared: " + varName, file);
+ CompilerKit::Detail::print_error("Variable not declared: " + varName, file);
break;
}
@@ -627,7 +627,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
}
if (syntax_tree.fUserValue.empty()) {
- Detail::print_error("Variable not declared: " + varName, file);
+ CompilerKit::Detail::print_error("Variable not declared: " + varName, file);
}
kRegisterMap.insert(kRegisterMap.end(), newVars.begin(), newVars.end());
@@ -679,7 +679,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
});
if (it == kOriginMap.end())
- Detail::print_error("Invalid return value: " + subText, file);
+ CompilerKit::Detail::print_error("Invalid return value: " + subText, file);
std::stringstream ss;
ss << it->second;
@@ -821,7 +821,7 @@ NECTI_MODULE(CompilerCPlusPlusAMD64) {
kFrontend = new CompilerFrontendCPlusPlusAMD64();
kAssembler.Mount(new AssemblyCPlusPlusInterfaceAMD64());
- CompilerKit::install_signal(SIGSEGV, Detail::drvi_crash_handler);
+ CompilerKit::install_signal(SIGSEGV, CompilerKit::Detail::drvi_crash_handler);
// Ensure cleanup on exit
std::atexit([]() {
@@ -866,7 +866,7 @@ NECTI_MODULE(CompilerCPlusPlusAMD64) {
CompilerKit::STLString err = "Unknown option: ";
err += argv[index];
- Detail::print_error(err, "cxxdrv");
+ CompilerKit::Detail::print_error(err, "cxxdrv");
continue;
}
diff --git a/src/CompilerKit/src/Linker/DynamicLinker64PEF.cc b/src/CompilerKit/src/DyanmicLinkers/DynamicLinker64+PEF.cc
index 58a06d2..5e8253b 100644
--- a/src/CompilerKit/src/Linker/DynamicLinker64PEF.cc
+++ b/src/CompilerKit/src/DyanmicLinkers/DynamicLinker64+PEF.cc
@@ -64,14 +64,14 @@ static CompilerKit::STLString kLinkerStart = kPefStart;
/* object code and list. */
static std::vector<CompilerKit::STLString> kObjectList;
-static std::vector<Detail::DynamicLinkerBlob> kObjectBytes;
+static std::vector<CompilerKit::Detail::Blob> kObjectBytes;
/// @brief NeCTI 64-bit Linker.
/// @note This linker is made for PEF executable, thus NeCTI based OSes.
NECTI_MODULE(DynamicLinker64PEF) {
bool is_executable = true;
- CompilerKit::install_signal(SIGSEGV, Detail::drvi_crash_handler);
+ CompilerKit::install_signal(SIGSEGV, CompilerKit::Detail::drvi_crash_handler);
/**
* @brief parse flags and trigger options.
diff --git a/src/CompilerKit/src/Macro/CPlusPlusPreprocessor.cc b/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc
index 4cf42dc..4cf42dc 100644
--- a/src/CompilerKit/src/Macro/CPlusPlusPreprocessor.cc
+++ b/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc
diff --git a/src/CompilerKit/src/StringKit.cc b/src/CompilerKit/src/StringKit.cc
deleted file mode 100644
index b3584e7..0000000
--- a/src/CompilerKit/src/StringKit.cc
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * ========================================================
- *
- * CompilerKit
- * Copyright (C) 2024-2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license.
- *
- * ========================================================
- */
-
-/**
- * @file StringKit.cc
- * @author Amlal (amlal@nekernel.org)
- * @brief C++ string manipulation API.
- * @version 0.0.2
- * @date 2024-01-23
- *
- * @copyright Copyright (c) Amlal El Mahrouss
- *
- */
-
-#include <CompilerKit/StringKit.h>
-#include <stdexcept>
-
-namespace CompilerKit {
-
-Char* NEString::Data() {
- return m_Data;
-}
-
-const Char* NEString::CData() const {
- return m_Data;
-}
-
-SizeType NEString::Length() const {
- return strlen(m_Data);
-}
-
-bool NEString::operator==(const NEString& rhs) const {
- const SizeType len = Length();
- if (rhs.Length() != len) return false;
- return memcmp(m_Data, rhs.m_Data, len) == 0;
-}
-
-bool NEString::operator==(const Char* rhs) const {
- const SizeType rhs_len = string_length(rhs);
- const SizeType len = Length();
- if (rhs_len != len) return false;
- return memcmp(m_Data, rhs, len) == 0;
-}
-
-bool NEString::operator!=(const NEString& rhs) const {
- return !(*this == rhs);
-}
-
-bool NEString::operator!=(const Char* rhs) const {
- return !(*this == rhs);
-}
-
-NEString NEStringBuilder::Construct(const Char* data) {
- if (!data || *data == 0) return NEString(0);
-
- NEString view(strlen(data));
- view += data;
-
- return view;
-}
-
-NEString NEStringBuilder::FromInt(const char* fmt, int i) {
- if (!fmt) return NEString(0);
-
- Char result[sizeof(int64_t)] = {0};
- if (!to_str(result, sizeof(int64_t), i)) return NEString(0);
-
- const SizeType fmt_len = string_length(fmt);
- const SizeType res_len = string_length(result);
-
- NEString output(fmt_len + res_len);
- bool inserted = false;
-
- for (SizeType idx = 0; idx < fmt_len; ++idx) {
- if (!inserted && fmt[idx] == '%') {
- output += result;
- inserted = true;
- continue;
- }
- output += Char{fmt[idx]};
- }
-
- return output;
-}
-
-NEString NEStringBuilder::FromBool(const char* fmt, bool val) {
- if (!fmt) return NEString(0);
-
- const Char* boolean_expr = val ? "true" : "false";
- const SizeType fmt_len = string_length(fmt);
- const SizeType res_len = string_length(boolean_expr);
-
- NEString output(fmt_len + res_len);
- bool inserted = false;
-
- for (SizeType idx = 0; idx < fmt_len; ++idx) {
- if (!inserted && fmt[idx] == '%') {
- output += boolean_expr;
- inserted = true;
- continue;
- }
- output += Char{fmt[idx]};
- }
-
- return output;
-}
-
-bool NEStringBuilder::Equals(const char* lhs, const char* rhs) {
- const SizeType lhs_len = string_length(lhs);
- const SizeType rhs_len = string_length(rhs);
-
- if (lhs_len != rhs_len) return false;
- return memcmp(lhs, rhs, lhs_len) == 0;
-}
-
-NEString NEStringBuilder::Format(const char* fmt, const char* fmtRight) {
- if (!fmt || !fmtRight) return NEString(0);
-
- const SizeType fmt_len = string_length(fmt);
- const SizeType rhs_len = string_length(fmtRight);
-
- NEString output(fmt_len + rhs_len);
- bool inserted = false;
-
- for (SizeType idx = 0; idx < fmt_len; ++idx) {
- if (!inserted && fmt[idx] == '%') {
- output += fmtRight;
- inserted = true;
- continue;
- }
- output += Char{fmt[idx]};
- }
-
- return output;
-}
-
-NEString& NEString::operator+=(const Char* rhs) {
- const SizeType rhs_len = strlen(rhs);
- if (this->m_Cur + rhs_len >= this->m_Sz) {
- throw std::runtime_error("out_of_bounds: NEString");
- }
-
- memcpy(this->m_Data + this->m_Cur, rhs, rhs_len);
-
- this->m_Cur += rhs_len;
- this->m_Data[this->m_Cur] = '\0';
-
- return *this;
-}
-
-NEString& NEString::operator+=(const NEString& rhs) {
- if (this->m_Cur + rhs.m_Cur >= this->m_Sz) {
- throw std::runtime_error("out_of_bounds: NEString");
- }
-
- memcpy(this->m_Data + this->m_Cur, rhs.CData(), rhs.m_Cur);
- this->m_Cur += rhs.m_Cur;
- this->m_Data[this->m_Cur] = '\0';
-
- return *this;
-}
-
-NEString& NEString::operator+=(const Char ch) {
- if (this->m_Cur + 1 >= this->m_Sz) {
- throw std::runtime_error("out_of_bounds.");
- }
-
- this->m_Data[this->m_Cur++] = ch;
- this->m_Data[this->m_Cur] = '\0';
-
- return *this;
-}
-
-} // namespace CompilerKit