summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-08 01:57:30 -0500
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-08 01:57:30 -0500
commit2ddaf86857828500235e8b8a65c11bb2dd91b8be (patch)
tree46899c14955bf356be2331e63c181afd4089d982 /src
parent9f7c44f1577f194cb76b03ac45a2af542a86c8b9 (diff)
chore! breaking API changes and new APIs introduced.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src')
-rw-r--r--src/CompilerKit/src/Assemblers/Assembler+64x0.cc16
-rw-r--r--src/CompilerKit/src/Assemblers/Assembler+AMD64.cc16
-rw-r--r--src/CompilerKit/src/Assemblers/Assembler+ARM64.cc12
-rw-r--r--src/CompilerKit/src/Assemblers/Assembler+PowerPC.cc18
-rw-r--r--src/CompilerKit/src/Compilers/CCompiler+64x0.cc18
-rw-r--r--src/CompilerKit/src/Compilers/CCompiler+ARM64.cc18
-rw-r--r--src/CompilerKit/src/Compilers/CCompiler+Power64.cc18
-rw-r--r--src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc74
-rw-r--r--src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc2
-rw-r--r--src/Tools/cppdrv.cc5
-rw-r--r--src/Tools/pef-amd64-cxxdrv.cc8
-rw-r--r--src/Tools/pef-arm64-cdrv.cc20
12 files changed, 107 insertions, 118 deletions
diff --git a/src/CompilerKit/src/Assemblers/Assembler+64x0.cc b/src/CompilerKit/src/Assemblers/Assembler+64x0.cc
index 3fd588a..35a6bb2 100644
--- a/src/CompilerKit/src/Assemblers/Assembler+64x0.cc
+++ b/src/CompilerKit/src/Assemblers/Assembler+64x0.cc
@@ -267,7 +267,7 @@ asm_fail_exit:
static bool asm_read_attributes(std::string line) {
// extern_segment is the opposite of public_segment, it signals to the ld
// that we need this symbol.
- if (CompilerKit::find_word(line, "extern_segment")) {
+ if (CompilerKit::ast_find_needle(line, "extern_segment")) {
if (kOutputAsBinary) {
CompilerKit::Detail::print_error("Invalid extern_segment directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_extern_segment_bin");
@@ -327,7 +327,7 @@ static bool asm_read_attributes(std::string line) {
// public_segment is a special keyword used by Assembler64x0 to tell the AE output stage to
// mark this section as a header. it currently supports .code64, .data64.,
// .zero64
- else if (CompilerKit::find_word(line, "public_segment")) {
+ else if (CompilerKit::ast_find_needle(line, "public_segment")) {
if (kOutputAsBinary) {
CompilerKit::Detail::print_error("Invalid public_segment directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_public_segment_bin");
@@ -413,9 +413,9 @@ bool is_valid_64x0(std::string str) {
std::string CompilerKit::Encoder64x0::CheckLine(std::string line, std::string file) {
std::string err_str;
- if (line.empty() || CompilerKit::find_word(line, "extern_segment") ||
- CompilerKit::find_word(line, "public_segment") || line.find('#') != std::string::npos ||
- CompilerKit::find_word(line, ";")) {
+ if (line.empty() || CompilerKit::ast_find_needle(line, "extern_segment") ||
+ CompilerKit::ast_find_needle(line, "public_segment") || line.find('#') != std::string::npos ||
+ CompilerKit::ast_find_needle(line, ";")) {
if (line.find('#') != std::string::npos) {
line.erase(line.find('#'));
} else if (line.find(';') != std::string::npos) {
@@ -497,7 +497,7 @@ std::string CompilerKit::Encoder64x0::CheckLine(std::string line, std::string fi
// if it is like that -> addr1, 0x0
if (auto it = std::find(filter_inst.begin(), filter_inst.end(), opcode64x0.fName);
it == filter_inst.cend()) {
- if (CompilerKit::find_word(line, opcode64x0.fName)) {
+ if (CompilerKit::ast_find_needle(line, opcode64x0.fName)) {
if (!isspace(line[line.find(opcode64x0.fName) + strlen(opcode64x0.fName)])) {
err_str += "\nMissing space between ";
err_str += opcode64x0.fName;
@@ -612,11 +612,11 @@ bool CompilerKit::Encoder64x0::WriteNumber(const std::size_t& pos, std::string&
/////////////////////////////////////////////////////////////////////////////////////////
bool CompilerKit::Encoder64x0::WriteLine(std::string line, std::string file) {
- if (CompilerKit::find_word(line, "public_segment ")) return true;
+ if (CompilerKit::ast_find_needle(line, "public_segment ")) return true;
for (auto& opcode64x0 : kOpcodes64x0) {
// strict check here
- if (CompilerKit::find_word(line, opcode64x0.fName) && CompilerKit::Detail::algorithm::is_valid_64x0(line)) {
+ if (CompilerKit::ast_find_needle(line, opcode64x0.fName) && CompilerKit::Detail::algorithm::is_valid_64x0(line)) {
std::string name(opcode64x0.fName);
std::string jump_label, cpy_jump_label;
diff --git a/src/CompilerKit/src/Assemblers/Assembler+AMD64.cc b/src/CompilerKit/src/Assemblers/Assembler+AMD64.cc
index 5b3d665..e69d4b6 100644
--- a/src/CompilerKit/src/Assemblers/Assembler+AMD64.cc
+++ b/src/CompilerKit/src/Assemblers/Assembler+AMD64.cc
@@ -338,7 +338,7 @@ asm_fail_exit:
static bool asm_read_attributes(std::string line) {
// extern_segment is the opposite of public_segment, it signals to the ld
// that we need this symbol.
- if (CompilerKit::find_word(line, "extern_segment")) {
+ if (CompilerKit::ast_find_needle(line, "extern_segment")) {
if (kOutputAsBinary) {
CompilerKit::Detail::print_error("Invalid directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_extern_segment_bin");
@@ -397,7 +397,7 @@ static bool asm_read_attributes(std::string line) {
// public_segment is a special keyword used by AssemblerAMD64 to tell the AE output stage to
// mark this section as a header. it currently supports .code64, .data64 and
// .zero64.
- else if (CompilerKit::find_word(line, "public_segment")) {
+ else if (CompilerKit::ast_find_needle(line, "public_segment")) {
if (kOutputAsBinary) {
CompilerKit::Detail::print_error("Invalid directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_public_segment_bin");
@@ -494,9 +494,9 @@ bool is_valid_amd64(std::string str) {
std::string CompilerKit::EncoderAMD64::CheckLine(std::string line, std::string file) {
std::string err_str;
- if (line.empty() || CompilerKit::find_word(line, "extern_segment") ||
- CompilerKit::find_word(line, "public_segment") ||
- CompilerKit::find_word(line, kAssemblerPragmaSymStr) || CompilerKit::find_word(line, ";") ||
+ if (line.empty() || CompilerKit::ast_find_needle(line, "extern_segment") ||
+ CompilerKit::ast_find_needle(line, "public_segment") ||
+ CompilerKit::ast_find_needle(line, kAssemblerPragmaSymStr) || CompilerKit::ast_find_needle(line, ";") ||
line[0] == kAssemblerPragmaSym) {
if (line.find(';') != std::string::npos) {
line.erase(line.find(';'));
@@ -547,7 +547,7 @@ std::string CompilerKit::EncoderAMD64::CheckLine(std::string line, std::string f
}
}
for (auto& opcodeAMD64 : kOpcodesAMD64) {
- if (CompilerKit::find_word(line, opcodeAMD64.fName)) {
+ if (CompilerKit::ast_find_needle(line, opcodeAMD64.fName)) {
return err_str;
}
}
@@ -952,7 +952,7 @@ bool CompilerKit::EncoderAMD64::WriteNumber8(const std::size_t& pos, std::string
/////////////////////////////////////////////////////////////////////////////////////////
bool CompilerKit::EncoderAMD64::WriteLine(std::string line, std::string file) {
- if (CompilerKit::find_word(line, "public_segment ")) return true;
+ if (CompilerKit::ast_find_needle(line, "public_segment ")) return true;
struct RegMapAMD64 {
CompilerKit::STLString fName;
@@ -970,7 +970,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) &&
+ if (CompilerKit::ast_find_needle(line, opcodeAMD64.fName) &&
CompilerKit::Detail::algorithm::is_valid_amd64(line)) {
foundInstruction = true;
std::string name(opcodeAMD64.fName);
diff --git a/src/CompilerKit/src/Assemblers/Assembler+ARM64.cc b/src/CompilerKit/src/Assemblers/Assembler+ARM64.cc
index 3bce0ff..c4e4fb6 100644
--- a/src/CompilerKit/src/Assemblers/Assembler+ARM64.cc
+++ b/src/CompilerKit/src/Assemblers/Assembler+ARM64.cc
@@ -272,7 +272,7 @@ asm_fail_exit:
static bool asm_read_attributes(std::string line) {
// extern_segment is the opposite of public_segment, it signals to the li
// that we need this symbol.
- if (CompilerKit::find_word(line, "extern_segment")) {
+ if (CompilerKit::ast_find_needle(line, "extern_segment")) {
if (kOutputAsBinary) {
CompilerKit::Detail::print_error("Invalid extern_segment directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_extern_segment_bin");
@@ -331,7 +331,7 @@ static bool asm_read_attributes(std::string line) {
// public_segment is a special keyword used by Assembler to tell the AE output stage to
// mark this section as a header. it currently supports .code64, .data64.,
// .zero64
- else if (CompilerKit::find_word(line, "public_segment")) {
+ else if (CompilerKit::ast_find_needle(line, "public_segment")) {
if (kOutputAsBinary) {
CompilerKit::Detail::print_error("Invalid public_segment directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_public_segment_bin");
@@ -417,9 +417,9 @@ bool is_valid_arm64(std::string str) {
std::string CompilerKit::EncoderARM64::CheckLine(std::string line, std::string file) {
std::string err_str;
- if (line.empty() || CompilerKit::find_word(line, "extern_segment") ||
- CompilerKit::find_word(line, "public_segment") || line.find('#') != std::string::npos ||
- CompilerKit::find_word(line, ";")) {
+ if (line.empty() || CompilerKit::ast_find_needle(line, "extern_segment") ||
+ CompilerKit::ast_find_needle(line, "public_segment") || line.find('#') != std::string::npos ||
+ CompilerKit::ast_find_needle(line, ";")) {
if (line.find('#') != std::string::npos) {
line.erase(line.find('#'));
} else if (line.find(';') != std::string::npos) {
@@ -578,7 +578,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 (CompilerKit::ast_find_needle(line, "public_segment")) return false;
if (!CompilerKit::Detail::algorithm::is_valid_arm64(line)) return false;
diff --git a/src/CompilerKit/src/Assemblers/Assembler+PowerPC.cc b/src/CompilerKit/src/Assemblers/Assembler+PowerPC.cc
index 4bb9876..6c698bd 100644
--- a/src/CompilerKit/src/Assemblers/Assembler+PowerPC.cc
+++ b/src/CompilerKit/src/Assemblers/Assembler+PowerPC.cc
@@ -272,7 +272,7 @@ asm_fail_exit:
static bool asm_read_attributes(std::string line) {
// extern_segment is the opposite of public_segment, it signals to the li
// that we need this symbol.
- if (CompilerKit::find_word(line, "extern_segment")) {
+ if (CompilerKit::ast_find_needle(line, "extern_segment")) {
if (kOutputAsBinary) {
CompilerKit::Detail::print_error("Invalid extern_segment directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_extern_segment_bin");
@@ -331,7 +331,7 @@ static bool asm_read_attributes(std::string line) {
// public_segment is a special keyword used by AssemblerPower to tell the AE output stage to
// mark this section as a header. it currently supports .code64, .data64.,
// .zero64
- else if (CompilerKit::find_word(line, "public_segment")) {
+ else if (CompilerKit::ast_find_needle(line, "public_segment")) {
if (kOutputAsBinary) {
CompilerKit::Detail::print_error("Invalid public_segment directive in flat binary mode.", "CompilerKit");
throw std::runtime_error("invalid_public_segment_bin");
@@ -417,9 +417,9 @@ bool is_valid_power64(std::string str) {
std::string CompilerKit::EncoderPowerPC::CheckLine(std::string line, std::string file) {
std::string err_str;
- if (line.empty() || CompilerKit::find_word(line, "extern_segment") ||
- CompilerKit::find_word(line, "public_segment") || line.find('#') != std::string::npos ||
- CompilerKit::find_word(line, ";")) {
+ if (line.empty() || CompilerKit::ast_find_needle(line, "extern_segment") ||
+ CompilerKit::ast_find_needle(line, "public_segment") || line.find('#') != std::string::npos ||
+ CompilerKit::ast_find_needle(line, ";")) {
if (line.find('#') != std::string::npos) {
line.erase(line.find('#'));
} else if (line.find(';') != std::string::npos) {
@@ -485,7 +485,7 @@ std::string CompilerKit::EncoderPowerPC::CheckLine(std::string line, std::string
std::vector<std::string> filter_inst = {"blr", "bl", "sc"};
for (auto& opcode_risc : kOpcodesPowerPC) {
- if (CompilerKit::find_word(line, opcode_risc.name)) {
+ if (CompilerKit::ast_find_needle(line, opcode_risc.name)) {
for (auto& op : operands_inst) {
// if only the instruction was found.
if (line == op) {
@@ -499,7 +499,7 @@ std::string CompilerKit::EncoderPowerPC::CheckLine(std::string line, std::string
// if it is like that -> addr1, 0x0
if (auto it = std::find(filter_inst.begin(), filter_inst.end(), opcode_risc.name);
it == filter_inst.cend()) {
- if (CompilerKit::find_word(line, opcode_risc.name)) {
+ if (CompilerKit::ast_find_needle(line, opcode_risc.name)) {
if (!isspace(line[line.find(opcode_risc.name) + strlen(opcode_risc.name)])) {
err_str += "\nMissing space between ";
err_str += opcode_risc.name;
@@ -615,12 +615,12 @@ 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 (CompilerKit::ast_find_needle(line, "public_segment")) return false;
if (!CompilerKit::Detail::algorithm::is_valid_power64(line)) return false;
for (auto& opcode_risc : kOpcodesPowerPC) {
// strict check here
- if (CompilerKit::find_word(line, opcode_risc.name)) {
+ if (CompilerKit::ast_find_needle(line, opcode_risc.name)) {
std::string name(opcode_risc.name);
std::string jump_label, cpy_jump_label;
std::vector<size_t> found_registers_index;
diff --git a/src/CompilerKit/src/Compilers/CCompiler+64x0.cc b/src/CompilerKit/src/Compilers/CCompiler+64x0.cc
index 8437722..06768eb 100644
--- a/src/CompilerKit/src/Compilers/CCompiler+64x0.cc
+++ b/src/CompilerKit/src/Compilers/CCompiler+64x0.cc
@@ -130,7 +130,7 @@ static bool kIfFound = false;
static size_t kBracesCount = 0UL;
/* @brief C compiler backend for C */
-class CompilerFrontend64x0 final : public CompilerKit::CompilerFrontendInterface {
+class CompilerFrontend64x0 final : public CompilerKit::ICompilerFrontend {
public:
explicit CompilerFrontend64x0() = default;
~CompilerFrontend64x0() override = default;
@@ -821,7 +821,7 @@ cc_next:
// extern does not declare anything, it extern_segments a variable.
// so that's why it's not declare upper.
- if (CompilerKit::find_word(ln, "extern")) {
+ if (CompilerKit::ast_find_needle(ln, "extern")) {
auto substr = ln.substr(ln.find("extern") + strlen("extern"));
kCompilerVariables.push_back({.fValue = substr});
}
@@ -878,7 +878,7 @@ cc_next:
skip_braces_check:
for (auto& key : kCompilerTypes) {
- if (CompilerKit::find_word(ln, key.fName)) {
+ if (CompilerKit::ast_find_needle(ln, key.fName)) {
if (isdigit(ln[ln.find(key.fName) + key.fName.size() + 1])) {
err_str += "\nNumber cannot be set for ";
err_str += key.fName;
@@ -951,9 +951,9 @@ skip_braces_check:
}
if (ln.find('(') != std::string::npos) {
- if (ln.find(';') == std::string::npos && !CompilerKit::find_word(ln, "|") &&
- !CompilerKit::find_word(ln, "||") && !CompilerKit::find_word(ln, "&") &&
- !CompilerKit::find_word(ln, "&&") && !CompilerKit::find_word(ln, "~")) {
+ if (ln.find(';') == std::string::npos && !CompilerKit::ast_find_needle(ln, "|") &&
+ !CompilerKit::ast_find_needle(ln, "||") && !CompilerKit::ast_find_needle(ln, "&") &&
+ !CompilerKit::ast_find_needle(ln, "&&") && !CompilerKit::ast_find_needle(ln, "~")) {
bool found_func = false;
size_t i = ln.find('(');
std::vector<char> opens;
@@ -1105,7 +1105,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE {
std::vector<std::string> access_keywords = {"->", "."};
for (auto& access_ident : access_keywords) {
- if (CompilerKit::find_word(leaf.fUserValue, access_ident)) {
+ if (CompilerKit::ast_find_needle(leaf.fUserValue, access_ident)) {
for (auto& struc : kState.kStructMap) {
/// TODO:
}
@@ -1113,7 +1113,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE {
}
for (auto& keyword : keywords) {
- if (CompilerKit::find_word(leaf.fUserValue, keyword)) {
+ if (CompilerKit::ast_find_needle(leaf.fUserValue, keyword)) {
std::size_t cnt = 0UL;
for (auto& reg : kState.kStackFrame) {
@@ -1137,7 +1137,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE {
}
}
- if (CompilerKit::find_word(leaf.fUserValue, needle)) {
+ if (CompilerKit::ast_find_needle(leaf.fUserValue, needle)) {
if (leaf.fUserValue.find("extern_segment " + needle) != std::string::npos) {
std::string range = "extern_segment " + needle;
leaf.fUserValue.replace(leaf.fUserValue.find("extern_segment " + needle),
diff --git a/src/CompilerKit/src/Compilers/CCompiler+ARM64.cc b/src/CompilerKit/src/Compilers/CCompiler+ARM64.cc
index 45ec9a3..ad4227b 100644
--- a/src/CompilerKit/src/Compilers/CCompiler+ARM64.cc
+++ b/src/CompilerKit/src/Compilers/CCompiler+ARM64.cc
@@ -132,7 +132,7 @@ static bool kIfFound = false;
static size_t kBracesCount = 0UL;
/* @brief C compiler backend for C */
-class CompilerFrontendARM64 final : public CompilerKit::CompilerFrontendInterface {
+class CompilerFrontendARM64 final : public CompilerKit::ICompilerFrontend {
public:
explicit CompilerFrontendARM64() = default;
~CompilerFrontendARM64() override = default;
@@ -821,7 +821,7 @@ cc_next:
// extern does not declare anything, it extern_segments a variable.
// so that's why it's not declare upper.
- if (CompilerKit::find_word(ln, "extern")) {
+ if (CompilerKit::ast_find_needle(ln, "extern")) {
auto substr = ln.substr(ln.find("extern") + strlen("extern"));
kCompilerVariables.push_back({.fValue = substr});
}
@@ -878,7 +878,7 @@ cc_next:
skip_braces_check:
for (auto& key : kCompilerTypes) {
- if (CompilerKit::find_word(ln, key.fName)) {
+ if (CompilerKit::ast_find_needle(ln, key.fName)) {
if (isdigit(ln[ln.find(key.fName) + key.fName.size() + 1])) {
err_str += "\nNumber cannot be set for ";
err_str += key.fName;
@@ -951,9 +951,9 @@ skip_braces_check:
}
if (ln.find('(') != std::string::npos) {
- if (ln.find(';') == std::string::npos && !CompilerKit::find_word(ln, "|") &&
- !CompilerKit::find_word(ln, "||") && !CompilerKit::find_word(ln, "&") &&
- !CompilerKit::find_word(ln, "&&") && !CompilerKit::find_word(ln, "~")) {
+ if (ln.find(';') == std::string::npos && !CompilerKit::ast_find_needle(ln, "|") &&
+ !CompilerKit::ast_find_needle(ln, "||") && !CompilerKit::ast_find_needle(ln, "&") &&
+ !CompilerKit::ast_find_needle(ln, "&&") && !CompilerKit::ast_find_needle(ln, "~")) {
bool found_func = false;
size_t i = ln.find('(');
std::vector<char> opens;
@@ -1105,7 +1105,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE {
std::vector<std::string> access_keywords = {"->", "."};
for (auto& access_ident : access_keywords) {
- if (CompilerKit::find_word(leaf.fUserValue, access_ident)) {
+ if (CompilerKit::ast_find_needle(leaf.fUserValue, access_ident)) {
for (auto& struc : kState.kStructMap) {
/// TODO:
}
@@ -1113,7 +1113,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE {
}
for (auto& keyword : keywords) {
- if (CompilerKit::find_word(leaf.fUserValue, keyword)) {
+ if (CompilerKit::ast_find_needle(leaf.fUserValue, keyword)) {
std::size_t cnt = 0UL;
for (auto& reg : kState.kStackFrame) {
@@ -1137,7 +1137,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE {
}
}
- if (CompilerKit::find_word(leaf.fUserValue, needle)) {
+ if (CompilerKit::ast_find_needle(leaf.fUserValue, needle)) {
if (leaf.fUserValue.find("extern_segment " + needle) != std::string::npos) {
std::string range = "extern_segment " + needle;
leaf.fUserValue.replace(leaf.fUserValue.find("extern_segment " + needle),
diff --git a/src/CompilerKit/src/Compilers/CCompiler+Power64.cc b/src/CompilerKit/src/Compilers/CCompiler+Power64.cc
index 7d5dc74..e123c3d 100644
--- a/src/CompilerKit/src/Compilers/CCompiler+Power64.cc
+++ b/src/CompilerKit/src/Compilers/CCompiler+Power64.cc
@@ -115,7 +115,7 @@ static bool kIfFound = false;
static size_t kBracesCount = 0UL;
/* @brief C compiler backend for C */
-class CompilerFrontendPower64 final : public CompilerKit::CompilerFrontendInterface {
+class CompilerFrontendPower64 final : public CompilerKit::ICompilerFrontend {
public:
explicit CompilerFrontendPower64() = default;
~CompilerFrontendPower64() override = default;
@@ -833,7 +833,7 @@ cc_next:
// extern does not declare anything, it extern_segments a variable.
// so that's why it's not declare upper.
- if (CompilerKit::find_word(ln, "extern")) {
+ if (CompilerKit::ast_find_needle(ln, "extern")) {
auto substr = ln.substr(ln.find("extern") + strlen("extern"));
kCompilerVariables.push_back({.fValue = substr});
}
@@ -890,7 +890,7 @@ cc_next:
skip_braces_check:
for (auto& key : kCompilerTypes) {
- if (CompilerKit::find_word(ln, key.fName)) {
+ if (CompilerKit::ast_find_needle(ln, key.fName)) {
if (isdigit(ln[ln.find(key.fName) + key.fName.size() + 1])) {
err_str += "\nNumber cannot be set for ";
err_str += key.fName;
@@ -963,9 +963,9 @@ skip_braces_check:
}
if (ln.find('(') != std::string::npos) {
- if (ln.find(';') == std::string::npos && !CompilerKit::find_word(ln, "|") &&
- !CompilerKit::find_word(ln, "||") && !CompilerKit::find_word(ln, "&") &&
- !CompilerKit::find_word(ln, "&&") && !CompilerKit::find_word(ln, "~")) {
+ if (ln.find(';') == std::string::npos && !CompilerKit::ast_find_needle(ln, "|") &&
+ !CompilerKit::ast_find_needle(ln, "||") && !CompilerKit::ast_find_needle(ln, "&") &&
+ !CompilerKit::ast_find_needle(ln, "&&") && !CompilerKit::ast_find_needle(ln, "~")) {
bool found_func = false;
size_t i = ln.find('(');
std::vector<char> opens;
@@ -1117,7 +1117,7 @@ class AssemblyMountpointCLang final CK_ASSEMBLY_INTERFACE {
std::vector<std::string> access_keywords = {"->", "."};
for (auto& access_ident : access_keywords) {
- if (CompilerKit::find_word(leaf.fUserValue, access_ident)) {
+ if (CompilerKit::ast_find_needle(leaf.fUserValue, access_ident)) {
for (auto& struc : kState.kStructMap) {
/// TODO:
}
@@ -1125,7 +1125,7 @@ class AssemblyMountpointCLang final CK_ASSEMBLY_INTERFACE {
}
for (auto& keyword : keywords) {
- if (CompilerKit::find_word(leaf.fUserValue, keyword)) {
+ if (CompilerKit::ast_find_needle(leaf.fUserValue, keyword)) {
std::size_t cnt = 0UL;
for (auto& reg : kState.kStackFrame) {
@@ -1149,7 +1149,7 @@ class AssemblyMountpointCLang final CK_ASSEMBLY_INTERFACE {
}
}
- if (CompilerKit::find_word(leaf.fUserValue, needle)) {
+ if (CompilerKit::ast_find_needle(leaf.fUserValue, needle)) {
if (leaf.fUserValue.find("extern_segment ") != std::string::npos) {
std::string range = "extern_segment ";
leaf.fUserValue.replace(leaf.fUserValue.find(range), range.size(), "");
diff --git a/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc b/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc
index d93256d..c54cc53 100644
--- a/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc
+++ b/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc
@@ -96,7 +96,7 @@ static Int32 kMachine = CompilerKit::AssemblyFactory::kArchAMD64;
/////////////////////////////////////////
-static std::vector<CompilerKit::CompilerKeyword> kKeywords;
+static std::vector<CompilerKit::SyntaxKeyword> kKeywords;
/////////////////////////////////////////
@@ -166,11 +166,11 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
if (text.empty()) return syntax_tree;
std::size_t index = 0UL;
- std::vector<std::pair<CompilerKit::CompilerKeyword, std::size_t>> keywords_list;
+ std::vector<std::pair<CompilerKit::SyntaxKeyword, std::size_t>> keywords_list;
for (auto& keyword : kKeywords) {
- if (text.find(keyword.keyword_name) != std::string::npos) {
- switch (keyword.keyword_kind) {
+ if (text.find(keyword.fKeywordName) != std::string::npos) {
+ switch (keyword.fKeywordKind) {
case CompilerKit::kKeywordKindCommentInline: {
break;
}
@@ -178,22 +178,22 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
break;
}
- std::size_t pos = text.find(keyword.keyword_name);
+ std::size_t pos = text.find(keyword.fKeywordName);
if (pos == std::string::npos) continue;
// can't go before start of string
if (pos > 0 && text[pos - 1] == '+' &&
- keyword.keyword_kind == CompilerKit::kKeywordKindVariableAssign)
+ keyword.fKeywordKind == CompilerKit::kKeywordKindVariableAssign)
continue;
if (pos > 0 && text[pos - 1] == '-' &&
- keyword.keyword_kind == CompilerKit::kKeywordKindVariableAssign)
+ keyword.fKeywordKind == CompilerKit::kKeywordKindVariableAssign)
continue;
// don't go out of range
- if ((pos + keyword.keyword_name.size()) < text.size() &&
- text[pos + keyword.keyword_name.size()] == '=' &&
- keyword.keyword_kind == CompilerKit::kKeywordKindVariableAssign)
+ if ((pos + keyword.fKeywordName.size()) < text.size() &&
+ text[pos + keyword.fKeywordName.size()] == '=' &&
+ keyword.fKeywordKind == CompilerKit::kKeywordKindVariableAssign)
continue;
keywords_list.emplace_back(std::make_pair(keyword, index));
@@ -202,15 +202,15 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
}
for (auto& keyword : keywords_list) {
- if (text.find(keyword.first.keyword_name) == CompilerKit::STLString::npos) continue;
+ if (text.find(keyword.first.fKeywordName) == CompilerKit::STLString::npos) continue;
- switch (keyword.first.keyword_kind) {
+ switch (keyword.first.fKeywordKind) {
case CompilerKit::KeywordKind::kKeywordKindClass: {
++kOnClassScope;
break;
}
case CompilerKit::KeywordKind::kKeywordKindIf: {
- std::size_t keywordPos = text.find(keyword.first.keyword_name);
+ std::size_t keywordPos = text.find(keyword.first.fKeywordName);
std::size_t openParen = text.find("(", keywordPos);
std::size_t closeParen = text.find(")", openParen);
@@ -225,7 +225,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
if (expr.find(">=") != CompilerKit::STLString::npos) {
auto left = text.substr(
- text.find(keyword.first.keyword_name) + keyword.first.keyword_name.size() + 2,
+ text.find(keyword.first.fKeywordName) + keyword.first.fKeywordName.size() + 2,
expr.find("<=") + strlen("<="));
auto right = text.substr(expr.find(">=") + strlen(">="), text.find(")") - 1);
@@ -282,7 +282,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
CompilerKit::STLString symbol_name_fn = text;
- symbol_name_fn.erase(symbol_name_fn.find(keyword.first.keyword_name));
+ symbol_name_fn.erase(symbol_name_fn.find(keyword.first.fKeywordName));
for (auto& ch : symbol_name_fn) {
if (ch == ' ') ch = '_';
@@ -388,43 +388,43 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
case CompilerKit::KeywordKind::kKeywordKindVariableAssign: {
CompilerKit::STLString valueOfVar = "";
- if (keyword.first.keyword_kind == CompilerKit::KeywordKind::kKeywordKindVariableInc) {
+ if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariableInc) {
valueOfVar = text.substr(text.find("+=") + 2);
- } else if (keyword.first.keyword_kind ==
+ } else if (keyword.first.fKeywordKind ==
CompilerKit::KeywordKind::kKeywordKindVariableDec) {
valueOfVar = text.substr(text.find("-=") + 2);
- } else if (keyword.first.keyword_kind ==
+ } else if (keyword.first.fKeywordKind ==
CompilerKit::KeywordKind::kKeywordKindVariableAssign) {
valueOfVar = text.substr(text.find("=") + 1);
- } else if (keyword.first.keyword_kind == CompilerKit::KeywordKind::kKeywordKindEndInstr) {
+ } else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindEndInstr) {
break;
}
while (valueOfVar.find(";") != CompilerKit::STLString::npos &&
- keyword.first.keyword_kind != CompilerKit::KeywordKind::kKeywordKindEndInstr) {
+ keyword.first.fKeywordKind != CompilerKit::KeywordKind::kKeywordKindEndInstr) {
valueOfVar.erase(valueOfVar.find(";"));
}
CompilerKit::STLString varName = text;
- if (keyword.first.keyword_kind == CompilerKit::KeywordKind::kKeywordKindVariableInc) {
+ if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariableInc) {
varName.erase(varName.find("+="));
- } else if (keyword.first.keyword_kind ==
+ } else if (keyword.first.fKeywordKind ==
CompilerKit::KeywordKind::kKeywordKindVariableDec) {
varName.erase(varName.find("-="));
- } else if (keyword.first.keyword_kind ==
+ } else if (keyword.first.fKeywordKind ==
CompilerKit::KeywordKind::kKeywordKindVariableAssign) {
varName.erase(varName.find("="));
- } else if (keyword.first.keyword_kind == CompilerKit::KeywordKind::kKeywordKindEndInstr) {
+ } else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindEndInstr) {
varName.erase(varName.find(";"));
}
static bool typeFound = false;
for (auto& keyword : kKeywords) {
- if (keyword.keyword_kind == CompilerKit::kKeywordKindType) {
- if (text.find(keyword.keyword_name) != CompilerKit::STLString::npos) {
- if (text[text.find(keyword.keyword_name)] == ' ') {
+ if (keyword.fKeywordKind == CompilerKit::kKeywordKindType) {
+ if (text.find(keyword.fKeywordName) != CompilerKit::STLString::npos) {
+ if (text[text.find(keyword.fKeywordName)] == ' ') {
typeFound = false;
continue;
}
@@ -439,8 +439,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
std::vector<CompilerKit::STLString> newVars;
if (typeFound &&
- keyword.first.keyword_kind != CompilerKit::KeywordKind::kKeywordKindVariableInc &&
- keyword.first.keyword_kind != CompilerKit::KeywordKind::kKeywordKindVariableDec) {
+ keyword.first.fKeywordKind != CompilerKit::KeywordKind::kKeywordKindVariableInc &&
+ keyword.first.fKeywordKind != CompilerKit::KeywordKind::kKeywordKindVariableDec) {
if (kRegisterMap.size() > kRegisterList.size()) {
++kFunctionEmbedLevel;
}
@@ -531,9 +531,9 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
done:
for (auto& keyword : kKeywords) {
- if (keyword.keyword_kind == CompilerKit::kKeywordKindType &&
- varName.find(keyword.keyword_name) != CompilerKit::STLString::npos) {
- varName.erase(varName.find(keyword.keyword_name), keyword.keyword_name.size());
+ if (keyword.fKeywordKind == CompilerKit::kKeywordKindType &&
+ varName.find(keyword.fKeywordName) != CompilerKit::STLString::npos) {
+ varName.erase(varName.find(keyword.fKeywordName), keyword.fKeywordName.size());
break;
}
}
@@ -546,20 +546,20 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
kRegisterMap.insert(kRegisterMap.end(), newVars.begin(), newVars.end());
if (keyword.second > 0 &&
- kKeywords[keyword.second - 1].keyword_kind == CompilerKit::kKeywordKindType ||
- kKeywords[keyword.second - 1].keyword_kind == CompilerKit::kKeywordKindTypePtr) {
+ kKeywords[keyword.second - 1].fKeywordKind == CompilerKit::kKeywordKindType ||
+ kKeywords[keyword.second - 1].fKeywordKind == CompilerKit::kKeywordKindTypePtr) {
syntax_tree.fUserValue = "\n";
continue;
}
- if (keyword.first.keyword_kind == CompilerKit::KeywordKind::kKeywordKindEndInstr) {
+ if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindEndInstr) {
syntax_tree.fUserValue = "\n";
continue;
}
- if (keyword.first.keyword_kind == CompilerKit::KeywordKind::kKeywordKindVariableInc) {
+ if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariableInc) {
instr = "add ";
- } else if (keyword.first.keyword_kind ==
+ } else if (keyword.first.fKeywordKind ==
CompilerKit::KeywordKind::kKeywordKindVariableDec) {
instr = "sub ";
}
diff --git a/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc b/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc
index 4cf42dc..4e34ab3 100644
--- a/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc
+++ b/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc
@@ -290,7 +290,7 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) {
}
for (auto macro : kMacros) {
- if (CompilerKit::find_word(hdr_line, macro.fName)) {
+ if (CompilerKit::ast_find_needle(hdr_line, macro.fName)) {
if (hdr_line.substr(hdr_line.find(macro.fName)).find(macro.fName + '(') !=
CompilerKit::STLString::npos) {
if (!macro.fArgs.empty()) {
diff --git a/src/Tools/cppdrv.cc b/src/Tools/cppdrv.cc
index 05ffcec..95d4c3a 100644
--- a/src/Tools/cppdrv.cc
+++ b/src/Tools/cppdrv.cc
@@ -4,14 +4,11 @@
======================================== */
-/// @file cxxdrv.cc
+/// @file cppdrv.cc
/// @brief NeCTI frontend preprocessor.
#include <CompilerKit/Detail/Config.h>
#include <CompilerKit/ErrorID.h>
-#include <cstring>
-#include <iostream>
-#include <vector>
CK_IMPORT_C int CPlusPlusPreprocessorMain(int argc, char const* argv[]);
diff --git a/src/Tools/pef-amd64-cxxdrv.cc b/src/Tools/pef-amd64-cxxdrv.cc
index 9c29a88..fa03d25 100644
--- a/src/Tools/pef-amd64-cxxdrv.cc
+++ b/src/Tools/pef-amd64-cxxdrv.cc
@@ -4,8 +4,8 @@
======================================== */
-/// @file cxxdrv.cc
-/// @brief NeCTI C++ frontend compiler.
+/// @file pef-amd64-cxxdrv.cc
+/// @brief NeCTI C++ frontend compiler for AMD64.
#include <CompilerKit/Detail/Config.h>
#include <CompilerKit/ErrorID.h>
@@ -21,10 +21,10 @@ static auto kPath = "/usr/lib/libCompilerKit.so";
static auto kSymbol = "CompilerCPlusPlusAMD64";
Int32 main(Int32 argc, Char const* argv[]) {
- CompilerKitDylibTraits dylib;
+ CompilerKit::DLLTraits dylib;
dylib(kPath, kSymbol);
- CompilerKitEntrypoint entrypoint_cxx = (CompilerKitEntrypoint) dylib.fEntrypoint;
+ CompilerKit::DLLTraits::Entrypoint entrypoint_cxx = reinterpret_cast<CompilerKit::DLLTraits::Entrypoint>(dylib.fEntrypoint);
if (!entrypoint_cxx) {
kStdOut;
diff --git a/src/Tools/pef-arm64-cdrv.cc b/src/Tools/pef-arm64-cdrv.cc
index 97812b7..3e6c3b2 100644
--- a/src/Tools/pef-arm64-cdrv.cc
+++ b/src/Tools/pef-arm64-cdrv.cc
@@ -4,8 +4,8 @@
======================================== */
-/// @file cxxdrv.cc
-/// @brief NeCTI C++ frontend compiler.
+/// @file pef-arm-cdrv.cc
+/// @brief NeCTI ARm64 C frontend compiler.
#include <CompilerKit/Detail/Config.h>
#include <CompilerKit/ErrorID.h>
@@ -21,28 +21,20 @@ static auto kPath = "/usr/lib/libCompilerKit.so";
static auto kSymbol = "CompilerCLangARM64";
Int32 main(Int32 argc, Char const* argv[]) {
- CompilerKitDylib handler = dlopen(kPath, RTLD_LAZY | RTLD_GLOBAL);
+ CompilerKit::DLLTraits dylib;
+ dylib(kPath, kSymbol);
- if (!handler) {
- kStdOut;
- std::printf("error: Could not load dylib in %s: %s\n", kPath, dlerror());
-
- return EXIT_FAILURE;
- }
-
- CompilerKitEntrypoint entrypoint_cxx = (CompilerKitEntrypoint) dlsym(handler, kSymbol);
+ CompilerKit::DLLTraits::Entrypoint entrypoint_cxx =
+ reinterpret_cast<CompilerKit::DLLTraits::Entrypoint>(dylib.fEntrypoint);
if (!entrypoint_cxx) {
kStdOut;
std::printf("error: Could not find entrypoint in %s: %s\n", kPath, dlerror());
- dlclose(handler);
return EXIT_FAILURE;
}
auto ret = (entrypoint_cxx(argc, argv) == NECTI_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE;
- dlclose(handler);
-
return ret;
}