summaryrefslogtreecommitdiffhomepage
path: root/include/CompilerKit
diff options
context:
space:
mode:
Diffstat (limited to 'include/CompilerKit')
-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
5 files changed, 53 insertions, 41 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;