diff options
| author | Amlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com> | 2024-03-27 20:42:17 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com> | 2024-03-27 20:42:17 +0100 |
| commit | bdedf1ec96cd4ea41f32794ebb37279e0737934c (patch) | |
| tree | 026532c65f6d6ecf6393d7e9b39cffe399f9e060 | |
| parent | 3939adadfecc486173df35e1f54c606a9bb4bb94 (diff) | |
cc: Striving to be ANSI C compliant now.
Signed-off-by: Amlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com>
| -rw-r--r-- | Examples/ExampleCDialect.S | 9 | ||||
| -rw-r--r-- | Examples/ExampleCDialect.c | 1 | ||||
| -rw-r--r-- | Examples/HelloWorld.asm | 4 | ||||
| -rw-r--r-- | Examples/HelloWorld.asm.pp | 4 | ||||
| -rw-r--r-- | Sources/64asm.cc | 16 | ||||
| -rw-r--r-- | Sources/Deprecated/ccplus.cc | 4 | ||||
| -rw-r--r-- | Sources/cc.cc | 20 | ||||
| -rw-r--r-- | Sources/i64asm.cc | 16 | ||||
| -rw-r--r-- | Sources/link.cc | 12 | ||||
| -rw-r--r-- | makefile | 26 |
10 files changed, 57 insertions, 55 deletions
diff --git a/Examples/ExampleCDialect.S b/Examples/ExampleCDialect.S index f1ed8fe..1937907 100644 --- a/Examples/ExampleCDialect.S +++ b/Examples/ExampleCDialect.S @@ -1,16 +1,17 @@ # Path: Examples/ExampleCDialect.c -# Language: MultiProcessor Assembly (Generated from C) +# Language: 64x0 Assembly (Generated from ANSI C) # Build Date: 2024-3-27 -dword export .text main +dword export .code64 main lda r2,0x1000 - lda r12, import __MPCC_IF_PROC_462562513200 + lda r12, import __MPCC_IF_PROC_794870926384 #r12 = Code to jump on, r11 right cond, r10 left cond. beq r10, r11, r12 -dword export .text __MPCC_IF_PROC_462562513200 +dword export .code64 __MPCC_IF_PROC_794870926384 + ldw r19, r2 diff --git a/Examples/ExampleCDialect.c b/Examples/ExampleCDialect.c index ed03b66..c8c72d1 100644 --- a/Examples/ExampleCDialect.c +++ b/Examples/ExampleCDialect.c @@ -3,6 +3,7 @@ int main(int argc, char const *argv[]) int* foo = 0x1000; if (foo == 57) { + foo = 0x2000; *foo = 5; return foo; } diff --git a/Examples/HelloWorld.asm b/Examples/HelloWorld.asm index 71e90f0..91b0235 100644 --- a/Examples/HelloWorld.asm +++ b/Examples/HelloWorld.asm @@ -6,11 +6,11 @@ %def gdtBase 0x1000 %def gdtLimit 0x100 -export .data GDT +export .data64 GDT .number gdtBase .number gdtLimit -export .text __start +export .code64 __start mov rcx, 47 ; exit program mov rdx, 0x0 ; exit code 0 int 50 diff --git a/Examples/HelloWorld.asm.pp b/Examples/HelloWorld.asm.pp index c9625c4..ccb8722 100644 --- a/Examples/HelloWorld.asm.pp +++ b/Examples/HelloWorld.asm.pp @@ -4,11 +4,11 @@ ; Start sequence of program. -export .data GDT +export .data64 GDT .number 0x1000 .number 0x100 -export .text __start +export .code64 __start mov rcx, 47 ; exit program mov rdx, 0x0 ; exit code 0 int 50 diff --git a/Sources/64asm.cc b/Sources/64asm.cc index 9fb3d14..c389974 100644 --- a/Sources/64asm.cc +++ b/Sources/64asm.cc @@ -208,7 +208,7 @@ MPCC_MODULE(HCoreAssembler64000) { if (kRecords.empty()) { kStdErr << "64asm: At least one record is needed to write an object " - "file.\n64asm: Make one using `export .text foo_bar`.\n"; + "file.\n64asm: Make one using `export .code64 foo_bar`.\n"; std::filesystem::remove(object_output); return -1; @@ -319,10 +319,10 @@ static bool asm_read_attributes(std::string &line) { result += name; - if (name.find(".text") != std::string::npos) { + if (name.find(".code64") != std::string::npos) { // data is treated as code. kCurrentRecord.fKind = CompilerKit::kPefCode; - } else if (name.find(".data") != std::string::npos) { + } else if (name.find(".data64") != std::string::npos) { // no code will be executed from here. kCurrentRecord.fKind = CompilerKit::kPefData; } else if (name.find(".page_zero") != std::string::npos) { @@ -353,7 +353,7 @@ static bool asm_read_attributes(std::string &line) { return true; } // export is a special keyword used by 64asm to tell the AE output stage to - // mark this section as a header. it currently supports .text, .data., + // mark this section as a header. it currently supports .code64, .data64., // page_zero else if (ParserKit::find_word(line, "export ")) { if (kOutputAsBinary) { @@ -370,15 +370,15 @@ static bool asm_read_attributes(std::string &line) { if (j == ' ') j = '$'; } - if (name.find(".text") != std::string::npos) { + if (name.find(".code64") != std::string::npos) { // data is treated as code. - name_copy.erase(name_copy.find(".text"), strlen(".text")); + name_copy.erase(name_copy.find(".code64"), strlen(".code64")); kCurrentRecord.fKind = CompilerKit::kPefCode; - } else if (name.find(".data") != std::string::npos) { + } else if (name.find(".data64") != std::string::npos) { // no code will be executed from here. - name_copy.erase(name_copy.find(".data"), strlen(".data")); + name_copy.erase(name_copy.find(".data64"), strlen(".data64")); kCurrentRecord.fKind = CompilerKit::kPefData; } else if (name.find(".page_zero") != std::string::npos) { // this is a bss section. diff --git a/Sources/Deprecated/ccplus.cc b/Sources/Deprecated/ccplus.cc index 00b6994..6d2e270 100644 --- a/Sources/Deprecated/ccplus.cc +++ b/Sources/Deprecated/ccplus.cc @@ -250,7 +250,7 @@ class AssemblyMountpointClang final : public CompilerKit::AssemblyInterface { if (kCompilerBackend == nullptr) return -1; /* @brief copy contents wihtout extension */ - std::string src_file = src.data(); + std::string src_file = src.data64(); std::ifstream src_fp = std::ifstream(src_file, std::ios::in); std::string dest; @@ -288,7 +288,7 @@ class AssemblyMountpointClang final : public CompilerKit::AssemblyInterface { while (std::getline(src_fp, source)) { // Compile into an AST format. - kCompilerBackend->Compile(source.c_str(), src.data()); + kCompilerBackend->Compile(source.c_str(), src.data64()); } if (kAcceptableErrors > 0) return -1; diff --git a/Sources/cc.cc b/Sources/cc.cc index 7485e09..fd8da08 100644 --- a/Sources/cc.cc +++ b/Sources/cc.cc @@ -167,7 +167,7 @@ class CompilerBackendCLang final : public ParserKit::CompilerBackend { std::string Check(const char *text, const char *file); bool Compile(const std::string &text, const char *file) override; - const char *Language() override { return "Mahrouss C."; } + const char *Language() override { return "ANSI C"; } }; static CompilerBackendCLang *kCompilerBackend = nullptr; @@ -356,7 +356,7 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) { kIfFunction += std::to_string(time_off._Raw); syntaxLeaf.fUserValue = "\tlda r12, import "; - syntaxLeaf.fUserValue += kIfFunction + "\n\t#r12 = Code to jump on, r11 right cond, r10 left cond.\n\tbeq r10, r11, r12\ndword export .text " + kIfFunction + "\n"; + syntaxLeaf.fUserValue += kIfFunction + "\n\t#r12 = Code to jump on, r11 right cond, r10 left cond.\n\tbeq r10, r11, r12\ndword export .code64 " + kIfFunction + "\n"; kState.fSyntaxTree->fLeafList.push_back(syntaxLeaf); kIfFound = true; @@ -425,7 +425,7 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) { substr += "\tldw "; } } else if (textBuffer.find('=') != std::string::npos && !kInBraces) { - substr += "stw export .data "; + substr += "stw export .data64 "; } int first_encountered = 0; @@ -457,8 +457,8 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) { if (textBuffer[text_index_2] == ' ' || textBuffer[text_index_2] == '\t') { if (first_encountered != 2) { if (textBuffer[text_index] != '=' && - substr.find("export .data") == std::string::npos && !kInStruct) - substr += "export .data "; + substr.find("export .data64") == std::string::npos && !kInStruct) + substr += "export .data64 "; } ++first_encountered; @@ -468,7 +468,7 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) { if (textBuffer[text_index_2] == '=') { if (!kInBraces) { - substr.replace(substr.find("export .data"), strlen("export .data"), + substr.replace(substr.find("export .data64"), strlen("export .data64"), "export .page_zero "); } @@ -496,8 +496,8 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) { if (substr.find("extern") != std::string::npos) { 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 .data64") != std::string::npos) + substr.erase(substr.find("export .data64"), strlen("export .data64")); } auto var_to_find = @@ -599,7 +599,7 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) { } else { syntaxLeaf.fUserValue.clear(); - syntaxLeaf.fUserValue += "export .text "; + syntaxLeaf.fUserValue += "export .code64 "; syntaxLeaf.fUserValue += substr; syntaxLeaf.fUserValue += "\n"; @@ -1133,7 +1133,7 @@ class AssemblyMountpointCLang final : public CompilerKit::AssemblyInterface { (*kState.fOutputAssembly) << "# Path: " << src_file << "\n"; (*kState.fOutputAssembly) - << "# Language: MultiProcessor Assembly (Generated from C)\n"; + << "# Language: 64x0 Assembly (Generated from ANSI C)\n"; (*kState.fOutputAssembly) << "# Build Date: " << fmt << "\n\n"; ParserKit::SyntaxLeafList syntax; diff --git a/Sources/i64asm.cc b/Sources/i64asm.cc index cdddfd6..dfb9e7b 100644 --- a/Sources/i64asm.cc +++ b/Sources/i64asm.cc @@ -259,7 +259,7 @@ MPCC_MODULE(HCoreAssemblerAMD64) { if (kRecords.empty()) { kStdErr << "i64asm: At least one record is needed to write an object " - "file.\ni64asm: Make one using `export .text foo_bar`.\n"; + "file.\ni64asm: Make one using `export .code64 foo_bar`.\n"; std::filesystem::remove(object_output); return -1; @@ -376,10 +376,10 @@ static bool asm_read_attributes(std::string &line) { result += name; - if (name.find(".text") != std::string::npos) { + if (name.find(".code64") != std::string::npos) { // data is treated as code. kCurrentRecord.fKind = CompilerKit::kPefCode; - } else if (name.find(".data") != std::string::npos) { + } else if (name.find(".data64") != std::string::npos) { // no code will be executed from here. kCurrentRecord.fKind = CompilerKit::kPefData; } else if (name.find(".page_zero") != std::string::npos) { @@ -411,7 +411,7 @@ static bool asm_read_attributes(std::string &line) { return true; } // export is a special keyword used by i64asm to tell the AE output stage to - // mark this section as a header. it currently supports .text, .data., + // mark this section as a header. it currently supports .code64, .data64., // page_zero else if (ParserKit::find_word(line, "export")) { if (kOutputAsBinary) { @@ -436,15 +436,15 @@ static bool asm_read_attributes(std::string &line) { kDefinedSymbols.push_back(name); - if (name.find(".text") != std::string::npos) { + if (name.find(".code64") != std::string::npos) { // data is treated as code. - name_copy.erase(name_copy.find(".text"), strlen(".text")); + name_copy.erase(name_copy.find(".code64"), strlen(".code64")); kCurrentRecord.fKind = CompilerKit::kPefCode; - } else if (name.find(".data") != std::string::npos) { + } else if (name.find(".data64") != std::string::npos) { // no code will be executed from here. - name_copy.erase(name_copy.find(".data"), strlen(".data")); + name_copy.erase(name_copy.find(".data64"), strlen(".data64")); kCurrentRecord.fKind = CompilerKit::kPefData; } else if (name.find(".page_zero") != std::string::npos) { // this is a bss section. diff --git a/Sources/link.cc b/Sources/link.cc index 204b84d..f80e45f 100644 --- a/Sources/link.cc +++ b/Sources/link.cc @@ -14,7 +14,7 @@ // @author Amlal El Mahrouss (amlel) // @brief Visual Linker. -// README: Do not look up for anything with .text/.data/.page_zero! +// README: Do not look up for anything with .code64/.data64/.page_zero! // It will be loaded when program will start up! #include <Headers/StdKit/ErrorID.hpp> @@ -269,9 +269,9 @@ MPCC_MODULE(HCoreLinker) { kPefNameLen); // check this header if it's any valid. - if (std::string(command_header.Name).find(".text") == + if (std::string(command_header.Name).find(".code64") == std::string::npos && - std::string(command_header.Name).find(".data") == + std::string(command_header.Name).find(".data64") == std::string::npos && std::string(command_header.Name).find(".page_zero") == std::string::npos) { @@ -289,7 +289,7 @@ MPCC_MODULE(HCoreLinker) { if (std::string(command_header.Name).find(kPefStart) != std::string::npos && - std::string(command_header.Name).find(".text") != + std::string(command_header.Name).find(".code64") != std::string::npos) { kStartFound = true; pef_container.Start = ae_records[ae_record_index].fOffset; @@ -484,8 +484,8 @@ MPCC_MODULE(HCoreLinker) { auto gen = uuids::uuid_random_generator{generator}; uuids::uuid id = gen(); - memcpy(uuidHeader.Name, "UUID_TYPE:4:", strlen("UUID_TYPE:4:")); - memcpy(uuidHeader.Name + strlen("UUID_TYPE:4:"), id.as_bytes().data(), id.as_bytes().size()); + memcpy(uuidHeader.Name, "UUID_KIND:4:", strlen("UUID_KIND:4:")); + memcpy(uuidHeader.Name + strlen("UUID_KIND:4:"), id.as_bytes().data(), id.as_bytes().size()); uuidHeader.Size = 16; uuidHeader.Offset = outputFc.tellp(); @@ -42,31 +42,31 @@ IASM_OUTPUT=Output/i64asm.exe all: pp cl link @echo "DONE." -.PHONY: pp -pp: +.PHONY: Preprocessor +Preprocessor: $(LINK_CC) $(COMMON_INC) $(PP_SRC) -o $(PP_OUTPUT) -.PHONY: cl -cl: +.PHONY: Compiler +Compiler: $(LINK_CC) $(COMMON_INC) $(CC_SRC) -o $(CC_OUTPUT) $(LINK_CC) $(COMMON_INC) $(IASM_SRC) -o $(IASM_OUTPUT) $(LINK_CC) $(COMMON_INC) $(ASM_SRC) -o $(ASM_OUTPUT) -.PHONY: link -link: +.PHONY: Linker +Linker: $(LINK_CC) $(COMMON_INC) $(LINK_SRC) -o $(LINK_OUTPUT) cp $(LINK_OUTPUT) $(LINK_ALT_OUTPUT) cp $(LINK_OUTPUT) $(LINK_ALT_2_OUTPUT) cp $(LINK_OUTPUT) $(LINK_ALT_3_OUTPUT) -.PHONY: help -help: - @echo "cl - Mahrouss Compilers." - @echo "pp - Mahrouss Preprocessors." - @echo "link - Mahrouss Linkers." +.PHONY: Help +Help: + @echo "Compiler - Mahrouss Compilers." + @echo "Preprocessor - Mahrouss Preprocessors." + @echo "Linker - Mahrouss Linkers." -.PHONY: clean -clean: +.PHONY: Clean +Clean: rm Output/$(MKCDFS_OUTPUT) rm Output/$(CC_OUTPUT) rm Output/$(PP_OUTPUT) |
