blob: 5c606e961c0c202d1c790cbd4c7d2506cd386141 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/* ========================================
Copyright (C) 2024-2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license
======================================== */
#include <CompilerKit/Compiler.h>
#include <CompilerKit/ErrorID.h>
/**
* @file AssemblyFactory.cc
* @author Amlal El Mahrouss (amlal@nekernel.org)
* @brief Assembly 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
|