summaryrefslogtreecommitdiffhomepage
path: root/CompilerDriver
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-07 12:17:28 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-07 12:21:39 +0100
commit282b4694b7199fe4905761965bdf5ddfdeefbf28 (patch)
tree7e399b877698e8f09f500fc07fc46dc4df7b0a81 /CompilerDriver
parent3f62373bd7903836f51869a313033f401ee24261 (diff)
compilers: introducing bccl, Binary Compatible Computer Language.
masm: fix add,dec and some issues regarding labels. mpcc: is now a BCCL/C++ compiler. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CompilerDriver')
-rw-r--r--CompilerDriver/.gitignore3
-rw-r--r--CompilerDriver/bccl.cc (renamed from CompilerDriver/cc.cc)73
-rw-r--r--CompilerDriver/ccplus.cc32
-rw-r--r--CompilerDriver/ld.cc7
-rw-r--r--CompilerDriver/makefile10
-rw-r--r--CompilerDriver/masm.cc27
6 files changed, 43 insertions, 109 deletions
diff --git a/CompilerDriver/.gitignore b/CompilerDriver/.gitignore
index 64ec12a..acd901f 100644
--- a/CompilerDriver/.gitignore
+++ b/CompilerDriver/.gitignore
@@ -6,9 +6,12 @@ bin/masm
bin/mkcdfs
bin/ccplus
bin/cppfront
+bin/bccl
bin/SourceUnitTest/*.c.pp
bin/SourceUnitTest/*.c
+bin/SourceUnitTest/*.bccl
+bin/SourceUnitTest/*.bccl.pp
bin/SourceUnitTest/*.cc.pp
bin/SourceUnitTest/*.cc
bin/SourceUnitTest/*.cpp.pp
diff --git a/CompilerDriver/cc.cc b/CompilerDriver/bccl.cc
index a4e5ec0..d44ff52 100644
--- a/CompilerDriver/cc.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 "Optimized 64x0 C"; }
+ const char* Language() override { return "MP-UX BCCL (64x0/32x0 target)"; }
};
static CompilerBackendClang *kCompilerBackend = nullptr;
@@ -176,52 +176,6 @@ static std::vector<detail::CompilerType> kCompilerVariables;
static std::vector<std::string> kCompilerFunctions;
static std::vector<detail::CompilerType> kCompilerTypes;
-// @brief this hook code before the start/end command.
-static std::string kAddIfAnyBegin;
-static std::string kAddIfAnyEnd;
-static std::string kLatestVar;
-
-// \brief parse a function call
-static std::string cc_parse_function_call(std::string &_text)
-{
- if (_text[0] == '(')
- {
- std::string substr;
- std::string args_buffer;
- std::string args;
-
- bool type_crossed = false;
-
- for (char substr_first_index : _text)
- {
- args_buffer += substr_first_index;
-
- if (substr_first_index == ';')
- {
- args_buffer = args_buffer.erase(0, args_buffer.find('('));
- 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 += "\tpsh ";
-
- while (args_buffer.find(',') != std::string::npos)
- {
- args_buffer.replace(args_buffer.find(','), 1, "\n\tpsh ");
- }
-
- args += args_buffer;
- args += "\n\tjb import ";
- }
- }
-
- return args;
- }
-
- return "";
-}
-
namespace detail
{
union number_cast
@@ -667,7 +621,6 @@ bool CompilerBackendClang::Compile(const std::string &text, const char *file)
if (_text[text_index_2] == '\"')
break;
- kLatestVar += _text[text_index_2];
substr += _text[text_index_2];
}
}
@@ -708,7 +661,6 @@ bool CompilerBackendClang::Compile(const std::string &text, const char *file)
continue;
}
- kLatestVar += _text[text_index_2];
substr += _text[text_index_2];
}
@@ -938,18 +890,7 @@ bool CompilerBackendClang::Compile(const std::string &text, const char *file)
if (kInStruct)
kInStruct = false;
- if (!kInBraces)
- {
- syntax_tree.fUserValue += kAddIfAnyEnd;
-
- kAddIfAnyEnd.clear();
-
- kState.fSyntaxTree->fLeafList.push_back(syntax_tree);
- }
- else
- {
- kState.fSyntaxTree->fLeafList.push_back(syntax_tree);
- }
+ kState.fSyntaxTree->fLeafList.push_back(syntax_tree);
}
syntax_tree.fUserValue.clear();
@@ -1657,6 +1598,12 @@ public:
if (ParserKit::find_word(leaf.fUserValue, needle))
{
+ if (leaf.fUserValue.find("ldw r19") != std::string::npos)
+ {
+ if (leaf.fUserValue.find("import") != std::string::npos)
+ leaf.fUserValue.erase(leaf.fUserValue.find("import"), strlen("import"));
+ }
+
leaf.fUserValue.replace(leaf.fUserValue.find(needle),
needle.size(), reg.fReg);
@@ -1689,7 +1636,7 @@ public:
/////////////////////////////////////////////////////////////////////////////////////////
#define kPrintF printf
-#define kSplashCxx() kPrintF(kWhite "%s\n", "cc, v1.14, (c) Mahrouss Logic")
+#define kSplashCxx() kPrintF(kWhite "%s\n", "cc, v1.15, (c) Mahrouss Logic")
static void cc_print_help()
{
@@ -1701,7 +1648,7 @@ static void cc_print_help()
/////////////////////////////////////////////////////////////////////////////////////////
-#define kExt ".c"
+#define kExt ".bccl"
int main(int argc, char **argv)
{
diff --git a/CompilerDriver/ccplus.cc b/CompilerDriver/ccplus.cc
index 1c278c8..5c1c6f2 100644
--- a/CompilerDriver/ccplus.cc
+++ b/CompilerDriver/ccplus.cc
@@ -183,40 +183,12 @@ namespace detail
UInt64 raw;
};
-
- struct ast_interface
- {
- explicit ast_interface(std::string& value)
- : mValue(value)
- {
- this->_Compile();
- }
-
- ~ast_interface() = default;
-
- CXXKIT_COPY_DEFAULT(ast_interface);
-
- private:
- std::string mProcessed;
- std::string mValue;
-
- void _Compile() noexcept
- {
- if (mValue.empty())
- {
- return;
- }
-
-
- }
-
- };
}
/////////////////////////////////////////////////////////////////////////////////////////
// @name Compile
-// @brief Generate MASM from a C source.
+// @brief Generate MASM from a C++ source.
/////////////////////////////////////////////////////////////////////////////////////////
@@ -520,7 +492,7 @@ public:
/////////////////////////////////////////////////////////////////////////////////////////
#define kPrintF printf
-#define kSplashCxx() kPrintF(kWhite "%s\n", "ccplus, v1.14, (c) Mahrouss Logic.")
+#define kSplashCxx() kPrintF(kWhite "%s\n", "ccplus, v1.15, (c) Mahrouss Logic.")
static void cxx_print_help()
{
diff --git a/CompilerDriver/ld.cc b/CompilerDriver/ld.cc
index 0cbf84c..b4d8a5e 100644
--- a/CompilerDriver/ld.cc
+++ b/CompilerDriver/ld.cc
@@ -9,8 +9,7 @@
// @file ld.cxx
// @author Amlal El Mahrouss (amlel)
-// @brief AE to PEF linker.
-// Use this to compile to PEF compliant OS.
+// @brief MP-UX linker.
// README: Do not look up for anything with .text/.data/.page_zero!
// It will be loaded when program will start up!
@@ -31,9 +30,9 @@
//! @brief standard PEF entry.
#define kPefStart "__start"
-#define kToolVersion "ld v1.17, (c) Mahrouss Logic"
+#define kToolVersion "ld v1.171, (c) Mahrouss Logic"
-#define StringCompare(dst, src) strcmp(dst, src)
+#define StringCompare(DST, SRC) strcmp(DST, SRC)
#define kPefNoCpu 0U
#define kPefNoSubCpu 0U
diff --git a/CompilerDriver/makefile b/CompilerDriver/makefile
index 740be21..db59ff2 100644
--- a/CompilerDriver/makefile
+++ b/CompilerDriver/makefile
@@ -19,15 +19,15 @@ PP_OUTPUT=bin/cpp
CC2_OUTPUT=bin/cppfront
CC2_SRC=cc2/source/cppfront.cpp
-CC_SRC=ccplus.cc ../CompilerKit/StdKit/*.cc ../CompilerKit/AsmKit/*.cc
-CC_OUTPUT=bin/ccplus
-
-CC_SRC=cc.cc ../CompilerKit/StdKit/*.cc ../CompilerKit/AsmKit/*.cc
-CC_OUTPUT=bin/cc
+# BC Compiler
+CC_SRC=bccl.cc ../CompilerKit/StdKit/*.cc ../CompilerKit/AsmKit/*.cc
+CC_OUTPUT=bin/bccl
+# C++ Compiler
CXX_SRC=ccplus.cc ../CompilerKit/StdKit/*.cc ../CompilerKit/AsmKit/*.cc
CXX_OUTPUT=bin/ccplus
+# MP-UX Assembly
MASM_SRC=masm.cc ../CompilerKit/StdKit/*.cc ../CompilerKit/AsmKit/*.cc
MASM_OUTPUT=bin/masm
diff --git a/CompilerDriver/masm.cc b/CompilerDriver/masm.cc
index c56b451..a558373 100644
--- a/CompilerDriver/masm.cc
+++ b/CompilerDriver/masm.cc
@@ -763,7 +763,8 @@ static void masm_read_instruction(std::string& line, const std::string& file)
for (auto& opcode64x0 : kOpcodes64x0)
{
// strict check here
- if (ParserKit::find_word(line, opcode64x0.fName))
+ if (ParserKit::find_word(line, opcode64x0.fName) &&
+ detail::algorithm::is_valid(line))
{
std::string name(opcode64x0.fName);
std::string jump_label, cpy_jump_label;
@@ -847,7 +848,20 @@ static void masm_read_instruction(std::string& line, const std::string& file)
name != "psh" &&
name != "ldw" &&
name != "lda" &&
- name != "stw")
+ name != "stw" &&
+ name != "jb")
+ {
+ detail::print_error("invalid combination of opcode and registers.\nline: " + line, file);
+ throw std::runtime_error("invalid_comb_op_reg");
+ }
+ else if (found_some == 1 &&
+ name == "add" )
+ {
+ detail::print_error("invalid combination of opcode and registers.\nline: " + line, file);
+ throw std::runtime_error("invalid_comb_op_reg");
+ }
+ else if (found_some == 1 &&
+ name == "dec")
{
detail::print_error("invalid combination of opcode and registers.\nline: " + line, file);
throw std::runtime_error("invalid_comb_op_reg");
@@ -871,17 +885,15 @@ static void masm_read_instruction(std::string& line, const std::string& file)
name == "stw" ||
name == "ldw" ||
name == "lda" ||
- name == "sta" ||
- name == "add" ||
- name == "dec")
+ name == "sta")
{
auto where_string = name;
+ // if we load something, we'd need it's symbol/literal
if (name == "stw" ||
name == "ldw" ||
name == "lda" ||
- name == "add" ||
- name == "dec")
+ name == "sta")
where_string = ",";
jump_label = line.substr(line.find(where_string) + where_string.size());
@@ -984,6 +996,7 @@ masm_write_label:
}
kBytes.push_back('\0');
+ break;
}
}