Kagome
Polkadot Runtime Engine in C++17
runtime_external_interface.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_RUNTIME_BINARYEN_RUNTIME_EXTERNAL_INTERFACE_HPP
7 #define KAGOME_CORE_RUNTIME_BINARYEN_RUNTIME_EXTERNAL_INTERFACE_HPP
8 
9 #include <binaryen/shell-interface.h>
10 
11 #include <boost/unordered_map.hpp>
12 
13 #include "log/logger.hpp"
14 
15 namespace kagome::host_api {
16  class HostApiFactory;
17  class HostApi;
18 } // namespace kagome::host_api
19 
20 namespace kagome::runtime {
21  class TrieStorageProvider;
22  class Memory;
23  class ExecutorFactory;
24 
25 } // namespace kagome::runtime
26 
27 namespace wasm {
28  class Function;
29 }
30 
31 namespace kagome::runtime::binaryen {
32 
33  class RuntimeExternalInterface : public wasm::ShellExternalInterface {
34  public:
35  explicit RuntimeExternalInterface(
36  std::shared_ptr<host_api::HostApi> host_api);
37 
38  wasm::Literal callImport(wasm::Function *import,
39  wasm::LiteralList &arguments) override;
40 
41  wasm::ShellExternalInterface::Memory *getMemory();
42 
43  void trap(const char *why) override {
44  logger_->error("Trap: {}", why);
45  throw wasm::TrapException{};
46  }
47 
48  private:
53  void checkArguments(std::string_view extern_name,
54  size_t expected,
55  size_t actual);
56 
57  void methodsRegistration();
58 
59  template <auto mf>
60  static wasm::Literal importCall(RuntimeExternalInterface &this_,
61  wasm::Function *import,
62  wasm::LiteralList &arguments);
63 
64  std::shared_ptr<host_api::HostApi> host_api_;
65 
66  using ImportFuncPtr = wasm::Literal (*)(RuntimeExternalInterface &this_,
67  wasm::Function *import,
68  wasm::LiteralList &arguments);
69 
70  boost::unordered_map<std::string, ImportFuncPtr> imports_;
72  };
73 
74 } // namespace kagome::runtime::binaryen
75 
76 #endif // KAGOME_CORE_RUNTIME_BINARYEN_RUNTIME_EXTERNAL_INTERFACE_HPP
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
wasm::Literal(*)(RuntimeExternalInterface &this_, wasm::Function *import, wasm::LiteralList &arguments) ImportFuncPtr
boost::unordered_map< std::string, ImportFuncPtr > imports_