diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp index 34d53b1c54b..bb7315afd87 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp @@ -11,7 +11,7 @@ namespace Wasm { -Optional Store::allocate(ModuleInstance& module, const Module::Function& function) +Optional Store::allocate(ModuleInstance& module, Module::Function const& function) { FunctionAddress address { m_functions.size() }; if (function.type().value() > module.types().size()) @@ -29,7 +29,7 @@ Optional Store::allocate(HostFunction&& function) return address; } -Optional Store::allocate(const TableType& type) +Optional Store::allocate(TableType const& type) { TableAddress address { m_tables.size() }; Vector> elements; @@ -38,21 +38,21 @@ Optional Store::allocate(const TableType& type) return address; } -Optional Store::allocate(const MemoryType& type) +Optional Store::allocate(MemoryType const& type) { MemoryAddress address { m_memories.size() }; m_memories.empend(MemoryInstance { type }); return address; } -Optional Store::allocate(const GlobalType& type, Value value) +Optional Store::allocate(GlobalType const& type, Value value) { GlobalAddress address { m_globals.size() }; m_globals.append(GlobalInstance { move(value), type.is_mutable() }); return address; } -Optional Store::allocate(const ValueType& type, Vector references) +Optional Store::allocate(ValueType const& type, Vector references) { ElementAddress address { m_elements.size() }; m_elements.append(ElementInstance { type, move(references) }); @@ -99,13 +99,13 @@ ElementInstance* Store::get(ElementAddress address) return &m_elements[value]; } -InstantiationResult AbstractMachine::instantiate(const Module& module, Vector externs) +InstantiationResult AbstractMachine::instantiate(Module const& module, Vector externs) { auto main_module_instance_pointer = make(); auto& main_module_instance = *main_module_instance_pointer; Optional instantiation_result; - module.for_each_section_of_type([&](const TypeSection& section) { + module.for_each_section_of_type([&](TypeSection const& section) { main_module_instance.types() = section.types(); }); @@ -147,7 +147,7 @@ InstantiationResult AbstractMachine::instantiate(const Module& module, Vector([&](const ElementSection& section) { + module.for_each_section_of_type([&](ElementSection const& section) { for (auto& segment : section.segments()) { Vector references; for (auto& entry : segment.init) { @@ -190,7 +190,7 @@ InstantiationResult AbstractMachine::instantiate(const Module& module, Vector([&](const ElementSection& section) { + module.for_each_section_of_type([&](ElementSection const& section) { size_t index = 0; for (auto& segment : section.segments()) { auto current_index = index; @@ -256,10 +256,10 @@ InstantiationResult AbstractMachine::instantiate(const Module& module, Vector([&](const DataSection& data_section) { + module.for_each_section_of_type([&](DataSection const& data_section) { for (auto& segment : data_section.data()) { segment.value().visit( - [&](const DataSection::Data::Active& data) { + [&](DataSection::Data::Active const& data) { Configuration config { m_store }; config.set_frame(Frame { main_module_instance, @@ -274,8 +274,8 @@ InstantiationResult AbstractMachine::instantiate(const Module& module, Vectoris_error()) return; if (main_module_instance.memories().size() <= data.index.value()) { @@ -293,13 +293,13 @@ InstantiationResult AbstractMachine::instantiate(const Module& module, Vectordata().overwrite(offset, data.init.data(), data.init.size()); } }, - [&](const DataSection::Data::Passive&) { + [&](DataSection::Data::Passive const&) { // FIXME: What do we do here? }); } }); - module.for_each_section_of_type([&](const StartSection& section) { + module.for_each_section_of_type([&](StartSection const& section) { auto& functions = main_module_instance.functions(); auto index = section.function().index(); if (functions.size() <= index.value()) { @@ -315,16 +315,16 @@ InstantiationResult AbstractMachine::instantiate(const Module& module, Vector AbstractMachine::allocate_all_initial_phase(const Module& module, ModuleInstance& module_instance, Vector& externs, Vector& global_values) +Optional AbstractMachine::allocate_all_initial_phase(Module const& module, ModuleInstance& module_instance, Vector& externs, Vector& global_values) { Optional result; for (auto& entry : externs) { entry.visit( - [&](const FunctionAddress& address) { module_instance.functions().append(address); }, - [&](const TableAddress& address) { module_instance.tables().append(address); }, - [&](const MemoryAddress& address) { module_instance.memories().append(address); }, - [&](const GlobalAddress& address) { module_instance.globals().append(address); }); + [&](FunctionAddress const& address) { module_instance.functions().append(address); }, + [&](TableAddress const& address) { module_instance.tables().append(address); }, + [&](MemoryAddress const& address) { module_instance.memories().append(address); }, + [&](GlobalAddress const& address) { module_instance.globals().append(address); }); } // FIXME: What if this fails? @@ -335,7 +335,7 @@ Optional AbstractMachine::allocate_all_initial_phase(const M module_instance.functions().append(*address); } - module.for_each_section_of_type([&](const TableSection& section) { + module.for_each_section_of_type([&](TableSection const& section) { for (auto& table : section.tables()) { auto table_address = m_store.allocate(table.type()); VERIFY(table_address.has_value()); @@ -343,7 +343,7 @@ Optional AbstractMachine::allocate_all_initial_phase(const M } }); - module.for_each_section_of_type([&](const MemorySection& section) { + module.for_each_section_of_type([&](MemorySection const& section) { for (auto& memory : section.memories()) { auto memory_address = m_store.allocate(memory.type()); VERIFY(memory_address.has_value()); @@ -351,7 +351,7 @@ Optional AbstractMachine::allocate_all_initial_phase(const M } }); - module.for_each_section_of_type([&](const GlobalSection& section) { + module.for_each_section_of_type([&](GlobalSection const& section) { size_t index = 0; for (auto& entry : section.entries()) { auto address = m_store.allocate(entry.type(), move(global_values[index])); @@ -360,29 +360,29 @@ Optional AbstractMachine::allocate_all_initial_phase(const M index++; } }); - module.for_each_section_of_type([&](const ExportSection& section) { + module.for_each_section_of_type([&](ExportSection const& section) { for (auto& entry : section.entries()) { Variant address { Empty {} }; entry.description().visit( - [&](const FunctionIndex& index) { + [&](FunctionIndex const& index) { if (module_instance.functions().size() > index.value()) address = FunctionAddress { module_instance.functions()[index.value()] }; else dbgln("Failed to export '{}', the exported address ({}) was out of bounds (min: 0, max: {})", entry.name(), index.value(), module_instance.functions().size()); }, - [&](const TableIndex& index) { + [&](TableIndex const& index) { if (module_instance.tables().size() > index.value()) address = TableAddress { module_instance.tables()[index.value()] }; else dbgln("Failed to export '{}', the exported address ({}) was out of bounds (min: 0, max: {})", entry.name(), index.value(), module_instance.tables().size()); }, - [&](const MemoryIndex& index) { + [&](MemoryIndex const& index) { if (module_instance.memories().size() > index.value()) address = MemoryAddress { module_instance.memories()[index.value()] }; else dbgln("Failed to export '{}', the exported address ({}) was out of bounds (min: 0, max: {})", entry.name(), index.value(), module_instance.memories().size()); }, - [&](const GlobalIndex& index) { + [&](GlobalIndex const& index) { if (module_instance.globals().size() > index.value()) address = GlobalAddress { module_instance.globals()[index.value()] }; else @@ -404,9 +404,9 @@ Optional AbstractMachine::allocate_all_initial_phase(const M return result; } -Optional AbstractMachine::allocate_all_final_phase(const Module& module, ModuleInstance& module_instance, Vector>& elements) +Optional AbstractMachine::allocate_all_final_phase(Module const& module, ModuleInstance& module_instance, Vector>& elements) { - module.for_each_section_of_type([&](const ElementSection& section) { + module.for_each_section_of_type([&](ElementSection const& section) { size_t index = 0; for (auto& segment : section.segments()) { auto address = m_store.allocate(segment.type, move(elements[index])); @@ -431,7 +431,7 @@ Result AbstractMachine::invoke(Interpreter& interpreter, FunctionAddress address return configuration.call(interpreter, address, move(arguments)); } -void Linker::link(const ModuleInstance& instance) +void Linker::link(ModuleInstance const& instance) { populate(); if (m_unresolved_imports.is_empty()) @@ -450,7 +450,7 @@ void Linker::link(const ModuleInstance& instance) m_unresolved_imports.remove(entry); } -void Linker::link(const HashMap& exports) +void Linker::link(HashMap const& exports) { populate(); if (m_unresolved_imports.is_empty()) @@ -498,7 +498,7 @@ void Linker::populate() // There better be at most one import section! bool already_seen_an_import_section = false; - m_module.for_each_section_of_type([&](const ImportSection& section) { + m_module.for_each_section_of_type([&](ImportSection const& section) { if (already_seen_an_import_section) { if (!m_error.has_value()) m_error = LinkError {}; diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h index ee3edd66cdb..f5a04db05d3 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h @@ -130,7 +130,7 @@ public: } } - Value(const Value& value) + Value(Value const& value) : m_value(AnyValueType { value.m_value }) , m_type(value.m_type) { @@ -149,7 +149,7 @@ public: return *this; } - Value& operator=(const Value& value) + Value& operator=(Value const& value) { m_value = value.m_value; m_type = value.m_type; @@ -167,7 +167,7 @@ public: else if constexpr (!IsFloatingPoint && IsSame>) result = value; }, - [&](const Reference& value) { + [&](Reference const& value) { if constexpr (IsSame) { result = value; } else if constexpr (IsSame) { @@ -279,7 +279,7 @@ private: class WasmFunction { public: - explicit WasmFunction(const FunctionType& type, const ModuleInstance& module, const Module::Function& code) + explicit WasmFunction(FunctionType const& type, ModuleInstance const& module, Module::Function const& code) : m_type(type) , m_module(module) , m_code(code) @@ -292,13 +292,13 @@ public: private: FunctionType m_type; - const ModuleInstance& m_module; - const Module::Function& m_code; + ModuleInstance const& m_module; + Module::Function const& m_code; }; class HostFunction { public: - explicit HostFunction(AK::Function&)> function, const FunctionType& type) + explicit HostFunction(AK::Function&)> function, FunctionType const& type) : m_function(move(function)) , m_type(type) { @@ -316,7 +316,7 @@ using FunctionInstance = Variant; class TableInstance { public: - explicit TableInstance(const TableType& type, Vector> elements) + explicit TableInstance(TableType const& type, Vector> elements) : m_elements(move(elements)) , m_type(type) { @@ -328,12 +328,12 @@ public: private: Vector> m_elements; - const TableType& m_type; + TableType const& m_type; }; class MemoryInstance { public: - explicit MemoryInstance(const MemoryType& type) + explicit MemoryInstance(MemoryType const& type) : m_type(type) { grow(m_type.limits().min() * Constants::page_size); @@ -360,7 +360,7 @@ public: } private: - const MemoryType& m_type; + MemoryType const& m_type; size_t m_size { 0 }; ByteBuffer m_data; }; @@ -406,12 +406,12 @@ class Store { public: Store() = default; - Optional allocate(ModuleInstance& module, const Module::Function& function); + Optional allocate(ModuleInstance& module, Module::Function const& function); Optional allocate(HostFunction&&); - Optional allocate(const TableType&); - Optional allocate(const MemoryType&); - Optional allocate(const GlobalType&, Value); - Optional allocate(const ValueType&, Vector); + Optional allocate(TableType const&); + Optional allocate(MemoryType const&); + Optional allocate(GlobalType const&, Value); + Optional allocate(ValueType const&, Vector); FunctionInstance* get(FunctionAddress); TableInstance* get(TableAddress); @@ -445,7 +445,7 @@ private: class Frame { public: - explicit Frame(const ModuleInstance& module, Vector locals, const Expression& expression, size_t arity) + explicit Frame(ModuleInstance const& module, Vector locals, Expression const& expression, size_t arity) : m_module(module) , m_locals(move(locals)) , m_expression(expression) @@ -460,9 +460,9 @@ public: auto arity() const { return m_arity; } private: - const ModuleInstance& m_module; + ModuleInstance const& m_module; Vector m_locals; - const Expression& m_expression; + Expression const& m_expression; size_t m_arity { 0 }; }; @@ -492,7 +492,7 @@ public: explicit AbstractMachine() = default; // Load and instantiate a module, and link it into this interpreter. - InstantiationResult instantiate(const Module&, Vector); + InstantiationResult instantiate(Module const&, Vector); Result invoke(FunctionAddress, Vector); Result invoke(Interpreter&, FunctionAddress, Vector); @@ -500,8 +500,8 @@ public: auto& store() { return m_store; } private: - Optional allocate_all_initial_phase(const Module&, ModuleInstance&, Vector&, Vector& global_values); - Optional allocate_all_final_phase(const Module&, ModuleInstance&, Vector>& elements); + Optional allocate_all_initial_phase(Module const&, ModuleInstance&, Vector&, Vector& global_values); + Optional allocate_all_final_phase(Module const&, ModuleInstance&, Vector>& elements); Store m_store; }; @@ -513,16 +513,16 @@ public: ImportSection::Import::ImportDesc type; }; - explicit Linker(const Module& module) + explicit Linker(Module const& module) : m_module(module) { } // Link a module, the import 'module name' is ignored with this. - void link(const ModuleInstance&); + void link(ModuleInstance const&); // Link a bunch of qualified values, also matches 'module name'. - void link(const HashMap&); + void link(HashMap const&); auto& unresolved_imports() { @@ -535,7 +535,7 @@ public: private: void populate(); - const Module& m_module; + Module const& m_module; HashMap m_resolved_imports; HashTable m_unresolved_imports; Vector m_ordered_imports; @@ -547,6 +547,6 @@ private: template<> struct AK::Traits : public AK::GenericTraits { static constexpr bool is_trivial() { return false; } - static unsigned hash(const Wasm::Linker::Name& entry) { return pair_int_hash(entry.module.hash(), entry.name.hash()); } - static bool equals(const Wasm::Linker::Name& a, const Wasm::Linker::Name& b) { return a.name == b.name && a.module == b.module; } + static unsigned hash(Wasm::Linker::Name const& entry) { return pair_int_hash(entry.module.hash(), entry.name.hash()); } + static bool equals(Wasm::Linker::Name const& a, Wasm::Linker::Name const& b) { return a.name == b.name && a.module == b.module; } }; diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp b/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp index 9823f2093e8..8e93ca5af0e 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp @@ -23,7 +23,7 @@ Optional