From 2eed4954c762bb8050e40798c3d9f1d3998324d1 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 23 May 2025 03:48:06 +0200 Subject: feat!(LibCompiler): Codebase and diagram has been improved. Signed-off-by: Amlal El Mahrouss --- dev/LibCompiler/src/CodeGen.cc | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 dev/LibCompiler/src/CodeGen.cc (limited to 'dev/LibCompiler/src/CodeGen.cc') diff --git a/dev/LibCompiler/src/CodeGen.cc b/dev/LibCompiler/src/CodeGen.cc new file mode 100644 index 0000000..31a809b --- /dev/null +++ b/dev/LibCompiler/src/CodeGen.cc @@ -0,0 +1,57 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved + +------------------------------------------- */ + +#include +#include + +/** + * @file AssemblyFactory.cxx + * @author amlal (amlal@nekernel.org) + * @brief Assembler Kit + * @version 0.1 + * @date 2024-01-27 + * + * @copyright Copyright (c) 2024-2025 Amlal El Mahrouss + * + */ + +//! @file Asm.cpp +//! @brief AssemblyKit source implementation. + +namespace LibCompiler { +///! @brief Compile for specific format (ELF, PEF, ZBIN) +Int32 AssemblyFactory::Compile(STLString sourceFile, const Int32& arch) noexcept { + if (sourceFile.length() < 1 || !fMounted) return LIBCOMPILER_UNIMPLEMENTED; + + if (!fMounted) return LIBCOMPILER_UNIMPLEMENTED; + + if (arch != fMounted->Arch()) return LIBCOMPILER_INVALID_ARCH; + + try { + return this->fMounted->CompileToFormat(sourceFile, arch); + } catch (std::exception& e) { + return LIBCOMPILER_EXEC_ERROR; + } +} + +///! @brief mount assembly backend. +void AssemblyFactory::Mount(AssemblyInterface* mountPtr) noexcept { + if (mountPtr) { + fMounted = mountPtr; + } +} + +///! @brief Unmount assembler. +AssemblyInterface* AssemblyFactory::Unmount() noexcept { + auto mount_prev = fMounted; + + if (mount_prev) { + fMounted = nullptr; + } + + return mount_prev; +} +} // namespace LibCompiler -- cgit v1.2.3