misalcedo / wasm-ast Goto Github PK
View Code? Open in Web Editor NEWA Rust-native WebAssembly syntax model useful for generating, reading, and emitting WebAssembly code.
License: Apache License 2.0
A Rust-native WebAssembly syntax model useful for generating, reading, and emitting WebAssembly code.
License: Apache License 2.0
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 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.
WASM defines features such as SIMD, multiple memory, etc.
WASM-AST should allow a configuration for the parser and emitter to fail if a feature is used that is not supported.
See https://github.com/bytecodealliance/wasmtime/blob/main/tests/all/wast.rs
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 examples as doc tests.
The binary should create a module and when emitted, should equal itself.
Use nom for the parser.
Need to find a way to define instructions as constant so that a constant expression can have only constant instructions at compile time.
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);
Currently it could mean working with an i32 exclusively. Perhaps making them suffixed with Partial again.
Use the WASM spec tests (wast) to validate the correctness of the WebAssembly model.
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.
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:
Expected behavior
The wasm binary is parsed successfully.
Desktop (please complete the following information):
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,
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.