summaryrefslogtreecommitdiffhomepage
path: root/Sources
diff options
context:
space:
mode:
authorAmlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com>2024-04-14 10:48:10 +0200
committerAmlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com>2024-04-14 10:48:10 +0200
commit180b333debbd1e555fbab5191656e2146dff6e8a (patch)
treed371c780283540df695a82384757d0b9f0d79bd2 /Sources
parentdd6d72026ac1c96bb85d5f108fa8ddfa2758f02b (diff)
see below.
- format code. - fix xcoff header. - add .dword, .long and .word for i64asm Signed-off-by: Amlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com>
Diffstat (limited to 'Sources')
-rw-r--r--Sources/32asm.cc7
-rw-r--r--Sources/64asm.cc20
-rw-r--r--Sources/64x0-cc.cc85
-rw-r--r--Sources/Detail/Readme.md1
-rw-r--r--Sources/Detail/asmutils.h6
-rw-r--r--Sources/bpp.cc14
-rw-r--r--Sources/ccplus.cc3
-rw-r--r--Sources/i64asm.cc37
-rw-r--r--Sources/link.cc49
-rw-r--r--Sources/ppc-cc.cc88
-rw-r--r--Sources/ppcasm.cc21
11 files changed, 170 insertions, 161 deletions
diff --git a/Sources/32asm.cc b/Sources/32asm.cc
index 12a83eb..e5aa500 100644
--- a/Sources/32asm.cc
+++ b/Sources/32asm.cc
@@ -26,9 +26,8 @@
#include <filesystem>
#include <fstream>
#include <iostream>
-#include <vector>
#include <memory>
-
+#include <vector>
/////////////////////
@@ -50,6 +49,4 @@
/////////////////////////////////////////////////////////////////////////////////////////
-MPCC_MODULE(NewOSAssembler32000) {
- return 0;
-}
+MPCC_MODULE(NewOSAssembler32000) { return 0; }
diff --git a/Sources/64asm.cc b/Sources/64asm.cc
index 58e02b4..b955ad6 100644
--- a/Sources/64asm.cc
+++ b/Sources/64asm.cc
@@ -23,12 +23,12 @@
#include <Headers/ParserKit.hpp>
#include <Headers/StdKit/AE.hpp>
#include <Headers/StdKit/PEF.hpp>
+#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iostream>
-#include <vector>
#include <memory>
-#include <algorithm>
+#include <vector>
/////////////////////
@@ -442,13 +442,13 @@ bool is_valid(const std::string &str) {
/////////////////////////////////////////////////////////////////////////////////////////
-std::string CompilerKit::Encoder64x0::CheckLine(
- std::string &line, const std::string &file) {
+std::string CompilerKit::Encoder64x0::CheckLine(std::string &line,
+ const std::string &file) {
std::string err_str;
if (line.empty() || ParserKit::find_word(line, "import") ||
- ParserKit::find_word(line, "export") || line.find('#') != std::string::npos ||
- ParserKit::find_word(line, ";")) {
+ ParserKit::find_word(line, "export") ||
+ line.find('#') != std::string::npos || ParserKit::find_word(line, ";")) {
if (line.find('#') != std::string::npos) {
line.erase(line.find('#'));
} else if (line.find(';') != std::string::npos) {
@@ -552,7 +552,7 @@ std::string CompilerKit::Encoder64x0::CheckLine(
}
bool CompilerKit::Encoder64x0::WriteNumber(const std::size_t &pos,
- std::string &jump_label) {
+ std::string &jump_label) {
if (!isdigit(jump_label[pos])) return false;
switch (jump_label[pos + 1]) {
@@ -659,7 +659,7 @@ bool CompilerKit::Encoder64x0::WriteNumber(const std::size_t &pos,
/////////////////////////////////////////////////////////////////////////////////////////
bool CompilerKit::Encoder64x0::WriteLine(std::string &line,
- const std::string &file) {
+ const std::string &file) {
if (ParserKit::find_word(line, "export ")) return true;
for (auto &opcode64x0 : kOpcodes64x0) {
@@ -907,9 +907,7 @@ bool CompilerKit::Encoder64x0::WriteLine(std::string &line,
/// don't go any further if:
/// load word (ldw) or store word. (stw)
- if (name == "ldw" ||
- name == "stw")
- break;
+ if (name == "ldw" || name == "stw") break;
auto mld_reloc_str = std::to_string(cpy_jump_label.size());
mld_reloc_str += kUndefinedSymbol;
diff --git a/Sources/64x0-cc.cc b/Sources/64x0-cc.cc
index 834217b..cd96c85 100644
--- a/Sources/64x0-cc.cc
+++ b/Sources/64x0-cc.cc
@@ -8,21 +8,20 @@
*/
/// BUGS: ?
-/// TODO:
+/// TODO:
#include <Headers/AsmKit/CPU/64x0.hpp>
#include <Headers/ParserKit.hpp>
+#include <Headers/UUID.hpp>
#include <cstdio>
+#include <filesystem>
#include <fstream>
#include <iostream>
+#include <memory>
+#include <random>
#include <string>
#include <utility>
#include <vector>
-#include <memory>
-#include <filesystem>
-
-#include <random>
-#include <Headers/UUID.hpp>
#define kOk 0
@@ -103,7 +102,7 @@ void print_error(std::string reason, std::string file) noexcept {
if (kState.fLastFile != file) {
std::cout << kRed << "[ cc ] " << kWhite
<< ((file == "cc") ? "internal compiler error "
- : ("in file, " + file))
+ : ("in file, " + file))
<< kBlank << std::endl;
std::cout << kRed << "[ cc ] " << kWhite << reason << kBlank << std::endl;
@@ -214,7 +213,7 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
// setup generator.
std::random_device rd;
- auto seed_data = std::array<int, std::mt19937::state_size> {};
+ auto seed_data = std::array<int, std::mt19937::state_size>{};
std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd));
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
std::mt19937 generator(seq);
@@ -292,8 +291,8 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
for (size_t return_index = text_index; return_index < textBuffer.size();
++return_index) {
if (textBuffer[return_index] != return_keyword[index]) {
- for (size_t value_index = return_index; value_index < textBuffer.size();
- ++value_index) {
+ for (size_t value_index = return_index;
+ value_index < textBuffer.size(); ++value_index) {
if (textBuffer[value_index] == ';') break;
value += textBuffer[value_index];
@@ -338,7 +337,7 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
}
}
- if (textBuffer[text_index] == 'i' && textBuffer[text_index+1] == 'f') {
+ if (textBuffer[text_index] == 'i' && textBuffer[text_index + 1] == 'f') {
auto expr = textBuffer.substr(text_index + 2);
textBuffer.erase(text_index, 2);
@@ -346,17 +345,19 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
expr.erase(expr.find("{"));
}
- if (expr.find("(") != std::string::npos)
- expr.erase(expr.find("("));
-
- if (expr.find(")") != std::string::npos)
- expr.erase(expr.find(")"));
-
+ if (expr.find("(") != std::string::npos) expr.erase(expr.find("("));
+
+ if (expr.find(")") != std::string::npos) expr.erase(expr.find(")"));
+
kIfFunction = "__MPCC_IF_PROC_";
kIfFunction += std::to_string(time_off._Raw);
syntaxLeaf.fUserValue = "\tlda r12, import ";
- syntaxLeaf.fUserValue += kIfFunction + "\n\t#r12 = Code to jump on, r11 right cond, r10 left cond.\n\tbeq r10, r11, r12\ndword export .code64 " + kIfFunction + "\n";
+ syntaxLeaf.fUserValue +=
+ kIfFunction +
+ "\n\t#r12 = Code to jump on, r11 right cond, r10 left cond.\n\tbeq "
+ "r10, r11, r12\ndword export .code64 " +
+ kIfFunction + "\n";
kState.fSyntaxTree->fLeafList.push_back(syntaxLeaf);
kIfFound = true;
@@ -374,7 +375,8 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
if (textBuffer.find("typedef ") != std::string::npos) continue;
if (textBuffer[text_index] == '=' && kInStruct) {
- detail::print_error("assignement of value in struct " + textBuffer, file);
+ detail::print_error("assignement of value in struct " + textBuffer,
+ file);
continue;
}
@@ -407,15 +409,16 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
continue;
}
- if (textBuffer[text_index + 1] == '=' || textBuffer[text_index - 1] == '!' ||
- textBuffer[text_index - 1] == '<' || textBuffer[text_index - 1] == '>') {
+ if (textBuffer[text_index + 1] == '=' ||
+ textBuffer[text_index - 1] == '!' ||
+ textBuffer[text_index - 1] == '<' ||
+ textBuffer[text_index - 1] == '>') {
continue;
}
std::string substr;
- if (textBuffer.find('=') != std::string::npos && kInBraces &&
- !kIfFound) {
+ if (textBuffer.find('=') != std::string::npos && kInBraces && !kIfFound) {
if (textBuffer.find("*") != std::string::npos) {
if (textBuffer.find("=") > textBuffer.find("*"))
substr += "\tlda ";
@@ -448,16 +451,19 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
}
}
- if (textBuffer[text_index_2] == '{' || textBuffer[text_index_2] == '}') continue;
+ if (textBuffer[text_index_2] == '{' || textBuffer[text_index_2] == '}')
+ continue;
if (textBuffer[text_index_2] == ';') {
break;
}
- if (textBuffer[text_index_2] == ' ' || textBuffer[text_index_2] == '\t') {
+ if (textBuffer[text_index_2] == ' ' ||
+ textBuffer[text_index_2] == '\t') {
if (first_encountered != 2) {
if (textBuffer[text_index] != '=' &&
- substr.find("export .data64") == std::string::npos && !kInStruct)
+ substr.find("export .data64") == std::string::npos &&
+ !kInStruct)
substr += "export .data64 ";
}
@@ -468,8 +474,8 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
if (textBuffer[text_index_2] == '=') {
if (!kInBraces) {
- substr.replace(substr.find("export .data64"), strlen("export .data64"),
- "export .page_zero ");
+ substr.replace(substr.find("export .data64"),
+ strlen("export .data64"), "export .page_zero ");
}
substr += ",";
@@ -533,7 +539,8 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
bool type_crossed = false;
- for (size_t idx = textBuffer.find('(') + 1; idx < textBuffer.size(); ++idx) {
+ for (size_t idx = textBuffer.find('(') + 1; idx < textBuffer.size();
+ ++idx) {
if (textBuffer[idx] == ',') continue;
if (textBuffer[idx] == ' ') continue;
@@ -637,8 +644,7 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
kBracesCount = 0;
}
- if (kIfFound)
- kIfFound = false;
+ if (kIfFound) kIfFound = false;
if (kInStruct) kInStruct = false;
@@ -1199,9 +1205,12 @@ class AssemblyMountpointCLang final : public CompilerKit::AssemblyInterface {
}
if (ParserKit::find_word(leaf.fUserValue, needle)) {
- if (leaf.fUserValue.find("import " + needle) != std::string::npos) {
+ if (leaf.fUserValue.find("import " + needle) !=
+ std::string::npos) {
std::string range = "import " + needle;
- leaf.fUserValue.replace(leaf.fUserValue.find("import " + needle), range.size(), needle);
+ leaf.fUserValue.replace(
+ leaf.fUserValue.find("import " + needle), range.size(),
+ needle);
}
if (leaf.fUserValue.find("ldw r6") != std::string::npos) {
@@ -1248,11 +1257,10 @@ class AssemblyMountpointCLang final : public CompilerKit::AssemblyInterface {
#include <Version.hxx>
#define kPrintF printf
-#define kSplashCxx() kPrintF(kWhite "cc, %s, (c) Mahrouss Logic\n", kDistVersion)
+#define kSplashCxx() \
+ kPrintF(kWhite "cc, %s, (c) Mahrouss Logic\n", kDistVersion)
-static void cc_print_help() {
- kSplashCxx();
-}
+static void cc_print_help() { kSplashCxx(); }
/////////////////////////////////////////////////////////////////////////////////////////
@@ -1291,8 +1299,7 @@ MPCC_MODULE(NewOSCompilerCLang64x0) {
continue;
}
- if (strcmp(argv[index], "-h") == 0 ||
- strcmp(argv[index], "-help") == 0) {
+ if (strcmp(argv[index], "-h") == 0 || strcmp(argv[index], "-help") == 0) {
cc_print_help();
return kOk;
diff --git a/Sources/Detail/Readme.md b/Sources/Detail/Readme.md
index aba110f..91d496a 100644
--- a/Sources/Detail/Readme.md
+++ b/Sources/Detail/Readme.md
@@ -1,2 +1 @@
# Compiler utilities.
-
diff --git a/Sources/Detail/asmutils.h b/Sources/Detail/asmutils.h
index 00d4daa..6a7d055 100644
--- a/Sources/Detail/asmutils.h
+++ b/Sources/Detail/asmutils.h
@@ -3,9 +3,9 @@
using namespace CompilerKit;
/// @brief Get Number from line.
-/// @param line
-/// @param name
-/// @return
+/// @param line
+/// @param name
+/// @return
static NumberCast32 GetNumber32(std::string line, std::string name) {
auto pos = line.find(name) + name.size();
diff --git a/Sources/bpp.cc b/Sources/bpp.cc
index dcebae7..1bc235c 100644
--- a/Sources/bpp.cc
+++ b/Sources/bpp.cc
@@ -11,11 +11,11 @@
#include <Headers/ParserKit.hpp>
#include <Headers/StdKit/ErrorID.hpp>
+#include <algorithm>
+#include <filesystem>
#include <fstream>
#include <iostream>
-#include <filesystem>
#include <vector>
-#include <algorithm>
#define kMacroPrefix '%'
@@ -72,8 +72,8 @@ static std::vector<std::string> kIncludes;
static std::string kWorkingDir;
static std::vector<std::string> kKeywords = {
- "include", "if", "pragma", "def", "elif",
- "ifdef", "ifndef", "else", "warning", "error"};
+ "include", "if", "pragma", "def", "elif",
+ "ifdef", "ifndef", "else", "warning", "error"};
#define kKeywordCxxCnt kKeywords.size()
@@ -281,7 +281,7 @@ void bpp_parse_file(std::ifstream &hdr_file, std::ofstream &pp_out) {
if (ParserKit::find_word(hdr_line, macro.fName) &&
hdr_line.find("%def") == std::string::npos) {
auto value = macro.fValue;
-
+
hdr_line.replace(hdr_line.find(macro.fName), macro.fName.size(),
value);
}
@@ -839,8 +839,8 @@ MPCC_MODULE(NewOSPreprocessor) {
kWorkingDir = inc;
}
- if (strcmp(argv[index], "-def") == 0 &&
- argv[index + 1] != nullptr && argv[index + 2] != nullptr) {
+ if (strcmp(argv[index], "-def") == 0 && argv[index + 1] != nullptr &&
+ argv[index + 2] != nullptr) {
std::string macro_key = argv[index + 1];
std::string macro_value;
diff --git a/Sources/ccplus.cc b/Sources/ccplus.cc
index 9075636..ee73093 100644
--- a/Sources/ccplus.cc
+++ b/Sources/ccplus.cc
@@ -391,8 +391,7 @@ MPCC_MODULE(CompilerCPlusPlus) {
continue;
}
- if (strcmp(argv[index], "-h") == 0 ||
- strcmp(argv[index], "-help") == 0) {
+ if (strcmp(argv[index], "-h") == 0 || strcmp(argv[index], "-help") == 0) {
cxx_print_help();
return kOk;
diff --git a/Sources/i64asm.cc b/Sources/i64asm.cc
index b85b6b3..f7fa5e5 100644
--- a/Sources/i64asm.cc
+++ b/Sources/i64asm.cc
@@ -30,13 +30,13 @@
#include <Headers/ParserKit.hpp>
#include <Headers/StdKit/AE.hpp>
#include <Headers/StdKit/PEF.hpp>
+#include <algorithm>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <memory>
#include <vector>
-#include <algorithm>
/////////////////////
@@ -125,8 +125,9 @@ MPCC_MODULE(NewOSAssemblerAMD64) {
"jno", "jnp", "jns", "jnz", "jo", "jp", "jpe", "jpo", "js", "jz"};
for (i64_hword_t i = 0; i < kJumpLimit; i++) {
- CpuOpcodeAMD64 code{.fName = opcodes_jump[i],
- .fOpcode = static_cast<i64_hword_t>(kAsmJumpOpcode + i)};
+ CpuOpcodeAMD64 code{
+ .fName = opcodes_jump[i],
+ .fOpcode = static_cast<i64_hword_t>(kAsmJumpOpcode + i)};
kOpcodesAMD64.push_back(code);
}
@@ -389,7 +390,7 @@ static bool asm_read_attributes(std::string &line) {
// this is a special case for the start stub.
// we want this so that ld can find it.
-
+
if (name == kPefStart) {
kCurrentRecord.fKind = CompilerKit::kPefCode;
}
@@ -411,7 +412,8 @@ static bool asm_read_attributes(std::string &line) {
return true;
}
// export is a special keyword used by i64asm to tell the AE output stage to
- // mark this section as a header. it currently supports .code64, .data64 and .zero64.
+ // mark this section as a header. it currently supports .code64, .data64 and
+ // .zero64.
else if (ParserKit::find_word(line, "export")) {
if (kOutputAsBinary) {
detail::print_error("Invalid directive in flat binary mode.", "i64asm");
@@ -1106,12 +1108,10 @@ bool CompilerKit::EncoderAMD64::WriteLine(std::string &line,
uint8_t modrm = 0x0;
- for (size_t i = 0; i < REGISTER_LIST.size(); ++i)
- {
- if (REGISTER_LIST[i].fModRM != currentRegList[0].fModRM)
- modrm += 16;
+ for (size_t i = 0; i < REGISTER_LIST.size(); ++i) {
+ if (REGISTER_LIST[i].fModRM != currentRegList[0].fModRM) modrm += 16;
}
-
+
modrm += currentRegList[1].fModRM;
kAppBytes.emplace_back(modrm);
@@ -1162,8 +1162,7 @@ bool CompilerKit::EncoderAMD64::WriteLine(std::string &line,
continue;
} else {
if (kVerbose) {
- kStdOut << "i64asm: Assembler origin set: " << kOrigin
- << std::endl;
+ kStdOut << "i64asm: origin set: " << kOrigin << std::endl;
}
break;
@@ -1172,9 +1171,17 @@ bool CompilerKit::EncoderAMD64::WriteLine(std::string &line,
}
}
}
-
- if (line.find(".number") != std::string::npos) {
- this->WriteNumber32(line.find(".number") + strlen(".number") + 1, line);
+ /// write a dword
+ else if (line.find(".dword") != std::string::npos) {
+ this->WriteNumber32(line.find(".dword") + strlen(".dword") + 1, line);
+ }
+ /// write a long
+ else if (line.find(".long") != std::string::npos) {
+ this->WriteNumber(line.find(".long") + strlen(".long") + 1, line);
+ }
+ /// write a 16-bit number
+ else if (line.find(".word") != std::string::npos) {
+ this->WriteNumber16(line.find(".word") + strlen(".word") + 1, line);
}
return true;
diff --git a/Sources/link.cc b/Sources/link.cc
index 36e9132..8c88411 100644
--- a/Sources/link.cc
+++ b/Sources/link.cc
@@ -24,12 +24,10 @@
//! Portable Executable Format
#include <Headers/StdKit/PEF.hpp>
-
-#include <vector>
+#include <Headers/UUID.hpp>
#include <filesystem>
-
#include <random>
-#include <Headers/UUID.hpp>
+#include <vector>
//! Advanced Executable Object Format
#include <Headers/StdKit/AE.hpp>
@@ -118,7 +116,7 @@ MPCC_MODULE(NewOSLinker) {
kArch = CompilerKit::kPefArch32000;
continue;
- } else if (StringCompare(argv[i], "-ppc64") == 0) {
+ } else if (StringCompare(argv[i], "-ppc64") == 0) {
kArch = CompilerKit::kPefArchPowerPC;
continue;
@@ -352,11 +350,9 @@ MPCC_MODULE(NewOSLinker) {
// check if this symbol needs to be resolved.
if (std::string(commandHdr.Name).find(kLdDefineSymbol) !=
std::string::npos &&
- std::string(commandHdr.Name).find(kLdDynamicSym) ==
- std::string::npos) {
+ std::string(commandHdr.Name).find(kLdDynamicSym) == std::string::npos) {
if (kVerbose)
- kStdOut << "link: found undefined symbol: " << commandHdr.Name
- << "\n";
+ kStdOut << "link: found undefined symbol: " << commandHdr.Name << "\n";
if (auto it = std::find(not_found.begin(), not_found.end(),
std::string(commandHdr.Name));
@@ -420,11 +416,12 @@ MPCC_MODULE(NewOSLinker) {
if (!kStartFound && is_executable) {
if (kVerbose)
- kStdOut << "link: undefined entrypoint: __start, you may have forget to link "
- "against your compiler's runtime library.\n";
+ kStdOut
+ << "link: undefined entrypoint: __start, you may have forget to link "
+ "against your compiler's runtime library.\n";
- kStdOut << "link: undefined entrypoint " << kPefStart << " for executable: "
- << kOutput << "\n";
+ kStdOut << "link: undefined entrypoint " << kPefStart
+ << " for executable: " << kOutput << "\n";
}
// step 4: write some pef commands.
@@ -482,7 +479,7 @@ MPCC_MODULE(NewOSLinker) {
std::random_device rd;
- auto seedData = std::array<int, std::mt19937::state_size> {};
+ auto seedData = std::array<int, std::mt19937::state_size>{};
std::generate(std::begin(seedData), std::end(seedData), std::ref(rd));
std::seed_seq seq(std::begin(seedData), std::end(seedData));
std::mt19937 generator(seq);
@@ -492,7 +489,8 @@ MPCC_MODULE(NewOSLinker) {
auto uuidStr = uuids::to_string(id);
memcpy(uuidHeader.Name, "Container:GUID:4:", strlen("Container:GUID:4:"));
- memcpy(uuidHeader.Name + strlen("Container:GUID:4:"), uuidStr.c_str(), uuidStr.size());
+ memcpy(uuidHeader.Name + strlen("Container:GUID:4:"), uuidStr.c_str(),
+ uuidStr.size());
uuidHeader.Size = 16;
uuidHeader.Offset = outputFc.tellp();
@@ -508,11 +506,12 @@ MPCC_MODULE(NewOSLinker) {
// Finally write down the command headers.
// And check for any duplications
- for (size_t commandHeaderIndex = 0UL; commandHeaderIndex < commandHdrsList.size(); ++commandHeaderIndex) {
- if (std::string(commandHdrsList[commandHeaderIndex].Name).find(kLdDefineSymbol) !=
- std::string::npos &&
- std::string(commandHdrsList[commandHeaderIndex].Name).find(kLdDynamicSym) ==
- std::string::npos) {
+ for (size_t commandHeaderIndex = 0UL;
+ commandHeaderIndex < commandHdrsList.size(); ++commandHeaderIndex) {
+ if (std::string(commandHdrsList[commandHeaderIndex].Name)
+ .find(kLdDefineSymbol) != std::string::npos &&
+ std::string(commandHdrsList[commandHeaderIndex].Name)
+ .find(kLdDynamicSym) == std::string::npos) {
// ignore :UndefinedSymbol: headers, they do not contain code.
continue;
}
@@ -525,14 +524,15 @@ MPCC_MODULE(NewOSLinker) {
outputFc << commandHdrsList[commandHeaderIndex];
- for (size_t subCommandHeaderIndex = 0UL; subCommandHeaderIndex < commandHdrsList.size();
+ for (size_t subCommandHeaderIndex = 0UL;
+ subCommandHeaderIndex < commandHdrsList.size();
++subCommandHeaderIndex) {
if (subCommandHeaderIndex == commandHeaderIndex) continue;
if (std::string(commandHdrsList[subCommandHeaderIndex].Name)
.find(kLdDefineSymbol) != std::string::npos &&
- std::string(commandHdrsList[subCommandHeaderIndex].Name).find(kLdDynamicSym) ==
- std::string::npos) {
+ std::string(commandHdrsList[subCommandHeaderIndex].Name)
+ .find(kLdDynamicSym) == std::string::npos) {
if (kVerbose) {
kStdOut << "link: ignore :UndefinedSymbol: command header...\n";
}
@@ -543,7 +543,8 @@ MPCC_MODULE(NewOSLinker) {
auto &commandHdr = commandHdrsList[subCommandHeaderIndex];
- if (commandHdr.Name == std::string(commandHdrsList[commandHeaderIndex].Name)) {
+ if (commandHdr.Name ==
+ std::string(commandHdrsList[commandHeaderIndex].Name)) {
if (std::find(duplSymbols.cbegin(), duplSymbols.cend(),
commandHdr.Name) == duplSymbols.cend()) {
duplSymbols.emplace_back(commandHdr.Name);
diff --git a/Sources/ppc-cc.cc b/Sources/ppc-cc.cc
index 27fc4ab..dc40383 100644
--- a/Sources/ppc-cc.cc
+++ b/Sources/ppc-cc.cc
@@ -8,21 +8,20 @@
*/
/// BUGS: 0
-/// TODO:
+/// TODO:
#include <Headers/AsmKit/CPU/ppc.hpp>
#include <Headers/ParserKit.hpp>
+#include <Headers/UUID.hpp>
#include <cstdio>
+#include <filesystem>
#include <fstream>
#include <iostream>
+#include <memory>
+#include <random>
#include <string>
#include <utility>
#include <vector>
-#include <memory>
-#include <filesystem>
-
-#include <random>
-#include <Headers/UUID.hpp>
#define kOk 0
@@ -103,7 +102,7 @@ void print_error(std::string reason, std::string file) noexcept {
if (kState.fLastFile != file) {
std::cout << kRed << "[ cc ] " << kWhite
<< ((file == "cc") ? "internal compiler error "
- : ("in file, " + file))
+ : ("in file, " + file))
<< kBlank << std::endl;
std::cout << kRed << "[ cc ] " << kWhite << reason << kBlank << std::endl;
@@ -214,7 +213,7 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
// setup generator.
std::random_device rd;
- auto seed_data = std::array<int, std::mt19937::state_size> {};
+ auto seed_data = std::array<int, std::mt19937::state_size>{};
std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd));
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
std::mt19937 generator(seq);
@@ -292,8 +291,8 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
for (size_t return_index = text_index; return_index < textBuffer.size();
++return_index) {
if (textBuffer[return_index] != return_keyword[index]) {
- for (size_t value_index = return_index; value_index < textBuffer.size();
- ++value_index) {
+ for (size_t value_index = return_index;
+ value_index < textBuffer.size(); ++value_index) {
if (textBuffer[value_index] == ';') break;
value += textBuffer[value_index];
@@ -338,7 +337,7 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
}
}
- if (textBuffer[text_index] == 'i' && textBuffer[text_index+1] == 'f') {
+ if (textBuffer[text_index] == 'i' && textBuffer[text_index + 1] == 'f') {
auto expr = textBuffer.substr(text_index + 2);
textBuffer.erase(text_index, 2);
@@ -346,17 +345,19 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
expr.erase(expr.find("{"));
}
- if (expr.find("(") != std::string::npos)
- expr.erase(expr.find("("));
-
- if (expr.find(")") != std::string::npos)
- expr.erase(expr.find(")"));
-
+ if (expr.find("(") != std::string::npos) expr.erase(expr.find("("));
+
+ if (expr.find(")") != std::string::npos) expr.erase(expr.find(")"));
+
kIfFunction = "__MPCC_IF_PROC_";
kIfFunction += std::to_string(time_off._Raw);
syntaxLeaf.fUserValue = "\tlda r12, import ";
- syntaxLeaf.fUserValue += kIfFunction + "\n\t#r12 = Code to jump on, r11 right cond, r10 left cond.\n\tbeq r10, r11, r12\ndword export .code64 " + kIfFunction + "\n";
+ syntaxLeaf.fUserValue +=
+ kIfFunction +
+ "\n\t#r12 = Code to jump on, r11 right cond, r10 left cond.\n\tbeq "
+ "r10, r11, r12\ndword export .code64 " +
+ kIfFunction + "\n";
kState.fSyntaxTree->fLeafList.push_back(syntaxLeaf);
kIfFound = true;
@@ -374,7 +375,8 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
if (textBuffer.find("typedef ") != std::string::npos) continue;
if (textBuffer[text_index] == '=' && kInStruct) {
- detail::print_error("assignement of value in struct " + textBuffer, file);
+ detail::print_error("assignement of value in struct " + textBuffer,
+ file);
continue;
}
@@ -407,15 +409,16 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
continue;
}
- if (textBuffer[text_index + 1] == '=' || textBuffer[text_index - 1] == '!' ||
- textBuffer[text_index - 1] == '<' || textBuffer[text_index - 1] == '>') {
+ if (textBuffer[text_index + 1] == '=' ||
+ textBuffer[text_index - 1] == '!' ||
+ textBuffer[text_index - 1] == '<' ||
+ textBuffer[text_index - 1] == '>') {
continue;
}
std::string substr;
- if (textBuffer.find('=') != std::string::npos && kInBraces &&
- !kIfFound) {
+ if (textBuffer.find('=') != std::string::npos && kInBraces && !kIfFound) {
if (textBuffer.find("*") != std::string::npos) {
if (textBuffer.find("=") > textBuffer.find("*"))
substr += "\tlda ";
@@ -448,16 +451,19 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
}
}
- if (textBuffer[text_index_2] == '{' || textBuffer[text_index_2] == '}') continue;
+ if (textBuffer[text_index_2] == '{' || textBuffer[text_index_2] == '}')
+ continue;
if (textBuffer[text_index_2] == ';') {
break;
}
- if (textBuffer[text_index_2] == ' ' || textBuffer[text_index_2] == '\t') {
+ if (textBuffer[text_index_2] == ' ' ||
+ textBuffer[text_index_2] == '\t') {
if (first_encountered != 2) {
if (textBuffer[text_index] != '=' &&
- substr.find("export .data64") == std::string::npos && !kInStruct)
+ substr.find("export .data64") == std::string::npos &&
+ !kInStruct)
substr += "export .data64 ";
}
@@ -468,8 +474,8 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
if (textBuffer[text_index_2] == '=') {
if (!kInBraces) {
- substr.replace(substr.find("export .data64"), strlen("export .data64"),
- "export .page_zero ");
+ substr.replace(substr.find("export .data64"),
+ strlen("export .data64"), "export .page_zero ");
}
substr += ",";
@@ -533,7 +539,8 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
bool type_crossed = false;
- for (size_t idx = textBuffer.find('(') + 1; idx < textBuffer.size(); ++idx) {
+ for (size_t idx = textBuffer.find('(') + 1; idx < textBuffer.size();
+ ++idx) {
if (textBuffer[idx] == ',') continue;
if (textBuffer[idx] == ' ') continue;
@@ -637,8 +644,7 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) {
kBracesCount = 0;
}
- if (kIfFound)
- kIfFound = false;
+ if (kIfFound) kIfFound = false;
if (kInStruct) kInStruct = false;
@@ -1155,8 +1161,7 @@ class AssemblyMountpointCLang final : public CompilerKit::AssemblyInterface {
if (kAcceptableErrors > 0) return -1;
- std::vector<std::string> keywords = {"ld", "stw",
- "add", "sub", "or"};
+ std::vector<std::string> keywords = {"ld", "stw", "add", "sub", "or"};
///
/// Replace, optimize, fix assembly output.
@@ -1199,9 +1204,12 @@ class AssemblyMountpointCLang final : public CompilerKit::AssemblyInterface {
}
if (ParserKit::find_word(leaf.fUserValue, needle)) {
- if (leaf.fUserValue.find("import " + needle) != std::string::npos) {
+ if (leaf.fUserValue.find("import " + needle) !=
+ std::string::npos) {
std::string range = "import " + needle;
- leaf.fUserValue.replace(leaf.fUserValue.find("import " + needle), range.size(), needle);
+ leaf.fUserValue.replace(
+ leaf.fUserValue.find("import " + needle), range.size(),
+ needle);
}
if (leaf.fUserValue.find("ldw r6") != std::string::npos) {
@@ -1248,11 +1256,10 @@ class AssemblyMountpointCLang final : public CompilerKit::AssemblyInterface {
#include <Version.hxx>
#define kPrintF printf
-#define kSplashCxx() kPrintF(kWhite "cc, %s, (c) Mahrouss Logic\n", kDistVersion)
+#define kSplashCxx() \
+ kPrintF(kWhite "cc, %s, (c) Mahrouss Logic\n", kDistVersion)
-static void cc_print_help() {
- kSplashCxx();
-}
+static void cc_print_help() { kSplashCxx(); }
/////////////////////////////////////////////////////////////////////////////////////////
@@ -1291,8 +1298,7 @@ MPCC_MODULE(NewOSCompilerCLangPowerPC) {
continue;
}
- if (strcmp(argv[index], "-h") == 0 ||
- strcmp(argv[index], "-help") == 0) {
+ if (strcmp(argv[index], "-h") == 0 || strcmp(argv[index], "-help") == 0) {
cc_print_help();
return kOk;
diff --git a/Sources/ppcasm.cc b/Sources/ppcasm.cc
index 69627bb..b010cf5 100644
--- a/Sources/ppcasm.cc
+++ b/Sources/ppcasm.cc
@@ -23,12 +23,12 @@
#include <Headers/ParserKit.hpp>
#include <Headers/StdKit/AE.hpp>
#include <Headers/StdKit/PEF.hpp>
+#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <memory>
#include <vector>
-#include <algorithm>
/////////////////////
@@ -664,11 +664,11 @@ bool CompilerKit::EncoderPowerPC::WriteNumber(const std::size_t &pos,
bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line,
const std::string &file) {
if (ParserKit::find_word(line, "export")) return true;
+ if (!detail::algorithm::is_valid(line)) return true;
for (auto &opcodePPC : kOpcodesPowerPC) {
// strict check here
- if (ParserKit::find_word(line, opcodePPC.name) &&
- detail::algorithm::is_valid(line)) {
+ if (ParserKit::find_word(line, opcodePPC.name)) {
std::string name(opcodePPC.name);
std::string jump_label, cpy_jump_label;
@@ -819,13 +819,13 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line,
/// FIXME: Prompt correct opcode in little endian.
if (opcodeName == "addi") {
-
if (found_some_count == 2 || found_some_count == 0)
kBytes.emplace_back(reg_index);
- else if (found_some_count == 1) kBytes.emplace_back(0x00);
+ else if (found_some_count == 1)
+ kBytes.emplace_back(0x00);
++found_some_count;
-
+
if (found_some_count > 3) {
detail::print_error("Too much registers. -> " + line, file);
throw std::runtime_error("too_much_regs");
@@ -912,13 +912,8 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line,
}
kOrigin += 0x04;
- } else {
- /// check if we got a valid sequence of characters.
- if (!isalnum(line[0])) {
- detail::print_error("syntax error", file);
- throw std::runtime_error("syntax_error");
- }
- }
+ break;
+ }
}
return true;