From 537afa87c6a306fd4c57e242a0883258ad7de177 Mon Sep 17 00:00:00 2001 From: Nikita Ushakov Date: Sun, 29 Sep 2024 22:03:30 +0100 Subject: [PATCH] Update api --- CMakeLists.txt | 2 +- external/plugify | 2 +- src/module.cpp | 82 ++++++++++++++++++++++++------------------------ src/module.h | 6 ++-- 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8320b5f..d07d16c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ set(GOLM_PCH_FILE "src/pch.h") add_library(${PROJECT_NAME} SHARED ${GOLM_SOURCES}) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) -set(GOLM_LINK_LIBRARIES plugify::plugify plugify::plugify-function plugify::plugify-assembly plugify::plugify-assembly asmjit::asmjit dyncall_s) +set(GOLM_LINK_LIBRARIES plugify::plugify plugify::plugify-assembly asmjit::asmjit dyncall_s dyncallback_s) if(NOT COMPILER_SUPPORTS_FORMAT) set(GOLM_LINK_LIBRARIES ${GOLM_LINK_LIBRARIES} fmt::fmt-header-only) diff --git a/external/plugify b/external/plugify index e4563aa..7060a96 160000 --- a/external/plugify +++ b/external/plugify @@ -1 +1 @@ -Subproject commit e4563aa257f7ae51964e11d2d25745d4b022abfe +Subproject commit 7060a966335407af6d6b68640e4ce9fe2f202afe diff --git a/src/module.cpp b/src/module.cpp index c13f11b..cbf5f14 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -330,13 +330,13 @@ LoadResult GoLanguageModule::OnPluginLoad(PluginRef plugin) { if (IsMethodPrimitive(method)) { methods.emplace_back(method, func); } else { - auto function = std::make_unique(_rt); - func = function->GetJitFunc(method, &InternalCall, func); + JitCallback callback(_rt); + func = callback.GetJitFunc(method, &InternalCall, func); if (!func) { funcErrors.emplace_back(method.GetName()); continue; } - _functions.emplace_back(std::move(function)); + _functions.emplace_back(std::move(callback)); methods.emplace_back(method, func); } } else { @@ -402,7 +402,7 @@ void GoLanguageModule::GetNativeMethod(std::string_view methodName, plugify::Mem } // C++ to Go -void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parameters* p, uint8_t count, const ReturnValue* ret) { +void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const JitCallback::Parameters* p, uint8_t count, const JitCallback::Return* ret) { PropertyRef retProp = method.GetReturnType(); ValueType retType = retProp.GetType(); std::span paramProps = method.GetParamTypes(); @@ -699,116 +699,116 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame } case ValueType::Bool: { bool val = dcCallBool(vm, addr); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::Char8: { char16_t val = static_cast(dcCallChar(vm, addr)); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::Char16: { char16_t val = static_cast(dcCallShort(vm, addr)); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::Int8: { int8_t val = dcCallChar(vm, addr); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::Int16: { int16_t val = dcCallShort(vm, addr); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::Int32: { int32_t val = dcCallInt(vm, addr); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::Int64: { int64_t val = dcCallLongLong(vm, addr); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::UInt8: { uint8_t val = static_cast(dcCallChar(vm, addr)); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::UInt16: { uint16_t val = static_cast(dcCallShort(vm, addr)); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::UInt32: { uint32_t val = static_cast(dcCallInt(vm, addr)); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::UInt64: { uint64_t val = static_cast(dcCallLongLong(vm, addr)); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::Pointer: { void* val = dcCallPointer(vm, addr); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::Float: { float val = dcCallFloat(vm, addr); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::Double: { double val = dcCallDouble(vm, addr); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::Function: { void* val = dcCallPointer(vm, addr); - ret->SetReturnPtr(val); + ret->SetReturn(val); break; } case ValueType::Vector2: { Vector2 source; dcCallAggr(vm, addr, ag, &source); - ret->SetReturnPtr(source); + ret->SetReturn(source); break; } #if GOLM_PLATFORM_WINDOWS case ValueType::Vector3: { auto* dest = p->GetArgument(0); dcCallAggr(vm, addr, ag, dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::Vector4: { auto* dest = p->GetArgument(0); dcCallAggr(vm, addr, ag, dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } #else case ValueType::Vector3: { Vector3 source; dcCallAggr(vm, addr, ag, &source); - ret->SetReturnPtr(source); + ret->SetReturn(source); break; } case ValueType::Vector4: { Vector4 source; dcCallAggr(vm, addr, ag, &source); - ret->SetReturnPtr(source); + ret->SetReturn(source); break; } #endif case ValueType::Matrix4x4: { auto* dest = p->GetArgument(0); dcCallAggr(vm, addr, ag, dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::String: { @@ -816,7 +816,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoString source; dcCallAggr(vm, addr, ag, &source); CopyGoStringToStringReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayBool: { @@ -824,7 +824,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayChar8: { @@ -832,7 +832,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayChar16: { @@ -840,7 +840,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayInt8: { @@ -848,7 +848,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayInt16: { @@ -856,7 +856,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayInt32: { @@ -864,7 +864,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayInt64: { @@ -872,7 +872,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayUInt8: { @@ -880,7 +880,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayUInt16: { @@ -888,7 +888,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayUInt32: { @@ -896,7 +896,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayUInt64: { @@ -904,7 +904,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayPointer: { @@ -912,7 +912,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayFloat: { @@ -920,7 +920,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayDouble: { @@ -928,7 +928,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } case ValueType::ArrayString: { @@ -936,7 +936,7 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame GoSlice source; dcCallAggr(vm, addr, ag, &source); CopyGoSliceToVectorReturn(source, *dest); - ret->SetReturnPtr(dest); + ret->SetReturn(dest); break; } default: diff --git a/src/module.h b/src/module.h index ba61d93..1698218 100644 --- a/src/module.h +++ b/src/module.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include @@ -106,7 +106,7 @@ namespace golm { void GetNativeMethod(std::string_view methodName, plugify::MemAddr* addressDest); private: - static void InternalCall(plugify::MethodRef method, plugify::MemAddr data, const plugify::Parameters* params, uint8_t count, const plugify::ReturnValue* ret); + static void InternalCall(plugify::MethodRef method, plugify::MemAddr data, const plugify::JitCallback::Parameters* params, uint8_t count, const plugify::JitCallback::Return* ret); static void DetectLeaks(); private: @@ -116,7 +116,7 @@ namespace golm { std::map _assemblyMap; std::unordered_map> _nativesMap; - std::vector> _functions; + std::vector _functions; std::vector _addresses; static const std::array _pluginApi;