summaryrefslogtreecommitdiffhomepage
path: root/dev/LibCompiler
diff options
context:
space:
mode:
Diffstat (limited to 'dev/LibCompiler')
-rw-r--r--dev/LibCompiler/Backend/32x0.h2
-rw-r--r--dev/LibCompiler/Backend/64x0.h31
-rw-r--r--dev/LibCompiler/Backend/Aarch64.h (renamed from dev/LibCompiler/Backend/arm64.h)2
-rw-r--r--dev/LibCompiler/Backend/Amd64.h (renamed from dev/LibCompiler/Backend/amd64.h)2
-rw-r--r--dev/LibCompiler/Backend/PowerPC.h (renamed from dev/LibCompiler/Backend/power64.h)0
-rw-r--r--dev/LibCompiler/Detail/AsmUtils.h (renamed from dev/LibCompiler/src/Detail/AsmUtils.h)7
-rw-r--r--dev/LibCompiler/Detail/ClUtils.h57
-rw-r--r--dev/LibCompiler/src/Assembler64x0.cc46
-rw-r--r--dev/LibCompiler/src/AssemblerAMD64.cc12
-rw-r--r--dev/LibCompiler/src/AssemblerARM64.cc14
-rw-r--r--dev/LibCompiler/src/AssemblerPower.cc12
-rw-r--r--dev/LibCompiler/src/CCompilerARM64.cc2
-rw-r--r--dev/LibCompiler/src/CCompilerPower64.cc2
-rw-r--r--dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc9
-rw-r--r--dev/LibCompiler/src/Detail/ClUtils.h18
15 files changed, 98 insertions, 118 deletions
diff --git a/dev/LibCompiler/Backend/32x0.h b/dev/LibCompiler/Backend/32x0.h
index bb0a5aa..49bb978 100644
--- a/dev/LibCompiler/Backend/32x0.h
+++ b/dev/LibCompiler/Backend/32x0.h
@@ -9,7 +9,7 @@
#include <LibCompiler/Defines.h>
// @brief 32x0 support.
-// @file Backend/32x0.hpp
+// @file Backend/32x0.h
#define kAsmOpcodeDecl(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \
{.fName = __NAME, .fOpcode = __OPCODE, .fFunct3 = __FUNCT3, .fFunct7 = __FUNCT7},
diff --git a/dev/LibCompiler/Backend/64x0.h b/dev/LibCompiler/Backend/64x0.h
index 745dff0..b2c4b56 100644
--- a/dev/LibCompiler/Backend/64x0.h
+++ b/dev/LibCompiler/Backend/64x0.h
@@ -10,7 +10,7 @@
#include <vector>
// @brief 64x0 support.
-// @file Backend/64x0.hpp
+// @file Backend/64x0.h
#define kAsmOpcodeDecl(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \
{.fName = __NAME, .fOpcode = __OPCODE, .fFunct3 = __FUNCT3, .fFunct7 = __FUNCT7},
@@ -38,23 +38,26 @@ inline std::vector<CpuOpcode64x0> kOpcodes64x0 = {
kAsmJump) // jump to linked return register
kAsmOpcodeDecl("jrl", 0b1110011, 0b0001111,
kAsmJump) // jump from return register.
- kAsmOpcodeDecl("mv", 0b0100011, 0b101, kAsmRegToReg) kAsmOpcodeDecl(
- "bg", 0b1100111, 0b111, kAsmRegToReg) kAsmOpcodeDecl("bl", 0b1100111, 0b011, kAsmRegToReg)
- kAsmOpcodeDecl("beq", 0b1100111, 0b000, kAsmRegToReg)
- kAsmOpcodeDecl("bne", 0b1100111, 0b001, kAsmRegToReg)
- kAsmOpcodeDecl("bge", 0b1100111, 0b101, kAsmRegToReg)
- kAsmOpcodeDecl("ble", 0b1100111, 0b100, kAsmRegToReg)
- kAsmOpcodeDecl("stw", 0b0001111, 0b100, kAsmImmediate)
- kAsmOpcodeDecl("ldw", 0b0001111, 0b100, kAsmImmediate)
- kAsmOpcodeDecl("lda", 0b0001111, 0b101, kAsmImmediate)
- kAsmOpcodeDecl("sta", 0b0001111, 0b001, kAsmImmediate)
+ kAsmOpcodeDecl("mv", 0b0100011, 0b101, kAsmRegToReg)
+ kAsmOpcodeDecl(
+ "bg", 0b1100111, 0b111, kAsmRegToReg)
+ kAsmOpcodeDecl("bl", 0b1100111, 0b011, kAsmRegToReg)
+ kAsmOpcodeDecl("beq", 0b1100111, 0b000, kAsmRegToReg)
+ kAsmOpcodeDecl("bne", 0b1100111, 0b001, kAsmRegToReg)
+ kAsmOpcodeDecl("bge", 0b1100111, 0b101, kAsmRegToReg)
+ kAsmOpcodeDecl("ble", 0b1100111, 0b100, kAsmRegToReg)
+ kAsmOpcodeDecl("stw", 0b0001111, 0b100, kAsmImmediate)
+ kAsmOpcodeDecl("ldw", 0b0001111, 0b100, kAsmImmediate)
+ kAsmOpcodeDecl("lda", 0b0001111, 0b101, kAsmImmediate)
+ kAsmOpcodeDecl("sta", 0b0001111, 0b001, kAsmImmediate)
// add/sub without carry flag
kAsmOpcodeDecl("add", 0b0101011, 0b100, kAsmImmediate)
- kAsmOpcodeDecl("sub", 0b0101011, 0b101, kAsmImmediate)
+ kAsmOpcodeDecl("sub", 0b0101011, 0b101, kAsmImmediate)
// add/sub with carry flag
kAsmOpcodeDecl("addc", 0b0101011, 0b110, kAsmImmediate)
- kAsmOpcodeDecl("subc", 0b0101011, 0b111, kAsmImmediate)
- kAsmOpcodeDecl("sc", 0b1110011, 0b00, kAsmSyscall)};
+ kAsmOpcodeDecl("subc", 0b0101011, 0b111, kAsmImmediate)
+ kAsmOpcodeDecl("sc", 0b1110011, 0b00, kAsmSyscall)
+};
// \brief 64x0 register prefix
// example: r32, r0
diff --git a/dev/LibCompiler/Backend/arm64.h b/dev/LibCompiler/Backend/Aarch64.h
index fb91a1c..dcafa0a 100644
--- a/dev/LibCompiler/Backend/arm64.h
+++ b/dev/LibCompiler/Backend/Aarch64.h
@@ -10,7 +10,7 @@ Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved
#include <stdint.h>
/// @brief ARM64 encoding support.
-/// @file Backend/arm64.hpp
+/// @file Backend/Aarch64.h
struct CpuOpcodeArm64;
diff --git a/dev/LibCompiler/Backend/amd64.h b/dev/LibCompiler/Backend/Amd64.h
index f42b131..a3fb8a2 100644
--- a/dev/LibCompiler/Backend/amd64.h
+++ b/dev/LibCompiler/Backend/Amd64.h
@@ -9,7 +9,7 @@
#include <LibCompiler/Defines.h>
// @brief AMD64 support.
-// @file Backend/amd64.hpp
+// @file Backend/Amd64.h
#define kAsmOpcodeDecl(__NAME, __OPCODE) {.fName = __NAME, .fOpcode = __OPCODE},
diff --git a/dev/LibCompiler/Backend/power64.h b/dev/LibCompiler/Backend/PowerPC.h
index 03aea49..03aea49 100644
--- a/dev/LibCompiler/Backend/power64.h
+++ b/dev/LibCompiler/Backend/PowerPC.h
diff --git a/dev/LibCompiler/src/Detail/AsmUtils.h b/dev/LibCompiler/Detail/AsmUtils.h
index 358700a..559df5f 100644
--- a/dev/LibCompiler/src/Detail/AsmUtils.h
+++ b/dev/LibCompiler/Detail/AsmUtils.h
@@ -9,12 +9,9 @@
#include <LibCompiler/AssemblyInterface.h>
#include <LibCompiler/Parser.h>
-using namespace LibCompiler;
+#include <LibCompiler/Detail/ClUtils.h>
-namespace Detail {
-extern void print_error(std::string reason, std::string file) noexcept;
-extern void print_warning(std::string reason, std::string file) noexcept;
-} // namespace Detail
+using namespace LibCompiler;
/// @brief Get Number from lineBuffer.
/// @param lineBuffer the lineBuffer to fetch from.
diff --git a/dev/LibCompiler/Detail/ClUtils.h b/dev/LibCompiler/Detail/ClUtils.h
new file mode 100644
index 0000000..b14d472
--- /dev/null
+++ b/dev/LibCompiler/Detail/ClUtils.h
@@ -0,0 +1,57 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved
+
+------------------------------------------- */
+
+#pragma once
+
+#include <LibCompiler/AssemblyInterface.h>
+#include <LibCompiler/Parser.h>
+
+#define kZero64Section ".zero64"
+#define kCode64Section ".code64"
+#define kData64Section ".data64"
+
+#define kZero128Section ".zero128"
+#define kCode128Section ".code128"
+#define kData128Section ".data128"
+
+#define kBlank "\e[0;30m"
+#define kRed "\e[0;31m"
+#define kWhite "\e[0;97m"
+#define kYellow "\e[0;33m"
+
+#define kStdOut (std::cout << kWhite)
+#define kStdErr (std::cout << kRed)
+
+inline static UInt32 kErrorLimit = 10;
+inline static UInt32 kAcceptableErrors = 0;
+inline static bool kVerbose = false;
+inline static bool kOutputAsBinary = false;
+
+namespace Detail {
+inline void print_error(std::string reason, std::string file) noexcept {
+ if (reason[0] == '\n') reason.erase(0, 1);
+
+ kStdErr << kRed << "[ asm ] " << kWhite
+ << ((file == "LibCompiler") ? "InternalErrorException: "
+ : ("FileException{ " + file + " }: "))
+ << kBlank << std::endl;
+ kStdErr << kRed << "[ asm ] " << kWhite << reason << kBlank << std::endl;
+
+ if (kAcceptableErrors > kErrorLimit) std::exit(3);
+
+ ++kAcceptableErrors;
+}
+
+inline void print_warning(std::string reason, std::string file) noexcept {
+ if (reason[0] == '\n') reason.erase(0, 1);
+
+ if (!file.empty()) {
+ kStdOut << kYellow << "[ asm ] " << kWhite << file << kBlank << std::endl;
+ }
+
+ kStdOut << kYellow << "[ asm ] " << kWhite << reason << kBlank << std::endl;
+}
+} // namespace Detail \ No newline at end of file
diff --git a/dev/LibCompiler/src/Assembler64x0.cc b/dev/LibCompiler/src/Assembler64x0.cc
index 7701982..9dc8e52 100644
--- a/dev/LibCompiler/src/Assembler64x0.cc
+++ b/dev/LibCompiler/src/Assembler64x0.cc
@@ -28,6 +28,7 @@
#include <fstream>
#include <iostream>
#include <vector>
+#include <LibCompiler/Detail/ClUtils.h>
/////////////////////
@@ -35,29 +36,16 @@
/////////////////////
-#define kBlank "\e[0;30m"
-#define kRed "\e[0;31m"
-#define kWhite "\e[0;97m"
-#define kYellow "\e[0;33m"
-
-#define kStdOut (std::cout << kWhite)
-#define kStdErr (std::cout << kRed)
-
static char kOutputArch = LibCompiler::kPefArch64000;
-static Boolean kOutputAsBinary = false;
-static UInt32 kErrorLimit = 10;
-static UInt32 kAcceptableErrors = 0;
-
-constexpr auto c64x0IPAlignment = 0x4U;
+/// @note The 64x0 is VLSIW, so we need to jump to 4 bytes.
+constexpr auto k64x0IPAlignment = 0x4U;
static std::size_t kCounter = 1UL;
static std::uintptr_t kOrigin = kPefBaseOrigin;
static std::vector<std::pair<std::string, std::uintptr_t>> kOriginLabel;
-static bool kVerbose = false;
-
static std::vector<e64k_num_t> kBytes;
static LibCompiler::AERecordHeader kCurrentRecord{
@@ -72,32 +60,6 @@ static const std::string kRelocSymbol = ":RuntimeSymbol:";
// \brief forward decl.
static bool asm_read_attributes(std::string& line);
-namespace Detail {
-void print_error(std::string reason, std::string file) noexcept {
- if (reason[0] == '\n') reason.erase(0, 1);
-
- kStdErr << kRed << "[ asm ] " << kWhite
- << ((file == "LibCompiler") ? "InternalErrorException: "
- : ("FileException{ " + file + " }: "))
- << kBlank << std::endl;
- kStdErr << kRed << "[ asm ] " << kWhite << reason << kBlank << std::endl;
-
- if (kAcceptableErrors > kErrorLimit) std::exit(3);
-
- ++kAcceptableErrors;
-}
-
-void print_warning(std::string reason, std::string file) noexcept {
- if (reason[0] == '\n') reason.erase(0, 1);
-
- if (!file.empty()) {
- kStdOut << kYellow << "[ asm ] " << kWhite << file << kBlank << std::endl;
- }
-
- kStdOut << kYellow << "[ asm ] " << kWhite << reason << kBlank << std::endl;
-}
-} // namespace Detail
-
/////////////////////////////////////////////////////////////////////////////////////////
// @brief 64x0 assembler entrypoint, the program/module starts here.
@@ -897,7 +859,7 @@ bool LibCompiler::Encoder64x0::WriteLine(std::string& line, const std::string& f
}
asm_end_label_cpy:
- kOrigin += c64x0IPAlignment;
+ kOrigin += k64x0IPAlignment;
break;
}
diff --git a/dev/LibCompiler/src/AssemblerAMD64.cc b/dev/LibCompiler/src/AssemblerAMD64.cc
index a5a7ee5..7dfa36a 100644
--- a/dev/LibCompiler/src/AssemblerAMD64.cc
+++ b/dev/LibCompiler/src/AssemblerAMD64.cc
@@ -27,7 +27,7 @@
#define kAssemblerPragmaSym '#'
#include <LibCompiler/AE.h>
-#include <LibCompiler/Backend/amd64.h>
+#include <LibCompiler/Backend/Amd64.h>
#include <LibCompiler/PEF.h>
#include <LibCompiler/Parser.h>
#include <algorithm>
@@ -52,12 +52,8 @@
#define kStdErr (std::cout << kRed)
static char kOutputArch = LibCompiler::kPefArchAMD64;
-static Boolean kOutputAsBinary = false;
-static UInt32 kErrorLimit = 10;
-static UInt32 kAcceptableErrors = 0;
-
-constexpr auto kIPAlignement = 0x4U;
+constexpr auto kIPAlignement = 0x1U;
static std::size_t kCounter = 1UL;
@@ -67,8 +63,6 @@ static std::vector<std::pair<std::string, std::uintptr_t>> kOriginLabel;
/// @brief keep it simple by default.
static std::int32_t kRegisterBitWidth = 16U;
-static bool kVerbose = false;
-
static std::vector<i64_byte_t> kAppBytes;
static LibCompiler::AERecordHeader kCurrentRecord{
@@ -83,7 +77,7 @@ static const std::string kUndefinedSymbol = ":UndefinedSymbol:";
// \brief forward decl.
static bool asm_read_attributes(std::string& line);
-#include <AsmUtils.h>
+#include <LibCompiler/Detail/AsmUtils.h>
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/dev/LibCompiler/src/AssemblerARM64.cc b/dev/LibCompiler/src/AssemblerARM64.cc
index d984845..98f12b8 100644
--- a/dev/LibCompiler/src/AssemblerARM64.cc
+++ b/dev/LibCompiler/src/AssemblerARM64.cc
@@ -18,11 +18,12 @@
#define __ASM_NEED_ARM64__ 1
#include <LibCompiler/AE.h>
-#include <LibCompiler/Backend/arm64.h>
+#include <LibCompiler/Backend/Aarch64.h>
#include <LibCompiler/ErrorID.h>
#include <LibCompiler/PEF.h>
#include <LibCompiler/Parser.h>
#include <LibCompiler/Version.h>
+#include <LibCompiler/Detail/AsmUtils.h>
#include <algorithm>
#include <filesystem>
#include <fstream>
@@ -43,21 +44,15 @@
#define kStdOut (std::cout << kWhite)
#define kStdErr (std::cout << kRed)
-constexpr auto cPowerIPAlignment = 0x4U;
+constexpr auto cPowerIPAlignment = 0x1U;
static CharType kOutputArch = LibCompiler::kPefArchARM64;
-static Boolean kOutputAsBinary = false;
-
-static UInt32 kErrorLimit = 10;
-static UInt32 kAcceptableErrors = 0;
static std::size_t kCounter = 1UL;
static std::uintptr_t kOrigin = kPefBaseOrigin;
static std::vector<std::pair<std::string, std::uintptr_t>> kOriginLabel;
-static bool kVerbose = false;
-
static std::vector<uint8_t> kBytes;
static LibCompiler::AERecordHeader kCurrentRecord{
@@ -72,9 +67,6 @@ static const std::string kRelocSymbol = ":RuntimeSymbol:";
// \brief forward decl.
static bool asm_read_attributes(std::string& line);
-/// Do not move it on top! it uses the assembler detail namespace!
-#include <Detail/AsmUtils.h>
-
/////////////////////////////////////////////////////////////////////////////////////////
/// @brief POWER assembler entrypoint, the program/module starts here.
diff --git a/dev/LibCompiler/src/AssemblerPower.cc b/dev/LibCompiler/src/AssemblerPower.cc
index 30b6d68..d3b3b6d 100644
--- a/dev/LibCompiler/src/AssemblerPower.cc
+++ b/dev/LibCompiler/src/AssemblerPower.cc
@@ -18,7 +18,7 @@
#define __ASM_NEED_PPC__ 1
#include <LibCompiler/AE.h>
-#include <LibCompiler/Backend/power64.h>
+#include <LibCompiler/Backend/PowerPC.h>
#include <LibCompiler/ErrorID.h>
#include <LibCompiler/PEF.h>
#include <LibCompiler/Parser.h>
@@ -28,6 +28,7 @@
#include <fstream>
#include <iostream>
#include <vector>
+#include <LibCompiler/Detail/AsmUtils.h>
/////////////////////
@@ -46,18 +47,12 @@
constexpr auto cPowerIPAlignment = 0x4U;
static CharType kOutputArch = LibCompiler::kPefArchPowerPC;
-static Boolean kOutputAsBinary = false;
-
-static UInt32 kErrorLimit = 10;
-static UInt32 kAcceptableErrors = 0;
static std::size_t kCounter = 1UL;
static std::uintptr_t kOrigin = kPefBaseOrigin;
static std::vector<std::pair<std::string, std::uintptr_t>> kOriginLabel;
-static bool kVerbose = false;
-
static std::vector<uint8_t> kBytes;
static LibCompiler::AERecordHeader kCurrentRecord{
@@ -72,9 +67,6 @@ static const std::string kRelocSymbol = ":RuntimeSymbol:";
// \brief forward decl.
static bool asm_read_attributes(std::string& line);
-/// Do not move it on top! it uses the assembler detail namespace!
-#include <AsmUtils.h>
-
/////////////////////////////////////////////////////////////////////////////////////////
/// @brief POWER assembler entrypoint, the program/module starts here.
diff --git a/dev/LibCompiler/src/CCompilerARM64.cc b/dev/LibCompiler/src/CCompilerARM64.cc
index accd9f9..7339840 100644
--- a/dev/LibCompiler/src/CCompilerARM64.cc
+++ b/dev/LibCompiler/src/CCompilerARM64.cc
@@ -10,7 +10,7 @@
/// BUGS: 0
/// TODO: none
-#include <LibCompiler/Backend/arm64.h>
+#include <LibCompiler/Backend/Aarch64.h>
#include <LibCompiler/Parser.h>
#include <LibCompiler/UUID.h>
#include <cstdio>
diff --git a/dev/LibCompiler/src/CCompilerPower64.cc b/dev/LibCompiler/src/CCompilerPower64.cc
index 90031a0..42c4a0a 100644
--- a/dev/LibCompiler/src/CCompilerPower64.cc
+++ b/dev/LibCompiler/src/CCompilerPower64.cc
@@ -7,7 +7,7 @@
* ========================================================
*/
-#include <LibCompiler/Backend/power64.h>
+#include <LibCompiler/Backend/PowerPC.h>
#include <LibCompiler/Parser.h>
#include <LibCompiler/UUID.h>
#include <cstdio>
diff --git a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc
index 66cf859..558a94d 100644
--- a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc
+++ b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc
@@ -21,10 +21,12 @@
// extern_segment, @autodelete { ... }, fn foo() -> auto { ... }
-#include <LibCompiler/Backend/amd64.h>
+#include <LibCompiler/Backend/Amd64.h>
#include <LibCompiler/Parser.h>
#include <LibCompiler/UUID.h>
+#include <LibCompiler/Detail/ClUtils.h>
+
#include <cstdio>
/* NE C++ Compiler */
@@ -99,12 +101,9 @@ struct CompilerState final {
} // namespace Detail
static Detail::CompilerState kState;
-static SizeType kErrorLimit = 100;
static Int32 kOnClassScope = 0;
-static Int32 kAcceptableErrors = 0;
-
namespace Detail {
/// @brief prints an error into stdout.
/// @param reason the reason of the error.
@@ -939,6 +938,8 @@ LIBCOMPILER_MODULE(CompilerCPlusPlusAMD64) {
kKeywords.push_back({.keyword_name = ">=", .keyword_kind = LibCompiler::kKeywordKindGreaterEq});
kKeywords.push_back({.keyword_name = "<=", .keyword_kind = LibCompiler::kKeywordKindLessEq});
+ kErrorLimit = 100;
+
kFactory.Mount(new AssemblyCPlusPlusInterface());
kCompilerFrontend = new CompilerFrontendCPlusPlus();
diff --git a/dev/LibCompiler/src/Detail/ClUtils.h b/dev/LibCompiler/src/Detail/ClUtils.h
deleted file mode 100644
index 024d0d2..0000000
--- a/dev/LibCompiler/src/Detail/ClUtils.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* -------------------------------------------
-
- Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved
-
-------------------------------------------- */
-
-#pragma once
-
-#include <LibCompiler/AssemblyInterface.h>
-#include <LibCompiler/Parser.h>
-
-#define kZero64Section ".zero64"
-#define kCode64Section ".code64"
-#define kData64Section ".data64"
-
-#define kZero128Section ".zero128"
-#define kCode128Section ".code128"
-#define kData128Section ".data128"