Merge pull request #1692 from fitzgen/update-to-wasmparser-0.55.0

Update to using `wasmparser` 0.55.0
This commit is contained in:
Nick Fitzgerald
2020-05-14 14:00:24 -07:00
committed by GitHub
26 changed files with 155 additions and 183 deletions

View File

@@ -36,7 +36,7 @@ log = "0.4.8"
serde = "1.0.8"
term = "0.6.1"
capstone = { version = "0.6.0", optional = true }
wat = { version = "1.0.7", optional = true }
wat = { version = "1.0.18", optional = true }
target-lexicon = "0.10"
pretty_env_logger = "0.4.0"
file-per-thread-logger = "0.1.2"

View File

@@ -8,12 +8,12 @@ repository = "https://github.com/bytecodealliance/wasmtime"
readme = "README.md"
edition = "2018"
[package.metadata.docs.rs]
rustdoc-args = [ "--document-private-items" ]
[dependencies]
cranelift-codegen-shared = { path = "../shared", version = "0.63.0" }
cranelift-entity = { path = "../../entity", version = "0.63.0" }
[badges]
maintenance = { status = "experimental" }
[package.metadata.docs.rs]
rustdoc-args = [ "--document-private-items" ]

View File

@@ -12,7 +12,7 @@ keywords = ["webassembly", "wasm"]
edition = "2018"
[dependencies]
wasmparser = { version = "0.52.0", default-features = false }
wasmparser = { version = "0.55.0", default-features = false }
cranelift-codegen = { path = "../codegen", version = "0.63.0", default-features = false }
cranelift-entity = { path = "../entity", version = "0.63.0" }
cranelift-frontend = { path = "../frontend", version = "0.63.0", default-features = false }
@@ -22,7 +22,7 @@ serde = { version = "1.0.94", features = ["derive"], optional = true }
thiserror = "1.0.4"
[dev-dependencies]
wat = "1.0.9"
wat = "1.0.18"
target-lexicon = "0.10"
# Enable the riscv feature for cranelift-codegen, as some tests require it
cranelift-codegen = { path = "../codegen", version = "0.63.0", default-features = false, features = ["riscv"] }

View File

