10 #include <binaryen/wasm-binary.h> 11 #include <binaryen/wasm-interpreter.h> 25 case Error::EMPTY_STATE_CODE:
26 return "Provided state code is empty, calling a function is impossible";
27 case Error::INVALID_STATE_CODE:
28 return "Invalid state code, calling a function is impossible";
30 return "Unknown error";
35 ModuleImpl::ModuleImpl(
36 std::unique_ptr<wasm::Module> &&module,
37 std::shared_ptr<const InstanceEnvironmentFactory> env_factory,
39 : env_factory_{std::move(env_factory)},
42 BOOST_ASSERT(
module_ !=
nullptr);
47 const std::vector<uint8_t> &code,
48 std::shared_ptr<const InstanceEnvironmentFactory> env_factory,
57 auto module = std::make_unique<wasm::Module>();
59 wasm::WasmBinaryBuilder parser(
61 reinterpret_cast<std::vector<char>
const &
>(code),
66 }
catch (wasm::ParseException &e) {
67 std::ostringstream msg;
69 log->error(msg.str());
76 std::unique_ptr<ModuleImpl> wasm_module_impl(
77 new ModuleImpl(std::move(module), std::move(env_factory), code_hash));
78 return wasm_module_impl;
84 return std::make_shared<ModuleInstanceImpl>(
std::shared_ptr< wasm::Module > module_
ModuleImpl(ModuleImpl &&)=default
OUTCOME_CPP_DEFINE_CATEGORY(kagome::runtime::binaryen, ModuleImpl::Error, e)
static const wasm::Name env
outcome::result< std::shared_ptr< ModuleInstance > > instantiate() const override
std::shared_ptr< const InstanceEnvironmentFactory > env_factory_
static constexpr auto kDefaultHeappages
Logger createLogger(const std::string &tag)
const common::Hash256 code_hash_
static outcome::result< std::unique_ptr< ModuleImpl > > createFromCode(const std::vector< uint8_t > &code, std::shared_ptr< const InstanceEnvironmentFactory > env_factory_, const common::Hash256 &code_hash)