mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:07:34 +00:00
LibWasm: Start implementing a naive bytecode interpreter
As the parser now flattens out the instructions and inserts synthetic nesting/structured instructions where needed, we can treat the whole thing as a simple parsed bytecode stream. This currently knows how to execute the following instructions: - unreachable - nop - local.get - local.set - {i,f}{32,64}.const - block - loop - if/else - branch / branch_if - i32_add - i32_and/or/xor - i32_ne This also extends the 'wasm' utility to optionally execute the first function in the module with optionally user-supplied arguments.
This commit is contained in:
parent
faa34a0a8b
commit
056be42c0b
10 changed files with 513 additions and 30 deletions
|
@ -74,4 +74,33 @@ Result Configuration::execute()
|
|||
return Result { move(results_moved) };
|
||||
}
|
||||
|
||||
void Configuration::dump_stack()
|
||||
{
|
||||
for (const auto& entry : stack().entries()) {
|
||||
entry.visit(
|
||||
[](const NonnullOwnPtr<Value>& v) {
|
||||
v->value().visit([]<typename T>(const T& v) {
|
||||
if constexpr (IsIntegral<T> || IsFloatingPoint<T>)
|
||||
dbgln(" {}", v);
|
||||
else
|
||||
dbgln(" *{}", v.value());
|
||||
});
|
||||
},
|
||||
[](const NonnullOwnPtr<Frame>& f) {
|
||||
dbgln(" frame({})", f->arity());
|
||||
for (auto& local : f->locals()) {
|
||||
local.value().visit([]<typename T>(const T& v) {
|
||||
if constexpr (IsIntegral<T> || IsFloatingPoint<T>)
|
||||
dbgln(" {}", v);
|
||||
else
|
||||
dbgln(" *{}", v.value());
|
||||
});
|
||||
}
|
||||
},
|
||||
[](const NonnullOwnPtr<Label>& l) {
|
||||
dbgln(" label({}) -> {}", l->arity(), l->continuation());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue