Git Product home page Git Product logo

wasm-ast's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wasm-ast's Issues

Allow a module to define where in custom sections will be emitted to.

Currently each module section is a field in the struct. However, custom sections can be found at any point of the WASM binary (start, end, or between other sections).

Also, I still want to ensure at compile time that only 1 of the non-custom sections is present.

Lastly, add a toggle to define whether the data count section should be emitted.

One option is to define multiple custom fields, but that would be excessive.

The other option is to add a field for insert at to the custom struct. Then, group by insertion point (maintaining order) and emit them as they come up. This trades ease of coding for runtime costs.

Yet another option is a map of insertion points to a vector of custom sections. Then, as we emit a section we can check which custom sections need to be emitted after wards. The initial custom sections have an insertion point 0, for the rest they are inserted after their insertion point, but before the next non-custom section.

Get rid of the need for Storage Size enum

Currently storage size is used to map integer types to their valid (read smaller) bit widths for type correctness.
We either create separate instructions for each 8 and 16 that accept any integer type (with a special instruction for the 32 bit one), or we give up on static typing and rely on runtime checks. I think the static typing is preferred here.

pub enum StorageSize {
    I32_8,
    I64_8,
    I32_16,
    I64_16,
    I64_32,
}

Access module function by index

I would like to access the functions of a module by its index.

I only found a way to access all function of a module

   //let module = ....;
  let functions = module.functions() // Option<&[Function]>

Is there a way to access a function directly by specifying its FunctionIndex?
Maybe something like:

  let index: FunctionIndex = 3;
  let myfunction = module.function(index);

Using I32Constant with negative value spins forever when emitting binary

Describe the bug
The body of the function below simply loads a single negative value constant on the stack and returns it. The emit_binary call will spin forever.

To Reproduce

#[test]
fn negative_one() {
    let mut builder = ModuleBuilder::new();
    let one_i32 = ResultType::from(vec![ValueType::I32]);
    let func_type = FunctionType::new(ResultType::empty(), one_i32);
    let func_type_index = builder.add_function_type(func_type).unwrap();
    let body: Expression = vec![
        NumericInstruction::I32Constant(-1).into(),  // any negative value will spin, any positive value will run
    ]
    .into();
    let main_func = Function::new(
        func_type_index,
        ResultType::empty(),
        body,
    );
    let main_func_index = builder.add_function(main_func).unwrap();

    let name = "spins_forever";
    let export = Export::function(name.into(), main_func_index);
    builder.add_export(export);
    let module = builder.build();

    let mut buffer = Vec::new();

    // This line spins forever if a negative value for the I32Constant is used
    emit_binary(&module, &mut buffer).unwrap();
}

Expected behavior
The I32Constant takes a rust i32 (signed 32bit integer). The constant should either take a u32 or work with negative values for i32

Toolchain
stable-x86_64-unknown-linux-gnu

Implement an emitter

The emitter should be similar to the Display trait.
Ideally, I would not have to implement my own trait.
However, supporting sync and async writers is going to be tough.
For now, the focus is on sync write.

Add vector integer support

Implement WASM vector support

https://webassembly.github.io/spec/core/syntax/values.html#vectors

Numeric vectors are 128-bit values that are processed by vector instructions (also known as SIMD instructions, single instruction multiple data). They are represented in the abstract syntax using . The interpretation of lane types (integer or floating-point numbers) and lane sizes are determined by the specific instruction operating on them.

Stack Overflow on read wasm binary with large size

Describe the bug

use wasm_ast::parser;

fn main() {
    /* first argument is the wasm file */
    let wasm_file_path = std::env::args().nth(1).expect("No wasm file provided");

    /* read the file */
    let contents = std::fs::read(wasm_file_path).unwrap();

    let wasm = parser::parse_binary(&contents).expect("Can't parse wasm binary");

    println!("parsed wasm binary");

}

thread 'main' has overflowed its stack
Parsing large wasm binaries results in this error.

To Reproduce
Steps to reproduce the behavior:

  1. Parse a large wasm binary

Expected behavior
The wasm binary is parsed successfully.

Desktop (please complete the following information):

  • Windows

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.