summaryrefslogtreecommitdiffhomepage
path: root/dev/LibCompiler/src/CodeGen.cc
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-29 10:48:12 +0200
committerGitHub <noreply@github.com>2025-05-29 10:48:12 +0200
commit433bb5ef102b2bfa0049468be00d63011da8b973 (patch)
treee0893a30710477045a5bb085cb7a27aada425c14 /dev/LibCompiler/src/CodeGen.cc
parent1ddeab9a4426abd781a5066ba79af2ba64de11d9 (diff)
parent756ee7f8dc954e27350fe5bdfbaa83b9f69780c8 (diff)
Merge pull request #6 from nekernel-org/dev
0.0.2e3
Diffstat (limited to 'dev/LibCompiler/src/CodeGen.cc')
-rw-r--r--dev/LibCompiler/src/CodeGen.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/dev/LibCompiler/src/CodeGen.cc b/dev/LibCompiler/src/CodeGen.cc
new file mode 100644
index 0000000..3f215c5
--- /dev/null
+++ b/dev/LibCompiler/src/CodeGen.cc
@@ -0,0 +1,56 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved
+
+------------------------------------------- */
+
+#include <LibCompiler/CodeGen.h>
+#include <LibCompiler/ErrorID.h>
+
+/**
+ * @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) 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 (fMounted) {
+ fMounted = nullptr;
+ }
+
+ return mount_prev;
+}
+} // namespace LibCompiler