@@ -1035,8 +1035,8 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
Operator::F32Le | Operator::F64Le => {
translate_fcmp(FloatCC::LessThanOrEqual, builder, state)
}
Operator::RefNull => state.push1(builder.ins().null(environ.reference_type())),
Operator::RefIsNull => {
Operator::RefNull { ty: _ } => state.push1(builder.ins().null(environ.reference_type())),
Operator::RefIsNull { ty: _ } => {
let arg = state.pop1();
let val = builder.ins().is_null(arg);
let val_int = builder.ins().bint(I32, val);
@@ -1435,18 +1435,12 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
// operands must match (hence the bitcast).
state.push1(builder.ins().bitselect(bitcast_c, bitcast_a, bitcast_b))
}
Operator::I8x16AnyTrue
| Operator::I16x8AnyTrue
| Operator::I32x4AnyTrue
| Operator::I64x2AnyTrue => {
Operator::I8x16AnyTrue | Operator::I16x8AnyTrue | Operator::I32x4AnyTrue => {
let a = pop1_with_bitcast(state, type_of(op), builder);
let bool_result = builder.ins().vany_true(a);
state.push1(builder.ins().bint(I32, bool_result))
}
Operator::I8x16AllTrue
| Operator::I16x8AllTrue
| Operator::I32x4AllTrue
| Operator::I64x2AllTrue => {
Operator::I8x16AllTrue | Operator::I16x8AllTrue | Operator::I32x4AllTrue => {
let a = pop1_with_bitcast(state, type_of(op), builder);
let bool_result = builder.ins().vall_true(a);
state.push1(builder.ins().bint(I32, bool_result))
@@ -1542,15 +1536,13 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let a = pop1_with_bitcast(state, I32X4, builder);
state.push1(builder.ins().fcvt_from_sint(F32X4, a))
}
Operator::I8x16Mul
| Operator::I64x2Mul
Operator::I64x2Mul
| Operator::I32x4TruncSatF32x4S
| Operator::I32x4TruncSatF32x4U
| Operator::I64x2TruncSatF64x2S
| Operator::I64x2TruncSatF64x2U
| Operator::F32x4ConvertI32x4U
| Operator::F64x2ConvertI64x2S
| Operator::F64x2ConvertI64x2U { .. }
| Operator::I8x16Abs
| Operator::I16x8Abs
| Operator::I32x4Abs
| Operator::I8x16NarrowI16x8S { .. }
| Operator::I8x16NarrowI16x8U { .. }
| Operator::I16x8NarrowI32x4S { .. }
@@ -1990,8 +1982,7 @@ fn type_of(operator: &Operator) -> Type {
| Operator::I8x16MinU
| Operator::I8x16MaxS
| Operator::I8x16MaxU
| Operator::I8x16RoundingAverageU
| Operator::I8x16Mul => I8X16,
| Operator::I8x16RoundingAverageU => I8X16,
Operator::I16x8Splat
| Operator::V16x8LoadSplat { .. }
@@ -2062,15 +2053,11 @@ fn type_of(operator: &Operator) -> Type {
| Operator::I64x2ExtractLane { .. }
| Operator::I64x2ReplaceLane { .. }
| Operator::I64x2Neg
| Operator::I64x2AnyTrue
| Operator::I64x2AllTrue
| Operator::I64x2Shl
| Operator::I64x2ShrS
| Operator::I64x2ShrU
| Operator::I64x2Add
| Operator::I64x2Sub
| Operator::F64x2ConvertI64x2S
| Operator::F64x2ConvertI64x2U => I64X2,
| Operator::I64x2Sub => I64X2,
Operator::F32x4Splat
| Operator::F32x4ExtractLane { .. }
@@ -2110,9 +2097,7 @@ fn type_of(operator: &Operator) -> Type {
| Operator::F64x2Mul
| Operator::F64x2Div
| Operator::F64x2Min
| Operator::F64x2Max
| Operator::I64x2TruncSatF64x2S
| Operator::I64x2TruncSatF64x2U => F64X2,
| Operator::F64x2Max => F64X2,
_ => unimplemented!(
"Currently only SIMD instructions are mapped to their return type; the \

View File

@@ -196,9 +196,8 @@ fn declare_locals<FE: FuncEnvironment + ?Sized>(
let constant_handle = builder.func.dfg.constants.insert([0; 16].to_vec().into());
builder.ins().vconst(ir::types::I8X16, constant_handle)
}
NullRef => builder.ins().null(environ.reference_type()),
AnyRef => builder.ins().null(environ.reference_type()),
AnyFunc => builder.ins().null(environ.reference_type()),
ExternRef => builder.ins().null(environ.reference_type()),
FuncRef => builder.ins().null(environ.reference_type()),
ty => return Err(wasm_unsupported!("unsupported local type {:?}", ty)),
};

View File

@@ -224,7 +224,7 @@ pub fn parse_global_section(
Operator::V128Const { value } => {
GlobalInit::V128Const(V128Imm::from(value.bytes().to_vec().as_slice()))
}
Operator::RefNull => GlobalInit::RefNullConst,
Operator::RefNull { ty: _ } => GlobalInit::RefNullConst,
Operator::RefFunc { function_index } => {
GlobalInit::RefFunc(FuncIndex::from_u32(function_index))
}
@@ -294,7 +294,7 @@ fn read_elems(items: &ElementItems) -> WasmResult<Box<[FuncIndex]>> {
let mut elems = Vec::with_capacity(usize::try_from(items_reader.get_count()).unwrap());
for item in items_reader {
let elem = match item? {
ElementItem::Null => FuncIndex::reserved_value(),
ElementItem::Null(_ty) => FuncIndex::reserved_value(),
ElementItem::Func(index) => FuncIndex::from_u32(index),
};
elems.push(elem);
@@ -311,7 +311,7 @@ pub fn parse_element_section<'data>(
for (index, entry) in elements.into_iter().enumerate() {
let Element { kind, items, ty } = entry?;
if ty != Type::AnyFunc {
if ty != Type::FuncRef {
return Err(wasm_unsupported!(
"unsupported table element type: {:?}",
ty

View File

@@ -143,9 +143,7 @@ pub fn type_to_type<PE: TargetEnvironment + ?Sized>(
wasmparser::Type::F32 => Ok(ir::types::F32),
wasmparser::Type::F64 => Ok(ir::types::F64),
wasmparser::Type::V128 => Ok(ir::types::I8X16),
wasmparser::Type::AnyRef | wasmparser::Type::AnyFunc | wasmparser::Type::NullRef => {
Ok(environ.reference_type())
}
wasmparser::Type::ExternRef | wasmparser::Type::FuncRef => Ok(environ.reference_type()),
ty => Err(wasm_unsupported!("type_to_type: wasm type {:?}", ty)),
}
}
@@ -162,8 +160,8 @@ pub fn tabletype_to_type<PE: TargetEnvironment + ?Sized>(
wasmparser::Type::F32 => Ok(Some(ir::types::F32)),
wasmparser::Type::F64 => Ok(Some(ir::types::F64)),
wasmparser::Type::V128 => Ok(Some(ir::types::I8X16)),
wasmparser::Type::AnyRef => Ok(Some(environ.reference_type())),
wasmparser::Type::AnyFunc => Ok(None),
wasmparser::Type::ExternRef => Ok(Some(environ.reference_type())),
wasmparser::Type::FuncRef => Ok(None),
ty => Err(wasm_unsupported!(
"tabletype_to_type: table wasm type {:?}",
ty
@@ -183,9 +181,8 @@ pub fn blocktype_params_results(
wasmparser::Type::F32 => (&[], &[wasmparser::Type::F32]),
wasmparser::Type::F64 => (&[], &[wasmparser::Type::F64]),
wasmparser::Type::V128 => (&[], &[wasmparser::Type::V128]),
wasmparser::Type::AnyRef => (&[], &[wasmparser::Type::AnyRef]),
wasmparser::Type::AnyFunc => (&[], &[wasmparser::Type::AnyFunc]),
wasmparser::Type::NullRef => (&[], &[wasmparser::Type::NullRef]),
wasmparser::Type::ExternRef => (&[], &[wasmparser::Type::ExternRef]),
wasmparser::Type::FuncRef => (&[], &[wasmparser::Type::FuncRef]),
wasmparser::Type::EmptyBlockType => (&[], &[]),
ty => return Err(wasm_unsupported!("blocktype_params_results: type {:?}", ty)),
},
@@ -218,7 +215,7 @@ pub fn block_with_params<PE: TargetEnvironment + ?Sized>(
wasmparser::Type::F64 => {
builder.append_block_param(block, ir::types::F64);
}
wasmparser::Type::AnyRef | wasmparser::Type::AnyFunc | wasmparser::Type::NullRef => {
wasmparser::Type::ExternRef | wasmparser::Type::FuncRef => {
builder.append_block_param(block, environ.reference_type());
}
wasmparser::Type::V128 => {

View File

@@ -83,7 +83,9 @@ fn read_module(path: &Path) -> Vec<u8> {
}
Some(ext) => match ext.to_str() {
Some("wasm") => read_file(path).expect("error reading wasm file"),
Some("wat") => wat::parse_file(path).expect("failed to parse wat"),
Some("wat") => wat::parse_file(path)
.map_err(|e| e.to_string())
.expect("failed to parse wat"),
None | Some(&_) => panic!("the file extension for {:?} is not wasm or wat", path),
},
}

View File

@@ -1,11 +1,11 @@
(module
(func (result nullref)
ref.null
(func (result externref)
(ref.null extern)
)
(func (result nullref)
(block (result nullref)
ref.null
(func (result externref)
(block (result externref)
(ref.null extern)
)
)
)

View File

@@ -1,12 +1,12 @@
(module
(func $imported (import "env" "f") (param i32) (result i32))
(func $local (result anyref anyref funcref funcref)
(func $local (result externref externref funcref funcref)
global.get 0
global.get 1
global.get 2
global.get 3)
(global (export "anyref-imported") anyref (ref.func $imported))
(global (export "anyref-local") anyref (ref.func $local))
(global (export "externref-imported") externref (ref.func $imported))
(global (export "externref-local") externref (ref.func $local))
(global (export "funcref-imported") funcref (ref.func $imported))
(global (export "funcref-local") funcref (ref.func $local)))

View File

@@ -5,15 +5,15 @@
i32.const 1
select)
(func $typed-select-1 (result anyref)
ref.null
ref.null
(func $typed-select-1 (result externref)
ref.null extern
ref.null extern
i32.const 1
select (result anyref))
select (result externref))
(func $typed-select-2 (param anyref) (result anyref)
ref.null
(func $typed-select-2 (param externref) (result externref)
ref.null extern
local.get 0
i32.const 1
select (result anyref))
select (result externref))
)