Update rustfmt to 0.9.0.
This commit is contained in:
@@ -24,8 +24,9 @@ pub enum SectionParsingError {
|
||||
}
|
||||
|
||||
/// Reads the Type Section of the wasm module and returns the corresponding function signatures.
|
||||
pub fn parse_function_signatures(parser: &mut Parser)
|
||||
-> Result<Vec<Signature>, SectionParsingError> {
|
||||
pub fn parse_function_signatures(
|
||||
parser: &mut Parser,
|
||||
) -> Result<Vec<Signature>, SectionParsingError> {
|
||||
let mut signatures: Vec<Signature> = Vec::new();
|
||||
loop {
|
||||
match *parser.read() {
|
||||
@@ -36,28 +37,22 @@ pub fn parse_function_signatures(parser: &mut Parser)
|
||||
ref returns,
|
||||
}) => {
|
||||
let mut sig = Signature::new(CallConv::Native);
|
||||
sig.argument_types
|
||||
.extend(params
|
||||
.iter()
|
||||
.map(|ty| {
|
||||
let cret_arg: cretonne::ir::Type = match type_to_type(ty) {
|
||||
Ok(ty) => ty,
|
||||
Err(()) => panic!("only numeric types are supported in\
|
||||
sig.argument_types.extend(params.iter().map(|ty| {
|
||||
let cret_arg: cretonne::ir::Type = match type_to_type(ty) {
|
||||
Ok(ty) => ty,
|
||||
Err(()) => panic!("only numeric types are supported in\
|
||||
function signatures"),
|
||||
};
|
||||
ArgumentType::new(cret_arg)
|
||||
}));
|
||||
sig.return_types
|
||||
.extend(returns
|
||||
.iter()
|
||||
.map(|ty| {
|
||||
let cret_arg: cretonne::ir::Type = match type_to_type(ty) {
|
||||
Ok(ty) => ty,
|
||||
Err(()) => panic!("only numeric types are supported in\
|
||||
};
|
||||
ArgumentType::new(cret_arg)
|
||||
}));
|
||||
sig.return_types.extend(returns.iter().map(|ty| {
|
||||
let cret_arg: cretonne::ir::Type = match type_to_type(ty) {
|
||||
Ok(ty) => ty,
|
||||
Err(()) => panic!("only numeric types are supported in\
|
||||
function signatures"),
|
||||
};
|
||||
ArgumentType::new(cret_arg)
|
||||
}));
|
||||
};
|
||||
ArgumentType::new(cret_arg)
|
||||
}));
|
||||
signatures.push(sig);
|
||||
}
|
||||
ref s @ _ => return Err(SectionParsingError::WrongSectionContent(format!("{:?}", s))),
|
||||
@@ -78,30 +73,30 @@ pub fn parse_import_section(parser: &mut Parser) -> Result<Vec<Import>, SectionP
|
||||
ty: ImportSectionEntryType::Memory(MemoryType { limits: ref memlimits }), ..
|
||||
} => {
|
||||
imports.push(Import::Memory(Memory {
|
||||
pages_count: memlimits.initial as usize,
|
||||
maximum: memlimits.maximum.map(|x| x as usize),
|
||||
}))
|
||||
pages_count: memlimits.initial as usize,
|
||||
maximum: memlimits.maximum.map(|x| x as usize),
|
||||
}))
|
||||
}
|
||||
ParserState::ImportSectionEntry {
|
||||
ty: ImportSectionEntryType::Global(ref ty), ..
|
||||
} => {
|
||||
imports.push(Import::Global(Global {
|
||||
ty: type_to_type(&ty.content_type).unwrap(),
|
||||
mutability: ty.mutability != 0,
|
||||
initializer: GlobalInit::Import(),
|
||||
}));
|
||||
ty: type_to_type(&ty.content_type).unwrap(),
|
||||
mutability: ty.mutability != 0,
|
||||
initializer: GlobalInit::Import(),
|
||||
}));
|
||||
}
|
||||
ParserState::ImportSectionEntry {
|
||||
ty: ImportSectionEntryType::Table(ref tab), ..
|
||||
} => {
|
||||
imports.push(Import::Table(Table {
|
||||
ty: match type_to_type(&tab.element_type) {
|
||||
Ok(t) => TableElementType::Val(t),
|
||||
Err(()) => TableElementType::Func(),
|
||||
},
|
||||
size: tab.limits.initial as usize,
|
||||
maximum: tab.limits.maximum.map(|x| x as usize),
|
||||
}));
|
||||
ty: match type_to_type(&tab.element_type) {
|
||||
Ok(t) => TableElementType::Val(t),
|
||||
Err(()) => TableElementType::Func(),
|
||||
},
|
||||
size: tab.limits.initial as usize,
|
||||
maximum: tab.limits.maximum.map(|x| x as usize),
|
||||
}));
|
||||
}
|
||||
ParserState::EndSection => break,
|
||||
ref s @ _ => return Err(SectionParsingError::WrongSectionContent(format!("{:?}", s))),
|
||||
@@ -111,8 +106,9 @@ pub fn parse_import_section(parser: &mut Parser) -> Result<Vec<Import>, SectionP
|
||||
}
|
||||
|
||||
/// Retrieves the correspondances between functions and signatures from the function section
|
||||
pub fn parse_function_section(parser: &mut Parser)
|
||||
-> Result<Vec<SignatureIndex>, SectionParsingError> {
|
||||
pub fn parse_function_section(
|
||||
parser: &mut Parser,
|
||||
) -> Result<Vec<SignatureIndex>, SectionParsingError> {
|
||||
let mut funcs = Vec::new();
|
||||
loop {
|
||||
match *parser.read() {
|
||||
@@ -125,8 +121,9 @@ pub fn parse_function_section(parser: &mut Parser)
|
||||
}
|
||||
|
||||
/// Retrieves the names of the functions from the export section
|
||||
pub fn parse_export_section(parser: &mut Parser)
|
||||
-> Result<HashMap<FunctionIndex, String>, SectionParsingError> {
|
||||
pub fn parse_export_section(
|
||||
parser: &mut Parser,
|
||||
) -> Result<HashMap<FunctionIndex, String>, SectionParsingError> {
|
||||
let mut exports: HashMap<FunctionIndex, String> = HashMap::new();
|
||||
loop {
|
||||
match *parser.read() {
|
||||
@@ -137,8 +134,10 @@ pub fn parse_export_section(parser: &mut Parser)
|
||||
} => {
|
||||
match kind {
|
||||
&ExternalKind::Function => {
|
||||
exports.insert(index as FunctionIndex,
|
||||
String::from(from_utf8(field).unwrap()));
|
||||
exports.insert(
|
||||
index as FunctionIndex,
|
||||
String::from(from_utf8(field).unwrap()),
|
||||
);
|
||||
}
|
||||
_ => (),//TODO: deal with other kind of exports
|
||||
}
|
||||
@@ -157,9 +156,9 @@ pub fn parse_memory_section(parser: &mut Parser) -> Result<Vec<Memory>, SectionP
|
||||
match *parser.read() {
|
||||
ParserState::MemorySectionEntry(ref ty) => {
|
||||
memories.push(Memory {
|
||||
pages_count: ty.limits.initial as usize,
|
||||
maximum: ty.limits.maximum.map(|x| x as usize),
|
||||
})
|
||||
pages_count: ty.limits.initial as usize,
|
||||
maximum: ty.limits.maximum.map(|x| x as usize),
|
||||
})
|
||||
}
|
||||
ParserState::EndSection => break,
|
||||
ref s @ _ => return Err(SectionParsingError::WrongSectionContent(format!("{:?}", s))),
|
||||
@@ -169,9 +168,10 @@ pub fn parse_memory_section(parser: &mut Parser) -> Result<Vec<Memory>, SectionP
|
||||
}
|
||||
|
||||
/// Retrieves the size and maximum fields of memories from the memory section
|
||||
pub fn parse_global_section(parser: &mut Parser,
|
||||
runtime: &mut WasmRuntime)
|
||||
-> Result<Vec<Global>, SectionParsingError> {
|
||||
pub fn parse_global_section(
|
||||
parser: &mut Parser,
|
||||
runtime: &mut WasmRuntime,
|
||||
) -> Result<Vec<Global>, SectionParsingError> {
|
||||
let mut globals = Vec::new();
|
||||
loop {
|
||||
let (content_type, mutability) = match *parser.read() {
|
||||
@@ -221,10 +221,11 @@ pub fn parse_global_section(parser: &mut Parser,
|
||||
Ok(globals)
|
||||
}
|
||||
|
||||
pub fn parse_data_section(parser: &mut Parser,
|
||||
runtime: &mut WasmRuntime,
|
||||
globals: &[Global])
|
||||
-> Result<(), SectionParsingError> {
|
||||
pub fn parse_data_section(
|
||||
parser: &mut Parser,
|
||||
runtime: &mut WasmRuntime,
|
||||
globals: &[Global],
|
||||
) -> Result<(), SectionParsingError> {
|
||||
loop {
|
||||
let memory_index = match *parser.read() {
|
||||
ParserState::BeginDataSectionEntry(memory_index) => memory_index,
|
||||
@@ -238,8 +239,10 @@ pub fn parse_data_section(parser: &mut Parser,
|
||||
let offset = match *parser.read() {
|
||||
ParserState::InitExpressionOperator(Operator::I32Const { value }) => {
|
||||
if value < 0 {
|
||||
return Err(SectionParsingError::WrongSectionContent(String::from("negative \
|
||||
offset value")));
|
||||
return Err(SectionParsingError::WrongSectionContent(String::from(
|
||||
"negative \
|
||||
offset value",
|
||||
)));
|
||||
} else {
|
||||
value as usize
|
||||
}
|
||||
@@ -248,15 +251,19 @@ pub fn parse_data_section(parser: &mut Parser,
|
||||
match globals[global_index as usize].initializer {
|
||||
GlobalInit::I32Const(value) => {
|
||||
if value < 0 {
|
||||
return Err(SectionParsingError::WrongSectionContent(String::from("\
|
||||
negative offset value")));
|
||||
return Err(SectionParsingError::WrongSectionContent(String::from(
|
||||
"\
|
||||
negative offset value",
|
||||
)));
|
||||
} else {
|
||||
value as usize
|
||||
}
|
||||
}
|
||||
GlobalInit::Import() => {
|
||||
return Err(SectionParsingError::WrongSectionContent(String::from("\
|
||||
imported globals not supported")))
|
||||
return Err(SectionParsingError::WrongSectionContent(String::from(
|
||||
"\
|
||||
imported globals not supported",
|
||||
)))
|
||||
} // TODO: add runtime support
|
||||
_ => panic!("should not happen"),
|
||||
}
|
||||
@@ -288,20 +295,21 @@ pub fn parse_data_section(parser: &mut Parser,
|
||||
}
|
||||
|
||||
/// Retrieves the tables from the table section
|
||||
pub fn parse_table_section(parser: &mut Parser,
|
||||
runtime: &mut WasmRuntime)
|
||||
-> Result<(), SectionParsingError> {
|
||||
pub fn parse_table_section(
|
||||
parser: &mut Parser,
|
||||
runtime: &mut WasmRuntime,
|
||||
) -> Result<(), SectionParsingError> {
|
||||
loop {
|
||||
match *parser.read() {
|
||||
ParserState::TableSectionEntry(ref table) => {
|
||||
runtime.declare_table(Table {
|
||||
ty: match type_to_type(&table.element_type) {
|
||||
Ok(t) => TableElementType::Val(t),
|
||||
Err(()) => TableElementType::Func(),
|
||||
},
|
||||
size: table.limits.initial as usize,
|
||||
maximum: table.limits.maximum.map(|x| x as usize),
|
||||
})
|
||||
ty: match type_to_type(&table.element_type) {
|
||||
Ok(t) => TableElementType::Val(t),
|
||||
Err(()) => TableElementType::Func(),
|
||||
},
|
||||
size: table.limits.initial as usize,
|
||||
maximum: table.limits.maximum.map(|x| x as usize),
|
||||
})
|
||||
}
|
||||
ParserState::EndSection => break,
|
||||
ref s @ _ => return Err(SectionParsingError::WrongSectionContent(format!("{:?}", s))),
|
||||
@@ -311,10 +319,11 @@ pub fn parse_table_section(parser: &mut Parser,
|
||||
}
|
||||
|
||||
/// Retrieves the tables from the table section
|
||||
pub fn parse_elements_section(parser: &mut Parser,
|
||||
runtime: &mut WasmRuntime,
|
||||
globals: &[Global])
|
||||
-> Result<(), SectionParsingError> {
|
||||
pub fn parse_elements_section(
|
||||
parser: &mut Parser,
|
||||
runtime: &mut WasmRuntime,
|
||||
globals: &[Global],
|
||||
) -> Result<(), SectionParsingError> {
|
||||
loop {
|
||||
let table_index = match *parser.read() {
|
||||
ParserState::BeginElementSectionEntry(ref table_index) => *table_index as TableIndex,
|
||||
@@ -328,8 +337,10 @@ pub fn parse_elements_section(parser: &mut Parser,
|
||||
let offset = match *parser.read() {
|
||||
ParserState::InitExpressionOperator(Operator::I32Const { value }) => {
|
||||
if value < 0 {
|
||||
return Err(SectionParsingError::WrongSectionContent(String::from("negative \
|
||||
offset value")));
|
||||
return Err(SectionParsingError::WrongSectionContent(String::from(
|
||||
"negative \
|
||||
offset value",
|
||||
)));
|
||||
} else {
|
||||
value as usize
|
||||
}
|
||||
@@ -338,8 +349,10 @@ pub fn parse_elements_section(parser: &mut Parser,
|
||||
match globals[global_index as usize].initializer {
|
||||
GlobalInit::I32Const(value) => {
|
||||
if value < 0 {
|
||||
return Err(SectionParsingError::WrongSectionContent(String::from("\
|
||||
negative offset value")));
|
||||
return Err(SectionParsingError::WrongSectionContent(String::from(
|
||||
"\
|
||||
negative offset value",
|
||||
)));
|
||||
} else {
|
||||
value as usize
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user