diff options
author | Spartan322 <Megacake1234@gmail.com> | 2024-07-24 09:25:12 +0200 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2024-08-03 23:57:07 +0200 |
commit | 97668cd39c5056629e357037f64417686f522083 (patch) | |
tree | d0e1c20c3de1ef5748f41081c2e99b53e43a4f77 /src/openvic-simulation/vm/Module.hpp | |
parent | 972ed9d7921637d4ac290dae214942dbe9bc05c3 (diff) |
Add outline for some instructions
Diffstat (limited to 'src/openvic-simulation/vm/Module.hpp')
-rw-r--r-- | src/openvic-simulation/vm/Module.hpp | 49 |
1 files changed, 18 insertions, 31 deletions
diff --git a/src/openvic-simulation/vm/Module.hpp b/src/openvic-simulation/vm/Module.hpp index d8a7c6e..9483e26 100644 --- a/src/openvic-simulation/vm/Module.hpp +++ b/src/openvic-simulation/vm/Module.hpp @@ -6,6 +6,7 @@ #include <range/v3/view/enumerate.hpp> +#include "vm/Utility.hpp" #include <lauf/asm/module.h> #include <lauf/asm/program.h> #include <lauf/asm/type.h> @@ -14,34 +15,8 @@ namespace OpenVic::Vm { template<typename T> concept Arithmetic = std::is_arithmetic_v<T>; - struct Module { - Module(const char* module_name) : _handle(lauf_asm_create_module(module_name)) {} - - Module(Module&&) = default; - Module& operator=(Module&&) = default; - - Module(Module const&) = delete; - Module& operator=(Module const&) = delete; - - ~Module() { - lauf_asm_destroy_module(_handle); - } - - lauf_asm_module* handle() { - return _handle; - } - - const lauf_asm_module* handle() const { - return _handle; - } - - operator lauf_asm_module*() { - return _handle; - } - - operator const lauf_asm_module*() const { - return _handle; - } + struct ModuleRef : utility::HandleBase<lauf_asm_module> { + using HandleBase::HandleBase; const char* name() const { return lauf_asm_module_name(_handle); @@ -80,7 +55,7 @@ namespace OpenVic::Vm { define_data(global, { sizeof(T), alignof(T) }, static_cast<const void*>(data)); } - static std::unique_ptr<const lauf_asm_module* const[]> make_list(std::span<Module> mods) { + static std::unique_ptr<const lauf_asm_module* const[]> make_list(std::span<ModuleRef> mods) { auto result = new const lauf_asm_module*[mods.size()]; auto span = std::span<const lauf_asm_module*> { result, mods.size() }; for (auto [count, element] : span | ranges::views::enumerate) { @@ -88,8 +63,20 @@ namespace OpenVic::Vm { } return std::unique_ptr<const lauf_asm_module* const[]>(result); } + }; + + struct Module : utility::MoveOnlyHandleDerived<Module, ModuleRef> { + using MoveOnlyHandleDerived::MoveOnlyHandleDerived; + using MoveOnlyHandleDerived::operator=; - private: - lauf_asm_module* _handle; + Module(const char* module_name) : MoveOnlyHandleDerived(lauf_asm_create_module(module_name)) {} + + ~Module() { + if (_handle == nullptr) { + return; + } + lauf_asm_destroy_module(_handle); + _handle = nullptr; + } }; } |