Bug 1703105 - wasm: Update wat to latest version. r=lth

Some SIMD instructions rely on a newer version of wat then we
have vendored.

Differential Revision: https://phabricator.services.mozilla.com/D111230
This commit is contained in:
Ryan Hunt 2021-04-20 14:36:29 +00:00
parent 7fe255e307
commit 8ac7e3ebca
11 changed files with 333 additions and 266 deletions

8
Cargo.lock generated
View File

@ -5714,18 +5714,18 @@ source = "git+https://github.com/mozilla-spidermonkey/wasm-tools?rev=1b7763faa48
[[package]]
name = "wast"
version = "34.0.0"
version = "35.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3de71ea922e46a60d0bde4b27ebf24ab7c4991006fd5de23ce9c58e129b3ab3c"
checksum = "1a5800e9f86a1eae935e38bea11e60fd253f6d514d153fb39b3e5535a7b37b56"
dependencies = [
"leb128",
]
[[package]]
name = "wat"
version = "1.0.35"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "474403335b9a90b21120ab8131dd888f0a8d041c2d365ab960feddfe5a73c4b6"
checksum = "8ec280a739b69173e0ffd12c1658507996836ba4e992ed9bc1e5385a0bd72a02"
dependencies = [
"wast",
]

View File

@ -20,5 +20,5 @@ smoosh = ['jsrust_shared/smoosh']
jsrust_shared = { path = "./shared" }
# Workaround for https://github.com/rust-lang/rust/issues/58393
mozglue-static = { path = "../../../mozglue/static/rust" }
wat = { version = "1.0.35" }
wat = { version = "1.0.37" }
wasmparser = { version = "0.48.2" }

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "wast"
version = "34.0.0"
version = "35.0.1"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
description = "Customizable Rust parsers for the WebAssembly Text formats WAT and WAST\n"
homepage = "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wast"

View File

