Bug 1625660 - Update the wat crate to 1.0.13. r=rhunt

Differential Revision: https://phabricator.services.mozilla.com/D68815

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Lars T Hansen 2020-03-30 16:16:36 +00:00
parent bf84528d4f
commit 1ccbc92228
16 changed files with 174 additions and 193 deletions

8
Cargo.lock generated
View File

@ -4842,18 +4842,18 @@ checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a"
[[package]]
name = "wast"
version = "11.0.0"
version = "12.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df4d67ba9266f4fcaf2e8a1afadc5e2a959e51aecc07b1ecbdf85a6ddaf08bde"
checksum = "0615ba420811bcda39cf80e8a1bd75997aec09222bda35165920a07ef15cc695"
dependencies = [
"leb128",
]
[[package]]
name = "wat"
version = "1.0.12"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a9400dc1c8512087b2d974b1b9b0a6c4e6e26e7e8acf629e3e351165a1ed301"
checksum = "095f615fbfcae695e3a4cea7d9f02f70561c81274c0142f45a12bf1e154d08bd"
dependencies = [
"wast",
]

View File

@ -9,5 +9,5 @@ crate-type = ["rlib"]
name = "wasm_rust"
[dependencies]
wat = { version = "1.0.12" }
wat = { version = "1.0.13" }
wasmparser = { version = "0.48.2" }

View File

