summaryrefslogtreecommitdiffhomepage
path: root/CompilerDriver
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-07 15:14:16 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-07 15:38:55 +0100
commit9dfa4caf79517545d88d0915460bff9f079aba48 (patch)
tree254632a3cf5b124c3f204d583263d0fd83a92948 /CompilerDriver
parent282b4694b7199fe4905761965bdf5ddfdeefbf28 (diff)
bccl: codegen correctly arguments call.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CompilerDriver')
-rw-r--r--CompilerDriver/bccl.cc224
-rw-r--r--CompilerDriver/ccplus.cc6
2 files changed, 14 insertions, 216 deletions
diff --git a/CompilerDriver/bccl.cc b/CompilerDriver/bccl.cc
index d44ff52..3c0e2ce 100644
--- a/CompilerDriver/bccl.cc
+++ b/CompilerDriver/bccl.cc
@@ -168,7 +168,7 @@ public:
std::string Check(const char *text, const char *file);
bool Compile(const std::string &text, const char *file) override;
- const char* Language() override { return "MP-UX BCCL (64x0/32x0 target)"; }
+ const char *Language() override { return "MP-UX BCCL (64x0/32x0 target)"; }
};
static CompilerBackendClang *kCompilerBackend = nullptr;
@@ -347,174 +347,6 @@ bool CompilerBackendClang::Compile(const std::string &text, const char *file)
}
}
- if (_text[text_index] == 'i' &&
- _text[text_index + 1] == 'f')
- {
- std::string format = "ldw r15, %s\nldw r16, %s2\n";
- std::string expr = format;
-
- if (ParserKit::find_word(_text, "=="))
- {
- expr += "\nbeq";
- }
-
- if (ParserKit::find_word(_text, "!="))
- {
- expr += "\nbneq";
- }
-
- if (ParserKit::find_word(_text, ">="))
- {
- expr += "\nbge";
- }
- else if (ParserKit::find_word(_text, ">"))
- {
- expr += "\nbg";
- }
-
- if (ParserKit::find_word(_text, "<="))
- {
- expr += "\nble";
- }
- else if (ParserKit::find_word(_text, "<"))
- {
- expr += "\nbl";
- }
-
- std::string substr = expr;
-
- std::string buf;
-
- for (size_t text_index_2 = (_text.find("if") + std::string("if").size()); text_index_2 < _text.size(); ++text_index_2)
- {
- if (_text[text_index_2] == ';')
- {
- buf.clear();
-
- for (size_t text_index_3 = text_index_2 + 1; text_index_3 < _text.size(); text_index_3++)
- {
- if (_text[text_index_3] == '{')
- continue;
-
- if (_text[text_index_3] == '}')
- continue;
-
- if (_text[text_index_3] == ' ')
- continue;
-
- if (_text[text_index_3] == '=')
- continue;
-
- if (_text[text_index_3] == '<' &&
- _text[text_index_3 + 1] == '=' ||
- _text[text_index_3] == '=' &&
- _text[text_index_3 + 1] == '=' ||
- _text[text_index_3] == '>' &&
- _text[text_index_3 + 1] == '=' ||
- _text[text_index_3] == '>' ||
- _text[text_index_3] == '<' &&
- _text[text_index_3 + 1] == '=' ||
- _text[text_index_3] == '!')
- {
- buf += ", ";
- continue;
- }
- else if (_text[text_index_3] == '=')
- {
- continue;
- }
-
- buf += _text[text_index_3];
- }
-
- break;
- }
-
- if (_text[text_index_2] == '{')
- continue;
-
- if (_text[text_index_2] == '}')
- continue;
-
- if (_text[text_index_2] == '<' &&
- _text[text_index_2 + 1] == '=' ||
- _text[text_index_2] == '=' &&
- _text[text_index_2 + 1] == '=' ||
- _text[text_index_2] == '>' &&
- _text[text_index_2 + 1] == '=' ||
- _text[text_index_2] == '>' ||
- _text[text_index_2] == '<' &&
- _text[text_index_2 + 1] == '=' ||
- _text[text_index_2] == '!')
- {
- buf += ", ";
- continue;
- }
- else if (_text[text_index_2] == '=')
- {
- continue;
- }
-
- buf += _text[text_index_2];
- }
-
- if (buf.find(",") == std::string::npos &&
- buf.find("(") != std::string::npos &&
- buf.find(")") != std::string::npos)
- {
-
- std::string cond = buf.substr(buf.find("(") + 1, buf.find(")") - 1);
- cond.erase(cond.find("("));
-
- std::string cond2 = buf.substr(buf.find("(") + 1, buf.find(")") - 1);
- cond2.erase(cond2.find(")"));
-
- substr.replace(substr.find("%s"), 2, cond);
- substr.replace(substr.find("%s2"), 3, cond2);
-
- buf.replace(buf.find(cond), cond.size(), "r15");
- buf.replace(buf.find(cond2), cond2.size(), "r16");
-
- substr += buf;
-
- syntax_tree.fUserValue = substr + "\n";
-
- kState.fSyntaxTree->fLeafList.push_back(syntax_tree);
-
- break;
- }
- else
- {
- continue;
- }
-
- // dealing with pointer
- if (buf.find("*") != std::string::npos)
- {
- buf.erase(buf.find("*"), 1);
- }
-
- std::string cond = buf.substr(buf.find("(") + 1, buf.find(",") - 1);
- cond.erase(cond.find(","));
-
- std::string cond2 = buf.substr(buf.find(",") + 1, buf.find(")") - 1);
- cond2.erase(cond2.find(")"));
-
- substr.replace(substr.find("%s"), 2, cond);
- substr.replace(substr.find("%s2"), 3, cond2);
-
- buf.replace(buf.find(cond), cond.size(), "r15");
- buf.replace(buf.find(cond2), cond2.size(), "r16");
-
- substr += buf;
-
- syntax_tree.fUserValue = substr + "\n";
-
- kState.fSyntaxTree->fLeafList.push_back(syntax_tree);
-
- break;
- }
-
// Parse expressions and instructions here.
// what does this mean?
// we encounter an assignment, or we reached the end of an expression.
@@ -751,7 +583,7 @@ bool CompilerBackendClang::Compile(const std::string &text, const char *file)
args_buffer = args_buffer.erase(args_buffer.find(';'), 1);
args_buffer = args_buffer.erase(args_buffer.find(')'), 1);
args_buffer = args_buffer.erase(args_buffer.find('('), 1);
-
+
if (!args_buffer.empty())
args += "\tldw r6, ";
@@ -817,24 +649,6 @@ bool CompilerBackendClang::Compile(const std::string &text, const char *file)
kCompilerFunctions.push_back(_text);
}
- if (_text[text_index] == 'u')
- {
- if (_text.find("union") != text_index)
- continue;
-
- if (_text.find(";") == std::string::npos)
- kInStruct = true;
- }
-
- if (_text[text_index] == 'e')
- {
- if (_text.find("enum") != text_index)
- continue;
-
- if (_text.find(";") == std::string::npos)
- kInStruct = true;
- }
-
if (_text[text_index] == '-' &&
_text[text_index + 1] == '-')
{
@@ -854,27 +668,6 @@ bool CompilerBackendClang::Compile(const std::string &text, const char *file)
break;
}
- if (_text[text_index] == '+' &&
- _text[text_index + 1] == '+')
- {
- _text = _text.replace(_text.find("++"), strlen("++"), "");
-
- for (int _text_i = 0; _text_i < _text.size(); ++_text_i)
- {
- if (_text[_text_i] == '\t' ||
- _text[_text_i] == ' ')
- _text.erase(_text_i, 1);
- }
-
- syntax_tree.fUserValue += "add ";
- syntax_tree.fUserValue += _text;
-
- if (syntax_tree.fUserValue.find(";") != std::string::npos)
- syntax_tree.fUserValue.erase(syntax_tree.fUserValue.find(";"), 1);
-
- kState.fSyntaxTree->fLeafList.push_back(syntax_tree);
- }
-
if (_text[text_index] == '}')
{
kRegisterCounter = kStartUsable;
@@ -1598,12 +1391,17 @@ public:
if (ParserKit::find_word(leaf.fUserValue, needle))
{
- if (leaf.fUserValue.find("ldw r19") != std::string::npos)
+ if (leaf.fUserValue.find("ldw r6") != std::string::npos)
{
- if (leaf.fUserValue.find("import") != std::string::npos)
- leaf.fUserValue.erase(leaf.fUserValue.find("import"), strlen("import"));
+ std::string::difference_type n = std::count(leaf.fUserValue.begin(),
+ leaf.fUserValue.end(), ',');
+
+ if (n == 1)
+ {
+ leaf.fUserValue.replace(leaf.fUserValue.find("ldw"), strlen("ldw"), "mv");
+ }
}
-
+
leaf.fUserValue.replace(leaf.fUserValue.find(needle),
needle.size(), reg.fReg);
diff --git a/CompilerDriver/ccplus.cc b/CompilerDriver/ccplus.cc
index 5c1c6f2..d6a68af 100644
--- a/CompilerDriver/ccplus.cc
+++ b/CompilerDriver/ccplus.cc
@@ -497,13 +497,13 @@ public:
static void cxx_print_help()
{
kSplashCxx();
- kPrintF(kWhite "--asm={MACHINE}: %s\n", "Compile with a specific syntax. (64x0, 32x0)");
- kPrintF(kWhite "--compiler={COMPILER}: %s\n", "Select compiler engine (builtin -> vanhalen++).");
+ kPrintF(kWhite "--asm={ASSEMBLER}: %s\n", "Compile with a specific syntax. (64x0, 32x0)");
+ kPrintF(kWhite "--compiler={COMPILER}: %s\n", "Select compiler engine (builtin -> vanhalen).");
}
/////////////////////////////////////////////////////////////////////////////////////////
-#define kExt ".cc"
+#define kExt ".cpp"
int main(int argc, char** argv)
{