1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:17:44 +00:00

LibWasm+wasm: Switch to east-const to comply with project style

Against my better judgement, this change is mandated by the project code
style rules, even if it's not actually enforced.
This commit is contained in:
Ali Mohammad Pur 2021-06-04 03:42:11 +04:30 committed by Ali Mohammad Pur
parent 23fd8bfd69
commit 1b083392fa
11 changed files with 209 additions and 209 deletions

View file

@ -11,7 +11,7 @@
namespace Wasm {
Optional<FunctionAddress> Store::allocate(ModuleInstance& module, const Module::Function& function)
Optional<FunctionAddress> 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<FunctionAddress> Store::allocate(HostFunction&& function)
return address;
}
Optional<TableAddress> Store::allocate(const TableType& type)
Optional<TableAddress> Store::allocate(TableType const& type)
{
TableAddress address { m_tables.size() };
Vector<Optional<Reference>> elements;
@ -38,21 +38,21 @@ Optional<TableAddress> Store::allocate(const TableType& type)
return address;
}
Optional<MemoryAddress> Store::allocate(const MemoryType& type)
Optional<MemoryAddress> Store::allocate(MemoryType const& type)
{
MemoryAddress address { m_memories.size() };
m_memories.empend(MemoryInstance { type });
return address;
}
Optional<GlobalAddress> Store::allocate(const GlobalType& type, Value value)
Optional<GlobalAddress> Store::allocate(GlobalType const& type, Value value)
{
GlobalAddress address { m_globals.size() };
m_globals.append(GlobalInstance { move(value), type.is_mutable() });
return address;
}
Optional<ElementAddress> Store::allocate(const ValueType& type, Vector<Reference> references)
Optional<ElementAddress> Store::allocate(ValueType const& type, Vector<Reference> 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<ExternValue> externs)
InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<ExternValue> externs)
{
auto main_module_instance_pointer = make<ModuleInstance>();
auto& main_module_instance = *main_module_instance_pointer;
Optional<InstantiationResult> instantiation_result;
module.for_each_section_of_type<TypeSection>([&](const TypeSection& section) {
module.for_each_section_of_type<TypeSection>([&](TypeSection const& section) {
main_module_instance.types() = section.types();
});
@ -147,7 +147,7 @@ InstantiationResult AbstractMachine::instantiate(const Module& module, Vector<Ex
if (auto result = allocate_all_initial_phase(module, main_module_instance, externs, global_values); result.has_value())
return result.release_value();
module.for_each_section_of_type<ElementSection>([&](const ElementSection& section) {
module.for_each_section_of_type<ElementSection>([&](ElementSection const& section) {
for (auto& segment : section.segments()) {
Vector<Reference> references;
for (auto& entry : segment.init) {
@ -190,7 +190,7 @@ InstantiationResult AbstractMachine::instantiate(const Module& module, Vector<Ex
if (auto result = allocate_all_final_phase(module, main_module_instance, elements); result.has_value())
return result.release_value();
module.for_each_section_of_type<ElementSection>([&](const ElementSection& section) {
module.for_each_section_of_type<ElementSection>([&](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<Ex
if (instantiation_result.has_value())
return instantiation_result.release_value();
module.for_each_section_of_type<DataSection>([&](const DataSection& data_section) {
module.for_each_section_of_type<DataSection>([&](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, Vector<Ex
}
size_t offset = 0;
result.values().first().value().visit(
[&](const auto& value) { offset = value; },
[&](const Reference&) { instantiation_result = InstantiationError { "Data segment offset returned a reference" }; });
[&](auto const& value) { offset = value; },
[&](Reference const&) { instantiation_result = InstantiationError { "Data segment offset returned a reference" }; });
if (instantiation_result.has_value() && instantiation_result->is_error())
return;
if (main_module_instance.memories().size() <= data.index.value()) {
@ -293,13 +293,13 @@ InstantiationResult AbstractMachine::instantiate(const Module& module, Vector<Ex
instance->data().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<StartSection>([&](const StartSection& section) {
module.for_each_section_of_type<StartSection>([&](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<Ex
return InstantiationResult { move(main_module_instance_pointer) };
}
Optional<InstantiationError> AbstractMachine::allocate_all_initial_phase(const Module& module, ModuleInstance& module_instance, Vector<ExternValue>& externs, Vector<Value>& global_values)
Optional<InstantiationError> AbstractMachine::allocate_all_initial_phase(Module const& module, ModuleInstance& module_instance, Vector<ExternValue>& externs, Vector<Value>& global_values)
{
Optional<InstantiationError> 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<InstantiationError> AbstractMachine::allocate_all_initial_phase(const M
module_instance.functions().append(*address);
}
module.for_each_section_of_type<TableSection>([&](const TableSection& section) {
module.for_each_section_of_type<TableSection>([&](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<InstantiationError> AbstractMachine::allocate_all_initial_phase(const M
}
});
module.for_each_section_of_type<MemorySection>([&](const MemorySection& section) {
module.for_each_section_of_type<MemorySection>([&](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<InstantiationError> AbstractMachine::allocate_all_initial_phase(const M
}
});
module.for_each_section_of_type<GlobalSection>([&](const GlobalSection& section) {
module.for_each_section_of_type<GlobalSection>([&](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<InstantiationError> AbstractMachine::allocate_all_initial_phase(const M
index++;
}
});
module.for_each_section_of_type<ExportSection>([&](const ExportSection& section) {
module.for_each_section_of_type<ExportSection>([&](ExportSection const& section) {
for (auto& entry : section.entries()) {
Variant<FunctionAddress, TableAddress, MemoryAddress, GlobalAddress, Empty> 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<InstantiationError> AbstractMachine::allocate_all_initial_phase(const M
return result;
}
Optional<InstantiationError> AbstractMachine::allocate_all_final_phase(const Module& module, ModuleInstance& module_instance, Vector<Vector<Reference>>& elements)
Optional<InstantiationError> AbstractMachine::allocate_all_final_phase(Module const& module, ModuleInstance& module_instance, Vector<Vector<Reference>>& elements)
{
module.for_each_section_of_type<ElementSection>([&](const ElementSection& section) {
module.for_each_section_of_type<ElementSection>([&](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<Linker::Name, ExternValue>& exports)
void Linker::link(HashMap<Linker::Name, ExternValue> 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<ImportSection>([&](const ImportSection& section) {
m_module.for_each_section_of_type<ImportSection>([&](ImportSection const& section) {
if (already_seen_an_import_section) {
if (!m_error.has_value())
m_error = LinkError {};

View file

@ -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<T> && IsSame<decltype(value), MakeSigned<T>>)
result = value;
},
[&](const Reference& value) {
[&](Reference const& value) {
if constexpr (IsSame<T, Reference>) {
result = value;
} else if constexpr (IsSame<T, Reference::Func>) {
@ -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<Result(Configuration&, Vector<Value>&)> function, const FunctionType& type)
explicit HostFunction(AK::Function<Result(Configuration&, Vector<Value>&)> function, FunctionType const& type)
: m_function(move(function))
, m_type(type)
{
@ -316,7 +316,7 @@ using FunctionInstance = Variant<WasmFunction, HostFunction>;
class TableInstance {
public:
explicit TableInstance(const TableType& type, Vector<Optional<Reference>> elements)
explicit TableInstance(TableType const& type, Vector<Optional<Reference>> elements)
: m_elements(move(elements))
, m_type(type)
{
@ -328,12 +328,12 @@ public:
private:
Vector<Optional<Reference>> 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<FunctionAddress> allocate(ModuleInstance& module, const Module::Function& function);
Optional<FunctionAddress> allocate(ModuleInstance& module, Module::Function const& function);
Optional<FunctionAddress> allocate(HostFunction&&);
Optional<TableAddress> allocate(const TableType&);
Optional<MemoryAddress> allocate(const MemoryType&);
Optional<GlobalAddress> allocate(const GlobalType&, Value);
Optional<ElementAddress> allocate(const ValueType&, Vector<Reference>);
Optional<TableAddress> allocate(TableType const&);
Optional<MemoryAddress> allocate(MemoryType const&);
Optional<GlobalAddress> allocate(GlobalType const&, Value);
Optional<ElementAddress> allocate(ValueType const&, Vector<Reference>);
FunctionInstance* get(FunctionAddress);
TableInstance* get(TableAddress);
@ -445,7 +445,7 @@ private:
class Frame {
public:
explicit Frame(const ModuleInstance& module, Vector<Value> locals, const Expression& expression, size_t arity)
explicit Frame(ModuleInstance const& module, Vector<Value> 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<Value> 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<ExternValue>);
InstantiationResult instantiate(Module const&, Vector<ExternValue>);
Result invoke(FunctionAddress, Vector<Value>);
Result invoke(Interpreter&, FunctionAddress, Vector<Value>);
@ -500,8 +500,8 @@ public:
auto& store() { return m_store; }
private:
Optional<InstantiationError> allocate_all_initial_phase(const Module&, ModuleInstance&, Vector<ExternValue>&, Vector<Value>& global_values);
Optional<InstantiationError> allocate_all_final_phase(const Module&, ModuleInstance&, Vector<Vector<Reference>>& elements);
Optional<InstantiationError> allocate_all_initial_phase(Module const&, ModuleInstance&, Vector<ExternValue>&, Vector<Value>& global_values);
Optional<InstantiationError> allocate_all_final_phase(Module const&, ModuleInstance&, Vector<Vector<Reference>>& 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<Name, ExternValue>&);
void link(HashMap<Name, ExternValue> const&);
auto& unresolved_imports()
{
@ -535,7 +535,7 @@ public:
private:
void populate();
const Module& m_module;
Module const& m_module;
HashMap<Name, ExternValue> m_resolved_imports;
HashTable<Name> m_unresolved_imports;
Vector<Name> m_ordered_imports;
@ -547,6 +547,6 @@ private:
template<>
struct AK::Traits<Wasm::Linker::Name> : public AK::GenericTraits<Wasm::Linker::Name> {
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; }
};

View file

@ -23,7 +23,7 @@ Optional<Label> Configuration::nth_label(size_t i)
return {};
}
void Configuration::unwind(Badge<CallFrameHandle>, const CallFrameHandle& frame_handle)
void Configuration::unwind(Badge<CallFrameHandle>, CallFrameHandle const& frame_handle)
{
if (m_stack.size() == frame_handle.stack_size && frame_handle.frame_index == m_current_frame_index)
return;
@ -92,18 +92,18 @@ void Configuration::dump_stack()
Printer { memory_stream }.print(vs...);
dbgln(format.view(), StringView(memory_stream.copy_into_contiguous_buffer()).trim_whitespace());
};
for (const auto& entry : stack().entries()) {
for (auto const& entry : stack().entries()) {
entry.visit(
[&](const Value& v) {
[&](Value const& v) {
print_value(" {}", v);
},
[&](const Frame& f) {
[&](Frame const& f) {
dbgln(" frame({})", f.arity());
for (auto& local : f.locals()) {
print_value(" {}", local);
}
},
[](const Label& l) {
[](Label const& l) {
dbgln(" label({}) -> {}", l.arity(), l.continuation());
});
}

View file

@ -57,7 +57,7 @@ public:
Configuration& configuration;
};
void unwind(Badge<CallFrameHandle>, const CallFrameHandle&);
void unwind(Badge<CallFrameHandle>, CallFrameHandle const&);
Result call(Interpreter&, FunctionAddress, Vector<Value> arguments);
Result execute(Interpreter&);

View file

@ -73,7 +73,7 @@ void BytecodeInterpreter::branch_to_label(Configuration& configuration, LabelInd
}
template<typename ReadType, typename PushType>
void BytecodeInterpreter::load_and_push(Configuration& configuration, const Instruction& instruction)
void BytecodeInterpreter::load_and_push(Configuration& configuration, Instruction const& instruction)
{
auto& address = configuration.frame().module().memories().first();
auto memory = configuration.store().get(address);
@ -98,7 +98,7 @@ void BytecodeInterpreter::load_and_push(Configuration& configuration, const Inst
configuration.stack().peek() = Value(static_cast<PushType>(read_value<ReadType>(slice)));
}
void BytecodeInterpreter::store_to_memory(Configuration& configuration, const Instruction& instruction, ReadonlyBytes data)
void BytecodeInterpreter::store_to_memory(Configuration& configuration, Instruction const& instruction, ReadonlyBytes data)
{
auto& address = configuration.frame().module().memories().first();
auto memory = configuration.store().get(address);
@ -120,8 +120,8 @@ void BytecodeInterpreter::call_address(Configuration& configuration, FunctionAdd
{
auto instance = configuration.store().get(address);
TRAP_IF_NOT(instance);
const FunctionType* type { nullptr };
instance->visit([&](const auto& function) { type = &function.type(); });
FunctionType const* type { nullptr };
instance->visit([&](auto const& function) { type = &function.type(); });
TRAP_IF_NOT(type);
TRAP_IF_NOT(configuration.stack().entries().size() > type->parameters().size());
Vector<Value> args;
@ -396,7 +396,7 @@ ALWAYS_INLINE static i32 ctz(T value)
VERIFY_NOT_REACHED();
}
void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPointer& ip, const Instruction& instruction)
void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPointer& ip, Instruction const& instruction)
{
dbgln_if(WASM_TRACE_DEBUG, "Executing instruction {} at ip {}", instruction_name(instruction.opcode()), ip.value());
@ -973,7 +973,7 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
}
}
void DebuggerBytecodeInterpreter::interpret(Configuration& configuration, InstructionPointer& ip, const Instruction& instruction)
void DebuggerBytecodeInterpreter::interpret(Configuration& configuration, InstructionPointer& ip, Instruction const& instruction)
{
if (pre_interpret_hook) {
auto result = pre_interpret_hook(configuration, ip, instruction);

View file

@ -37,11 +37,11 @@ struct BytecodeInterpreter : public Interpreter {
};
protected:
virtual void interpret(Configuration&, InstructionPointer&, const Instruction&);
virtual void interpret(Configuration&, InstructionPointer&, Instruction const&);
void branch_to_label(Configuration&, LabelIndex);
template<typename ReadT, typename PushT>
void load_and_push(Configuration&, const Instruction&);
void store_to_memory(Configuration&, const Instruction&, ReadonlyBytes data);
void load_and_push(Configuration&, Instruction const&);
void store_to_memory(Configuration&, Instruction const&, ReadonlyBytes data);
void call_address(Configuration&, FunctionAddress);
template<typename V, typename T>
@ -66,11 +66,11 @@ protected:
struct DebuggerBytecodeInterpreter : public BytecodeInterpreter {
virtual ~DebuggerBytecodeInterpreter() override = default;
Function<bool(Configuration&, InstructionPointer&, const Instruction&)> pre_interpret_hook;
Function<bool(Configuration&, InstructionPointer&, const Instruction&, const Interpreter&)> post_interpret_hook;
Function<bool(Configuration&, InstructionPointer&, Instruction const&)> pre_interpret_hook;
Function<bool(Configuration&, InstructionPointer&, Instruction const&, Interpreter const&)> post_interpret_hook;
private:
virtual void interpret(Configuration&, InstructionPointer&, const Instruction&) override;
virtual void interpret(Configuration&, InstructionPointer&, Instruction const&) override;
};
}