summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWasm
AgeCommit message (Collapse)Author
2021-06-09LibWasm: ALWAYS_INLINE some very hot functionsAli Mohammad Pur
These function couldn't be inlined before because the compiler would've started flagging invalid paths in Variant as maybe-uninitialized.
2021-06-09LibWasm: Implement saturating float truncation instructionsAli Mohammad Pur
With these, the only remaining unimplemented instructions are the following: - memory.init - data.drop - memory.copy - memory.fill - table.init - elem.drop - table.copy - table.grow - table.size - table.fill
2021-06-09LibWasm: Implement sign extension instructionsAli Mohammad Pur
2021-06-09LibWasm: Implement spec-compliant float min/max opsAli Mohammad Pur
2021-06-05LibWasm: Move Wasm::BytecodeInterpreter into its own headerSahan Fernando
2021-06-04LibWasm+wasm: Switch to east-const to comply with project styleAli Mohammad Pur
Against my better judgement, this change is mandated by the project code style rules, even if it's not actually enforced.
2021-06-04LibWasm: Load and instantiate tablesAli Mohammad Pur
This commit is a fairly large refactor, mainly because it unified the two different ways that existed to represent references. Now Reference values are also a kind of value. It also implements a printer for values/references instead of copying the implementation everywhere.
2021-06-04LibWasm: Implement the br.table instructionAli Mohammad Pur
Unlike its name, this instruction has nothing to do with tables, it's just a very simple switch-case instruction.
2021-06-04LibWasm: Read from and write to memory as little-endianAli Mohammad Pur
The spec says so, we must do so.
2021-06-03LibWasm: Use builtins for clz, ctz, and popcntBrandonKi
2021-06-03LibWasm: Implement rotr and rotlBrandonKi
2021-06-02AK+LibWasm+LibJS: Disallow Variant.has() on types that aren't containedAli Mohammad Pur
Checking for this (and get()'ing it) is always invalid, so let's just disallow it. This also finds two bugs where the code is checking for types that can never actually be in the variant (which was actually a refactor artifact).
2021-06-02LibWasm: Ensure that value signs are preserved when castingAli Mohammad Pur
Also makes normal arithmetic operations more spec-compliant by actually ignoring overflow on them.
2021-06-02LibWasm: Parse the "extend" set of instructionsAli Mohammad Pur
2021-06-02LibWasm: Don't execute the last instruction in the frame after returnAli Mohammad Pur
2021-06-02wasm: Add a way to create dummy function exportsAli Mohammad Pur
This should allow running modules with their imports stubbed out in wasm, to debug them.
2021-06-02LibWasm: Implement reference instructions (ref.{null,func,is_null})Ali Mohammad Pur
2021-05-31AK: Replace ByteBuffer::grow with resize()/ensure_capacity()Gunnar Beutner
Previously ByteBuffer::grow() behaved like Vector<T>::resize(). However the function name was somewhat ambiguous - and so this patch updates ByteBuffer to behave more like Vector<T> by replacing grow() with resize() and adding an ensure_capacity() method. This also lets the user change the buffer's capacity without affecting the size which was not previously possible. Additionally this patch makes the capacity() method public (again).
2021-05-30LibWasm: Make f32-add/sub actually perform addition/subtractionAli Mohammad Pur
Instead of applying a unary operator to the ToS. This alone fixes 4% of the spec test issues.
2021-05-30LibWasm: Avoid OOB accesses caused by user inputAli Mohammad Pur
Just trap instead of crashing.
2021-05-29LibWasm: Fix logic error in Limits::parse()Ali Mohammad Pur
The check was negated, and it errored out when the read actually succeeded.
2021-05-27LibWasm: Avoid excessive pop()-then-push() on the stackAli Mohammad Pur
Also make the stack a lot bigger, since we now have only one of these instead of one per function call.
2021-05-27LibWasm: Let the interpreter itself manage the call frameAli Mohammad Pur
2021-05-27LibWasm: Add a copy assignment operator to ValueAli Mohammad Pur
2021-05-27LibWasm: Make Interpreter a virtual interfaceAli Mohammad Pur
This allows multiply different kinds of interpreters to be used by the runtime; currently a BytecodeInterpreter and a DebuggerBytecodeInterpreter is provided.
2021-05-27LibWasm: Use the current configuration to run call opsAli Mohammad Pur
This should make it easier to implement multiple types of interpreters on top of a configuration, and also give a small speed boost in not initialising as many Stack objects.
2021-05-27LibWasm: Make Frame a value type as wellAli Mohammad Pur
This means stack operations will no longer do extra allocations.
2021-05-27LibWasm: Don't put values and labels in OwnPtrsAli Mohammad Pur
Doing that was causing a lot of malloc/free traffic, but since there's no need to have a stable pointer to them, we can just store them by value. This makes execution significantly faster :^)
2021-05-26LibWasm: Add execution hooks and a debugger mode to the wasm toolAli Mohammad Pur
This is useful for debugging *our* implementation of wasm :P
2021-05-26LibWasm: Drop previous frame when a structured end instruction is runAli Mohammad Pur
2021-05-26LibWasm: Turn memory read failures into trapsAli Mohammad Pur
2021-05-26LibWasm: Once more fix structured instruction label indicesAli Mohammad Pur
This finally works correctly. :tm:
2021-05-26LibWasm: Drop the correct number of framesAli Mohammad Pur
Prior to this commit, we would be dropping an extra frame.
2021-05-26LibWasm: Implement checked truncation instructionsAli Mohammad Pur
This implements the 8 i<n>.truncate.f<n>_<s> instructions.
2021-05-26LibWasm+LibWeb: Partially resolve memory exportsAli Mohammad Pur
This allows the JS side to access the wasm memory, assuming it's exported by the module. This can be used to draw stuff on the wasm side and display them from the js side, for example :^)
2021-05-26LibWasm: Correct memory init size when instantiatingAli Mohammad Pur
These limits are in units of page size, not bytes. Also fixes incorrect debug logs.
2021-05-26LibWasm+LibWeb: Implement (a very basic version of) the JS link/importAli Mohammad Pur
This allows Wasm code to call javascript functions.
2021-05-21LibWasm: Print instruction arguments tooAli Mohammad Pur
2021-05-21LibWasm: Fix nested structured instruction parsingAli Mohammad Pur
Previously, the ip would not be propagated correctly, and we would produce invalid jumps when more than one level of nesting was involved. This makes loops work :P
2021-05-21LibWasm: Resolve labels starting from the top of the stackAli Mohammad Pur
Otherwise "label index 0" would be the first ever created label, not the last one (as the spec wants) :^(
2021-05-21LibWasm: Implement a very basic linkerAli Mohammad Pur
This will simply "link" any given module instances and produce a list of external values that can be used to instantiate a module. Note that this is extremely basic and cannot resolve circular dependencies, and depends on the instance order.
2021-05-21LibWasm: Make the instantiation process produce an OwnPtrAli Mohammad Pur
Managing the instantiated modules becomes a pain if they're on the stack, since an instantiated module will eventually reference itself. To make using this simpler, just avoid copying the instance.
2021-05-21LibWasm: Decouple ModuleInstance from the AbstractMachineAli Mohammad Pur
This fixes a FIXME and will allow linking only select modules together, instead of linking every instantiated module into a big mess of exported entities :P
2021-05-21LibWasm: Trap instead of VERIFY()'ingAli Mohammad Pur
...unless something really is an assertion.
2021-05-21LibWasm+Meta: Add test-wasm and optionally test the conformance testsAli Mohammad Pur
This only tests "can it be parsed", but the goal of this commit is to provide a test framework that can be built upon :) The conformance tests are downloaded, compiled* and installed only if the INCLUDE_WASM_SPEC_TESTS cmake option is enabled. (*) Since we do not yet have a wast parser, the compilation is delegated to an external tool from binaryen, `wasm-as`, which is required for the test suite download/install to succeed. This *does* run the tests in CI, but it currently does not include the spec conformance tests.
2021-05-17LibWasm: Make clang happy by removing an 'extra' set of parenthesisAli Mohammad Pur
These aren't actually an extra set, without them the fold operation would be syntactically invalid. Also remove possible cast of float->double/double->float in Value::to()
2021-05-17LibWasm: Implement memory.grow, memory.size and dropAli Mohammad Pur
These allow a very basic memory-using program to work.
2021-05-17LibWasm: Execute the start function, if one existsAli Mohammad Pur
2021-05-17LibWasm: Implement most of the remaining instructionsAli Mohammad Pur
This commit is a bit of a mixed bag, but most of the changes are repetitive enough to just include in a single commit. The following instructions remain unimplemented: - br.table - table.init - table.get - table.set - table.copy - table.size - table.grow - table.fill - ref.null - ref.func - ref.is_null - drop - i32/i64.clz - i32/i64.ctz - i32/i64.popcnt - i32/i64.rotl - i32/i64.rotr - X.trunc.Y - X.trunc_sat.Y - memory.size - memory.grow - memory.init - memory.copy - memory.fill - elem.drop - data.drop
2021-05-17LibWasm: Start implementing a naive bytecode interpreterAli Mohammad Pur
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.