mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00
LibWasm: Let the interpreter itself manage the call frame
This commit is contained in:
parent
85794f8244
commit
477ab6dc4c
3 changed files with 18 additions and 2 deletions
|
@ -128,7 +128,7 @@ void BytecodeInterpreter::call_address(Configuration& configuration, FunctionAdd
|
||||||
|
|
||||||
Result result { Trap {} };
|
Result result { Trap {} };
|
||||||
{
|
{
|
||||||
Configuration::CallFrameHandle handle { configuration };
|
CallFrameHandle handle { *this, configuration };
|
||||||
result = configuration.call(*this, address, move(args));
|
result = configuration.call(*this, address, move(args));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,7 +437,10 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
|
||||||
for (size_t i = 0; i < frame.arity(); ++i)
|
for (size_t i = 0; i < frame.arity(); ++i)
|
||||||
results.prepend(configuration.stack().pop());
|
results.prepend(configuration.stack().pop());
|
||||||
// drop all locals
|
// drop all locals
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||||
Optional<Label> last_label;
|
Optional<Label> last_label;
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
for (; !configuration.stack().is_empty();) {
|
for (; !configuration.stack().is_empty();) {
|
||||||
auto entry = configuration.stack().pop();
|
auto entry = configuration.stack().pop();
|
||||||
if (entry.has<Label>()) {
|
if (entry.has<Label>()) {
|
||||||
|
|
|
@ -23,6 +23,19 @@ struct BytecodeInterpreter : public Interpreter {
|
||||||
virtual bool did_trap() const override { return m_do_trap; }
|
virtual bool did_trap() const override { return m_do_trap; }
|
||||||
virtual void clear_trap() override { m_do_trap = false; }
|
virtual void clear_trap() override { m_do_trap = false; }
|
||||||
|
|
||||||
|
struct CallFrameHandle {
|
||||||
|
explicit CallFrameHandle(BytecodeInterpreter& interpreter, Configuration& configuration)
|
||||||
|
: m_configuration_handle(configuration)
|
||||||
|
, m_interpreter(interpreter)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~CallFrameHandle() = default;
|
||||||
|
|
||||||
|
Configuration::CallFrameHandle m_configuration_handle;
|
||||||
|
BytecodeInterpreter& m_interpreter;
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void interpret(Configuration&, InstructionPointer&, const Instruction&);
|
virtual void interpret(Configuration&, InstructionPointer&, const Instruction&);
|
||||||
void branch_to_label(Configuration&, LabelIndex);
|
void branch_to_label(Configuration&, LabelIndex);
|
||||||
|
|
|
@ -193,7 +193,7 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi
|
||||||
|
|
||||||
Wasm::Result result { Wasm::Trap {} };
|
Wasm::Result result { Wasm::Trap {} };
|
||||||
{
|
{
|
||||||
Wasm::Configuration::CallFrameHandle handle { config };
|
Wasm::BytecodeInterpreter::CallFrameHandle handle { g_interpreter, config };
|
||||||
result = config.call(g_interpreter, *address, move(values));
|
result = config.call(g_interpreter, *address, move(values));
|
||||||
}
|
}
|
||||||
if (result.is_trap())
|
if (result.is_trap())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue