Skip to content

Commit

Permalink
Add assembler
Browse files Browse the repository at this point in the history
  • Loading branch information
neri committed Dec 4, 2024
1 parent 946be90 commit 11fcd27
Show file tree
Hide file tree
Showing 70 changed files with 10,500 additions and 281 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tests/* linguist-vendored
tools/* linguist-vendored
docs/* linguist-documentation

lib/wasm_asm/src/_generated/* linguist-generated
src/_generated/* linguist-generated
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
run: cargo test --workspace --verbose
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"rust-analyzer.linkedProjects": [
"./Cargo.toml",
"./example/cli/Cargo.toml",
"./example/hello/Cargo.toml",
"example/cli/Cargo.toml",
"example/hello/Cargo.toml",
"tools/wat2wasm/Cargo.toml",
]
}
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["edition2024"]

[package]
authors = ["Nerry <[email protected]>"]
edition = "2024"
Expand All @@ -13,12 +11,20 @@ default = []

[dependencies]
wami_macro = {path="./lib/wami_macro"}
leb128 = {path="./lib/leb128"}

libm = {version="0.2.8"}
libm = {version="0.2.11"}
smallvec = {version = "1.13.2", default-features = false}

[dev-dependencies]
wa_asm = { path = "./lib/wa_asm" }

[workspace]
members = [
"example/cli",
"example/hello",
"tools/wat2wasm",
"lib/wami_macro",
"lib/leb128",
"lib/wa_asm",
]
5 changes: 3 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
collections::BTreeMap,
fs::{read_to_string, File},
fs::{File, read_to_string},
io::*,
num::ParseIntError,
result,
Expand Down Expand Up @@ -178,8 +178,9 @@ fn make_opcode(os: &mut File, lines: &[String]) {
"//
// This file is automatically generated at build time. DO NOT EDIT DIRECTLY.
//
use crate::{{leb128::*, BrTableVec, WasmBlockType, WasmCompileErrorKind, WasmMemArg}};
use core::fmt;
use crate::{{BrTableVec, WasmBlockType, WasmCompileErrorKind, WasmMemArg}};
use leb128::*;
/// WebAssembly Opcode
#[non_exhaustive]
Expand Down
2 changes: 0 additions & 2 deletions example/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["edition2024"]

[package]
authors = ["Nerry <[email protected]>"]
edition = "2024"
Expand Down
4 changes: 1 addition & 3 deletions example/hello/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
cargo-features = ["edition2024"]


[package]
authors = ["Nerry <[email protected]>"]
edition = "2024"
Expand All @@ -11,3 +8,4 @@ version = "0.1.0"

[dependencies]
wami = { path="../../" }
wa_asm = { path = "../../lib/wa_asm" }
3 changes: 0 additions & 3 deletions example/hello/Makefile

This file was deleted.

Binary file removed example/hello/hello.wasm
Binary file not shown.
13 changes: 0 additions & 13 deletions example/hello/hello.wat

This file was deleted.

21 changes: 18 additions & 3 deletions example/hello/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
// Hello world

use wa_asm::WasmAssembler;
use wami::prelude::*;

fn main() {
let env = Env {};
let instance = WebAssembly::instantiate(include_bytes!("../hello.wasm"), &env).unwrap();
let src = r#"
(module
(import "env" "println" (func $println (param i32) (param i32)))
(memory 1)
(data (i32.const 16) "hello world!")
(func $main (export "main")
i32.const 12
i32.const 16
call $println
)
)
"#;
let bin = WasmAssembler::to_wasm("hello.wat", src.as_bytes().to_vec()).unwrap();
let instance = WebAssembly::instantiate(&bin, &Env {}).unwrap();
instance.exports().main().unwrap();
}

Expand Down
6 changes: 6 additions & 0 deletions lib/leb128/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "leb128"
version = "0.1.0"
edition = "2024"

[dependencies]
Loading

0 comments on commit 11fcd27

Please sign in to comment.