mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-25 02:12:13 +00:00
Revert Wasm parsing to improved old style, fixing singlepass
This commit is contained in:
parent
cb20cd9b2d
commit
56e47c17b0
@ -266,55 +266,64 @@ pub fn read_module<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut operator_parser = parser.create_binary_reader();
|
let info_read = info.read().unwrap();
|
||||||
|
let mut cur_pos = parser.current_poisiton() as u32;
|
||||||
// read locals in function body
|
let mut state = parser.read();
|
||||||
{
|
// loop until the function body starts
|
||||||
let local_count = operator_parser.read_local_count().unwrap();
|
loop {
|
||||||
let mut total = 0;
|
match state {
|
||||||
for _ in 0..local_count {
|
ParserState::Error(err) => return Err(err.into()),
|
||||||
let cur_pos =
|
ParserState::FunctionBodyLocals { ref locals } => {
|
||||||
range.start as u32 + operator_parser.current_position() as u32;
|
for &(count, ty) in locals.iter() {
|
||||||
let (count, ty) = operator_parser
|
fcg.feed_local(ty, count as usize, cur_pos)
|
||||||
.read_local_decl(&mut total)
|
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
||||||
.expect("Expected local");
|
}
|
||||||
fcg.feed_local(ty, count as usize, cur_pos)
|
}
|
||||||
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
ParserState::CodeOperator(_) => {
|
||||||
|
// the body of the function has started
|
||||||
|
fcg.begin_body(&info_read)
|
||||||
|
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
||||||
|
middlewares
|
||||||
|
.run(
|
||||||
|
Some(fcg),
|
||||||
|
Event::Internal(InternalEvent::FunctionBegin(id as u32)),
|
||||||
|
&info_read,
|
||||||
|
cur_pos,
|
||||||
|
)
|
||||||
|
.map_err(LoadError::Codegen)?;
|
||||||
|
// go to other loop
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ParserState::EndFunctionBody => break,
|
||||||
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
cur_pos = parser.current_poisiton() as u32;
|
||||||
|
state = parser.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
// loop until the function body ends
|
||||||
let info_read = info.read().unwrap();
|
loop {
|
||||||
let mut cur_pos =
|
match state {
|
||||||
range.start as u32 + operator_parser.current_position() as u32;
|
ParserState::Error(err) => return Err(err.into()),
|
||||||
fcg.begin_body(&info_read)
|
ParserState::CodeOperator(op) => {
|
||||||
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
middlewares
|
||||||
middlewares
|
.run(Some(fcg), Event::Wasm(op), &info_read, cur_pos)
|
||||||
.run(
|
.map_err(LoadError::Codegen)?;
|
||||||
Some(fcg),
|
}
|
||||||
Event::Internal(InternalEvent::FunctionBegin(id as u32)),
|
ParserState::EndFunctionBody => break,
|
||||||
&info_read,
|
_ => unreachable!(),
|
||||||
cur_pos,
|
|
||||||
)
|
|
||||||
.map_err(LoadError::Codegen)?;
|
|
||||||
|
|
||||||
while let Ok(op) = operator_parser.read_operator() {
|
|
||||||
middlewares
|
|
||||||
.run(Some(fcg), Event::WasmOwned(op), &info_read, cur_pos)
|
|
||||||
.map_err(LoadError::Codegen)?;
|
|
||||||
cur_pos = range.start as u32 + operator_parser.current_position() as u32;
|
|
||||||
}
|
}
|
||||||
|
cur_pos = parser.current_poisiton() as u32;
|
||||||
cur_pos = range.start as u32 + operator_parser.current_position() as u32;
|
state = parser.read();
|
||||||
middlewares
|
|
||||||
.run(
|
|
||||||
Some(fcg),
|
|
||||||
Event::Internal(InternalEvent::FunctionEnd),
|
|
||||||
&info_read,
|
|
||||||
cur_pos,
|
|
||||||
)
|
|
||||||
.map_err(LoadError::Codegen)?;
|
|
||||||
}
|
}
|
||||||
|
middlewares
|
||||||
|
.run(
|
||||||
|
Some(fcg),
|
||||||
|
Event::Internal(InternalEvent::FunctionEnd),
|
||||||
|
&info_read,
|
||||||
|
cur_pos,
|
||||||
|
)
|
||||||
|
.map_err(LoadError::Codegen)?;
|
||||||
|
|
||||||
fcg.finalize()
|
fcg.finalize()
|
||||||
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user