summaryrefslogtreecommitdiffhomepage
path: root/CompilerDriver
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-06 16:13:47 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-06 16:13:47 +0100
commita19b61d41d79e7d7a9122b0cbacc381b3202bd7c (patch)
treee93a08e6fe631c08852b67f96e6abb4df05266b2 /CompilerDriver
parent0507ce6ab5b7bd126ab847a1df0930c05a5b5197 (diff)
masm && isa: deprecate machine halt and scall, sbreak. Breaking changes.
gitingore/driver: ignore .cc and .cc.pp files. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CompilerDriver')
-rw-r--r--CompilerDriver/.gitignore2
-rw-r--r--CompilerDriver/cc.cc36
-rw-r--r--CompilerDriver/ccplus.cc54
-rw-r--r--CompilerDriver/masm.cc40
4 files changed, 86 insertions, 46 deletions
diff --git a/CompilerDriver/.gitignore b/CompilerDriver/.gitignore
index 021e796..64ec12a 100644
--- a/CompilerDriver/.gitignore
+++ b/CompilerDriver/.gitignore
@@ -9,6 +9,8 @@ bin/cppfront
bin/SourceUnitTest/*.c.pp
bin/SourceUnitTest/*.c
+bin/SourceUnitTest/*.cc.pp
+bin/SourceUnitTest/*.cc
bin/SourceUnitTest/*.cpp.pp
bin/SourceUnitTest/*.cpp
bin/SourceUnitTest/*.cxx.pp
diff --git a/CompilerDriver/cc.cc b/CompilerDriver/cc.cc
index 7be9c35..9544490 100644
--- a/CompilerDriver/cc.cc
+++ b/CompilerDriver/cc.cc
@@ -213,7 +213,7 @@ static std::string cc_parse_function_call(std::string& _text)
}
args += args_buffer;
- args += "\n\tjb __import ";
+ args += "\n\tjb import ";
}
}
@@ -337,7 +337,7 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file)
if (kOnWhileLoop ||
kOnForLoop)
{
- syntax_tree.fUserValue = "void __export .text _L";
+ syntax_tree.fUserValue = "void export .text _L";
syntax_tree.fUserValue += std::to_string(kBracesCount) + "_" + std::to_string(time_off.raw);
}
@@ -388,7 +388,7 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file)
value.clear();
- value += " __import";
+ value += " import";
value += tmp;
}
@@ -664,7 +664,7 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file)
else if (_text.find('=') != std::string::npos &&
!kInBraces)
{
- substr += "stw __export .data ";
+ substr += "stw export .data ";
}
int first_encountered = 0;
@@ -705,14 +705,14 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file)
if (first_encountered != 2)
{
if (_text[text_index] != '=' &&
- substr.find("__export .data") == std::string::npos &&
+ substr.find("export .data") == std::string::npos &&
!kInStruct &&
_text.find("struct") == std::string::npos &&
_text.find("extern") == std::string::npos &&
_text.find("union") == std::string::npos &&
_text.find("class") == std::string::npos &&
_text.find("typedef") == std::string::npos)
- substr += "__export .data ";
+ substr += "export .data ";
}
++first_encountered;
@@ -724,7 +724,7 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file)
{
if (!kInBraces)
{
- substr.replace(substr.find("__export .data"), strlen("__export .data"), "__export .page_zero ");
+ substr.replace(substr.find("export .data"), strlen("export .data"), "export .page_zero ");
}
substr += ",";
@@ -770,14 +770,14 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file)
if (substr.find("static") != std::string::npos)
{
- substr.replace(substr.find("static"), strlen("static"), "__export .data ");
+ substr.replace(substr.find("static"), strlen("static"), "export .data ");
}
else if (substr.find("extern") != std::string::npos)
{
- substr.replace(substr.find("extern"), strlen("extern"), "__import ");
+ substr.replace(substr.find("extern"), strlen("extern"), "import ");
- if (substr.find("__export .data") != std::string::npos)
- substr.erase(substr.find("__export .data"), strlen("__export .data"));
+ if (substr.find("export .data") != std::string::npos)
+ substr.erase(substr.find("export .data"), strlen("export .data"));
}
auto var_to_find = std::find_if(kCompilerVariables.cbegin(), kCompilerVariables.cend(), [&](detail::CompilerType type) {
@@ -850,7 +850,7 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file)
}
args += args_buffer;
- args += "\n\tjb __import ";
+ args += "\n\tjb import ";
}
}
@@ -888,7 +888,7 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file)
{
syntax_tree.fUserValue.clear();
- syntax_tree.fUserValue += "__export .text ";
+ syntax_tree.fUserValue += "export .text ";
syntax_tree.fUserValue += substr;
syntax_tree.fUserValue += "\n";
@@ -971,7 +971,7 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file)
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\n__export .text __end%s\njlr\nvoid __export .text __continue%s\njb _L";
+ 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)
@@ -1071,7 +1071,7 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file)
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\n__export .text __end%s\njlr\nvoid __export .text __continue%s\njb _L";
+ 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)
@@ -1802,11 +1802,11 @@ 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") != std::string::npos)
{
- if (leaf.fUserValue.find("__import") < leaf.fUserValue.find(needle))
+ if (leaf.fUserValue.find("import") < leaf.fUserValue.find(needle))
{
- leaf.fUserValue.erase(leaf.fUserValue.find("__import"), strlen("__import"));
+ leaf.fUserValue.erase(leaf.fUserValue.find("import"), strlen("import"));
}
}
diff --git a/CompilerDriver/ccplus.cc b/CompilerDriver/ccplus.cc
index d63ca1d..bc395b8 100644
--- a/CompilerDriver/ccplus.cc
+++ b/CompilerDriver/ccplus.cc
@@ -257,8 +257,6 @@ bool CompilerBackendClang::Compile(const std::string& text, const char* file)
{
syntax_tree.fUserData = keyword.first;
kState.fSyntaxTree->fLeafList.emplace_back(syntax_tree);
-
- std::cout << keyword.first << "\n";
}
return true;
@@ -343,6 +341,7 @@ public:
};
std::vector<scope_type> scope;
+
bool found_type = false;
bool is_pointer = false;
bool found_expr = false;
@@ -406,14 +405,14 @@ public:
if (leaf.fUserData == "=")
{
- auto& front = scope.front();
-
if (found_type)
{
+ auto& front = scope.front();
+
std::string reg = "r";
reg += std::to_string(front.reg_cnt);
++front.reg_cnt;
-
+
leaf.fUserValue = !is_pointer ? "ldw %s, %s1\n" : "lda %s, %s1\n";
for (auto& ln : lines)
@@ -422,17 +421,55 @@ public:
ln.find(";") != std::string::npos)
{
auto val = ln.substr(ln.find(leaf.fUserData) + leaf.fUserData.size());
- val.erase(val.find(";"), 1);
+
+ if (val.find(";") != std::string::npos)
+ val.erase(val.find(";"), 1);
leaf.fUserValue.replace(leaf.fUserValue.find("%s1"), strlen("%s1"), val);
}
}
leaf.fUserValue.replace(leaf.fUserValue.find("%s"), strlen("%s"), reg);
+
+ found_type = false;
}
+ else
+ {
+ leaf.fUserValue = !is_pointer ? "ldw %s, %s1\n" : "lda %s, %s1\n";
- is_pointer = false;
- found_type = false;
+ for (auto& ln : lines)
+ {
+ if (ln.find(leaf.fUserData) != std::string::npos &&
+ ln.find(";") != std::string::npos)
+ {
+ std::string nm;
+ for (auto i = ln.find('=') + 1; i < ln.size(); ++i)
+ {
+ if (ln[i] == ';')
+ break;
+
+ nm.push_back(ln[i]);
+ }
+
+ if (!nm.empty())
+ {
+ leaf.fUserValue.replace(leaf.fUserValue.find("%s1"), strlen("%s1"), nm);
+ break;
+ }
+ }
+ }
+
+ auto& front = scope.front();
+
+ std::string reg = "r";
+ reg += std::to_string(front.reg_cnt - 1);
+ leaf.fUserValue.replace(leaf.fUserValue.find("%s"), strlen("%s"), reg);
+
+ if (is_pointer)
+ {
+ is_pointer = false;
+ }
+ }
}
if (leaf.fUserData == "return")
@@ -461,6 +498,7 @@ public:
continue;
}
+ std::cout << leaf.fUserData;
lines.emplace_back(leaf.fUserData);
}
diff --git a/CompilerDriver/masm.cc b/CompilerDriver/masm.cc
index aab621c..00ed4b7 100644
--- a/CompilerDriver/masm.cc
+++ b/CompilerDriver/masm.cc
@@ -330,11 +330,11 @@ masm_fail_exit:
static bool masm_read_attributes(std::string& line)
{
- // __import is the opposite of export, it signals to the ld
+ // import is the opposite of export, it signals to the ld
// that we need this symbol.
- if (ParserKit::find_word(line, "__import"))
+ if (ParserKit::find_word(line, "import"))
{
- auto name = line.substr(line.find("__import") + strlen("__import"));
+ auto name = line.substr(line.find("import") + strlen("import"));
std::string result = std::to_string(name.size());
result += kUndefinedSymbol;
@@ -391,11 +391,11 @@ static bool masm_read_attributes(std::string& line)
return true;
}
- // __export is a special keyword used by masm to tell the AE output stage to mark this section as a header.
+ // export is a special keyword used by masm to tell the AE output stage to mark this section as a header.
// it currently supports .text, .data., page_zero
- if (ParserKit::find_word(line, "__export"))
+ if (ParserKit::find_word(line, "export"))
{
- auto name = line.substr(line.find("__export") + strlen("__export"));
+ auto name = line.substr(line.find("export") + strlen("export"));
for (char& j : name)
{
@@ -465,8 +465,8 @@ namespace detail::algorithm
bool is_valid(const std::string &str)
{
- if (ParserKit::find_word(str, "__export") ||
- ParserKit::find_word(str, "__import"))
+ if (ParserKit::find_word(str, "export") ||
+ ParserKit::find_word(str, "import"))
return true;
return find_if(str.begin(), str.end(), is_not_alnum_space) == str.end();
@@ -489,8 +489,8 @@ static std::string masm_check_line(std::string& line, const std::string& file)
line.erase(line.find('\t'), 1);
if (line.empty() ||
- ParserKit::find_word(line, "__import") ||
- ParserKit::find_word(line, "__export") ||
+ ParserKit::find_word(line, "import") ||
+ ParserKit::find_word(line, "export") ||
ParserKit::find_word(line, "#") ||
ParserKit::find_word(line, ";") ||
ParserKit::find_word(line, "layout"))
@@ -565,7 +565,7 @@ static std::string masm_check_line(std::string& line, const std::string& file)
std::vector<std::string> operands_inst = { "jb", "psh", "stw", "ldw", "lda", "sta" };
// these don't.
- std::vector<std::string> filter_inst = { "jlr", "jrl", "scall", "sbreak" };
+ std::vector<std::string> filter_inst = { "jlr", "jrl", "syscall" };
for (auto& opcode64x0 : kOpcodes64x0)
{
@@ -757,7 +757,7 @@ static bool masm_write_number(const std::size_t& pos, std::string& jump_label)
static void masm_read_instruction(std::string& line, const std::string& file)
{
- if (ParserKit::find_word(line, "__export"))
+ if (ParserKit::find_word(line, "export"))
return;
for (auto& opcode64x0 : kOpcodes64x0)
@@ -913,9 +913,9 @@ static void masm_read_instruction(std::string& line, const std::string& file)
else
{
if (name == "sta" &&
- cpy_jump_label.find("__import") != std::string::npos)
+ cpy_jump_label.find("import") != std::string::npos)
{
- detail::print_error("invalid usage __import on 'sta', here: " + line, file);
+ detail::print_error("invalid usage import on 'sta', here: " + line, file);
throw std::runtime_error("invalid_sta_usage");
}
}
@@ -928,23 +928,23 @@ masm_write_label:
if (cpy_jump_label.find('\n') != std::string::npos)
cpy_jump_label.erase(cpy_jump_label.find('\n'), 1);
- if (cpy_jump_label.find("__import") == std::string::npos &&
+ if (cpy_jump_label.find("import") == std::string::npos &&
name == "psh" ||
- cpy_jump_label.find("__import") == std::string::npos &&
+ cpy_jump_label.find("import") == std::string::npos &&
name == "jb")
{
- detail::print_error("__import not found on jump label, please add one.", file);
+ detail::print_error("import not found on jump label, please add one.", file);
throw std::runtime_error("import_jmp_lbl");
}
- else if (cpy_jump_label.find("__import") != std::string::npos)
+ else if (cpy_jump_label.find("import") != std::string::npos)
{
if (name == "sta")
{
- detail::print_error("__import is not allowed on a sta operation.", file);
+ detail::print_error("import is not allowed on a sta operation.", file);
throw std::runtime_error("import_sta_op");
}
- cpy_jump_label.erase(cpy_jump_label.find("__import"), strlen("__import"));
+ cpy_jump_label.erase(cpy_jump_label.find("import"), strlen("import"));
}
while (cpy_jump_label.find(' ') != std::string::npos)