diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-07 12:17:28 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-07 12:21:39 +0100 |
| commit | 282b4694b7199fe4905761965bdf5ddfdeefbf28 (patch) | |
| tree | 7e399b877698e8f09f500fc07fc46dc4df7b0a81 | |
| parent | 3f62373bd7903836f51869a313033f401ee24261 (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>
| -rw-r--r-- | CompilerDriver/.gitignore | 3 | ||||
| -rw-r--r-- | CompilerDriver/bccl.cc (renamed from CompilerDriver/cc.cc) | 73 | ||||
| -rw-r--r-- | CompilerDriver/ccplus.cc | 32 | ||||
| -rw-r--r-- | CompilerDriver/ld.cc | 7 | ||||
| -rw-r--r-- | CompilerDriver/makefile | 10 | ||||
| -rw-r--r-- | CompilerDriver/masm.cc | 27 | ||||
| -rw-r--r-- | CompilerFrontend/cl/.gitignore | 1 | ||||
| -rw-r--r-- | CompilerFrontend/cl/compiler.d | 14 | ||||
| -rw-r--r-- | CompilerFrontend/cl/man/mpcc.8 | 4 |
9 files changed, 49 insertions, 122 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; } } diff --git a/CompilerFrontend/cl/.gitignore b/CompilerFrontend/cl/.gitignore index 2641307..5d8c5e5 100644 --- a/CompilerFrontend/cl/.gitignore +++ b/CompilerFrontend/cl/.gitignore @@ -6,6 +6,7 @@ bin/masm bin/mkcdfs bin/ccplus bin/cppfront +bin/bccl test/*.cc test/*.64x *.c.pp diff --git a/CompilerFrontend/cl/compiler.d b/CompilerFrontend/cl/compiler.d index 5043b9e..77c9a9a 100644 --- a/CompilerFrontend/cl/compiler.d +++ b/CompilerFrontend/cl/compiler.d @@ -66,7 +66,7 @@ public class CompileCommand import std.datetime; - mcc_summon_executable("/usr/local/bin/bin/cpp --define __64x0__ 1 --define __LP64__ 1 --define __64000__ 1 --define __OPTIMIZED_C__ 1 " ~ + mcc_summon_executable("/usr/local/bin/bin/cpp --define __64x0__ 1 --define __LP64__ 1 --define __64000__ 1 --define __BCCL__ 1 " ~ "--define __FILE__ " ~ file ~ " --define __DATE__ " ~ Clock.currTime(UTC()).toString() ~ " " ~ " --working-dir ./ --include-dir " ~ includePath ~ " " ~ file); @@ -89,16 +89,8 @@ public class CompileCommand ext ~= ch; } - if (ext == ".cc") - { - mcc_summon_executable("/usr/local/bin/bin/ccplus --asm=masm -fmax-exceptions 20 --compiler=dolvik " ~ - file ~ ".pp"); - } - else - { - mcc_summon_executable("/usr/local/bin/bin/cc --asm=masm -fmax-exceptions 20 --compiler=dolvik " ~ - file ~ ".pp"); - } + mcc_summon_executable("/usr/local/bin/bin/bccl --asm=masm -fmax-exceptions 20 --compiler=dolvik " ~ + file ~ ".pp"); changed ~= ".64x"; diff --git a/CompilerFrontend/cl/man/mpcc.8 b/CompilerFrontend/cl/man/mpcc.8 index 4cf55d0..d362e5a 100644 --- a/CompilerFrontend/cl/man/mpcc.8 +++ b/CompilerFrontend/cl/man/mpcc.8 @@ -4,8 +4,8 @@ .Sh NAME .Nm mcc -.Nd Mahrouss Logic C/C++ Compiler +.Nd Mahrouss Logic BCCL/C++ Compiler .Sh DESCRIPTION -This program compiles C/C++ sources into MP-UX Preferred Executable Format.
\ No newline at end of file +This program compiles BCCL/C++ sources into MP-UX Preferred Executable Format.
\ No newline at end of file |
