summaryrefslogtreecommitdiffhomepage
path: root/dev/CompilerKit/src/AssemblyFactory.cc
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-08-16 19:55:22 +0200
committerGitHub <noreply@github.com>2025-08-16 19:55:22 +0200
commit5467549fa5d656afd0c6bf12c6c3928a8c919591 (patch)
tree755d6bf288f0bd474641d9ace1de290991feffee /dev/CompilerKit/src/AssemblyFactory.cc
parent433bb5ef102b2bfa0049468be00d63011da8b973 (diff)
parent0c14f7cff6535d110bc95a7699db043d8aa9aa1a (diff)
Merge pull request #9 from nekernel-org/dev
v0.0.3
Diffstat (limited to 'dev/CompilerKit/src/AssemblyFactory.cc')
-rw-r--r--dev/CompilerKit/src/AssemblyFactory.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/dev/CompilerKit/src/AssemblyFactory.cc b/dev/CompilerKit/src/AssemblyFactory.cc
new file mode 100644
index 0000000..1f08b32
--- /dev/null
+++ b/dev/CompilerKit/src/AssemblyFactory.cc
@@ -0,0 +1,52 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved
+
+------------------------------------------- */
+
+#include <CompilerKit/Compiler.h>
+#include <CompilerKit/ErrorID.h>
+
+/**
+ * @file AssemblyFactory.cc
+ * @author Amlal El Mahrouss (amlal@nekernel.org)
+ * @brief Compiler API of NeCTI
+ * @version 0.0.2
+ *
+ * @copyright Copyright (c) 2024-2025 Amlal El Mahrouss
+ *
+ */
+
+namespace CompilerKit {
+///! @brief Compile for specific format (ELF, PEF, ZBIN)
+Int32 AssemblyFactory::Compile(STLString sourceFile, const Int32& arch) noexcept {
+ if (sourceFile.length() < 1) return NECTI_UNIMPLEMENTED;
+
+ if (!fMounted) return NECTI_UNIMPLEMENTED;
+ if (arch != fMounted->Arch()) return NECTI_INVALID_ARCH;
+
+ try {
+ return this->fMounted->CompileToFormat(sourceFile, arch);
+ } catch (std::exception& e) {
+ return NECTI_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 CompilerKit