Kagome
Polkadot Runtime Engine in C++17
intrinsic_resolver_impl.cpp
Go to the documentation of this file.
1 
7 
8 #include <WAVM/Runtime/Intrinsics.h>
9 
10 #include "intrinsic_functions.hpp"
13 
14 namespace kagome::runtime::wavm {
15 
17  std::shared_ptr<IntrinsicModuleInstance> module_instance)
18  : module_instance_{std::move(module_instance)},
19  logger_{log::createLogger("IntrinsicResolver", "wavm")} {
20  BOOST_ASSERT(module_instance_ != nullptr);
21  }
22 
23  bool IntrinsicResolverImpl::resolve(const std::string &moduleName,
24  const std::string &exportName,
25  WAVM::IR::ExternType type,
26  WAVM::Runtime::Object *&outObject) {
27  BOOST_ASSERT(moduleName == "env");
28  if (exportName == "memory") {
29  if (type.kind == WAVM::IR::ExternKind::memory) {
30  outObject =
31  WAVM::Runtime::asObject(module_instance_->getExportedMemory());
32  return true;
33  }
34  return false;
35  }
36  if (type.kind == WAVM::IR::ExternKind::function) {
37  auto export_func = module_instance_->getExportedFunction(
38  exportName, asFunctionType(type));
39  if (export_func == nullptr) {
40  logger_->warn("Host function not implemented: {}", exportName);
41  return false;
42  }
43  outObject = WAVM::Runtime::asObject(export_func);
44  return true;
45  }
46  return false;
47  }
48 
49 } // namespace kagome::runtime::wavm
std::shared_ptr< IntrinsicModuleInstance > module_instance_
IntrinsicResolverImpl(std::shared_ptr< IntrinsicModuleInstance > module_instance)
bool resolve(const std::string &moduleName, const std::string &exportName, WAVM::IR::ExternType type, WAVM::Runtime::Object *&outObject) override
Logger createLogger(const std::string &tag)
Definition: logger.cpp:112