@ -1 +1 @@
{"files":{"Cargo.toml":"024dfda3c577aff8df638038afab60592e156745cb30f633e2964ee20c4821db","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"ad8c69458e8f19f6a796d1d791d15f014a045ed11616fe27d987aa37b49599a0","src/ast/assert_expr.rs":"0f6310eccb8a602722a13b2230cfa56dbc470e4c0ba5eb300237a81dc1bfff43","src/ast/custom.rs":"4c926ba719013537696e075c9acd8043da92a833cd28b0d843abcbfb71080fc3","src/ast/event.rs":"18f5106a87635d50b5f3b13fedd08247d3eb8158df454790151acadd41d1e0ab","src/ast/export.rs":"f296bd3238c7f9886f626d619d3a41ff0797bd51cb7bec7053278a62d8cb5355","src/ast/expr.rs":"c8ef762bbea3135d8f6a1d652d1d55ef97bfa03c9bda4a28dfedeb1d2bd84741","src/ast/func.rs":"149d947957414548b65739212a2cf1362f0ec9ecdda517653ae83949aa8a89f5","src/ast/gc.rs":"90049f183f359158e6664e7a038ee50082b2e7935450a799f9edce0d4e6a828c","src/ast/global.rs":"41b617886012277e7377600047611b78564c2c594d8c0792de1509b89676244f","src/ast/import.rs":"53f39569b8486cd5fde6b3a826bc7dc221fc925afa043e45a0a1550987332ba7","src/ast/memory.rs":"836135f8f5a7bffa90ddaad1a862b9133d9c0e680b63736daa3e2377c23cb785","src/ast/mod.rs":"f6cf3886ca07283a4f38b2524d00d46d96b55327c8c6d9dd1e2e30a2d9acaad5","src/ast/module.rs":"9f34d3d945c71fef57bb38d5ec129d2fd5787b95bbffff76cc58a724f3e70aed","src/ast/table.rs":"74e9a0588515dd039c76e8e775470ee752607f06ece3e05c7d6a4141adfb89ea","src/ast/token.rs":"0bceed5587ca46d7c5c6865fb04e2afc0eba05d503bc9055840ce7d88456a8b4","src/ast/types.rs":"12261956028dade22d921737cd90165d885bfc00d8a01d841486b511611e281e","src/ast/wast.rs":"e2a69b8fd2ff84f7f69934d1e4c7651645efd8d90d5a3ee4762576f5d5dfee29","src/binary.rs":"23fc7334a9daec9747aa88eddfeca12af99ef8f3093cafba1f09152d2e319cc8","src/lexer.rs":"1e62516a22ca89aa9510d255c264a27776a86c831b4c22a1fd00d20272e7b96c","src/lib.rs":"5fc7614c3d4a89f5fcac328d4a82cecaa445e0620bdf6bd55308cb1ead73d297","src/parser.rs":"eb0a681be02f27e1ecda97f4d8a2a0336e23be9d30a1d66a36d226ef019a4c58","src/resolve/expand.rs":"f7ecf82bb00d7c770f78f5582ec5427c25189ff11943c052572ffab2f996b12c","src/resolve/mod.rs":"916ce2c88f633e36609767f3bccfabef4438586e98475cc8f0e4cbea5d2caaf4","src/resolve/names.rs":"82b990dab9c8f58f5e20ccff1d03a90e848727b3a33b1ad1434c43c5dc06869d","src/resolve/tyexpand.rs":"69701f2fc566fd5da4b253643a91e3048dd3c41795d5fed6ac94a386ec01947a"},"package":"df4d67ba9266f4fcaf2e8a1afadc5e2a959e51aecc07b1ecbdf85a6ddaf08bde"}
{"files":{"Cargo.toml":"2fcd4e5b104f6cd5f0d5aa528d37f95cf787004b836acae5be5858938e6d629f","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"ad8c69458e8f19f6a796d1d791d15f014a045ed11616fe27d987aa37b49599a0","src/ast/assert_expr.rs":"0f6310eccb8a602722a13b2230cfa56dbc470e4c0ba5eb300237a81dc1bfff43","src/ast/custom.rs":"4c926ba719013537696e075c9acd8043da92a833cd28b0d843abcbfb71080fc3","src/ast/event.rs":"18f5106a87635d50b5f3b13fedd08247d3eb8158df454790151acadd41d1e0ab","src/ast/export.rs":"f296bd3238c7f9886f626d619d3a41ff0797bd51cb7bec7053278a62d8cb5355","src/ast/expr.rs":"d83bb97f2588c6086e34d0aa060e99a528fdda0ca9c7aa83c6fa2a7125b8b8e9","src/ast/func.rs":"149d947957414548b65739212a2cf1362f0ec9ecdda517653ae83949aa8a89f5","src/ast/gc.rs":"90049f183f359158e6664e7a038ee50082b2e7935450a799f9edce0d4e6a828c","src/ast/global.rs":"41b617886012277e7377600047611b78564c2c594d8c0792de1509b89676244f","src/ast/import.rs":"53f39569b8486cd5fde6b3a826bc7dc221fc925afa043e45a0a1550987332ba7","src/ast/memory.rs":"836135f8f5a7bffa90ddaad1a862b9133d9c0e680b63736daa3e2377c23cb785","src/ast/mod.rs":"f6cf3886ca07283a4f38b2524d00d46d96b55327c8c6d9dd1e2e30a2d9acaad5","src/ast/module.rs":"65abd96046703915c84fee8b6d5bd6e2782450f59582ba08939660fc8df5de2e","src/ast/table.rs":"74e9a0588515dd039c76e8e775470ee752607f06ece3e05c7d6a4141adfb89ea","src/ast/token.rs":"cdaaa6f50a9868ed7d0ec7088447ba94e3df5c81d38bc471c55d0968c249f73c","src/ast/types.rs":"12261956028dade22d921737cd90165d885bfc00d8a01d841486b511611e281e","src/ast/wast.rs":"9e64d00baf809d09181a06073a3fa9ac5907ac8248336cfd2089735d017075e3","src/binary.rs":"becf5819190a2411dbe01caa4a646a76c0a6db5e0c4bc8f3029cbb6bd9434914","src/lexer.rs":"1e62516a22ca89aa9510d255c264a27776a86c831b4c22a1fd00d20272e7b96c","src/lib.rs":"5fc7614c3d4a89f5fcac328d4a82cecaa445e0620bdf6bd55308cb1ead73d297","src/parser.rs":"f62dc8251809b395820cd511071e864bf2748db60b37b16ec0d130a17ead7d5d","src/resolve/expand.rs":"f7ecf82bb00d7c770f78f5582ec5427c25189ff11943c052572ffab2f996b12c","src/resolve/mod.rs":"916ce2c88f633e36609767f3bccfabef4438586e98475cc8f0e4cbea5d2caaf4","src/resolve/names.rs":"cf7eeabe4ae525d387292f48184e4a28a1b6e3d9732ab35627a034f159b29cc5","src/resolve/tyexpand.rs":"69701f2fc566fd5da4b253643a91e3048dd3c41795d5fed6ac94a386ec01947a"},"package":"0615ba420811bcda39cf80e8a1bd75997aec09222bda35165920a07ef15cc695"}

View File

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

View File

@ -837,6 +837,10 @@ instructions! {
I8x16AvgrU : [0xfd, 0xd9] : "i8x16.avgr_u",
I16x8AvgrU : [0xfd, 0xda] : "i16x8.avgr_u",
I8x16Abs : [0xfd, 0xe1] : "i8x16.abs",
I16x8Abs : [0xfd, 0xe2] : "i16x8.abs",
I32x4Abs : [0xfd, 0xe3] : "i32x4.abs",
Try(BlockType<'a>) : [0x06] : "try",
Catch : [0x07] : "catch",
Throw(ast::Index<'a>) : [0x08] : "throw",

View File

@ -15,12 +15,12 @@ pub struct Wat<'a> {
impl<'a> Parse<'a> for Wat<'a> {
fn parse(parser: Parser<'a>) -> Result<Self> {
if !parser.has_tokens() {
return Err(parser.error("expected at least one module field"));
}
let _r = parser.register_annotation("custom");
let module = if !parser.peek2::<kw::module>() {
let fields = ModuleField::parse_remaining(parser)?;
if fields.is_empty() {
return Err(parser.error("expected at least one module field"));
}
Module {
span: ast::Span { offset: 0 },
id: None,

View File

@ -1,12 +1,12 @@
use crate::ast::annotation;
use crate::lexer::FloatVal;
use crate::parser::{Cursor, Parse, Parser, Peek, Result};
use std::fmt;
use std::hash::{Hash, Hasher};
use std::str;
use crate::ast::annotation;
/// A position in the original source stream, used to render errors.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct Span {
pub(crate) offset: usize,
}
@ -235,7 +235,7 @@ impl Peek for &'_ [u8] {
impl<'a> Parse<'a> for &'a str {
fn parse(parser: Parser<'a>) -> Result<Self> {
str::from_utf8(parser.parse()?).map_err(|_| parser.error("invalid UTF-8 encoding"))
str::from_utf8(parser.parse()?).map_err(|_| parser.error("malformed UTF-8 encoding"))
}
}

View File

@ -53,6 +53,10 @@ impl Peek for WastDirectiveToken {
#[allow(missing_docs)]
pub enum WastDirective<'a> {
Module(ast::Module<'a>),
QuoteModule {
span: ast::Span,
source: Vec<&'a [u8]>,
},
AssertMalformed {
span: ast::Span,
module: QuoteModule<'a>,
@ -98,6 +102,7 @@ impl WastDirective<'_> {
WastDirective::Module(m) => m.span,
WastDirective::AssertMalformed { span, .. }
| WastDirective::Register { span, .. }
| WastDirective::QuoteModule{ span, .. }
| WastDirective::AssertTrap { span, .. }
| WastDirective::AssertReturn { span, .. }
| WastDirective::AssertExhaustion { span, .. }
@ -112,7 +117,17 @@ impl<'a> Parse<'a> for WastDirective<'a> {
fn parse(parser: Parser<'a>) -> Result<Self> {
let mut l = parser.lookahead1();
if l.peek::<kw::module>() {
Ok(WastDirective::Module(parser.parse()?))
if parser.peek2::<kw::quote>() {
parser.parse::<kw::module>()?;
let span = parser.parse::<kw::quote>()?.0;
let mut source = Vec::new();
while !parser.is_empty() {
source.push(parser.parse()?);
}
Ok(WastDirective::QuoteModule { span, source })
} else {
Ok(WastDirective::Module(parser.parse()?))
}
} else if l.peek::<kw::assert_malformed>() {
let span = parser.parse::<kw::assert_malformed>()?.0;
Ok(WastDirective::AssertMalformed {
@ -296,7 +311,7 @@ impl<'a> Parse<'a> for WastInvoke<'a> {
#[allow(missing_docs)]
pub enum QuoteModule<'a> {
Module(ast::Module<'a>),
Quote(Vec<&'a str>),
Quote(Vec<&'a [u8]>),
}
impl<'a> Parse<'a> for QuoteModule<'a> {

View File

@ -60,8 +60,8 @@ pub fn encode(module: &Module<'_>) -> Vec<u8> {
e.section_list(3, Func, &functys);
e.section_list(4, Table, &tables);
e.section_list(5, Memory, &memories);
e.section_list(6, Global, &globals);
e.section_list(13, Event, &events);
e.section_list(6, Global, &globals);
e.section_list(7, Export, &exports);
e.custom_sections(Before(Start));
if let Some(start) = start.get(0) {

View File

@ -329,17 +329,76 @@ impl ParseBuffer<'_> {
for token in Lexer::new(input) {
tokens.push((token?, Cell::new(NextTokenAt::Unknown)));
}
Ok(ParseBuffer {
let ret = ParseBuffer {
tokens: tokens.into_boxed_slice(),
cur: Cell::new(0),
input,
known_annotations: Default::default(),
})
};
ret.validate_annotations()?;
Ok(ret)
}
fn parser(&self) -> Parser<'_> {
Parser { buf: self }
}
// Validates that all annotations properly parse in that they have balanced
// delimiters. This is required since while parsing we generally skip
// annotations and there's no real opportunity to return a parse error.
fn validate_annotations(&self) -> Result<()> {
use crate::lexer::Source::*;
use crate::lexer::Token::*;
enum State {
None,
LParen,
Annotation { depth: usize, span: Span },
}
let mut state = State::None;
for token in self.tokens.iter() {
state = match (&token.0, state) {
// From nothing, a `(` starts the search for an annotation
(Token(LParen(_)), State::None) => State::LParen,
// ... otherwise in nothing we alwyas preserve that state.
(_, State::None) => State::None,
// If the previous state was an `LParen`, we may have an
// annotation if the next keyword is reserved
(Token(Reserved(s)), State::LParen) if s.starts_with("@") && s.len() > 0 => {
let offset = self.input_pos(s);
State::Annotation {
span: Span { offset },
depth: 1,
}
}
// ... otherwise anything after an `LParen` kills the lparen
// state.
(_, State::LParen) => State::None,
// Once we're in an annotation we need to balance parentheses,
// so handle the depth changes.
(Token(LParen(_)), State::Annotation { span, depth }) => State::Annotation {
span,
depth: depth + 1,
},
(Token(RParen(_)), State::Annotation { depth: 1, .. }) => State::None,
(Token(RParen(_)), State::Annotation { span, depth }) => State::Annotation {
span,
depth: depth - 1,
},
// ... and otherwise all tokens are allowed in annotations.
(_, s @ State::Annotation { .. }) => s,
};
}
if let State::Annotation { span, .. } = state {
return Err(Error::new(span, format!("unclosed annotation")));
}
Ok(())
}
fn input_pos(&self, src: &str) -> usize {
src.as_ptr() as usize - self.input.as_ptr() as usize
}
}
impl<'a> Parser<'a> {
@ -359,6 +418,11 @@ impl<'a> Parser<'a> {
}
}
pub(crate) fn has_tokens(self) -> bool {
let cursor = self.cursor();
cursor.cur < self.buf.tokens.len()
}
/// Parses a `T` from this [`Parser`].
///
/// This method has a trivial definition (it simply calls
@ -635,10 +699,6 @@ impl<'a> Parser<'a> {
Error::parse(span, self.buf.input, msg.to_string())
}
fn input_pos(self, src: &'a str) -> usize {
src.as_ptr() as usize - self.buf.input.as_ptr() as usize
}
/// Returns the span of the current token
pub fn cur_span(&self) -> Span {
self.cursor().cur_span()
@ -802,7 +862,7 @@ impl<'a> Cursor<'a> {
/// Does not take into account whitespace or comments.
pub fn cur_span(&self) -> Span {
let offset = match self.clone().advance_token() {
Some(t) => self.parser.input_pos(t.src()),
Some(t) => self.parser.buf.input_pos(t.src()),
None => self.parser.buf.input.len(),
};
Span { offset }

View File

@ -341,7 +341,7 @@ impl<'a> Namespace<'a> {
if desc != "elem" && desc != "data" {
return Err(Error::new(
name.span(),
format!("duplicate identifier for {}", desc),
format!("duplicate {} identifier", desc),
));
}
}

File diff suppressed because one or more lines are too long

6
third_party/rust/wat/Cargo.lock generated vendored
View File

@ -323,16 +323,16 @@ checksum = "a40d24f114a3f24b459ec292019220cff6388673b4a2c0a11483665b599ef15c"
[[package]]
name = "wast"
version = "11.0.0"
version = "12.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df4d67ba9266f4fcaf2e8a1afadc5e2a959e51aecc07b1ecbdf85a6ddaf08bde"
checksum = "0615ba420811bcda39cf80e8a1bd75997aec09222bda35165920a07ef15cc695"
dependencies = [
"leb128",
]
[[package]]
name = "wat"
version = "1.0.12"
version = "1.0.13"
dependencies = [
"anyhow",
"getopts",

View File

@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "wat"
version = "1.0.12"
version = "1.0.13"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
exclude = ["tests/wabt", "tests/testsuite"]
description = "Rust parser for the WebAssembly Text format, WAT\n"
@ -35,7 +35,7 @@ harness = false
name = "parse-fail"
harness = false
[dependencies.wast]
version = "11.0.0"
version = "12.0.0"
[dev-dependencies.anyhow]
version = "1.0"

View File

@ -1,147 +0,0 @@
(@a)
(@aas-3!@$d-@#4)
(@@) (@$) (@+) (@0) (@.) (@!$@#$23414@#$)
(@a x y z)
(@a x-y $yz "aa" -2 0.3 0x3)
(@a x-y$yz"aa"-2)
(@a block func module i32.add)
(@a 0x 8q 0xfa #4g0-.@f#^&@#$*0sf -- @#)
(@a , ; ] [ }} }x{ ({) ,{{};}] ;)
(@a (bla) () (5-g) ("aa" a) ($x) (bla bla) (x (y)) ")" "(" x")"y)
(@a @ @x (@x) (@x y) (@) (@ x) (@(@(@(@)))))
(@a (;bla;) (; ) ;)
;; bla)
;; bla (@x
)
(assert_malformed (module quote "( @a)") "unknown operator")
(assert_malformed (module quote "(@)") "malformed annotation id")
(assert_malformed (module quote "(@ )") "malformed annotation id")
(assert_malformed (module quote "(@ x)") "malformed annotation id")
(assert_malformed (module quote "(@(@a)x)") "malformed annotation id")
(assert_malformed (module quote "(@x ") "unclosed annotation")
(assert_malformed (module quote "(@x ()") "unclosed annotation")
(assert_malformed (module quote "(@x (y (z))") "unclosed annotation")
(assert_malformed (module quote "(@x (@y )") "unclosed annotation")
(assert_malformed (module quote "(@x))") "unexpected token")
(assert_malformed (module quote "(@x ()))") "unexpected token")
(assert_malformed (module quote "(@x (y (z))))") "unexpected token")
(assert_malformed (module quote "(@x (@y )))") "unexpected token")
(assert_malformed (module quote "(@x \"") "unclosed string")
(assert_malformed (module quote "(@x \")") "unclosed string")
(assert_malformed (module quote "((@a)@b)") "unknown operator")
(assert_malformed (module quote "(func $(@a))") "unknown operator")
(assert_malformed (module quote "(func $(@a)f)") "unknown operator")
((@a) module (@a) $m (@a) (@a)
((@a) import (@a) "spectest" (@a) "global_i32" (@a)
((@a) global (@a) $g (@a) i32 (@a)) (@a)
) (@a)
((@a) import (@a) "spectest" (@a) "table" (@a)
((@a) table (@a) $t (@a) 10 (@a) 20 (@a) funcref (@a)) (@a)
) (@a)
((@a) import (@a) "spectest" (@a) "memory" (@a)
((@a) memory (@a) $m (@a) 1 (@a) 2 (@a)) (@a)
) (@a)
((@a) import (@a) "spectest" (@a) "print_i32_f32" (@a)
((@a) func (@a) $f (@a)
((@a) param (@a) i32 (@a) f32 (@a)) (@a)
((@a) result (@a)) (@a)
) (@a)
) (@a)
((@a) export (@a) "g" (@a)
((@a) global (@a) $g (@a)) (@a)
) (@a)
((@a) export (@a) "t" (@a)
((@a) table (@a) $t (@a)) (@a)
) (@a)
((@a) export (@a) "m" (@a)
((@a) memory (@a) $m (@a)) (@a)
) (@a)
((@a) export (@a) "f" (@a)
((@a) func (@a) $f (@a)) (@a)
) (@a)
) (@a)
((@a) module (@a) $m (@a) (@a)
((@a) global (@a) $g (@a)
((@a) export (@a) "g" (@a)) (@a)
((@a) import (@a) "spectest" (@a) "global_i32" (@a)) (@a)
i32 (@a)
) (@a)
((@a) table (@a) $t (@a)
((@a) export (@a) "t" (@a)) (@a)
((@a) import (@a) "spectest" (@a) "table" (@a)) (@a)
10 (@a) 20 (@a)
funcref (@a)
) (@a)
((@a) memory (@a) $m (@a)
((@a) export (@a) "m" (@a)) (@a)
((@a) import (@a) "spectest" (@a) "memory" (@a)) (@a)
1 (@a) 2 (@a)
) (@a)
((@a) func (@a) $f (@a)
((@a) export (@a) "f" (@a)) (@a)
((@a) import (@a) "spectest" (@a) "print_i32_f32" (@a)) (@a)
((@a) param (@a) i32 (@a) f32 (@a)) (@a)
((@a) result (@a)) (@a)
) (@a)
) (@a)
((@a) module (@a) $m (@a) (@a)
((@a) type (@a) $T (@a)
((@a) func (@a)
((@a) param (@a) i32 (@a) i64 (@a)) (@a)
((@a) param (@a) $x (@a) i32 (@a)) (@a)
((@a) result (@a) i32 (@a)) (@a)
) (@a)
) (@a)
((@a) global (@a) $g (@a)
((@a) export (@a) "g" (@a)) (@a)
i32 (@a)
((@a) i32.const (@a) 42 (@a)) (@a)
) (@a)
((@a) table (@a) $t (@a)
((@a) export (@a) "t" (@a)) (@a)
10 (@a) 20 (@a)
funcref (@a)
) (@a)
((@a) memory (@a) $m (@a)
((@a) export (@a) "m" (@a)) (@a)
1 (@a) 2 (@a)
) (@a)
((@a) func (@a) $f (@a)
((@a) export (@a) "f" (@a)) (@a)
((@a) param (@a) i32 (@a) i64 (@a)) (@a)
((@a) param (@a) $x (@a) i32 (@a)) (@a)
((@a) result (@a) i32 (@a)) (@a)
((@a) local (@a) i32 (@a) i32 (@a)) (@a)
((@a) local (@a) $y (@a) i32 (@a)) (@a)
((@a) block (@a)
((@a) result (@a) i32 (@a)) (@a)
((@a) i32.add (@a)
((@a) local.get (@a) $x (@a)) (@a)
((@a) local.get (@a) 0 (@a)) (@a)
)
)
) (@a)
((@a) elem (@a)
((@a) offset (@a) ((@a) i32.const (@a) 0 (@a)) (@a)) (@a)
$f (@a) $f (@a) (@a) $f (@a)
) (@a)
((@a) data (@a)
((@a) offset (@a) ((@a) i32.const (@a) 0 (@a)) (@a)) (@a)
"bla" (@a) "\43" (@a) (@a) "" (@a)
) (@a)
(func $s)
((@a) start (@a) $s (@a)) (@a)
) (@a)

View File

@ -12,6 +12,7 @@ use rayon::prelude::*;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str;
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
use wast::parser::ParseBuffer;
use wast::*;
@ -138,23 +139,25 @@ fn test_wast(test: &Path, contents: &str, ntests: &AtomicUsize) -> anyhow::Resul
}
}
WastDirective::QuoteModule { source, span } => {
if let Err(e) = parse_quote_module(span, &source) {
let (line, col) = span.linecol_in(&contents);
anyhow::bail!(
"in test {}:{}:{} parsed with\nerror: {}",
test.display(),
line + 1,
col + 1,
e,
);
}
}
WastDirective::AssertMalformed {
span,
module: QuoteModule::Quote(source),
message,
} => {
let source = source.join(" ");
let result = ParseBuffer::new(&source)
.map_err(|e| e.into())
.and_then(|b| -> Result<(), wast::Error> {
let mut wat = parser::parse::<Wat>(&b)?;
wat.module.encode()?;
Ok(())
})
.map_err(|mut e| {
e.set_text(&source);
e
});
let result = parse_quote_module(span, &source);
let (line, col) = span.linecol_in(&contents);
match result {
Ok(()) => anyhow::bail!(
@ -208,6 +211,26 @@ fn test_wast(test: &Path, contents: &str, ntests: &AtomicUsize) -> anyhow::Resul
anyhow::bail!("{}", s)
}
fn parse_quote_module(span: Span, source: &[&[u8]]) -> Result<(), wast::Error> {
let mut ret = String::new();
for src in source {
match str::from_utf8(src) {
Ok(s) => ret.push_str(s),
Err(_) => {
return Err(wast::Error::new(
span,
"malformed UTF-8 encoding".to_string(),
))
}
}
ret.push_str(" ");
}
let buf = ParseBuffer::new(&ret)?;
let mut wat = parser::parse::<Wat>(&buf)?;
wat.module.encode()?;
Ok(())
}
fn error_matches(error: &str, message: &str) -> bool {
if error.contains(message) {
return true;
@ -223,13 +246,27 @@ fn error_matches(error: &str, message: &str) -> bool {
|| message == "malformed annotation id"
|| message == "alignment must be a power of two"
{
return error.contains("expected ") || error.contains("constant out of range");
return error.contains("expected ")
|| error.contains("constant out of range")
|| error.contains("extra tokens remaining");
}
if message == "illegal character" {
return error.contains("unexpected character");
}
if message == "unclosed string" {
return error.contains("unexpected end-of-file");
}
if message == "invalid UTF-8 encoding" {
return error.contains("malformed UTF-8 encoding");
}
if message == "duplicate identifier" {
return error.contains("duplicate") && error.contains("identifier");
}
return false;
}
@ -249,6 +286,7 @@ fn find_tests() -> Vec<PathBuf> {
find_tests("tests/regression".as_ref(), &mut tests);
find_tests("tests/testsuite".as_ref(), &mut tests);
tests.sort();
return tests;
fn find_tests(path: &Path, tests: &mut Vec<PathBuf>) {
@ -454,9 +492,20 @@ fn skip_test(test: &Path, contents: &str) -> bool {
return true;
}
// Waiting for https://github.com/WebAssembly/annotations/pull/7 to make its
// way into the testsuite repo.
if test.ends_with("testsuite/proposals/annotations/annotations.wast") {
// Currently wabt's implemented syntax is slightly different from ours
if contents.contains("--enable-gc") {
return true;
}
// Waiting for wabt to recognize the integer abs simd opcodes; they have been added
// upstream in the spec test suite, https://github.com/WebAssembly/simd/pull/197,
// but need to be pulled, filed https://github.com/WebAssembly/wabt/issues/1379.
if test.ends_with("wabt/third_party/testsuite/proposals/simd/simd_f32x4.wast") {
return true;
}
// wait for wabt to catch up on the annotations spec test
if test.ends_with("wabt/third_party/testsuite/proposals/annotations/annotations.wast") {
return true;
}