Make wasm_unsupported be composeable

This commit is contained in:
Anthony Ramine
2019-09-22 14:31:54 +02:00
committed by Benjamin Bouvier
parent 26accbadf8
commit eeb3159fe9
5 changed files with 43 additions and 18 deletions

View File

@@ -907,7 +907,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
| Operator::I64AtomicRmw16UCmpxchg { .. }
| Operator::I64AtomicRmw32UCmpxchg { .. }
| Operator::Fence { .. } => {
wasm_unsupported!("proposed thread operator {:?}", op);
return Err(wasm_unsupported!("proposed thread operator {:?}", op));
}
Operator::MemoryInit { .. }
| Operator::DataDrop { .. }
@@ -920,7 +920,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
| Operator::TableSet { .. }
| Operator::TableGrow { .. }
| Operator::TableSize { .. } => {
wasm_unsupported!("proposed bulk memory operator {:?}", op);
return Err(wasm_unsupported!("proposed bulk memory operator {:?}", op));
}
Operator::V128Const { value } => {
let handle = builder.func.dfg.constants.insert(value.bytes().to_vec());
@@ -1109,7 +1109,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
| Operator::I16x8LoadSplat { .. }
| Operator::I32x4LoadSplat { .. }
| Operator::I64x2LoadSplat { .. } => {
wasm_unsupported!("proposed SIMD operator {:?}", op);
return Err(wasm_unsupported!("proposed SIMD operator {:?}", op));
}
};
Ok(())

View File

@@ -80,7 +80,7 @@ pub enum WasmError {
/// on the arguments to this macro.
#[macro_export]
macro_rules! wasm_unsupported {
($($arg:tt)*) => { return Err($crate::environ::WasmError::Unsupported(format!($($arg)*))) }
($($arg:tt)*) => { $crate::environ::WasmError::Unsupported(format!($($arg)*)) }
}
impl From<BinaryReaderError> for WasmError {

View File

@@ -184,7 +184,7 @@ fn declare_locals<FE: FuncEnvironment + ?Sized>(
builder.ins().vconst(ir::types::I8X16, constant_handle)
}
AnyRef => builder.ins().null(environ.reference_type()),
ty => wasm_unsupported!("unsupported local type {:?}", ty),
ty => return Err(wasm_unsupported!("unsupported local type {:?}", ty)),
};
let ty = builder.func.dfg.value_type(zeroval);

View File

@@ -53,7 +53,12 @@ pub fn parse_type_section(
}));
environ.declare_signature(sig)?;
}
ty => wasm_unsupported!("unsupported type in type section: {:?}", ty),
ty => {
return Err(wasm_unsupported!(
"unsupported type in type section: {:?}",
ty
))
}
}
}
Ok(())
@@ -209,7 +214,10 @@ pub fn parse_global_section(
GlobalInit::GetGlobal(GlobalIndex::from_u32(global_index))
}
ref s => {
wasm_unsupported!("unsupported init expr in global section: {:?}", s);
return Err(wasm_unsupported!(
"unsupported init expr in global section: {:?}",
s
));
}
};
let global = Global {
@@ -284,7 +292,10 @@ pub fn parse_element_section<'data>(
(Some(GlobalIndex::from_u32(global_index)), 0)
}
ref s => {
wasm_unsupported!("unsupported init expr in element section: {:?}", s);
return Err(wasm_unsupported!(
"unsupported init expr in element section: {:?}",
s
));
}
};
let items_reader = items.get_items_reader()?;
@@ -300,7 +311,10 @@ pub fn parse_element_section<'data>(
elems.into_boxed_slice(),
)?
} else {
wasm_unsupported!("unsupported passive elements section: {:?}", kind);
return Err(wasm_unsupported!(
"unsupported passive elements section: {:?}",
kind
));
}
}
Ok(())
@@ -340,7 +354,12 @@ pub fn parse_data_section<'data>(
Operator::GetGlobal { global_index } => {
(Some(GlobalIndex::from_u32(global_index)), 0)
}
ref s => wasm_unsupported!("unsupported init expr in data section: {:?}", s),
ref s => {
return Err(wasm_unsupported!(
"unsupported init expr in data section: {:?}",
s
))
}
};
environ.declare_data_initialization(
MemoryIndex::from_u32(memory_index),
@@ -349,7 +368,10 @@ pub fn parse_data_section<'data>(
data,
)?;
} else {
wasm_unsupported!("unsupported passive data section: {:?}", kind);
return Err(wasm_unsupported!(
"unsupported passive data section: {:?}",
kind
));
}
}

View File

@@ -124,7 +124,7 @@ pub fn type_to_type(ty: wasmparser::Type) -> WasmResult<ir::Type> {
wasmparser::Type::F32 => Ok(ir::types::F32),
wasmparser::Type::F64 => Ok(ir::types::F64),
wasmparser::Type::V128 => Ok(ir::types::I8X16),
ty => wasm_unsupported!("type_to_type: wasm type {:?}", ty),
ty => Err(wasm_unsupported!("type_to_type: wasm type {:?}", ty)),
}
}
@@ -138,7 +138,10 @@ pub fn tabletype_to_type(ty: wasmparser::Type) -> WasmResult<Option<ir::Type>> {
wasmparser::Type::F64 => Ok(Some(ir::types::F64)),
wasmparser::Type::V128 => Ok(Some(ir::types::I8X16)),
wasmparser::Type::AnyFunc => Ok(None),
ty => wasm_unsupported!("tabletype_to_type: table wasm type {:?}", ty),
ty => Err(wasm_unsupported!(
"tabletype_to_type: table wasm type {:?}",
ty
)),
}
}
@@ -152,12 +155,12 @@ pub fn blocktype_to_type(ty_or_ft: wasmparser::TypeOrFuncType) -> WasmResult<Opt
wasmparser::Type::F64 => Ok(Some(ir::types::F64)),
wasmparser::Type::V128 => Ok(Some(ir::types::I8X16)),
wasmparser::Type::EmptyBlockType => Ok(None),
ty => wasm_unsupported!("blocktype_to_type: type {:?}", ty),
ty => Err(wasm_unsupported!("blocktype_to_type: type {:?}", ty)),
},
wasmparser::TypeOrFuncType::FuncType(_) => wasm_unsupported!(
wasmparser::TypeOrFuncType::FuncType(_) => Err(wasm_unsupported!(
"blocktype_to_type: multi-value block signature {:?}",
ty_or_ft
),
)),
}
}
@@ -181,10 +184,10 @@ pub fn num_return_values(ty: wasmparser::TypeOrFuncType) -> WasmResult<usize> {
| wasmparser::Type::I64
| wasmparser::Type::F64
| wasmparser::Type::V128 => Ok(1),
ty => wasm_unsupported!("unsupported return value type {:?}", ty),
ty => Err(wasm_unsupported!("unsupported return value type {:?}", ty)),
},
wasmparser::TypeOrFuncType::FuncType(_) => {
wasm_unsupported!("multi-value block signature {:?}", ty);
Err(wasm_unsupported!("multi-value block signature {:?}", ty))
}
}
}