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

LibWasm: Add basic support for module instantiation and execution stubs

This adds very basic support for module instantiation/allocation, as
well as a stub for an interpreter (and executions APIs).
The 'wasm' utility is further expanded to instantiate, and attempt
executing the first non-imported function in the module.
Note that as the execution is a stub, the expected result is a zero.
Regardless, this will allow future commits to implement the JS
WebAssembly API. :^)
This commit is contained in:
Ali Mohammad Pur 2021-05-01 01:08:51 +04:30 committed by Linus Groh
parent 2b755f1fbf
commit 4d9246ac9d
8 changed files with 938 additions and 1 deletions

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWasm/AbstractMachine/AbstractMachine.h>
namespace Wasm {
typedef u64 (*HostFunctionType)(Store&, Vector<Value>&);
class Configuration {
public:
explicit Configuration(Store& store)
: m_store(store)
{
}
Optional<Label> nth_label(size_t);
void set_frame(NonnullOwnPtr<Frame> frame)
{
m_current_frame = frame.ptr();
m_stack.push(move(frame));
m_stack.push(make<Label>(m_current_frame->expression().instructions().size() - 1));
}
auto& frame() const { return m_current_frame; }
auto& frame() { return m_current_frame; }
auto& ip() const { return m_ip; }
auto& ip() { return m_ip; }
auto& depth() const { return m_depth; }
auto& depth() { return m_depth; }
auto& stack() const { return m_stack; }
auto& stack() { return m_stack; }
Result call(FunctionAddress, Vector<Value> arguments);
Result execute();
private:
Store& m_store;
Frame* m_current_frame { nullptr };
Stack m_stack;
size_t m_depth { 0 };
InstructionPointer m_ip;
};
}