summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-09 03:07:48 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-09 03:07:48 +0100
commit0c54fbd1a74242c568749b7293f2f319c4842d44 (patch)
tree86cdac041fc0a0f4e17d839d48e5ff7cea3cc5a7 /include
parentcfa04915a4c7d77996b49279b5891d1402f439a5 (diff)
chore: codebase chore and API breaking changes.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/CompilerKit/AE.h6
-rw-r--r--include/CompilerKit/CodeGenerator.h25
-rw-r--r--include/CompilerKit/Detail/Config.h4
-rw-r--r--include/CompilerKit/Detail/PreConfig.h6
-rw-r--r--include/CompilerKit/Utilities/DLL.h53
-rw-r--r--include/DebuggerKit/DebuggerContract.h8
-rw-r--r--include/DebuggerKit/POSIXMachContract.h14
7 files changed, 65 insertions, 51 deletions
diff --git a/include/CompilerKit/AE.h b/include/CompilerKit/AE.h
index cf6e71b..c1c6ed9 100644
--- a/include/CompilerKit/AE.h
+++ b/include/CompilerKit/AE.h
@@ -97,13 +97,13 @@ namespace CompilerKit::Utils {
*/
class AEReadableProtocol final {
public:
- std::ifstream file_pointer_;
+ std::ifstream fFilePtr;
public:
explicit AEReadableProtocol() = default;
~AEReadableProtocol() = default;
- NECTI_COPY_DELETE(AEReadableProtocol);
+ NECTI_COPY_DELETE(AEReadableProtocol)
/**
* @brief Read AE Record headers.
@@ -129,7 +129,7 @@ class AEReadableProtocol final {
*/
template <typename TypeClass>
TypeClass* Read_(char* raw, std::size_t sz) {
- file_pointer_.read(raw, std::streamsize(sz));
+ fFilePtr.read(raw, std::streamsize(sz));
return reinterpret_cast<TypeClass*>(raw);
}
};
diff --git a/include/CompilerKit/CodeGenerator.h b/include/CompilerKit/CodeGenerator.h
index 259c52d..8119c58 100644
--- a/include/CompilerKit/CodeGenerator.h
+++ b/include/CompilerKit/CodeGenerator.h
@@ -11,7 +11,7 @@
#include <cstring>
#define CK_ASSEMBLY_INTERFACE : public ::CompilerKit::IAssembly
-#define CK_ENCODER : public ::CompilerKit::EncoderInterface
+#define CK_ENCODER : public ::CompilerKit::IAssemblyEncoder
namespace CompilerKit {
class AssemblyFactory;
@@ -75,6 +75,11 @@ class IAssembly {
union NumberCastBase {
NumberCastBase() = default;
~NumberCastBase() = default;
+
+ static constexpr auto kLimit = 1;
+
+ Char number[kLimit];
+ UInt64 raw;
};
union NumberCast64 final {
@@ -126,12 +131,12 @@ union NumberCast8 final {
/// =========================================================== ///
/// @brief Assembly encoder interface.
/// =========================================================== ///
-class EncoderInterface {
+class IAssemblyEncoder {
public:
- explicit EncoderInterface() = default;
- virtual ~EncoderInterface() = default;
+ explicit IAssemblyEncoder() = default;
+ virtual ~IAssemblyEncoder() = default;
- NECTI_COPY_DEFAULT(EncoderInterface);
+ NECTI_COPY_DEFAULT(IAssemblyEncoder);
virtual STLString CheckLine(STLString line, STLString file) = 0;
virtual bool WriteLine(STLString line, STLString file) = 0;
@@ -144,7 +149,7 @@ class EncoderInterface {
#ifdef __ASM_NEED_AMD64__
-class EncoderAMD64 final : public EncoderInterface {
+class EncoderAMD64 final : public IAssemblyEncoder {
public:
explicit EncoderAMD64() = default;
~EncoderAMD64() override = default;
@@ -164,7 +169,7 @@ class EncoderAMD64 final : public EncoderInterface {
#ifdef __ASM_NEED_ARM64__
-class EncoderARM64 final : public EncoderInterface {
+class EncoderARM64 final : public IAssemblyEncoder {
public:
explicit EncoderARM64() = default;
~EncoderARM64() override = default;
@@ -180,7 +185,7 @@ class EncoderARM64 final : public EncoderInterface {
#ifdef __ASM_NEED_64x0__
-class Encoder64x0 final : public EncoderInterface {
+class Encoder64x0 final : public IAssemblyEncoder {
public:
explicit Encoder64x0() = default;
~Encoder64x0() override = default;
@@ -196,7 +201,7 @@ class Encoder64x0 final : public EncoderInterface {
#ifdef __ASM_NEED_32x0__
-class Encoder32x0 final : public EncoderInterface {
+class Encoder32x0 final : public IAssemblyEncoder {
public:
explicit Encoder32x0() = default;
~Encoder32x0() override = default;
@@ -212,7 +217,7 @@ class Encoder32x0 final : public EncoderInterface {
#ifdef __ASM_NEED_PPC__
-class EncoderPowerPC final : public EncoderInterface {
+class EncoderPowerPC final : public IAssemblyEncoder {
public:
explicit EncoderPowerPC() = default;
~EncoderPowerPC() override = default;
diff --git a/include/CompilerKit/Detail/Config.h b/include/CompilerKit/Detail/Config.h
index 74d0724..198db7c 100644
--- a/include/CompilerKit/Detail/Config.h
+++ b/include/CompilerKit/Detail/Config.h
@@ -15,8 +15,8 @@
#include <CompilerKit/Detail/PreConfig.h>
namespace CompilerKit {
-inline constexpr int kBaseYear = 1900;
-using STLString = std::string;
+inline static constexpr int kBaseYear = 1900;
+using STLString = std::string;
inline STLString current_date() noexcept {
auto time_data = time(nullptr);
diff --git a/include/CompilerKit/Detail/PreConfig.h b/include/CompilerKit/Detail/PreConfig.h
index 6742c53..0279072 100644
--- a/include/CompilerKit/Detail/PreConfig.h
+++ b/include/CompilerKit/Detail/PreConfig.h
@@ -4,7 +4,8 @@
======================================== */
-#pragma once
+#ifndef __COMPILERKIT_PRECONFIG_H__
+#define __COMPILERKIT_PRECONFIG_H__
#ifndef Yes
#define Yes true
@@ -116,5 +117,8 @@
KLASS& operator=(KLASS&&) = default; \
KLASS(KLASS&&) = default;
+#define CK_IMPORT_CXX extern "C++"
#define CK_IMPORT_C extern "C"
#define CK_IMPORT extern
+
+#endif // __COMPILERKIT_PRECONFIG_H__ \ No newline at end of file
diff --git a/include/CompilerKit/Utilities/DLL.h b/include/CompilerKit/Utilities/DLL.h
index 490017e..8e32d2b 100644
--- a/include/CompilerKit/Utilities/DLL.h
+++ b/include/CompilerKit/Utilities/DLL.h
@@ -11,52 +11,55 @@
#include <mutex>
namespace CompilerKit {
-struct DLLTraits final {
- typedef Int32 (*Entrypoint)(Int32 argc, Char const* argv[]);
- using DLL = VoidPtr;
+class DLLLoader final {
+ public:
+ typedef Int32 (*EntryT)(Int32 argc, Char const* argv[]);
+ using DLL = VoidPtr;
+ using Mutex = std::mutex;
+ EntryT fEntrypoint{nullptr};
- DLL fDylib{nullptr};
- Entrypoint fEntrypoint{nullptr};
- std::mutex fMutex;
+ private:
+ DLL mDLL{nullptr};
+ Mutex mMutex;
- explicit operator bool() { return fDylib && fEntrypoint; }
-
- DLLTraits& operator()(const Char* path, const Char* fEntrypoint) {
- std::lock_guard<std::mutex> lock(this->fMutex);
+ public:
+ explicit operator bool() { return this->mDLL && this->fEntrypoint; }
+ DLLLoader& operator()(const Char* path, const Char* fEntrypoint) {
if (!path || !fEntrypoint) return *this;
- if (this->fDylib) {
- dlclose(this->fDylib);
- this->fDylib = nullptr;
+ std::lock_guard<Mutex> lock(this->mMutex);
+
+ if (this->mDLL) {
+ this->Destroy();
}
- this->fDylib = dlopen(path, RTLD_LAZY);
+ this->mDLL = ::dlopen(path, RTLD_LAZY);
- if (!this->fDylib) {
+ if (!this->mDLL) {
return *this;
}
- this->fEntrypoint = (Entrypoint) dlsym(this->fDylib, fEntrypoint);
+ this->fEntrypoint = reinterpret_cast<EntryT>(::dlsym(this->mDLL, fEntrypoint));
if (!this->fEntrypoint) {
- dlclose(this->fDylib);
- this->fDylib = nullptr;
-
+ this->Destroy();
return *this;
}
return *this;
}
- NECTI_COPY_DELETE(DLLTraits)
+ NECTI_COPY_DELETE(DLLLoader)
- explicit DLLTraits() = default;
+ explicit DLLLoader() = default;
+ ~DLLLoader() { this->Destroy(); }
- ~DLLTraits() {
- if (this->fDylib) {
- dlclose(this->fDylib);
- this->fDylib = nullptr;
+ private:
+ void Destroy() noexcept {
+ if (this->mDLL) {
+ ::dlclose(this->mDLL);
+ this->mDLL = nullptr;
}
this->fEntrypoint = nullptr;
diff --git a/include/DebuggerKit/DebuggerContract.h b/include/DebuggerKit/DebuggerContract.h
index e205e26..d172f78 100644
--- a/include/DebuggerKit/DebuggerContract.h
+++ b/include/DebuggerKit/DebuggerContract.h
@@ -34,10 +34,12 @@ class IDebuggerContract {
virtual bool Continue() noexcept = 0;
virtual bool Detach() noexcept = 0;
- virtual std::unordered_map<uintptr_t, uintptr_t>& Get() { return m_breakpoints; }
+ using BreakpointMap = std::unordered_map<uintptr_t, uintptr_t>;
+
+ virtual BreakpointMap& Get() { return mBreakpoints; }
protected:
- ProcessID m_pid{(ProcessID) ~0};
- std::unordered_map<uintptr_t, uintptr_t> m_breakpoints;
+ ProcessID mPid{(ProcessID) ~0};
+ BreakpointMap mBreakpoints;
};
} // namespace DebuggerKit
diff --git a/include/DebuggerKit/POSIXMachContract.h b/include/DebuggerKit/POSIXMachContract.h
index abf23b5..f2ae8a2 100644
--- a/include/DebuggerKit/POSIXMachContract.h
+++ b/include/DebuggerKit/POSIXMachContract.h
@@ -67,9 +67,9 @@ class POSIXMachContract final DK_DEBUGGER_CONTRACT {
}
m_path = path;
- m_pid = pid;
+ mPid = pid;
- pid = this->m_pid;
+ pid = this->mPid;
return true;
}
@@ -99,7 +99,7 @@ class POSIXMachContract final DK_DEBUGGER_CONTRACT {
#ifdef __APPLE__
task_read_t task;
- task_for_pid(mach_task_self(), m_pid, &task);
+ task_for_pid(mach_task_self(), mPid, &task);
uint32_t brk_inst = 0xD43E0000;
@@ -118,7 +118,7 @@ class POSIXMachContract final DK_DEBUGGER_CONTRACT {
#ifdef __APPLE__
bool Break() noexcept override {
task_read_t task;
- task_for_pid(mach_task_self(), m_pid, &task);
+ task_for_pid(mach_task_self(), mPid, &task);
kern_return_t ret = task_suspend(task);
@@ -127,7 +127,7 @@ class POSIXMachContract final DK_DEBUGGER_CONTRACT {
bool Continue() noexcept override {
task_read_t task;
- task_for_pid(mach_task_self(), m_pid, &task);
+ task_for_pid(mach_task_self(), mPid, &task);
kern_return_t ret = task_resume(task);
@@ -138,7 +138,7 @@ class POSIXMachContract final DK_DEBUGGER_CONTRACT {
this->Continue();
task_read_t task;
- task_for_pid(mach_task_self(), m_pid, &task);
+ task_for_pid(mach_task_self(), mPid, &task);
kern_return_t kr = mach_port_deallocate(mach_task_self(), task);
@@ -147,7 +147,7 @@ class POSIXMachContract final DK_DEBUGGER_CONTRACT {
#endif
private:
- ProcessID m_pid{0};
+ ProcessID mPid{0};
CompilerKit::STLString m_path;
};
} // namespace DebuggerKit::POSIX