Initial commit

This commit is contained in:
ktkk 2025-10-15 11:30:58 +00:00
commit ef40bd03c5
14 changed files with 276 additions and 0 deletions

11
include/Assembler.h Executable file
View file

@ -0,0 +1,11 @@
#include <vector>
#include "Types.h"
struct Assembler {
explicit Assembler(std::vector<u8>&);
std::vector<u8>& output;
void emit8(u8) const;
};

26
include/Executable.h Executable file
View file

@ -0,0 +1,26 @@
#include <cstddef>
#include "Types.h"
#include "Noncopyable.h"
class Executable {
MAKE_NONCOPYABLE(Executable);
MAKE_NONMOVABLE(Executable);
public:
Executable(void* code, std::size_t code_size);
~Executable();
template<typename Return>
Return run() const
{
using ExecutableFunction = Return();
auto executable_function = reinterpret_cast<ExecutableFunction*>(m_code);
return executable_function();
}
private:
void* m_code;
std::size_t m_code_size;
};

9
include/Noncopyable.h Executable file
View file

@ -0,0 +1,9 @@
#define MAKE_NONCOPYABLE(c) \
private: \
c(c const&) = delete; \
c& operator=(c const&) = delete
#define MAKE_NONMOVABLE(c) \
private: \
c(c&&) = delete; \
c& operator=(c&&) = delete

23
include/Types.h Executable file
View file

@ -0,0 +1,23 @@
using u64 = __UINT64_TYPE__;
using u32 = __UINT32_TYPE__;
using u16 = __UINT16_TYPE__;
using u8 = __UINT8_TYPE__;
using i64 = __INT64_TYPE__;
using i32 = __INT32_TYPE__;
using i16 = __INT16_TYPE__;
using i8 = __INT8_TYPE__;
using f32 = float;
static_assert(__FLT_MANT_DIG__ == 24 && __FLT_MAX_EXP__ == 128);
using f64 = double;
static_assert(__DBL_MANT_DIG__ == 53 && __DBL_MAX_EXP__ == 1024);
#if __LDBL_MANT_DIG__ == 64 && __LDBL_MAX__EXP__ == 16384
using f80 = long double;
#elif __LDBL_MANT_DIG__ == 113 && __LDBL_MAX_EXP__ == 16384
using f128 = long double;
#endif
using size_t = __SIZE_TYPE__;