//===---- CallSPSViaEPC.h - EPCCalls using SPS serialization ----*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // EPCCalls using SimplePackedSerialization. // //===----------------------------------------------------------------------===// #ifndef LLVM_EXECUTIONENGINE_ORC_CALLSPSVIAEPC_H #define LLVM_EXECUTIONENGINE_ORC_CALLSPSVIAEPC_H #include "llvm/ExecutionEngine/Orc/CallViaEPC.h" #include "llvm/ExecutionEngine/Orc/CallableTraitsHelper.h" #include "llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h" namespace llvm::orc { namespace detail { template struct SPSCallSerializationImpl { using RetSerialization = shared::SPSArgList; using ArgSerialization = shared::SPSArgList; template Expected serialize(ArgTs &&...Args) { auto Buffer = shared::WrapperFunctionBuffer::allocate( ArgSerialization::size(Args...)); shared::SPSOutputBuffer OB(Buffer.data(), Buffer.size()); if (!ArgSerialization::serialize(OB, Args...)) return make_error("Could not serialize arguments", inconvertibleErrorCode()); return std::move(Buffer); } }; template struct SPSCallSerialization : public CallableTraitsHelper {}; } // namespace detail /// SPS serialization for non-void calls. template struct SPSCallSerializer : public detail::SPSCallSerialization { template Expected deserialize(shared::WrapperFunctionBuffer ResultBytes) { using RetDeserialization = typename detail::SPSCallSerialization::RetSerialization; shared::SPSInputBuffer IB(ResultBytes.data(), ResultBytes.size()); RetT ReturnValue; if (!RetDeserialization::deserialize(IB, ReturnValue)) return make_error("Could not deserialize return value", inconvertibleErrorCode()); return ReturnValue; } }; /// SPS serialization for void calls. template struct SPSCallSerializer : public detail::SPSCallSerialization { template std::enable_if_t, Error> deserialize(shared::WrapperFunctionBuffer ResultBytes) { if (!ResultBytes.empty()) return make_error("Could not deserialize return value", inconvertibleErrorCode()); return Error::success(); } }; template class SPSEPCCaller : public EPCCaller> { public: SPSEPCCaller(ExecutorProcessControl &EPC) : EPCCaller>(EPC, SPSCallSerializer()) { } }; template class SPSEPCCall : public EPCCall> { public: SPSEPCCall(ExecutorProcessControl &EPC, ExecutorSymbolDef Fn) : EPCCall>(EPC, SPSCallSerializer(), std::move(Fn)) {} }; } // namespace llvm::orc #endif // LLVM_EXECUTIONENGINE_ORC_CALLSPSVIAEPC_H