Skip to content

src/runtime/binaryen/runtime_external_interface.hpp

Namespaces

Name
sgns
sgns::runtime
sgns::runtime::binaryen

Classes

Name
class sgns::runtime::binaryen::RuntimeExternalInterface

Source code

#ifndef SUPERGENIUS_SRC_RUNTIME_BINARYEN_RUNTIME_EXTERNAL_INTERFACE_HPP
#define SUPERGENIUS_SRC_RUNTIME_BINARYEN_RUNTIME_EXTERNAL_INTERFACE_HPP

#include <binaryen/shell-interface.h>

#include "base/logger.hpp"
#include "extensions/extension_factory.hpp"
#include "runtime/wasm_memory.hpp"
#include "runtime/trie_storage_provider.hpp"

namespace sgns::runtime::binaryen {

  class RuntimeExternalInterface : public wasm::ShellExternalInterface {
   public:
    explicit RuntimeExternalInterface(
        const std::shared_ptr<extensions::ExtensionFactory>& extension_factory,
        std::shared_ptr<TrieStorageProvider> storage_provider);

    wasm::Literal callImport(wasm::Function *import,
                             wasm::LiteralList &arguments) override;

    inline std::shared_ptr<WasmMemory> memory() const {
      return extension_->memory();
    }

   private:
    void checkArguments(std::string_view extern_name,
                        size_t expected,
                        size_t actual);

    std::unique_ptr<extensions::Extension> extension_;
    base::Logger logger_ = base::createLogger(kDefaultLoggerTag);

    constexpr static auto kDefaultLoggerTag = "Runtime external interface";
  };

}  // namespace sgns::runtime::binaryen

#endif  // SUPERGENIUS_SRC_RUNTIME_BINARYEN_RUNTIME_EXTERNAL_INTERFACE_HPP

Updated on 2026-03-04 at 13:10:45 -0800