Skip to content

Commit

Permalink
Merge with upstream (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhil authored Mar 22, 2024
2 parents 35e08b7 + c7c3c60 commit 16e91e5
Show file tree
Hide file tree
Showing 484 changed files with 1,657,327 additions and 322 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ jobs:
- run: cargo check --no-default-features --features metadata
- run: cargo check --no-default-features --features wit-smith
- run: cargo check --no-default-features --features addr2line
- run: cargo check --no-default-features --features json-from-wast
- run: cargo check --no-default-features --features completion
- run: cargo check --no-default-features -p wit-parser
- run: cargo check --no-default-features -p wit-parser --features wat
- run: cargo check --no-default-features -p wit-parser --features serde
Expand Down
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,14 @@ default = [
'wit-smith',
'addr2line',
'completion',
'json-from-wast',
]

# Each subcommand is gated behind a feature and lists the dependencies it needs
validate = ['dep:wasmparser', 'rayon']
print = []
parse = []
smith = ['wasm-smith', 'arbitrary', 'serde', 'serde_derive', 'serde_json']
smith = ['wasm-smith', 'arbitrary', 'dep:serde', 'dep:serde_derive', 'dep:serde_json']
shrink = ['wasm-shrink', 'is_executable']
mutate = ['wasm-mutate']
dump = ['dep:wasmparser']
Expand All @@ -183,12 +184,13 @@ demangle = ['rustc-demangle', 'cpp_demangle', 'dep:wasmparser', 'wasm-encoder']
component = [
'wit-component',
'wit-parser',
'wast',
'dep:wast',
'wasm-encoder',
'dep:wasmparser',
'serde_json',
'dep:serde_json',
]
metadata = ['dep:wasmparser', 'wasm-metadata', 'serde_json']
metadata = ['dep:wasmparser', 'wasm-metadata', 'dep:serde_json']
wit-smith = ['dep:wit-smith', 'arbitrary']
addr2line = ['dep:addr2line', 'dep:gimli', 'dep:wasmparser']
completion = ['dep:clap_complete']
json-from-wast = ['dep:serde_derive', 'dep:serde_json', 'dep:wast', 'dep:serde']
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ that can be use programmatically as well:
| `wasm-tools metadata add` | | Add name or producer metadata to a component or module |
| `wasm-tools addr2line` | | Translate wasm offsets to filename/line numbers with DWARF |
| `wasm-tools completion` | | Generate shell completion scripts for `wasm-tools` |
| `wasm-tools json-from-wast` | | Convert a `*.wast` file into JSON commands |

[wasmparser]: https://crates.io/crates/wasmparser
[wat]: https://crates.io/crates/wat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
(export (;7;) "h" (func (type 7)))
(type (;8;) (func (param "x" u64)))
(export (;8;) "i" (func (type 8)))
(type (;9;) (func (param "x" float32)))
(type (;9;) (func (param "x" f32)))
(export (;9;) "j" (func (type 9)))
(type (;10;) (func (param "x" float64)))
(type (;10;) (func (param "x" f64)))
(export (;10;) "k" (func (type 10)))
(type (;11;) (func (param "x" bool)))
(export (;11;) "l" (func (type 11)))
(type (;12;) (func (param "x" string)))
(export (;12;) "m" (func (type 12)))
(type (;13;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string)))
(type (;13;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" f32) (field "j" f64) (field "k" bool) (field "l" string)))
(export (;14;) "record1" (type (eq 13)))
(type (;15;) (func (param "x" 14)))
(export (;13;) "n" (func (type 15)))
Expand All @@ -67,7 +67,7 @@
(export (;27;) "option1" (type (eq 26)))
(type (;28;) (func (param "x" 27)))
(export (;18;) "s" (func (type 28)))
(type (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" 14)))
(type (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" f32) (case "j" f64) (case "k" bool) (case "l" string) (case "m" 14)))
(export (;30;) "variant1" (type (eq 29)))
(type (;31;) (option 30))
(type (;32;) (func (param "x" 31)))
Expand All @@ -90,15 +90,15 @@
(import "b" (component (;1;) (type 1)))
(type (;2;)
(component
(type (;0;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string)))
(type (;0;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" f32) (field "j" f64) (field "k" bool) (field "l" string)))
(export (;1;) "record1" (type (eq 0)))
(type (;2;) (flags "a" "b" "c"))
(export (;3;) "flags1" (type (eq 2)))
(type (;4;) (enum "a" "b" "c"))
(export (;5;) "enum1" (type (eq 4)))
(type (;6;) (option 1))
(export (;7;) "option1" (type (eq 6)))
(type (;8;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" 1)))
(type (;8;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" f32) (case "j" f64) (case "k" bool) (case "l" string) (case "m" 1)))
(export (;9;) "variant1" (type (eq 8)))
(type (;10;) (func))
(export (;0;) "a" (func (type 10)))
Expand All @@ -118,9 +118,9 @@
(export (;7;) "h" (func (type 17)))
(type (;18;) (func (param "x" u64)))
(export (;8;) "i" (func (type 18)))
(type (;19;) (func (param "x" float32)))
(type (;19;) (func (param "x" f32)))
(export (;9;) "j" (func (type 19)))
(type (;20;) (func (param "x" float64)))
(type (;20;) (func (param "x" f64)))
(export (;10;) "k" (func (type 20)))
(type (;21;) (func (param "x" bool)))
(export (;11;) "l" (func (type 21)))
Expand Down
8 changes: 4 additions & 4 deletions crates/wasm-compose/tests/compositions/complex/a.wat
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
(type $t6 (func (param "x" u32)))
(type $t7 (func (param "x" s64)))
(type $t8 (func (param "x" u64)))
(type $t9 (func (param "x" float32)))
(type $t10 (func (param "x" float64)))
(type $t9 (func (param "x" f32)))
(type $t10 (func (param "x" f64)))
(type $t11 (func (param "x" bool)))
(type $t12 (func (param "x" string)))
(type $t13' (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string)))
(type $t13' (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" f32) (field "j" f64) (field "k" bool) (field "l" string)))
(export $t13 "record1" (type $t13'))
(type $t14 (func (param "x" $t13)))
(type $t15 (list $t13))
Expand All @@ -28,7 +28,7 @@
(type $t23' (option $t13))
(export $t23 "option1" (type $t23'))
(type $t24 (func (param "x" $t23)))
(type $t25' (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" $t13)))
(type $t25' (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" f32) (case "j" f64) (case "k" bool) (case "l" string) (case "m" $t13)))
(export $t25 "variant1" (type $t25'))
(type $t26 (option $t25))
(type $t27 (func (param "x" $t26)))
Expand Down
8 changes: 4 additions & 4 deletions crates/wasm-compose/tests/compositions/complex/b.wat
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
(type $f7 (func (param "x" u32)))
(type $f8 (func (param "x" s64)))
(type $f9 (func (param "x" u64)))
(type $f10 (func (param "x" float32)))
(type $f11 (func (param "x" float64)))
(type $f10 (func (param "x" f32)))
(type $f11 (func (param "x" f64)))
(type $f12 (func (param "x" bool)))
(type $f13 (func (param "x" string)))
(export "a" (func (type $f1)))
Expand All @@ -27,7 +27,7 @@
(export "k" (func (type $f11)))
(export "l" (func (type $f12)))
(export "m" (func (type $f13)))
(type $t1' (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string)))
(type $t1' (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" f32) (field "j" f64) (field "k" bool) (field "l" string)))
(export $t1 "record1" (type (eq $t1')))
(type $f14 (func (param "x" $t1)))
(export "n" (func (type $f14)))
Expand All @@ -49,7 +49,7 @@
(export $t6 "option1" (type (eq $t6')))
(type $f19 (func (param "x" $t6)))
(export "s" (func (type $f19)))
(type $t7' (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" $t1)))
(type $t7' (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" f32) (case "j" f64) (case "k" bool) (case "l" string) (case "m" $t1)))
(export $t7 "variant1" (type (eq $t7')))
(type $t8 (option $t7))
(type $f20 (func (param "x" $t8)))
Expand Down
16 changes: 8 additions & 8 deletions crates/wasm-compose/tests/compositions/complex/composed.wat
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
(type (;6;) (func (param "x" u32)))
(type (;7;) (func (param "x" s64)))
(type (;8;) (func (param "x" u64)))
(type (;9;) (func (param "x" float32)))
(type (;10;) (func (param "x" float64)))
(type (;9;) (func (param "x" f32)))
(type (;10;) (func (param "x" f64)))
(type (;11;) (func (param "x" bool)))
(type (;12;) (func (param "x" string)))
(export (;0;) "a" (func (type 0)))
Expand All @@ -42,7 +42,7 @@
(export (;10;) "k" (func (type 10)))
(export (;11;) "l" (func (type 11)))
(export (;12;) "m" (func (type 12)))
(type (;13;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string)))
(type (;13;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" f32) (field "j" f64) (field "k" bool) (field "l" string)))
(export (;14;) "record1" (type (eq 13)))
(type (;15;) (func (param "x" 14)))
(export (;13;) "n" (func (type 15)))
Expand All @@ -64,7 +64,7 @@
(export (;27;) "option1" (type (eq 26)))
(type (;28;) (func (param "x" 27)))
(export (;18;) "s" (func (type 28)))
(type (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" 14)))
(type (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" f32) (case "j" f64) (case "k" bool) (case "l" string) (case "m" 14)))
(export (;30;) "variant1" (type (eq 29)))
(type (;31;) (option 30))
(type (;32;) (func (param "x" 31)))
Expand Down Expand Up @@ -327,11 +327,11 @@
(type $t6 (;6;) (func (param "x" u32)))
(type $t7 (;7;) (func (param "x" s64)))
(type $t8 (;8;) (func (param "x" u64)))
(type $t9 (;9;) (func (param "x" float32)))
(type $t10 (;10;) (func (param "x" float64)))
(type $t9 (;9;) (func (param "x" f32)))
(type $t10 (;10;) (func (param "x" f64)))
(type $t11 (;11;) (func (param "x" bool)))
(type $t12 (;12;) (func (param "x" string)))
(type $t13' (;13;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string)))
(type $t13' (;13;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" f32) (field "j" f64) (field "k" bool) (field "l" string)))
(export $t13 (;14;) "record1" (type $t13'))
(type $t14 (;15;) (func (param "x" $t13)))
(type $t15 (;16;) (list $t13))
Expand All @@ -347,7 +347,7 @@
(type $t23' (;26;) (option $t13))
(export $t23 (;27;) "option1" (type $t23'))
(type $t24 (;28;) (func (param "x" $t23)))
(type $t25' (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" $t13)))
(type $t25' (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" f32) (case "j" f64) (case "k" bool) (case "l" string) (case "m" $t13)))
(export $t25 (;30;) "variant1" (type $t25'))
(type $t26 (;31;) (option $t25))
(type $t27 (;32;) (func (param "x" $t26)))
Expand Down
16 changes: 8 additions & 8 deletions crates/wasm-encoder/src/component/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,10 @@ pub enum PrimitiveValType {
S64,
/// The type is an unsigned 64-bit integer.
U64,
/// The type is a 32-bit floating point number.
Float32,
/// The type is a 64-bit floating point number.
Float64,
/// The type is a 32-bit floating point number with only one NaN.
F32,
/// The type is a 64-bit floating point number with only one NaN.
F64,
/// The type is a Unicode character.
Char,
/// The type is a string.
Expand All @@ -519,8 +519,8 @@ impl Encode for PrimitiveValType {
Self::U32 => 0x79,
Self::S64 => 0x78,
Self::U64 => 0x77,
Self::Float32 => 0x76,
Self::Float64 => 0x75,
Self::F32 => 0x76,
Self::F64 => 0x75,
Self::Char => 0x74,
Self::String => 0x73,
});
Expand All @@ -540,8 +540,8 @@ impl From<wasmparser::PrimitiveValType> for PrimitiveValType {
wasmparser::PrimitiveValType::U32 => PrimitiveValType::U32,
wasmparser::PrimitiveValType::S64 => PrimitiveValType::S64,
wasmparser::PrimitiveValType::U64 => PrimitiveValType::U64,
wasmparser::PrimitiveValType::Float32 => PrimitiveValType::Float32,
wasmparser::PrimitiveValType::Float64 => PrimitiveValType::Float64,
wasmparser::PrimitiveValType::F32 => PrimitiveValType::F32,
wasmparser::PrimitiveValType::F64 => PrimitiveValType::F64,
wasmparser::PrimitiveValType::Char => PrimitiveValType::Char,
wasmparser::PrimitiveValType::String => PrimitiveValType::String,
}
Expand Down
16 changes: 8 additions & 8 deletions crates/wasm-smith/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,8 +1308,8 @@ impl ComponentBuilder {
6 => Ok(PrimitiveValType::U32),
7 => Ok(PrimitiveValType::S64),
8 => Ok(PrimitiveValType::U64),
9 => Ok(PrimitiveValType::Float32),
10 => Ok(PrimitiveValType::Float64),
9 => Ok(PrimitiveValType::F32),
10 => Ok(PrimitiveValType::F64),
11 => Ok(PrimitiveValType::Char),
12 => Ok(PrimitiveValType::String),
_ => unreachable!(),
Expand Down Expand Up @@ -1773,8 +1773,8 @@ fn canonical_abi_for(func_ty: &FuncType) -> Rc<crate::core::FuncType> {
| PrimitiveValType::S32
| PrimitiveValType::U32 => ValType::I32,
PrimitiveValType::S64 | PrimitiveValType::U64 => ValType::I64,
PrimitiveValType::Float32 => ValType::F32,
PrimitiveValType::Float64 => ValType::F64,
PrimitiveValType::F32 => ValType::F32,
PrimitiveValType::F64 => ValType::F64,
PrimitiveValType::String => {
unimplemented!("non-scalar types are not supported yet")
}
Expand Down Expand Up @@ -1819,8 +1819,8 @@ fn inverse_scalar_canonical_abi_for(
ComponentValType::Primitive(PrimitiveValType::U64),
])
.cloned(),
ValType::F32 => Ok(ComponentValType::Primitive(PrimitiveValType::Float32)),
ValType::F64 => Ok(ComponentValType::Primitive(PrimitiveValType::Float64)),
ValType::F32 => Ok(ComponentValType::Primitive(PrimitiveValType::F32)),
ValType::F64 => Ok(ComponentValType::Primitive(PrimitiveValType::F64)),
ValType::V128 | ValType::Ref(_) => {
unreachable!("not used in canonical ABI")
}
Expand Down Expand Up @@ -2055,8 +2055,8 @@ fn is_scalar(ty: &ComponentValType) -> bool {
| PrimitiveValType::U32
| PrimitiveValType::S64
| PrimitiveValType::U64
| PrimitiveValType::Float32
| PrimitiveValType::Float64
| PrimitiveValType::F32
| PrimitiveValType::F64
| PrimitiveValType::Char => true,
PrimitiveValType::String => false,
},
Expand Down
16 changes: 8 additions & 8 deletions crates/wasmparser/src/readers/component/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ pub enum PrimitiveValType {
S64,
/// The type is an unsigned 64-bit integer.
U64,
/// The type is a 32-bit floating point number.
Float32,
/// The type is a 64-bit floating point number.
Float64,
/// The type is a 32-bit floating point number with only one NaN.
F32,
/// The type is a 64-bit floating point number with only one NaN.
F64,
/// The type is a Unicode character.
Char,
/// The type is a string.
Expand All @@ -185,8 +185,8 @@ impl PrimitiveValType {
0x79 => PrimitiveValType::U32,
0x78 => PrimitiveValType::S64,
0x77 => PrimitiveValType::U64,
0x76 => PrimitiveValType::Float32,
0x75 => PrimitiveValType::Float64,
0x76 => PrimitiveValType::F32,
0x75 => PrimitiveValType::F64,
0x74 => PrimitiveValType::Char,
0x73 => PrimitiveValType::String,
_ => return None,
Expand Down Expand Up @@ -222,8 +222,8 @@ impl fmt::Display for PrimitiveValType {
U32 => "u32",
S64 => "s64",
U64 => "u64",
Float32 => "float32",
Float64 => "float64",
F32 => "f32",
F64 => "f64",
Char => "char",
String => "string",
};
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmparser/src/validator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ fn push_primitive_wasm_types(ty: &PrimitiveValType, lowered_types: &mut LoweredT
| PrimitiveValType::U32
| PrimitiveValType::Char => lowered_types.push(ValType::I32),
PrimitiveValType::S64 | PrimitiveValType::U64 => lowered_types.push(ValType::I64),
PrimitiveValType::Float32 => lowered_types.push(ValType::F32),
PrimitiveValType::Float64 => lowered_types.push(ValType::F64),
PrimitiveValType::F32 => lowered_types.push(ValType::F32),
PrimitiveValType::F64 => lowered_types.push(ValType::F64),
PrimitiveValType::String => {
lowered_types.push(ValType::I32) && lowered_types.push(ValType::I32)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmprinter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1648,8 +1648,8 @@ impl Printer {
PrimitiveValType::U32 => self.result.push_str("u32"),
PrimitiveValType::S64 => self.result.push_str("s64"),
PrimitiveValType::U64 => self.result.push_str("u64"),
PrimitiveValType::Float32 => self.result.push_str("float32"),
PrimitiveValType::Float64 => self.result.push_str("float64"),
PrimitiveValType::F32 => self.result.push_str("f32"),
PrimitiveValType::F64 => self.result.push_str("f64"),
PrimitiveValType::Char => self.result.push_str("char"),
PrimitiveValType::String => self.result.push_str("string"),
}
Expand Down
Loading

0 comments on commit 16e91e5

Please sign in to comment.