Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: wasmx/fizzy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 79890f2e6e9af5df728f47f442e6cbe1ca5c8e06
Choose a base ref
..
head repository: wasmx/fizzy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 62e3de7093aace8776247faf44eb28190c361b77
Choose a head ref
Showing with 17 additions and 9 deletions.
  1. +9 −5 lib/fizzy/instantiate.cpp
  2. +8 −4 lib/fizzy/instantiate.hpp
14 changes: 9 additions & 5 deletions lib/fizzy/instantiate.cpp
Original file line number Diff line number Diff line change
@@ -305,7 +305,8 @@ ExternalGlobal find_imported_global(const std::string& module, const std::string
return {it->value, module_global_type};
}

std::optional<uint32_t> find_export(const Module& module, ExternalKind kind, std::string_view name)
std::optional<uint32_t> find_export(
const Module& module, ExternalKind kind, std::string_view name) noexcept
{
const auto it = std::find_if(module.exportsec.begin(), module.exportsec.end(),
[kind, name](const auto& export_) { return export_.kind == kind && export_.name == name; });
@@ -488,12 +489,14 @@ std::vector<ExternalGlobal> resolve_imported_globals(
return external_globals;
}

std::optional<FuncIdx> find_exported_function_index(const Module& module, std::string_view name)
std::optional<FuncIdx> find_exported_function_index(
const Module& module, std::string_view name) noexcept
{
return find_export(module, ExternalKind::Function, name);
}

std::optional<ExternalFunction> find_exported_function(Instance& instance, std::string_view name)
std::optional<ExternalFunction> find_exported_function(
Instance& instance, std::string_view name) noexcept
{
const auto opt_index = find_export(*instance.module, ExternalKind::Function, name);
if (!opt_index.has_value())
@@ -504,7 +507,8 @@ std::optional<ExternalFunction> find_exported_function(Instance& instance, std::
ExecuteFunction(instance, idx), instance.module->get_function_type(idx)};
}

std::optional<ExternalGlobal> find_exported_global(Instance& instance, std::string_view name)
std::optional<ExternalGlobal> find_exported_global(
Instance& instance, std::string_view name) noexcept
{
const auto opt_index = find_export(*instance.module, ExternalKind::Global, name);
if (!opt_index.has_value())
@@ -526,7 +530,7 @@ std::optional<ExternalGlobal> find_exported_global(Instance& instance, std::stri
}
}

std::optional<ExternalTable> find_exported_table(Instance& instance, std::string_view name)
std::optional<ExternalTable> find_exported_table(Instance& instance, std::string_view name) noexcept
{
// Index returned from find_export is discarded, because there's no more than 1 table
if (!find_export(*instance.module, ExternalKind::Table, name))
12 changes: 8 additions & 4 deletions lib/fizzy/instantiate.hpp
Original file line number Diff line number Diff line change
@@ -236,16 +236,20 @@ std::vector<ExternalGlobal> resolve_imported_globals(
const Module& module, const std::vector<ImportedGlobal>& imported_globals);

/// Find exported function index by name.
std::optional<FuncIdx> find_exported_function_index(const Module& module, std::string_view name);
std::optional<FuncIdx> find_exported_function_index(
const Module& module, std::string_view name) noexcept;

/// Find exported function by name.
std::optional<ExternalFunction> find_exported_function(Instance& instance, std::string_view name);
std::optional<ExternalFunction> find_exported_function(
Instance& instance, std::string_view name) noexcept;

/// Find exported global by name.
std::optional<ExternalGlobal> find_exported_global(Instance& instance, std::string_view name);
std::optional<ExternalGlobal> find_exported_global(
Instance& instance, std::string_view name) noexcept;

/// Find exported table by name.
std::optional<ExternalTable> find_exported_table(Instance& instance, std::string_view name);
std::optional<ExternalTable> find_exported_table(
Instance& instance, std::string_view name) noexcept;

/// Find exported memory by name.
std::optional<ExternalMemory> find_exported_memory(