@ -200,9 +200,9 @@ impl<'a> ExpressionParser<'a> {
return Err(parser.error("previous `try` had no `do`"));
}
Level::Try(Try::CatchUnwindOrDelegate) => {
return Err(
parser.error("previous `try` had no `catch`, `catch_all`, `unwind`, or `delegate`")
);
return Err(parser.error(
"previous `try` had no `catch`, `catch_all`, `unwind`, or `delegate`",
));
}
Level::Try(Try::Delegate) => {}
Level::Try(_) => {
@ -375,8 +375,8 @@ impl<'a> ExpressionParser<'a> {
self.instrs.push(Instruction::Delegate(depth));
*i = Try::Delegate;
match self.paren(parser)? {
Paren::Left | Paren::None => { return Ok(false) }
Paren::Right => { return Ok(true) }
Paren::Left | Paren::None => return Ok(false),
Paren::Right => return Ok(true),
}
}
return Ok(false);
@ -868,259 +868,262 @@ instructions! {
I64AtomicRmw32CmpxchgU(MemArg<4>) : [0xfe, 0x4e] : "i64.atomic.rmw32.cmpxchg_u",
// proposal: simd
V128Load(MemArg<16>) : [0xfd, 0x00] : "v128.load",
V128Load8x8S(MemArg<8>) : [0xfd, 0x01] : "v128.load8x8_s",
V128Load8x8U(MemArg<8>) : [0xfd, 0x02] : "v128.load8x8_u",
V128Load16x4S(MemArg<8>) : [0xfd, 0x03] : "v128.load16x4_s",
V128Load16x4U(MemArg<8>) : [0xfd, 0x04] : "v128.load16x4_u",
V128Load32x2S(MemArg<8>) : [0xfd, 0x05] : "v128.load32x2_s",
V128Load32x2U(MemArg<8>) : [0xfd, 0x06] : "v128.load32x2_u",
V128Load8Splat(MemArg<1>) : [0xfd, 0x07] : "v128.load8_splat",
V128Load16Splat(MemArg<2>) : [0xfd, 0x08] : "v128.load16_splat",
V128Load32Splat(MemArg<4>) : [0xfd, 0x09] : "v128.load32_splat",
V128Load64Splat(MemArg<8>) : [0xfd, 0x0a] : "v128.load64_splat",
V128Store(MemArg<16>) : [0xfd, 0x0b] : "v128.store",
//
// https://webassembly.github.io/simd/core/binary/instructions.html
V128Load(MemArg<16>) : [0xfd, 0] : "v128.load",
V128Load8x8S(MemArg<8>) : [0xfd, 1] : "v128.load8x8_s",
V128Load8x8U(MemArg<8>) : [0xfd, 2] : "v128.load8x8_u",
V128Load16x4S(MemArg<8>) : [0xfd, 3] : "v128.load16x4_s",
V128Load16x4U(MemArg<8>) : [0xfd, 4] : "v128.load16x4_u",
V128Load32x2S(MemArg<8>) : [0xfd, 5] : "v128.load32x2_s",
V128Load32x2U(MemArg<8>) : [0xfd, 6] : "v128.load32x2_u",
V128Load8Splat(MemArg<1>) : [0xfd, 7] : "v128.load8_splat",
V128Load16Splat(MemArg<2>) : [0xfd, 8] : "v128.load16_splat",
V128Load32Splat(MemArg<4>) : [0xfd, 9] : "v128.load32_splat",
V128Load64Splat(MemArg<8>) : [0xfd, 10] : "v128.load64_splat",
V128Load32Zero(MemArg<4>) : [0xfd, 92] : "v128.load32_zero",
V128Load64Zero(MemArg<8>) : [0xfd, 93] : "v128.load64_zero",
V128Store(MemArg<16>) : [0xfd, 11] : "v128.store",
V128Const(V128Const) : [0xfd, 0x0c] : "v128.const",
I8x16Shuffle(I8x16Shuffle) : [0xfd, 0x0d] : "i8x16.shuffle",
I8x16Swizzle : [0xfd, 0x0e] : "i8x16.swizzle",
V128Load8Lane(LoadOrStoreLane<1>) : [0xfd, 84] : "v128.load8_lane",
V128Load16Lane(LoadOrStoreLane<2>) : [0xfd, 85] : "v128.load16_lane",
V128Load32Lane(LoadOrStoreLane<4>) : [0xfd, 86] : "v128.load32_lane",
V128Load64Lane(LoadOrStoreLane<8>): [0xfd, 87] : "v128.load64_lane",
V128Store8Lane(LoadOrStoreLane<1>) : [0xfd, 88] : "v128.store8_lane",
V128Store16Lane(LoadOrStoreLane<2>) : [0xfd, 89] : "v128.store16_lane",
V128Store32Lane(LoadOrStoreLane<4>) : [0xfd, 90] : "v128.store32_lane",
V128Store64Lane(LoadOrStoreLane<8>) : [0xfd, 91] : "v128.store64_lane",
I8x16Splat : [0xfd, 0x0f] : "i8x16.splat",
I16x8Splat : [0xfd, 0x10] : "i16x8.splat",
I32x4Splat : [0xfd, 0x11] : "i32x4.splat",
I64x2Splat : [0xfd, 0x12] : "i64x2.splat",
F32x4Splat : [0xfd, 0x13] : "f32x4.splat",
F64x2Splat : [0xfd, 0x14] : "f64x2.splat",
V128Const(V128Const) : [0xfd, 12] : "v128.const",
I8x16Shuffle(I8x16Shuffle) : [0xfd, 13] : "i8x16.shuffle",
I8x16ExtractLaneS(LaneArg) : [0xfd, 0x15] : "i8x16.extract_lane_s",
I8x16ExtractLaneU(LaneArg) : [0xfd, 0x16] : "i8x16.extract_lane_u",
I8x16ReplaceLane(LaneArg) : [0xfd, 0x17] : "i8x16.replace_lane",
I16x8ExtractLaneS(LaneArg) : [0xfd, 0x18] : "i16x8.extract_lane_s",
I16x8ExtractLaneU(LaneArg) : [0xfd, 0x19] : "i16x8.extract_lane_u",
I16x8ReplaceLane(LaneArg) : [0xfd, 0x1a] : "i16x8.replace_lane",
I32x4ExtractLane(LaneArg) : [0xfd, 0x1b] : "i32x4.extract_lane",
I32x4ReplaceLane(LaneArg) : [0xfd, 0x1c] : "i32x4.replace_lane",
I64x2ExtractLane(LaneArg) : [0xfd, 0x1d] : "i64x2.extract_lane",
I64x2ReplaceLane(LaneArg) : [0xfd, 0x1e] : "i64x2.replace_lane",
F32x4ExtractLane(LaneArg) : [0xfd, 0x1f] : "f32x4.extract_lane",
F32x4ReplaceLane(LaneArg) : [0xfd, 0x20] : "f32x4.replace_lane",
F64x2ExtractLane(LaneArg) : [0xfd, 0x21] : "f64x2.extract_lane",
F64x2ReplaceLane(LaneArg) : [0xfd, 0x22] : "f64x2.replace_lane",
I8x16ExtractLaneS(LaneArg) : [0xfd, 21] : "i8x16.extract_lane_s",
I8x16ExtractLaneU(LaneArg) : [0xfd, 22] : "i8x16.extract_lane_u",
I8x16ReplaceLane(LaneArg) : [0xfd, 23] : "i8x16.replace_lane",
I16x8ExtractLaneS(LaneArg) : [0xfd, 24] : "i16x8.extract_lane_s",
I16x8ExtractLaneU(LaneArg) : [0xfd, 25] : "i16x8.extract_lane_u",
I16x8ReplaceLane(LaneArg) : [0xfd, 26] : "i16x8.replace_lane",
I32x4ExtractLane(LaneArg) : [0xfd, 27] : "i32x4.extract_lane",
I32x4ReplaceLane(LaneArg) : [0xfd, 28] : "i32x4.replace_lane",
I64x2ExtractLane(LaneArg) : [0xfd, 29] : "i64x2.extract_lane",
I64x2ReplaceLane(LaneArg) : [0xfd, 30] : "i64x2.replace_lane",
F32x4ExtractLane(LaneArg) : [0xfd, 31] : "f32x4.extract_lane",
F32x4ReplaceLane(LaneArg) : [0xfd, 32] : "f32x4.replace_lane",
F64x2ExtractLane(LaneArg) : [0xfd, 33] : "f64x2.extract_lane",
F64x2ReplaceLane(LaneArg) : [0xfd, 34] : "f64x2.replace_lane",
I8x16Eq : [0xfd, 0x23] : "i8x16.eq",
I8x16Ne : [0xfd, 0x24] : "i8x16.ne",
I8x16LtS : [0xfd, 0x25] : "i8x16.lt_s",
I8x16LtU : [0xfd, 0x26] : "i8x16.lt_u",
I8x16GtS : [0xfd, 0x27] : "i8x16.gt_s",
I8x16GtU : [0xfd, 0x28] : "i8x16.gt_u",
I8x16LeS : [0xfd, 0x29] : "i8x16.le_s",
I8x16LeU : [0xfd, 0x2a] : "i8x16.le_u",
I8x16GeS : [0xfd, 0x2b] : "i8x16.ge_s",
I8x16GeU : [0xfd, 0x2c] : "i8x16.ge_u",
I16x8Eq : [0xfd, 0x2d] : "i16x8.eq",
I16x8Ne : [0xfd, 0x2e] : "i16x8.ne",
I16x8LtS : [0xfd, 0x2f] : "i16x8.lt_s",
I16x8LtU : [0xfd, 0x30] : "i16x8.lt_u",
I16x8GtS : [0xfd, 0x31] : "i16x8.gt_s",
I16x8GtU : [0xfd, 0x32] : "i16x8.gt_u",
I16x8LeS : [0xfd, 0x33] : "i16x8.le_s",
I16x8LeU : [0xfd, 0x34] : "i16x8.le_u",
I16x8GeS : [0xfd, 0x35] : "i16x8.ge_s",
I16x8GeU : [0xfd, 0x36] : "i16x8.ge_u",
I32x4Eq : [0xfd, 0x37] : "i32x4.eq",
I32x4Ne : [0xfd, 0x38] : "i32x4.ne",
I32x4LtS : [0xfd, 0x39] : "i32x4.lt_s",
I32x4LtU : [0xfd, 0x3a] : "i32x4.lt_u",
I32x4GtS : [0xfd, 0x3b] : "i32x4.gt_s",
I32x4GtU : [0xfd, 0x3c] : "i32x4.gt_u",
I32x4LeS : [0xfd, 0x3d] : "i32x4.le_s",
I32x4LeU : [0xfd, 0x3e] : "i32x4.le_u",
I32x4GeS : [0xfd, 0x3f] : "i32x4.ge_s",
I32x4GeU : [0xfd, 0x40] : "i32x4.ge_u",
I8x16Swizzle : [0xfd, 14] : "i8x16.swizzle",
I8x16Splat : [0xfd, 15] : "i8x16.splat",
I16x8Splat : [0xfd, 16] : "i16x8.splat",
I32x4Splat : [0xfd, 17] : "i32x4.splat",
I64x2Splat : [0xfd, 18] : "i64x2.splat",
F32x4Splat : [0xfd, 19] : "f32x4.splat",
F64x2Splat : [0xfd, 20] : "f64x2.splat",
F32x4Eq : [0xfd, 0x41] : "f32x4.eq",
F32x4Ne : [0xfd, 0x42] : "f32x4.ne",
F32x4Lt : [0xfd, 0x43] : "f32x4.lt",
F32x4Gt : [0xfd, 0x44] : "f32x4.gt",
F32x4Le : [0xfd, 0x45] : "f32x4.le",
F32x4Ge : [0xfd, 0x46] : "f32x4.ge",
F64x2Eq : [0xfd, 0x47] : "f64x2.eq",
F64x2Ne : [0xfd, 0x48] : "f64x2.ne",
F64x2Lt : [0xfd, 0x49] : "f64x2.lt",
F64x2Gt : [0xfd, 0x4a] : "f64x2.gt",
F64x2Le : [0xfd, 0x4b] : "f64x2.le",
F64x2Ge : [0xfd, 0x4c] : "f64x2.ge",
I8x16Eq : [0xfd, 35] : "i8x16.eq",
I8x16Ne : [0xfd, 36] : "i8x16.ne",
I8x16LtS : [0xfd, 37] : "i8x16.lt_s",
I8x16LtU : [0xfd, 38] : "i8x16.lt_u",
I8x16GtS : [0xfd, 39] : "i8x16.gt_s",
I8x16GtU : [0xfd, 40] : "i8x16.gt_u",
I8x16LeS : [0xfd, 41] : "i8x16.le_s",
I8x16LeU : [0xfd, 42] : "i8x16.le_u",
I8x16GeS : [0xfd, 43] : "i8x16.ge_s",
I8x16GeU : [0xfd, 44] : "i8x16.ge_u",
V128Not : [0xfd, 0x4d] : "v128.not",
V128And : [0xfd, 0x4e] : "v128.and",
V128Andnot : [0xfd, 0x4f] : "v128.andnot",
V128Or : [0xfd, 0x50] : "v128.or",
V128Xor : [0xfd, 0x51] : "v128.xor",
V128Bitselect : [0xfd, 0x52] : "v128.bitselect",
V128AnyTrue : [0xfd, 0x53] : "v128.any_true",
I16x8Eq : [0xfd, 45] : "i16x8.eq",
I16x8Ne : [0xfd, 46] : "i16x8.ne",
I16x8LtS : [0xfd, 47] : "i16x8.lt_s",
I16x8LtU : [0xfd, 48] : "i16x8.lt_u",
I16x8GtS : [0xfd, 49] : "i16x8.gt_s",
I16x8GtU : [0xfd, 50] : "i16x8.gt_u",
I16x8LeS : [0xfd, 51] : "i16x8.le_s",
I16x8LeU : [0xfd, 52] : "i16x8.le_u",
I16x8GeS : [0xfd, 53] : "i16x8.ge_s",
I16x8GeU : [0xfd, 54] : "i16x8.ge_u",
V128Load8Lane(LoadOrStoreLane<1>) : [0xfd, 0x54] : "v128.load8_lane",
V128Load16Lane(LoadOrStoreLane<2>) : [0xfd, 0x55] : "v128.load16_lane",
V128Load32Lane(LoadOrStoreLane<4>) : [0xfd, 0x56] : "v128.load32_lane",
V128Load64Lane(LoadOrStoreLane<8>): [0xfd, 0x57] : "v128.load64_lane",
V128Store8Lane(LoadOrStoreLane<1>) : [0xfd, 0x58] : "v128.store8_lane",
V128Store16Lane(LoadOrStoreLane<2>) : [0xfd, 0x59] : "v128.store16_lane",
V128Store32Lane(LoadOrStoreLane<4>) : [0xfd, 0x5a] : "v128.store32_lane",
V128Store64Lane(LoadOrStoreLane<8>) : [0xfd, 0x5b] : "v128.store64_lane",
I32x4Eq : [0xfd, 55] : "i32x4.eq",
I32x4Ne : [0xfd, 56] : "i32x4.ne",
I32x4LtS : [0xfd, 57] : "i32x4.lt_s",
I32x4LtU : [0xfd, 58] : "i32x4.lt_u",
I32x4GtS : [0xfd, 59] : "i32x4.gt_s",
I32x4GtU : [0xfd, 60] : "i32x4.gt_u",
I32x4LeS : [0xfd, 61] : "i32x4.le_s",
I32x4LeU : [0xfd, 62] : "i32x4.le_u",
I32x4GeS : [0xfd, 63] : "i32x4.ge_s",
I32x4GeU : [0xfd, 64] : "i32x4.ge_u",
V128Load32Zero(MemArg<4>) : [0xfd, 0x5c] : "v128.load32_zero",
V128Load64Zero(MemArg<8>) : [0xfd, 0x5d] : "v128.load64_zero",
I64x2Eq : [0xfd, 214] : "i64x2.eq",
I64x2Ne : [0xfd, 215] : "i64x2.ne",
I64x2LtS : [0xfd, 216] : "i64x2.lt_s",
I64x2GtS : [0xfd, 217] : "i64x2.gt_s",
I64x2LeS : [0xfd, 218] : "i64x2.le_s",
I64x2GeS : [0xfd, 219] : "i64x2.ge_s",
F32x4DemoteF64x2Zero : [0xfd, 0x5e] : "f32x4.demote_f64x2_zero",
F64x2PromoteLowF32x4 : [0xfd, 0x5f] : "f64x2.promote_low_f32x4",
F32x4Eq : [0xfd, 65] : "f32x4.eq",
F32x4Ne : [0xfd, 66] : "f32x4.ne",
F32x4Lt : [0xfd, 67] : "f32x4.lt",
F32x4Gt : [0xfd, 68] : "f32x4.gt",
F32x4Le : [0xfd, 69] : "f32x4.le",
F32x4Ge : [0xfd, 70] : "f32x4.ge",
I8x16Abs : [0xfd, 0x60] : "i8x16.abs",
I8x16Neg : [0xfd, 0x61] : "i8x16.neg",
I8x16Popcnt : [0xfd, 0x62] : "i8x16.popcnt",
I8x16AllTrue : [0xfd, 0x63] : "i8x16.all_true",
I8x16Bitmask : [0xfd, 0x64] : "i8x16.bitmask",
I8x16NarrowI16x8S : [0xfd, 0x65] : "i8x16.narrow_i16x8_s",
I8x16NarrowI16x8U : [0xfd, 0x66] : "i8x16.narrow_i16x8_u",
F32x4Ceil : [0xfd, 0x67] : "f32x4.ceil",
F32x4Floor : [0xfd, 0x68] : "f32x4.floor",
F32x4Trunc : [0xfd, 0x69] : "f32x4.trunc",
F32x4Nearest : [0xfd, 0x6a] : "f32x4.nearest",
I8x16Shl : [0xfd, 0x6b] : "i8x16.shl",
I8x16ShrS : [0xfd, 0x6c] : "i8x16.shr_s",
I8x16ShrU : [0xfd, 0x6d] : "i8x16.shr_u",
I8x16Add : [0xfd, 0x6e] : "i8x16.add",
I8x16AddSatS : [0xfd, 0x6f] : "i8x16.add_sat_s",
I8x16AddSatU : [0xfd, 0x70] : "i8x16.add_sat_u",
I8x16Sub : [0xfd, 0x71] : "i8x16.sub",
I8x16SubSatS : [0xfd, 0x72] : "i8x16.sub_sat_s",
I8x16SubSatU : [0xfd, 0x73] : "i8x16.sub_sat_u",
F64x2Ceil : [0xfd, 0x74] : "f64x2.ceil",
F64x2Floor : [0xfd, 0x75] : "f64x2.floor",
I8x16MinS : [0xfd, 0x76] : "i8x16.min_s",
I8x16MinU : [0xfd, 0x77] : "i8x16.min_u",
I8x16MaxS : [0xfd, 0x78] : "i8x16.max_s",
I8x16MaxU : [0xfd, 0x79] : "i8x16.max_u",
F64x2Trunc : [0xfd, 0x7a] : "f64x2.trunc",
I8x16AvgrU : [0xfd, 0x7b] : "i8x16.avgr_u",
I16x8ExtAddPairwiseI8x16S : [0xfd, 0x7c] : "i16x8.extadd_pairwise_i8x16_s",
I16x8ExtAddPairwiseI8x16U : [0xfd, 0x7d] : "i16x8.extadd_pairwise_i8x16_u",
I32x4ExtAddPairwiseI16x8S : [0xfd, 0x7e] : "i32x4.extadd_pairwise_i16x8_s",
I32x4ExtAddPairwiseI16x8U : [0xfd, 0x7f] : "i32x4.extadd_pairwise_i16x8_u",
F64x2Eq : [0xfd, 71] : "f64x2.eq",
F64x2Ne : [0xfd, 72] : "f64x2.ne",
F64x2Lt : [0xfd, 73] : "f64x2.lt",
F64x2Gt : [0xfd, 74] : "f64x2.gt",
F64x2Le : [0xfd, 75] : "f64x2.le",
F64x2Ge : [0xfd, 76] : "f64x2.ge",
I16x8Abs : [0xfd, 0x80] : "i16x8.abs",
I16x8Neg : [0xfd, 0x81] : "i16x8.neg",
I16x8Q15MulrSatS : [0xfd, 0x82] : "i16x8.q15mulr_sat_s",
I16x8AllTrue : [0xfd, 0x83] : "i16x8.all_true",
I16x8Bitmask : [0xfd, 0x84] : "i16x8.bitmask",
I16x8NarrowI32x4S : [0xfd, 0x85] : "i16x8.narrow_i32x4_s",
I16x8NarrowI32x4U : [0xfd, 0x86] : "i16x8.narrow_i32x4_u",
I16x8WidenLowI8x16S : [0xfd, 0x87] : "i16x8.widen_low_i8x16_s",
I16x8WidenHighI8x16S : [0xfd, 0x88] : "i16x8.widen_high_i8x16_s",
I16x8WidenLowI8x16U : [0xfd, 0x89] : "i16x8.widen_low_i8x16_u",
I16x8WidenHighI8x16u : [0xfd, 0x8a] : "i16x8.widen_high_i8x16_u",
I16x8Shl : [0xfd, 0x8b] : "i16x8.shl",
I16x8ShrS : [0xfd, 0x8c] : "i16x8.shr_s",
I16x8ShrU : [0xfd, 0x8d] : "i16x8.shr_u",
I16x8Add : [0xfd, 0x8e] : "i16x8.add",
I16x8AddSatS : [0xfd, 0x8f] : "i16x8.add_sat_s",
I16x8AddSatU : [0xfd, 0x90] : "i16x8.add_sat_u",
I16x8Sub : [0xfd, 0x91] : "i16x8.sub",
I16x8SubSatS : [0xfd, 0x92] : "i16x8.sub_sat_s",
I16x8SubSatU : [0xfd, 0x93] : "i16x8.sub_sat_u",
F64x2Nearest : [0xfd, 0x94] : "f64x2.nearest",
I16x8Mul : [0xfd, 0x95] : "i16x8.mul",
I16x8MinS : [0xfd, 0x96] : "i16x8.min_s",
I16x8MinU : [0xfd, 0x97] : "i16x8.min_u",
I16x8MaxS : [0xfd, 0x98] : "i16x8.max_s",
I16x8MaxU : [0xfd, 0x99] : "i16x8.max_u",
I16x8AvgrU : [0xfd, 0x9b] : "i16x8.avgr_u",
I16x8ExtMulLowI8x16S : [0xfd, 0x9c] : "i16x8.extmul_low_i8x16_s",
I16x8ExtMulHighI8x16S : [0xfd, 0x9d] : "i16x8.extmul_high_i8x16_s",
I16x8ExtMulLowI8x16U : [0xfd, 0x9e] : "i16x8.extmul_low_i8x16_u",
I16x8ExtMulHighI8x16U : [0xfd, 0x9f] : "i16x8.extmul_high_i8x16_u",
V128Not : [0xfd, 77] : "v128.not",
V128And : [0xfd, 78] : "v128.and",
V128Andnot : [0xfd, 79] : "v128.andnot",
V128Or : [0xfd, 80] : "v128.or",
V128Xor : [0xfd, 81] : "v128.xor",
V128Bitselect : [0xfd, 82] : "v128.bitselect",
V128AnyTrue : [0xfd, 83] : "v128.any_true",
I32x4Abs : [0xfd, 0xa0] : "i32x4.abs",
I32x4Neg : [0xfd, 0xa1] : "i32x4.neg",
I32x4AllTrue : [0xfd, 0xa3] : "i32x4.all_true",
I32x4Bitmask : [0xfd, 0xa4] : "i32x4.bitmask",
I32x4WidenLowI16x8S : [0xfd, 0xa7] : "i32x4.widen_low_i16x8_s",
I32x4WidenHighI16x8S : [0xfd, 0xa8] : "i32x4.widen_high_i16x8_s",
I32x4WidenLowI16x8U : [0xfd, 0xa9] : "i32x4.widen_low_i16x8_u",
I32x4WidenHighI16x8U : [0xfd, 0xaa] : "i32x4.widen_high_i16x8_u",
I32x4Shl : [0xfd, 0xab] : "i32x4.shl",
I32x4ShrS : [0xfd, 0xac] : "i32x4.shr_s",
I32x4ShrU : [0xfd, 0xad] : "i32x4.shr_u",
I32x4Add : [0xfd, 0xae] : "i32x4.add",
I32x4Sub : [0xfd, 0xb1] : "i32x4.sub",
I32x4Mul : [0xfd, 0xb5] : "i32x4.mul",
I32x4MinS : [0xfd, 0xb6] : "i32x4.min_s",
I32x4MinU : [0xfd, 0xb7] : "i32x4.min_u",
I32x4MaxS : [0xfd, 0xb8] : "i32x4.max_s",
I32x4MaxU : [0xfd, 0xb9] : "i32x4.max_u",
I32x4DotI16x8S : [0xfd, 0xba] : "i32x4.dot_i16x8_s",
I32x4ExtMulLowI16x8S : [0xfd, 0xbc] : "i32x4.extmul_low_i16x8_s",
I32x4ExtMulHighI16x8S : [0xfd, 0xbd] : "i32x4.extmul_high_i16x8_s",
I32x4ExtMulLowI16x8U : [0xfd, 0xbe] : "i32x4.extmul_low_i16x8_u",
I32x4ExtMulHighI16x8U : [0xfd, 0xbf] : "i32x4.extmul_high_i16x8_u",
I8x16Abs : [0xfd, 96] : "i8x16.abs",
I8x16Neg : [0xfd, 97] : "i8x16.neg",
I8x16Popcnt : [0xfd, 98] : "i8x16.popcnt",
I8x16AllTrue : [0xfd, 99] : "i8x16.all_true",
I8x16Bitmask : [0xfd, 100] : "i8x16.bitmask",
I8x16NarrowI16x8S : [0xfd, 101] : "i8x16.narrow_i16x8_s",
I8x16NarrowI16x8U : [0xfd, 102] : "i8x16.narrow_i16x8_u",
I8x16Shl : [0xfd, 107] : "i8x16.shl",
I8x16ShrS : [0xfd, 108] : "i8x16.shr_s",
I8x16ShrU : [0xfd, 109] : "i8x16.shr_u",
I8x16Add : [0xfd, 110] : "i8x16.add",
I8x16AddSatS : [0xfd, 111] : "i8x16.add_sat_s",
I8x16AddSatU : [0xfd, 112] : "i8x16.add_sat_u",
I8x16Sub : [0xfd, 113] : "i8x16.sub",
I8x16SubSatS : [0xfd, 114] : "i8x16.sub_sat_s",
I8x16SubSatU : [0xfd, 115] : "i8x16.sub_sat_u",
I8x16MinS : [0xfd, 118] : "i8x16.min_s",
I8x16MinU : [0xfd, 119] : "i8x16.min_u",
I8x16MaxS : [0xfd, 120] : "i8x16.max_s",
I8x16MaxU : [0xfd, 121] : "i8x16.max_u",
I8x16AvgrU : [0xfd, 123] : "i8x16.avgr_u",
I64x2Abs : [0xfd, 0xc0] : "i64x2.abs",
I64x2Neg : [0xfd, 0xc1] : "i64x2.neg",
I64x2AllTrue : [0xfd, 0xc3] : "i64x2.all_true",
I64x2Bitmask : [0xfd, 0xc4] : "i64x2.bitmask",
I64x2WidenLowI32x4S : [0xfd, 0xc7] : "i64x2.widen_low_i32x4_s",
I64x2WidenHighI32x4S : [0xfd, 0xc8] : "i64x2.widen_high_i32x4_s",
I64x2WidenLowI32x4U : [0xfd, 0xc9] : "i64x2.widen_low_i32x4_u",
I64x2WidenHighI32x4U : [0xfd, 0xca] : "i64x2.widen_high_i32x4_u",
I64x2Shl : [0xfd, 0xcb] : "i64x2.shl",
I64x2ShrS : [0xfd, 0xcc] : "i64x2.shr_s",
I64x2ShrU : [0xfd, 0xcd] : "i64x2.shr_u",
I64x2Add : [0xfd, 0xce] : "i64x2.add",
I64x2Sub : [0xfd, 0xd1] : "i64x2.sub",
I64x2Mul : [0xfd, 0xd5] : "i64x2.mul",
I64x2Eq : [0xfd, 0xd6] : "i64x2.eq",
I64x2Ne : [0xfd, 0xd7] : "i64x2.ne",
I64x2LtS : [0xfd, 0xd8] : "i64x2.lt_s",
I64x2GtS : [0xfd, 0xd9] : "i64x2.gt_s",
I64x2LeS : [0xfd, 0xda] : "i64x2.le_s",
I64x2GeS : [0xfd, 0xdb] : "i64x2.ge_s",
I64x2ExtMulLowI32x4S : [0xfd, 0xdc] : "i64x2.extmul_low_i32x4_s",
I64x2ExtMulHighI32x4S : [0xfd, 0xdd] : "i64x2.extmul_high_i32x4_s",
I64x2ExtMulLowI32x4U : [0xfd, 0xde] : "i64x2.extmul_low_i32x4_u",
I64x2ExtMulHighI32x4U : [0xfd, 0xdf] : "i64x2.extmul_high_i32x4_u",
I16x8ExtAddPairwiseI8x16S : [0xfd, 124] : "i16x8.extadd_pairwise_i8x16_s",
I16x8ExtAddPairwiseI8x16U : [0xfd, 125] : "i16x8.extadd_pairwise_i8x16_u",
I16x8Abs : [0xfd, 128] : "i16x8.abs",
I16x8Neg : [0xfd, 129] : "i16x8.neg",
I16x8Q15MulrSatS : [0xfd, 130] : "i16x8.q15mulr_sat_s",
I16x8AllTrue : [0xfd, 131] : "i16x8.all_true",
I16x8Bitmask : [0xfd, 132] : "i16x8.bitmask",
I16x8NarrowI32x4S : [0xfd, 133] : "i16x8.narrow_i32x4_s",
I16x8NarrowI32x4U : [0xfd, 134] : "i16x8.narrow_i32x4_u",
I16x8ExtendLowI8x16S : [0xfd, 135] : "i16x8.extend_low_i8x16_s",
I16x8ExtendHighI8x16S : [0xfd, 136] : "i16x8.extend_high_i8x16_s",
I16x8ExtendLowI8x16U : [0xfd, 137] : "i16x8.extend_low_i8x16_u",
I16x8ExtendHighI8x16u : [0xfd, 138] : "i16x8.extend_high_i8x16_u",
I16x8Shl : [0xfd, 139] : "i16x8.shl",
I16x8ShrS : [0xfd, 140] : "i16x8.shr_s",
I16x8ShrU : [0xfd, 141] : "i16x8.shr_u",
I16x8Add : [0xfd, 142] : "i16x8.add",
I16x8AddSatS : [0xfd, 143] : "i16x8.add_sat_s",
I16x8AddSatU : [0xfd, 144] : "i16x8.add_sat_u",
I16x8Sub : [0xfd, 145] : "i16x8.sub",
I16x8SubSatS : [0xfd, 146] : "i16x8.sub_sat_s",
I16x8SubSatU : [0xfd, 147] : "i16x8.sub_sat_u",
I16x8Mul : [0xfd, 149] : "i16x8.mul",
I16x8MinS : [0xfd, 150] : "i16x8.min_s",
I16x8MinU : [0xfd, 151] : "i16x8.min_u",
I16x8MaxS : [0xfd, 152] : "i16x8.max_s",
I16x8MaxU : [0xfd, 153] : "i16x8.max_u",
I16x8AvgrU : [0xfd, 155] : "i16x8.avgr_u",
I16x8ExtMulLowI8x16S : [0xfd, 156] : "i16x8.extmul_low_i8x16_s",
I16x8ExtMulHighI8x16S : [0xfd, 157] : "i16x8.extmul_high_i8x16_s",
I16x8ExtMulLowI8x16U : [0xfd, 158] : "i16x8.extmul_low_i8x16_u",
I16x8ExtMulHighI8x16U : [0xfd, 159] : "i16x8.extmul_high_i8x16_u",
F32x4Abs : [0xfd, 0xe0] : "f32x4.abs",
F32x4Neg : [0xfd, 0xe1] : "f32x4.neg",
F32x4Sqrt : [0xfd, 0xe3] : "f32x4.sqrt",
F32x4Add : [0xfd, 0xe4] : "f32x4.add",
F32x4Sub : [0xfd, 0xe5] : "f32x4.sub",
F32x4Mul : [0xfd, 0xe6] : "f32x4.mul",
F32x4Div : [0xfd, 0xe7] : "f32x4.div",
F32x4Min : [0xfd, 0xe8] : "f32x4.min",
F32x4Max : [0xfd, 0xe9] : "f32x4.max",
F32x4PMin : [0xfd, 0xea] : "f32x4.pmin",
F32x4PMax : [0xfd, 0xeb] : "f32x4.pmax",
I32x4ExtAddPairwiseI16x8S : [0xfd, 126] : "i32x4.extadd_pairwise_i16x8_s",
I32x4ExtAddPairwiseI16x8U : [0xfd, 127] : "i32x4.extadd_pairwise_i16x8_u",
I32x4Abs : [0xfd, 160] : "i32x4.abs",
I32x4Neg : [0xfd, 161] : "i32x4.neg",
I32x4AllTrue : [0xfd, 163] : "i32x4.all_true",
I32x4Bitmask : [0xfd, 164] : "i32x4.bitmask",
I32x4ExtendLowI16x8S : [0xfd, 167] : "i32x4.extend_low_i16x8_s",
I32x4ExtendHighI16x8S : [0xfd, 168] : "i32x4.extend_high_i16x8_s",
I32x4ExtendLowI16x8U : [0xfd, 169] : "i32x4.extend_low_i16x8_u",
I32x4ExtendHighI16x8U : [0xfd, 170] : "i32x4.extend_high_i16x8_u",
I32x4Shl : [0xfd, 171] : "i32x4.shl",
I32x4ShrS : [0xfd, 172] : "i32x4.shr_s",
I32x4ShrU : [0xfd, 173] : "i32x4.shr_u",
I32x4Add : [0xfd, 174] : "i32x4.add",
I32x4Sub : [0xfd, 177] : "i32x4.sub",
I32x4Mul : [0xfd, 181] : "i32x4.mul",
I32x4MinS : [0xfd, 182] : "i32x4.min_s",
I32x4MinU : [0xfd, 183] : "i32x4.min_u",
I32x4MaxS : [0xfd, 184] : "i32x4.max_s",
I32x4MaxU : [0xfd, 185] : "i32x4.max_u",
I32x4DotI16x8S : [0xfd, 186] : "i32x4.dot_i16x8_s",
I32x4ExtMulLowI16x8S : [0xfd, 188] : "i32x4.extmul_low_i16x8_s",
I32x4ExtMulHighI16x8S : [0xfd, 189] : "i32x4.extmul_high_i16x8_s",
I32x4ExtMulLowI16x8U : [0xfd, 190] : "i32x4.extmul_low_i16x8_u",
I32x4ExtMulHighI16x8U : [0xfd, 191] : "i32x4.extmul_high_i16x8_u",
F64x2Abs : [0xfd, 0xec] : "f64x2.abs",
F64x2Neg : [0xfd, 0xed] : "f64x2.neg",
F64x2Sqrt : [0xfd, 0xef] : "f64x2.sqrt",
F64x2Add : [0xfd, 0xf0] : "f64x2.add",
F64x2Sub : [0xfd, 0xf1] : "f64x2.sub",
F64x2Mul : [0xfd, 0xf2] : "f64x2.mul",
F64x2Div : [0xfd, 0xf3] : "f64x2.div",
F64x2Min : [0xfd, 0xf4] : "f64x2.min",
F64x2Max : [0xfd, 0xf5] : "f64x2.max",
F64x2PMin : [0xfd, 0xf6] : "f64x2.pmin",
F64x2PMax : [0xfd, 0xf7] : "f64x2.pmax",
I64x2Abs : [0xfd, 192] : "i64x2.abs",
I64x2Neg : [0xfd, 193] : "i64x2.neg",
I64x2AllTrue : [0xfd, 195] : "i64x2.all_true",
I64x2Bitmask : [0xfd, 196] : "i64x2.bitmask",
I64x2ExtendLowI32x4S : [0xfd, 199] : "i64x2.extend_low_i32x4_s",
I64x2ExtendHighI32x4S : [0xfd, 200] : "i64x2.extend_high_i32x4_s",
I64x2ExtendLowI32x4U : [0xfd, 201] : "i64x2.extend_low_i32x4_u",
I64x2ExtendHighI32x4U : [0xfd, 202] : "i64x2.extend_high_i32x4_u",
I64x2Shl : [0xfd, 203] : "i64x2.shl",
I64x2ShrS : [0xfd, 204] : "i64x2.shr_s",
I64x2ShrU : [0xfd, 205] : "i64x2.shr_u",
I64x2Add : [0xfd, 206] : "i64x2.add",
I64x2Sub : [0xfd, 209] : "i64x2.sub",
I64x2Mul : [0xfd, 213] : "i64x2.mul",
I64x2ExtMulLowI32x4S : [0xfd, 220] : "i64x2.extmul_low_i32x4_s",
I64x2ExtMulHighI32x4S : [0xfd, 221] : "i64x2.extmul_high_i32x4_s",
I64x2ExtMulLowI32x4U : [0xfd, 222] : "i64x2.extmul_low_i32x4_u",
I64x2ExtMulHighI32x4U : [0xfd, 223] : "i64x2.extmul_high_i32x4_u",
I32x4TruncSatF32x4S : [0xfd, 0xf8] : "i32x4.trunc_sat_f32x4_s",
I32x4TruncSatF32x4U : [0xfd, 0xf9] : "i32x4.trunc_sat_f32x4_u",
F32x4ConvertI32x4S : [0xfd, 0xfa] : "f32x4.convert_i32x4_s",
F32x4ConvertI32x4U : [0xfd, 0xfb] : "f32x4.convert_i32x4_u",
F32x4Ceil : [0xfd, 103] : "f32x4.ceil",
F32x4Floor : [0xfd, 104] : "f32x4.floor",
F32x4Trunc : [0xfd, 105] : "f32x4.trunc",
F32x4Nearest : [0xfd, 106] : "f32x4.nearest",
F32x4Abs : [0xfd, 224] : "f32x4.abs",
F32x4Neg : [0xfd, 225] : "f32x4.neg",
F32x4Sqrt : [0xfd, 227] : "f32x4.sqrt",
F32x4Add : [0xfd, 228] : "f32x4.add",
F32x4Sub : [0xfd, 229] : "f32x4.sub",
F32x4Mul : [0xfd, 230] : "f32x4.mul",
F32x4Div : [0xfd, 231] : "f32x4.div",
F32x4Min : [0xfd, 232] : "f32x4.min",
F32x4Max : [0xfd, 233] : "f32x4.max",
F32x4PMin : [0xfd, 234] : "f32x4.pmin",
F32x4PMax : [0xfd, 235] : "f32x4.pmax",
I32x4TruncSatF64x2SZero : [0xfd, 0xfc] : "i32x4.trunc_sat_f64x2_s_zero",
I32x4TruncSatF64x2UZero : [0xfd, 0xfd] : "i32x4.trunc_sat_f64x2_u_zero",
F64x2ConvertLowI32x4S : [0xfd, 0xfe] : "f64x2.convert_low_i32x4_s",
F64x2ConvertLowI32x4U : [0xfd, 0xff] : "f64x2.convert_low_i32x4_u",
F64x2Ceil : [0xfd, 116] : "f64x2.ceil",
F64x2Floor : [0xfd, 117] : "f64x2.floor",
F64x2Trunc : [0xfd, 122] : "f64x2.trunc",
F64x2Nearest : [0xfd, 148] : "f64x2.nearest",
F64x2Abs : [0xfd, 236] : "f64x2.abs",
F64x2Neg : [0xfd, 237] : "f64x2.neg",
F64x2Sqrt : [0xfd, 239] : "f64x2.sqrt",
F64x2Add : [0xfd, 240] : "f64x2.add",
F64x2Sub : [0xfd, 241] : "f64x2.sub",
F64x2Mul : [0xfd, 242] : "f64x2.mul",
F64x2Div : [0xfd, 243] : "f64x2.div",
F64x2Min : [0xfd, 244] : "f64x2.min",
F64x2Max : [0xfd, 245] : "f64x2.max",
F64x2PMin : [0xfd, 246] : "f64x2.pmin",
F64x2PMax : [0xfd, 247] : "f64x2.pmax",
I32x4TruncSatF32x4S : [0xfd, 248] : "i32x4.trunc_sat_f32x4_s",
I32x4TruncSatF32x4U : [0xfd, 249] : "i32x4.trunc_sat_f32x4_u",
F32x4ConvertI32x4S : [0xfd, 250] : "f32x4.convert_i32x4_s",
F32x4ConvertI32x4U : [0xfd, 251] : "f32x4.convert_i32x4_u",
I32x4TruncSatF64x2SZero : [0xfd, 252] : "i32x4.trunc_sat_f64x2_s_zero",
I32x4TruncSatF64x2UZero : [0xfd, 253] : "i32x4.trunc_sat_f64x2_u_zero",
F64x2ConvertLowI32x4S : [0xfd, 254] : "f64x2.convert_low_i32x4_s",
F64x2ConvertLowI32x4U : [0xfd, 255] : "f64x2.convert_low_i32x4_u",
F32x4DemoteF64x2Zero : [0xfd, 94] : "f32x4.demote_f64x2_zero",
F64x2PromoteLowF32x4 : [0xfd, 95] : "f64x2.promote_low_f32x4",
// Exception handling proposal
Try(BlockType<'a>) : [0x06] : "try",
@ -1315,14 +1318,14 @@ pub struct LoadOrStoreLane<'a> {
/// The memory argument for this instruction.
pub memarg: MemArg<'a>,
/// The lane argument for this instruction.
pub lane: LaneArg
pub lane: LaneArg,
}
impl<'a> LoadOrStoreLane<'a> {
fn parse(parser: Parser<'a>, default_align: u32) -> Result<Self> {
Ok(LoadOrStoreLane {
memarg: MemArg::parse(parser, default_align)?,
lane: LaneArg::parse(parser)?
lane: LaneArg::parse(parser)?,
})
}
}

View File

@ -89,8 +89,9 @@ impl<'a> Expander<'a> {
}
ModuleField::Elem(e) => {
if let ElemKind::Active { table, .. } = &mut e.kind {
if let ElemKind::Active { table, offset, .. } = &mut e.kind {
self.expand(table);
self.expand_expr(offset);
}
match &mut e.payload {
ElemPayload::Indices(funcs) => {
@ -203,6 +204,10 @@ impl<'a> Expander<'a> {
MemorySize(m) | MemoryGrow(m) | MemoryFill(m) => self.expand(&mut m.mem),
Let(t) => self.expand_type_use(&mut t.block.ty),
Block(bt) | If(bt) | Loop(bt) | Try(bt) => self.expand_type_use(&mut bt.ty),
_ => {}
}
}

View File

@ -759,7 +759,7 @@ impl<'a, 'b> ExprResolver<'a, 'b> {
));
}
Br(i) | BrIf(i) | BrOnNull(i) => {
Br(i) | BrIf(i) | BrOnNull(i) | Delegate(i) => {
self.resolve_label(i)?;
}

View File

@ -99,6 +99,7 @@ fn get_name_section(wasm: &[u8]) -> anyhow::Result<NameSectionReader<'_>> {
name: "name",
data,
data_offset,
range: _,
} = payload?
{
return Ok(NameSectionReader::new(data, data_offset)?);

View File

@ -1 +1 @@
{"files":{"Cargo.toml":"c7339baf9b180c8ab620bd9fc8b896a4d50a56a319378c4ca433fe41a6710718","README.md":"6653a386a2210f0f7e36964f15214bc441e2c723c42867dfe90dfcedcd301814","src/lib.rs":"03652351228b7f7a520f4e7f1e689fa34a37b8e5e0fc8367a167cc893cdbc449"},"package":"474403335b9a90b21120ab8131dd888f0a8d041c2d365ab960feddfe5a73c4b6"}
{"files":{"Cargo.toml":"d7c42a752448eafe3bbd07c9c36af786d035e1dc2853a42793efa4d23f4822bc","README.md":"6653a386a2210f0f7e36964f15214bc441e2c723c42867dfe90dfcedcd301814","src/lib.rs":"b272ee59a5a1b713625cdf4443e5055d888966b9ec78014e01087895e9fc09bc"},"package":"8ec280a739b69173e0ffd12c1658507996836ba4e992ed9bc1e5385a0bd72a02"}

View File

@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "wat"
version = "1.0.35"
version = "1.0.37"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
description = "Rust parser for the WebAssembly Text format, WAT\n"
homepage = "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wat"
@ -22,4 +22,4 @@ readme = "README.md"
license = "Apache-2.0 WITH LLVM-exception"
repository = "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wat"
[dependencies.wast]
version = "34.0.0"
version = "35.0.0"

View File

@ -69,7 +69,7 @@
use std::borrow::Cow;
use std::fmt;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::str;
use wast::parser::{self, ParseBuffer};
@ -103,15 +103,13 @@ fn _parse_file(file: &Path) -> Result<Vec<u8>> {
let contents = std::fs::read(file).map_err(|err| Error {
kind: Box::new(ErrorKind::Io {
err,
msg: format!("failed to read `{}` to a string", file.display()),
file: Some(file.to_owned()),
}),
})?;
match parse_bytes(&contents) {
Ok(bytes) => Ok(bytes.into_owned()),
Err(mut e) => {
if let ErrorKind::Wast(e) = &mut *e.kind {
e.set_path(file);
}
e.set_path(file);
Err(e)
}
}
@ -163,7 +161,10 @@ pub fn parse_bytes(bytes: &[u8]) -> Result<Cow<'_, [u8]>> {
match str::from_utf8(bytes) {
Ok(s) => _parse_str(s).map(|s| s.into()),
Err(_) => Err(Error {
kind: Box::new(ErrorKind::Custom(format!("input bytes aren't valid utf-8"))),
kind: Box::new(ErrorKind::Custom {
msg: "input bytes aren't valid utf-8".to_string(),
file: None,
}),
}),
}
}
@ -240,8 +241,14 @@ pub struct Error {
#[derive(Debug)]
enum ErrorKind {
Wast(wast::Error),
Io { err: std::io::Error, msg: String },
Custom(String),
Io {
err: std::io::Error,
file: Option<PathBuf>,
},
Custom {
msg: String,
file: Option<PathBuf>,
},
}
impl Error {
@ -252,14 +259,38 @@ impl Error {
kind: Box::new(ErrorKind::Wast(err)),
}
}
/// To provide a more useful error this function can be used to set
/// the file name that this error is associated with.
///
/// The `file` here will be stored in this error and later rendered in the
/// `Display` implementation.
pub fn set_path<P: AsRef<Path>>(&mut self, file: P) {
let file = file.as_ref();
match &mut *self.kind {
ErrorKind::Wast(e) => e.set_path(file),
ErrorKind::Custom { file: f, .. } => *f = Some(file.to_owned()),
ErrorKind::Io { file: f, .. } => *f = Some(file.to_owned()),
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &*self.kind {
ErrorKind::Wast(err) => err.fmt(f),
ErrorKind::Custom(err) => err.fmt(f),
ErrorKind::Io { msg, .. } => msg.fmt(f),
ErrorKind::Custom { msg, file, .. } => match file {
Some(file) => {
write!(f, "failed to parse `{}`: {}", file.display(), msg)
}
None => msg.fmt(f),
},
ErrorKind::Io { err, file, .. } => match file {
Some(file) => {
write!(f, "failed to read from `{}`: {}", file.display(), err)
}
None => err.fmt(f),
},
}
}
}
@ -268,8 +299,35 @@ impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match &*self.kind {
ErrorKind::Wast(_) => None,
ErrorKind::Custom(_) => None,
ErrorKind::Custom { .. } => None,
ErrorKind::Io { err, .. } => Some(err),
}
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_set_path() {
let mut e = parse_bytes(&[0xFF]).unwrap_err();
e.set_path("foo");
assert_eq!(
e.to_string(),
"failed to parse `foo`: input bytes aren't valid utf-8"
);
let e = parse_file("_does_not_exist_").unwrap_err();
assert!(e
.to_string()
.starts_with("failed to read from `_does_not_exist_`: "));
let mut e = parse_bytes("()".as_bytes()).unwrap_err();
e.set_path("foo");
assert_eq!(
e.to_string(),
"expected valid module field\n --> foo:1:2\n |\n 1 | ()\n | ^"
);
}
}