diff options
Diffstat (limited to 'dev/LibCompiler/src')
| -rw-r--r-- | dev/LibCompiler/src/Frontend/CPlusPlusCompilerAMD64.cc | 43 | ||||
| -rw-r--r-- | dev/LibCompiler/src/Linker/DynamicLinker64PEF.cc | 12 |
2 files changed, 29 insertions, 26 deletions
diff --git a/dev/LibCompiler/src/Frontend/CPlusPlusCompilerAMD64.cc b/dev/LibCompiler/src/Frontend/CPlusPlusCompilerAMD64.cc index 793385c..726b277 100644 --- a/dev/LibCompiler/src/Frontend/CPlusPlusCompilerAMD64.cc +++ b/dev/LibCompiler/src/Frontend/CPlusPlusCompilerAMD64.cc @@ -16,8 +16,8 @@ #include <LibCompiler/Backend/X64.h> #include <LibCompiler/Frontend.h> -#include <LibCompiler/UUID.h> #include <LibCompiler/PEF.h> +#include <LibCompiler/UUID.h> #include <LibCompiler/Util/CompilerUtils.h> /* NeKernel C++ Compiler Driver */ @@ -270,21 +270,23 @@ LibCompiler::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( for (auto pairRight : kRegisterMap) { ++indexRight; + LibCompiler::STLString instr = "mov "; + if (pairRight != valueOfVar) { auto& valueOfVarOpposite = isdigit(left[0]) ? left : right; syntax_tree.fUserValue += - "mov " + kRegisterList[indexRight + 1] + ", " + valueOfVarOpposite + "\n"; + instr + kRegisterList[indexRight + 1] + ", " + valueOfVarOpposite + "\n"; syntax_tree.fUserValue += "cmp " + kRegisterList[kRegisterMap.size() - 1] + "," + kRegisterList[indexRight + 1] + "\n"; - goto done_iterarting_on_if; + goto lc_done_iterarting_on_if; } auto& valueOfVarOpposite = isdigit(left[0]) ? left : right; syntax_tree.fUserValue += - "mov " + kRegisterList[indexRight + 1] + ", " + valueOfVarOpposite + "\n"; + instr + kRegisterList[indexRight + 1] + ", " + valueOfVarOpposite + "\n"; syntax_tree.fUserValue += "cmp " + kRegisterList[kRegisterMap.size() - 1] + ", " + kRegisterList[indexRight + 1] + "\n"; @@ -293,12 +295,13 @@ LibCompiler::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( } } - done_iterarting_on_if: + lc_done_iterarting_on_if: + + LibCompiler::STLString symbol_name_fn = text; - LibCompiler::STLString fnName = text; - fnName.erase(fnName.find(keyword.first.keyword_name)); + symbol_name_fn.erase(symbol_name_fn.find(keyword.first.keyword_name)); - for (auto& ch : fnName) { + for (auto& ch : symbol_name_fn) { if (ch == ' ') ch = '_'; } @@ -321,7 +324,7 @@ LibCompiler::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( break; accept: - LibCompiler::STLString fnName = text; + LibCompiler::STLString symbol_name_fn = text; size_t indexFnName = 0; // this one is for the type. @@ -332,7 +335,7 @@ LibCompiler::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( if (ch == ' ') break; } - fnName = text.substr(indexFnName); + symbol_name_fn = text.substr(indexFnName); if (text.find("return ") != LibCompiler::STLString::npos) { text.erase(0, text.find("return ")); @@ -342,35 +345,35 @@ LibCompiler::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( if (text.ends_with(";") && text.find("return") == LibCompiler::STLString::npos) goto lc_write_assembly; else if (text.size() <= indexFnName) - Detail::print_error("Invalid function name: " + fnName, file); + Detail::print_error("Invalid function name: " + symbol_name_fn, file); indexFnName = 0; - for (auto& ch : fnName) { + for (auto& ch : symbol_name_fn) { if (ch == ' ' || ch == '\t') { - if (fnName[indexFnName - 1] != ')') - Detail::print_error("Invalid function name: " + fnName, file); + if (symbol_name_fn[indexFnName - 1] != ')') + Detail::print_error("Invalid function name: " + symbol_name_fn, file); } ++indexFnName; } - if (fnName.find("(") != LibCompiler::STLString::npos) { - fnName.erase(fnName.find("(")); + if (symbol_name_fn.find("(") != LibCompiler::STLString::npos) { + symbol_name_fn.erase(symbol_name_fn.find("(")); } - syntax_tree.fUserValue = "public_segment .code64 __LIBCOMPILER_" + fnName + "\n"; + syntax_tree.fUserValue = "public_segment .code64 __LIBCOMPILER_" + symbol_name_fn + "\n"; ++kFunctionEmbedLevel; - kOriginMap.push_back({"__LIBCOMPILER_" + fnName, kOrigin}); + kOriginMap.push_back({"__LIBCOMPILER_" + symbol_name_fn, kOrigin}); break; lc_write_assembly: auto it = std::find_if(kOriginMap.begin(), kOriginMap.end(), - [&fnName](std::pair<LibCompiler::STLString, std::uintptr_t> pair) -> bool { - return fnName == pair.first; + [&symbol_name_fn](std::pair<LibCompiler::STLString, std::uintptr_t> pair) -> bool { + return symbol_name_fn == pair.first; }); if (it != kOriginMap.end()) { diff --git a/dev/LibCompiler/src/Linker/DynamicLinker64PEF.cc b/dev/LibCompiler/src/Linker/DynamicLinker64PEF.cc index 47ff9e5..698cf61 100644 --- a/dev/LibCompiler/src/Linker/DynamicLinker64PEF.cc +++ b/dev/LibCompiler/src/Linker/DynamicLinker64PEF.cc @@ -262,21 +262,21 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { archs |= hdr.fArch; std::size_t cnt = hdr.fCount; - if (kVerbose) kConsoleOut << "Object header found, record count: " << cnt << "\n"; + if (kVerbose) kConsoleOut << "header found, record count: " << cnt << "\n"; pef_container.Count = cnt; char_type* raw_ae_records = new char_type[cnt * sizeof(LibCompiler::AERecordHeader)]; if (!raw_ae_records) { - if (kVerbose) kConsoleOut << "Allocation failure for records of count: " << cnt << "\n"; + if (kVerbose) kConsoleOut << "allocation failed for records of count: " << cnt << "\n"; } - memset(raw_ae_records, 0, cnt * sizeof(LibCompiler::AERecordHeader)); + std::memset(raw_ae_records, 0, cnt * sizeof(LibCompiler::AERecordHeader)); auto* ae_records = reader_protocol.Read(raw_ae_records, cnt); - auto org = kLinkerDefaultOrigin; + size_t org = kLinkerDefaultOrigin; for (size_t ae_record_index = 0; ae_record_index < cnt; ++ae_record_index) { LibCompiler::PEFCommandHeader command_header{0}; @@ -342,7 +342,7 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { continue; } - kConsoleOut << "Not an AE container: " << objectFile << std::endl; + kConsoleOut << "not an object container: " << objectFile << std::endl; // don't continue, it is a fatal error. return LIBCOMPILER_EXEC_ERROR; @@ -353,7 +353,7 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { output_fc << pef_container; if (kVerbose) { - kConsoleOut << "Wrote container to: " << output_fc.tellp() << ".\n"; + kConsoleOut << "wrote container to: " << output_fc.tellp() << ".\n"; } output_fc.seekp(std::streamsize(pef_container.HdrSz)); |
