6 #ifndef KAGOME_CORE_RUNTIME_WAVM_IMPL_INTRINSIC_MODULE_HPP 7 #define KAGOME_CORE_RUNTIME_WAVM_IMPL_INTRINSIC_MODULE_HPP 11 #include <boost/assert.hpp> 12 #include <unordered_map> 24 WAVM::IR::MemoryType intrinsic_memory_type)
28 &
module_, kIntrinsicMemoryName.data(), intrinsic_memory_type} {}
31 WAVM::IR::MemoryType intrinsic_memory_type)
35 &
module_, kIntrinsicMemoryName.data(), intrinsic_memory_type} {}
37 std::unique_ptr<IntrinsicModuleInstance>
instantiate()
const {
40 "Host API methods are not registered within IntrinsicModule! See " 41 "runtime/wavm/intrinsics/intrinsic_functions.hpp");
42 return std::make_unique<IntrinsicModuleInstance>(
43 WAVM::Intrinsics::instantiateModule(
compartment_->getCompartment(),
45 "Intrinsic Module Instance"),
50 template <
typename Ret,
typename... Args>
52 Ret (*f)(WAVM::Runtime::ContextRuntimeData *, Args...),
53 WAVM::IR::FunctionType type) {
54 auto inferred_type = WAVM::Intrinsics::inferIntrinsicFunctionType(f);
55 BOOST_ASSERT(type.results() == inferred_type.results());
56 BOOST_ASSERT(type.params() == inferred_type.params());
57 auto intrinsic = std::make_unique<WAVM::Intrinsics::Function>(
58 &
module_, name.data(), (
void *)f, inferred_type);
59 functions_.insert(std::pair{name, std::move(intrinsic)});
70 std::unordered_map<std::string, std::unique_ptr<WAVM::Intrinsics::Function>>
76 #endif // KAGOME_CORE_RUNTIME_WAVM_IMPL_INTRINSIC_MODULE_HPP std::unique_ptr< IntrinsicModuleInstance > instantiate() const
IntrinsicModule(IntrinsicModule &module, WAVM::IR::MemoryType intrinsic_memory_type)
IntrinsicModule(std::shared_ptr< CompartmentWrapper > compartment, WAVM::IR::MemoryType intrinsic_memory_type)
std::unordered_map< std::string, std::unique_ptr< WAVM::Intrinsics::Function > > functions_
void addFunction(std::string_view name, Ret(*f)(WAVM::Runtime::ContextRuntimeData *, Args...), WAVM::IR::FunctionType type)
std::shared_ptr< CompartmentWrapper > compartment_
WAVM::Intrinsics::Memory memory_
WAVM::Intrinsics::Module module_
WAVM::IR::MemoryType intrinsic_memory_type_
static constexpr std::string_view kIntrinsicMemoryName