From b03f3d83efcbc012c4153da14eaf158bb50031d2 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 3 Jan 2024 23:40:16 +0100 Subject: tools: incremental changes, support for a C compiler will soon be here. alongside the 32x0. Signed-off-by: Amlal El Mahrouss --- C++Kit/AsmKit/Arch/32k.hpp | 4 ++-- C++Kit/AsmKit/Arch/64k.hpp | 4 ++-- C++Kit/AsmKit/AsmKit.cc | 47 ++++++++++++++++++++++++++++++++++++++++++++++ C++Kit/AsmKit/AsmKit.cpp | 47 ---------------------------------------------- C++Kit/AsmKit/AsmKit.hpp | 8 ++++---- 5 files changed, 55 insertions(+), 55 deletions(-) create mode 100644 C++Kit/AsmKit/AsmKit.cc delete mode 100644 C++Kit/AsmKit/AsmKit.cpp (limited to 'C++Kit/AsmKit') diff --git a/C++Kit/AsmKit/Arch/32k.hpp b/C++Kit/AsmKit/Arch/32k.hpp index cb948b5..2e73efa 100644 --- a/C++Kit/AsmKit/Arch/32k.hpp +++ b/C++Kit/AsmKit/Arch/32k.hpp @@ -28,7 +28,7 @@ #define kAsmHWord 1 #define kAsmWord 2 -struct NCOpcode +struct CpuCode32x0 { const char fName[16]; char fOpcode; @@ -41,7 +41,7 @@ struct NCOpcode #define kAsmHWordStr ".h" #define kAsmByteStr ".b" -inline std::vector kOpcodesStd = { +inline std::vector kOpcodes32x0 = { kAsmOpcodeDecl("nop", 0b0100011, 0b0000000, kAsmImmediate) // nothing to do. kAsmOpcodeDecl("jmp", 0b1110011, 0b0000011, kAsmJump) // jump to branch kAsmOpcodeDecl("move", 0b0100011, 0b101, kAsmImmediate) diff --git a/C++Kit/AsmKit/Arch/64k.hpp b/C++Kit/AsmKit/Arch/64k.hpp index c4ce648..00ab973 100644 --- a/C++Kit/AsmKit/Arch/64k.hpp +++ b/C++Kit/AsmKit/Arch/64k.hpp @@ -25,7 +25,7 @@ #define kAsmSyscall 0x02 #define kAsmJump 0x03 -struct NCOpcode +struct CpuCode64x0 { const char fName[16]; char fOpcode; @@ -33,7 +33,7 @@ struct NCOpcode char fFunct7; }; -inline std::vector kOpcodesStd = { +inline std::vector kOpcodes64x0 = { kAsmOpcodeDecl("np", 0b0100011, 0b0000000, kAsmImmediate) // mv r0, r0 kAsmOpcodeDecl("jb", 0b1110011, 0b0000011, kAsmJump) // jump to branch kAsmOpcodeDecl("jlr", 0b1110011, 0b0000111, kAsmJump) // jump and link return register diff --git a/C++Kit/AsmKit/AsmKit.cc b/C++Kit/AsmKit/AsmKit.cc new file mode 100644 index 0000000..d44874d --- /dev/null +++ b/C++Kit/AsmKit/AsmKit.cc @@ -0,0 +1,47 @@ +/* + * ======================================================== + * + * C++Kit + * Copyright Western Company, all rights reserved. + * + * ======================================================== + */ + +#include +#include + +#include + +//! @file AsmKit.cpp +//! @brief AssemblyKit + +namespace CxxKit +{ + //! @brief Compile for specific format (ELF, PEF, ZBIN) + Int32 AssemblyFactory::Compile(StringView& sourceFile, + const Int32& arch) noexcept + { + if (sourceFile.Length() < 1 || + !fMounted) + return CXXKIT_UNIMPLEMENTED; + + return fMounted->CompileToFormat(sourceFile, arch); + } + + //! @brief mount assembly backend. + void AssemblyFactory::Mount(AssemblyMountpoint* mountPtr) noexcept + { + if (mountPtr) + fMounted = mountPtr; + } + + AssemblyMountpoint* AssemblyFactory::Unmount() noexcept + { + auto mount_prev = fMounted; + + if (mount_prev) + fMounted = nullptr; + + return mount_prev; + } +} diff --git a/C++Kit/AsmKit/AsmKit.cpp b/C++Kit/AsmKit/AsmKit.cpp deleted file mode 100644 index d44874d..0000000 --- a/C++Kit/AsmKit/AsmKit.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * ======================================================== - * - * C++Kit - * Copyright Western Company, all rights reserved. - * - * ======================================================== - */ - -#include -#include - -#include - -//! @file AsmKit.cpp -//! @brief AssemblyKit - -namespace CxxKit -{ - //! @brief Compile for specific format (ELF, PEF, ZBIN) - Int32 AssemblyFactory::Compile(StringView& sourceFile, - const Int32& arch) noexcept - { - if (sourceFile.Length() < 1 || - !fMounted) - return CXXKIT_UNIMPLEMENTED; - - return fMounted->CompileToFormat(sourceFile, arch); - } - - //! @brief mount assembly backend. - void AssemblyFactory::Mount(AssemblyMountpoint* mountPtr) noexcept - { - if (mountPtr) - fMounted = mountPtr; - } - - AssemblyMountpoint* AssemblyFactory::Unmount() noexcept - { - auto mount_prev = fMounted; - - if (mount_prev) - fMounted = nullptr; - - return mount_prev; - } -} diff --git a/C++Kit/AsmKit/AsmKit.hpp b/C++Kit/AsmKit/AsmKit.hpp index 8674922..68ea4c0 100644 --- a/C++Kit/AsmKit/AsmKit.hpp +++ b/C++Kit/AsmKit/AsmKit.hpp @@ -27,11 +27,12 @@ namespace CxxKit CXXKIT_COPY_DEFAULT(AssemblyMountpoint); //@ brief compile to object file. - // Example C++ -> Assembly -> AE object. + // Example C++ -> MASM -> AE object. virtual Int32 CompileToFormat(StringView& src, Int32 arch) = 0; }; + /// @brief Simple assembly factory class AssemblyFactory final { public: @@ -44,9 +45,8 @@ namespace CxxKit enum { kArchAMD64, - kArchARM64, - kArchPowerPC, - kArchARC, + kArch32x0, + kArch64x0, kArchRISCV, kArchUnknown, }; -- cgit v1.2.3