Remove all checked in *.wasm files to the repo (#563)
* Tidy up the `hello` example for `wasmtime` * Remove the `*.wat` and `*.wasm` files and instead just inline the `*.wat` into the example. * Touch up comments so they're not just a repeat of the `println!` below. * Move `*.wat` for `memory` example inline No need to handle auxiliary files with the ability to parse it inline! * Move `multi.wasm` inline into `multi.rs` example * Move `*.wasm` for gcd example inline * Move `*.wat` inline with `import_calling_export` test * Remove checked in `lightbeam/test.wasm` Instead move the `*.wat` into the source and parse it into wasm there. * Run rustfmt
This commit is contained in:
@@ -30,6 +30,7 @@ more-asserts = "0.2.1"
|
||||
lazy_static = "1.2"
|
||||
wat = "1.0.2"
|
||||
quickcheck = "0.9.0"
|
||||
anyhow = "1.0"
|
||||
|
||||
[badges]
|
||||
maintenance = { status = "experimental" }
|
||||
|
||||
@@ -1,34 +1,16 @@
|
||||
use lightbeam::translate;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
|
||||
fn read_to_end<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
|
||||
let mut buffer = Vec::new();
|
||||
if path.as_ref() == Path::new("-") {
|
||||
let stdin = io::stdin();
|
||||
let mut stdin = stdin.lock();
|
||||
stdin.read_to_end(&mut buffer)?;
|
||||
} else {
|
||||
let mut file = File::open(path)?;
|
||||
file.read_to_end(&mut buffer)?;
|
||||
}
|
||||
Ok(buffer)
|
||||
}
|
||||
const WAT: &str = r#"
|
||||
(module
|
||||
(func (param i32) (param i32) (result i32) (i32.add (get_local 0) (get_local 1)))
|
||||
)
|
||||
"#;
|
||||
|
||||
fn maybe_main() -> Result<(), String> {
|
||||
let data = read_to_end("test.wasm").map_err(|e| e.to_string())?;
|
||||
let translated = translate(&data).map_err(|e| e.to_string())?;
|
||||
let result: u32 = translated.execute_func(0, (5u32, 3u32)).unwrap();
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let data = wat::parse_str(WAT)?;
|
||||
let translated = translate(&data)?;
|
||||
let result: u32 = translated.execute_func(0, (5u32, 3u32))?;
|
||||
println!("f(5, 3) = {}", result);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match maybe_main() {
|
||||
Ok(()) => (),
|
||||
Err(e) => eprintln!("error: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use cranelift_codegen::{
|
||||
};
|
||||
use memoffset::offset_of;
|
||||
use more_asserts::assert_le;
|
||||
use thiserror::Error;
|
||||
use wasmparser::{FuncType, MemoryType, ModuleReader, SectionCode, Type};
|
||||
|
||||
pub trait AsValueType {
|
||||
@@ -133,9 +134,11 @@ impl TranslatedModule {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Error)]
|
||||
pub enum ExecutionError {
|
||||
#[error("function index out of bounds")]
|
||||
FuncIndexOutOfBounds,
|
||||
#[error("type mismatch")]
|
||||
TypeMismatch,
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,3 +0,0 @@
|
||||
(module
|
||||
(func (param i32) (param i32) (result i32) (i32.add (get_local 0) (get_local 1)))
|
||||
)
|
||||
Reference in New Issue
Block a user