diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 18:54:26 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 18:55:23 +0100 |
| commit | c377ebc1fcc5e44829b2411ae9507b91fa606a15 (patch) | |
| tree | fcbb4263970e1a899f06bd1234b60732194b8f7f /CompilerDriver | |
| parent | a19b61d41d79e7d7a9122b0cbacc381b3202bd7c (diff) | |
masm+cc+ccplus: fix assembler errornous way to tell if a register is
invalid, also improved Optimized C codegen.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CompilerDriver')
| -rw-r--r-- | CompilerDriver/cc.cc | 106 | ||||
| -rw-r--r-- | CompilerDriver/ccplus.cc | 6 | ||||
| -rw-r--r-- | CompilerDriver/masm.cc | 3 |
3 files changed, 11 insertions, 104 deletions
diff --git a/CompilerDriver/cc.cc b/CompilerDriver/cc.cc index 9544490..dc89f03 100644 --- a/CompilerDriver/cc.cc +++ b/CompilerDriver/cc.cc @@ -47,7 +47,7 @@ namespace detail { // \brief name to register struct. - struct CompilerRegisterMap + struct CompilerRegisterMap final { std::string fName; std::string fReg; @@ -55,7 +55,7 @@ namespace detail // \brief Map for C structs // \author amlel - struct CompilerStructMap + struct CompilerStructMap final { // 'my_foo' std::string fName; @@ -70,7 +70,7 @@ namespace detail std::vector<std::pair<Int32, std::string>> fOffsets; }; - struct CompilerState + struct CompilerState final { std::vector<ParserKit::SyntaxLeafList> fSyntaxTreeList; std::vector<CompilerRegisterMap> kStackFrame; @@ -118,7 +118,7 @@ namespace detail ++kAcceptableErrors; } - struct CompilerType + struct CompilerType final { std::string fName; std::string fValue; @@ -172,7 +172,7 @@ public: }; -static CompilerBackendClang* kCompilerBackend = nullptr; +static CompilerBackendClang* kCompilerBackend = nullptr; static std::vector<detail::CompilerType> kCompilerVariables; static std::vector<std::string> kCompilerFunctions; static std::vector<detail::CompilerType> kCompilerTypes; @@ -952,62 +952,6 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file) break; } - // while loop - if (_text[text_index] == 'w') - { - if (_text.find("while") == std::string::npos) - continue; - - if (_text.find("while") != text_index) - continue; - - syntax_tree.fUserValue = "jrl [r32+0x04]"; - - std::string symbol_loop = "_loop_while_"; - symbol_loop += std::to_string(time_off.raw); - symbol_loop += " "; - - syntax_tree.fUserValue = "beq "; - syntax_tree.fUserValue += kState.kStackFrame[kState.kStackFrame.size() - 2].fReg; - syntax_tree.fUserValue += ","; - syntax_tree.fUserValue += kState.kStackFrame[kState.kStackFrame.size() - 1].fReg; - syntax_tree.fUserValue += ", __end%s\njb __continue%s\nexport .text __end%s\njlr\nvoid export .text __continue%s\njb _L"; - syntax_tree.fUserValue += std::to_string(kBracesCount + 1) + "_" + std::to_string(time_off.raw); - - while (syntax_tree.fUserValue.find("%s") != std::string::npos) - { - syntax_tree.fUserValue.replace(syntax_tree.fUserValue.find("%s"), strlen("%s"), symbol_loop); - } - - kState.fSyntaxTree->fLeafList.push_back(syntax_tree); - - kOnWhileLoop = true; - - break; - } - - if (_text[text_index] == 'f') - { - if (_text.find("for") == std::string::npos) - continue; - - if (_text.find("for") != text_index) - continue; - - syntax_tree.fUserValue = "jrl [r32+0x1]\n"; - - // actually set registers now. - - auto expr = _text.substr(_text.find("for") + strlen("for")); - - kLatestVar.clear(); - - kState.fSyntaxTree->fLeafList.push_back(syntax_tree); - - kOnForLoop = true; - break; - } - if (_text[text_index] == '+' && _text[text_index+1] == '+') { @@ -1054,37 +998,7 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file) } else { - if (kOnWhileLoop || - kOnForLoop) - { - if (kOnForLoop) - kOnForLoop = false; - - if (kOnWhileLoop) - kOnWhileLoop = false; - - std::string symbol_loop = "_loop_for_"; - symbol_loop += std::to_string(time_off.raw); - symbol_loop += " "; - - syntax_tree.fUserValue = "beq "; - syntax_tree.fUserValue += kState.kStackFrame[kState.kStackFrame.size() - 2].fReg; - syntax_tree.fUserValue += ","; - syntax_tree.fUserValue += kState.kStackFrame[kState.kStackFrame.size() - 1].fReg; - syntax_tree.fUserValue += ", __end%s\njb __continue%s\nexport .text __end%s\njlr\nvoid export .text __continue%s\njb _L"; - syntax_tree.fUserValue += std::to_string(kBracesCount + 1) + "_" + std::to_string(time_off.raw); - - while (syntax_tree.fUserValue.find("%s") != std::string::npos) - { - syntax_tree.fUserValue.replace(syntax_tree.fUserValue.find("%s"), strlen("%s"), symbol_loop); - } - - kState.fSyntaxTree->fLeafList.push_back(syntax_tree); - } - else - { - kState.fSyntaxTree->fLeafList.push_back(syntax_tree); - } + kState.fSyntaxTree->fLeafList.push_back(syntax_tree); } } @@ -1802,14 +1716,6 @@ public: leaf.fUserValue.replace(leaf.fUserValue.find(needle), needle.size(), reg.fReg); - if (leaf.fUserValue.find("import") != std::string::npos) - { - if (leaf.fUserValue.find("import") < leaf.fUserValue.find(needle)) - { - leaf.fUserValue.erase(leaf.fUserValue.find("import"), strlen("import")); - } - } - ++cnt; } } diff --git a/CompilerDriver/ccplus.cc b/CompilerDriver/ccplus.cc index bc395b8..1c278c8 100644 --- a/CompilerDriver/ccplus.cc +++ b/CompilerDriver/ccplus.cc @@ -46,14 +46,14 @@ namespace detail { - struct CompilerRegisterMap + struct CompilerRegisterMap final { std::string fName; std::string fReg; }; // \brief Offset based struct/class - struct CompilerStructMap + struct CompilerStructMap final { std::string fName; std::string fReg; @@ -65,7 +65,7 @@ namespace detail std::vector<std::pair<Int32, std::string>> fOffsets; }; - struct CompilerState + struct CompilerState final { std::vector<ParserKit::SyntaxLeafList> fSyntaxTreeList; std::vector<CompilerRegisterMap> kStackFrame; diff --git a/CompilerDriver/masm.cc b/CompilerDriver/masm.cc index 00ed4b7..c56b451 100644 --- a/CompilerDriver/masm.cc +++ b/CompilerDriver/masm.cc @@ -801,7 +801,8 @@ static void masm_read_instruction(std::string& line, const std::string& file) if (kOutputArch == CompilerKit::kPefArch64000) { - if (isdigit(line[line_index + 3])) + 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 + "\nnote: 64x0 accepts registers from r0 to r20.", file); |
