diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-04-22 08:37:45 +0000 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-04-22 08:37:45 +0000 |
| commit | bfe0c2d9172b8d7f831efab7db4cc3d479a58f21 (patch) | |
| tree | 0734be5a848ab99b55b63904b25a16e84ed3d5e0 /Sources | |
| parent | d7f222089835335d575233d264b4c721d9d2087c (diff) | |
| parent | 209abc044af82897acce2ede571934af0d77b257 (diff) | |
Merged in MHR-4 (pull request #2)
MHR-4
Diffstat (limited to 'Sources')
| -rw-r--r-- | Sources/64asm.cc | 12 | ||||
| -rw-r--r-- | Sources/64x0-cc.cc | 2 | ||||
| -rw-r--r-- | Sources/compile_flags.txt | 3 | ||||
| -rw-r--r-- | Sources/i64asm.cc | 15 | ||||
| -rw-r--r-- | Sources/ppc-cc.cc | 49 | ||||
| -rw-r--r-- | Sources/ppcasm.cc | 56 |
6 files changed, 67 insertions, 70 deletions
diff --git a/Sources/64asm.cc b/Sources/64asm.cc index 1d6404e..566dfd8 100644 --- a/Sources/64asm.cc +++ b/Sources/64asm.cc @@ -144,7 +144,7 @@ MPCC_MODULE(NewOSAssembler64000) { } } - object_output += kObjectFileExt; + object_output += kOutputAsBinary ? kBinaryFileExt : kObjectFileExt; std::ifstream file_ptr(argv[i]); std::ofstream file_ptr_out(object_output, std::ofstream::binary); @@ -311,11 +311,9 @@ static bool asm_read_attributes(std::string &line) { auto name = line.substr(line.find("import") + strlen("import")); /// sanity check to avoid stupid linker errors. - if (name.size() == 0) - { - detail::print_error("Invalid import", - "ppcasm"); - throw std::runtime_error("invalid_import"); + if (name.size() == 0) { + detail::print_error("Invalid import", "ppcasm"); + throw std::runtime_error("invalid_import"); } std::string result = std::to_string(name.size()); @@ -554,7 +552,7 @@ std::string CompilerKit::Encoder64x0::CheckLine(std::string &line, } } - err_str += "Unrecognized instruction and operands: " + line; + err_str += "Unrecognized instruction: " + line; return err_str; } diff --git a/Sources/64x0-cc.cc b/Sources/64x0-cc.cc index cd96c85..7cee282 100644 --- a/Sources/64x0-cc.cc +++ b/Sources/64x0-cc.cc @@ -166,7 +166,7 @@ class CompilerBackendCLang final : public ParserKit::CompilerBackend { std::string Check(const char *text, const char *file); bool Compile(const std::string &text, const char *file) override; - const char *Language() override { return "64x0 C"; } + const char *Language() override { return "64k C"; } }; static CompilerBackendCLang *kCompilerBackend = nullptr; diff --git a/Sources/compile_flags.txt b/Sources/compile_flags.txt index bf90a5c..028be9d 100644 --- a/Sources/compile_flags.txt +++ b/Sources/compile_flags.txt @@ -1,4 +1,5 @@ -std=c++20 -I../ --I../CompilerKit +-I../StdKit -I./ +-I./Detail/ diff --git a/Sources/i64asm.cc b/Sources/i64asm.cc index d19c515..634c070 100644 --- a/Sources/i64asm.cc +++ b/Sources/i64asm.cc @@ -24,6 +24,7 @@ #define __ASM_NEED_AMD64__ 1 +#define kAssemblerPragmaSymStr "#" #define kAssemblerPragmaSym '#' #include <Headers/AsmKit/CPU/amd64.hpp> @@ -192,7 +193,7 @@ MPCC_MODULE(NewOSAssemblerAMD64) { } } - object_output += kObjectFileExt; + object_output += kOutputAsBinary ? kBinaryFileExt : kObjectFileExt; std::ifstream file_ptr(argv[i]); std::ofstream file_ptr_out(object_output, std::ofstream::binary); @@ -520,8 +521,9 @@ std::string CompilerKit::EncoderAMD64::CheckLine(std::string &line, std::string err_str; if (line.empty() || ParserKit::find_word(line, "import") || - ParserKit::find_word(line, "export") || ParserKit::find_word(line, "#") || - ParserKit::find_word(line, ";")) { + ParserKit::find_word(line, "export") || ParserKit::find_word(line, kAssemblerPragmaSymStr) || + ParserKit::find_word(line, ";") || + line[0] == kAssemblerPragmaSym) { if (line.find(';') != std::string::npos) { line.erase(line.find(';')); } else { @@ -577,6 +579,13 @@ std::string CompilerKit::EncoderAMD64::CheckLine(std::string &line, } } } + for (auto &opcodeAMD64 : kOpcodesAMD64) { + if (ParserKit::find_word(line, opcodeAMD64.fName)) { + return err_str; + } + } + + err_str += "\nUnrecognized instruction -> " + line; return err_str; } diff --git a/Sources/ppc-cc.cc b/Sources/ppc-cc.cc index 770efb0..318cf0a 100644 --- a/Sources/ppc-cc.cc +++ b/Sources/ppc-cc.cc @@ -95,8 +95,7 @@ namespace detail { void print_error(std::string reason, std::string file) noexcept { if (reason[0] == '\n') reason.erase(0, 1); - if (file.find(".pp") != std::string::npos) - file.erase(file.find(".pp"), 3); + if (file.find(".pp") != std::string::npos) file.erase(file.find(".pp"), 3); if (kState.fLastFile != file) { std::cout << kRed << "[ cc ] " << kWhite @@ -333,18 +332,15 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) { bool found = false; - for (auto& reg : kState.kStackFrame) - { - if (value.find(reg.fName) != std::string::npos) - { - found = true; - syntaxLeaf.fUserValue += reg.fReg; - break; - } + for (auto ® : kState.kStackFrame) { + if (value.find(reg.fName) != std::string::npos) { + found = true; + syntaxLeaf.fUserValue += reg.fReg; + break; + } } - if (!found) - syntaxLeaf.fUserValue += "r0"; + if (!found) syntaxLeaf.fUserValue += "r0"; } syntaxLeaf.fUserValue += "\n\tblr"; @@ -374,8 +370,8 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) { "\tcmpw " "r10, r11"; - syntaxLeaf.fUserValue += "\n\tbeq import" + kIfFunction + " \ndword export .code64 " + - kIfFunction + "\n"; + syntaxLeaf.fUserValue += "\n\tbeq import" + kIfFunction + + " \ndword export .code64 " + kIfFunction + "\n"; kState.fSyntaxTree->fLeafList.push_back(syntaxLeaf); @@ -394,8 +390,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 inside a struct " + textBuffer, - file); + detail::print_error( + "assignement of value inside a struct " + textBuffer, file); continue; } @@ -531,9 +527,9 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) { return type.fName.find(substr) != std::string::npos; }); - kCompilerVariables.push_back({.fName = substr}); + kCompilerVariables.push_back({.fName = substr}); - if (textBuffer[text_index] == ';') break; + if (textBuffer[text_index] == ';') break; std::string reg = kAsmRegisterPrefix; @@ -545,18 +541,17 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) { std::string symbol; for (size_t start = 0; start < newSubstr.size(); ++start) { - if (newSubstr[start] == ',') - break; + if (newSubstr[start] == ',') break; - if (newSubstr[start] == ' ') - continue; + if (newSubstr[start] == ' ') continue; symbol += (newSubstr[start]); } kState.kStackFrame.push_back({.fName = symbol, .fReg = reg}); - syntaxLeaf.fUserValue += "\n\tli " + reg + substr.substr(substr.find(',')); + syntaxLeaf.fUserValue += + "\n\tli " + reg + substr.substr(substr.find(',')); kState.fSyntaxTree->fLeafList.push_back(syntaxLeaf); } @@ -1235,12 +1230,10 @@ class AssemblyMountpointCLang final : public CompilerKit::AssemblyInterface { } if (ParserKit::find_word(leaf.fUserValue, needle)) { - if (leaf.fUserValue.find("import ") != - std::string::npos) { + if (leaf.fUserValue.find("import ") != std::string::npos) { std::string range = "import "; - leaf.fUserValue.replace( - leaf.fUserValue.find(range), range.size(), - ""); + leaf.fUserValue.replace(leaf.fUserValue.find(range), + range.size(), ""); } if (leaf.fUserValue.find("ldw r6") != std::string::npos) { diff --git a/Sources/ppcasm.cc b/Sources/ppcasm.cc index f83af8a..f95020e 100644 --- a/Sources/ppcasm.cc +++ b/Sources/ppcasm.cc @@ -23,6 +23,7 @@ #include <Headers/ParserKit.hpp> #include <Headers/StdKit/AE.hpp> #include <Headers/StdKit/PEF.hpp> +#include <Headers/Version.hxx> #include <algorithm> #include <filesystem> #include <fstream> @@ -111,7 +112,7 @@ MPCC_MODULE(NewOSAssemblerPowerPC) { for (size_t i = 1; i < argc; ++i) { if (argv[i][0] == '-') { if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) { - kStdOut << "ppcasm: POWER Assembler.\nppcasm: v1.10\nppcasm: " + kStdOut << "ppcasm: POWER Assembler.\nppcasm: " << kDistVersion << "\nppcasm: " "Copyright (c) " "2024 Mahrouss Logic.\n"; return 0; @@ -149,7 +150,7 @@ MPCC_MODULE(NewOSAssemblerPowerPC) { } } - object_output += kObjectFileExt; + object_output += kOutputAsBinary ? kBinaryFileExt : kObjectFileExt; std::ifstream file_ptr(argv[i]); std::ofstream file_ptr_out(object_output, std::ofstream::binary); @@ -315,11 +316,9 @@ static bool asm_read_attributes(std::string &line) { auto name = line.substr(line.find("import") + strlen("import") + 1); - if (name.size() == 0) - { - detail::print_error("Invalid import", - "ppcasm"); - throw std::runtime_error("invalid_import"); + if (name.size() == 0) { + detail::print_error("Invalid import", "ppcasm"); + throw std::runtime_error("invalid_import"); } std::string result = std::to_string(name.size()); @@ -526,7 +525,7 @@ std::string CompilerKit::EncoderPowerPC::CheckLine(std::string &line, std::vector<std::string> filter_inst = {"blr", "bl", "sc"}; for (auto &opcodePPC : kOpcodesPowerPC) { - if (line.find(opcodePPC.name) != std::string::npos) { + if (ParserKit::find_word(line, opcodePPC.name)) { for (auto &op : operands_inst) { // if only the instruction was found. if (line == op) { @@ -556,7 +555,7 @@ std::string CompilerKit::EncoderPowerPC::CheckLine(std::string &line, } } - err_str += "Unrecognized instruction and operands: " + line; + err_str += "Unrecognized instruction: " + line; return err_str; } @@ -778,15 +777,14 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, } if ((opcodeName[0] == 's' && opcodeName[1] == 't')) { - if (register_sum == 0) { - for (size_t indexReg = 0UL; indexReg < reg_index; ++indexReg) { - register_sum += 0x20; - - } - } - else { - register_sum += reg_index; + if (register_sum == 0) { + for (size_t indexReg = 0UL; indexReg < reg_index; + ++indexReg) { + register_sum += 0x20; } + } else { + register_sum += reg_index; + } } if (opcodeName == "mr") { @@ -897,21 +895,19 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, if (opcodeName == "addi") { kBytes.emplace_back(0x38); } - if ((opcodeName[0] == 's' && - opcodeName[1] == 't') - ) { - size_t offset = 0UL; - - if (line.find('+') != std::string::npos) { - auto number = GetNumber32(line.substr(line.find("+")), "+"); - offset = number.raw; - } + if ((opcodeName[0] == 's' && opcodeName[1] == 't')) { + size_t offset = 0UL; + + if (line.find('+') != std::string::npos) { + auto number = GetNumber32(line.substr(line.find("+")), "+"); + offset = number.raw; + } - kBytes.push_back(offset); - kBytes.push_back(0x00); - kBytes.push_back(register_sum); + kBytes.push_back(offset); + kBytes.push_back(0x00); + kBytes.push_back(register_sum); - kBytes.emplace_back(0x90); + kBytes.emplace_back(0x90); } if (opcodeName == "mr") { |
