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,27 +266,21 @@ pub fn read_module<
|
||||
}
|
||||
}
|
||||
|
||||
let mut operator_parser = parser.create_binary_reader();
|
||||
|
||||
// read locals in function body
|
||||
{
|
||||
let local_count = operator_parser.read_local_count().unwrap();
|
||||
let mut total = 0;
|
||||
for _ in 0..local_count {
|
||||
let cur_pos =
|
||||
range.start as u32 + operator_parser.current_position() as u32;
|
||||
let (count, ty) = operator_parser
|
||||
.read_local_decl(&mut total)
|
||||
.expect("Expected local");
|
||||
let info_read = info.read().unwrap();
|
||||
let mut cur_pos = parser.current_poisiton() as u32;
|
||||
let mut state = parser.read();
|
||||
// loop until the function body starts
|
||||
loop {
|
||||
match state {
|
||||
ParserState::Error(err) => return Err(err.into()),
|
||||
ParserState::FunctionBodyLocals { ref locals } => {
|
||||
for &(count, ty) in locals.iter() {
|
||||
fcg.feed_local(ty, count as usize, cur_pos)
|
||||
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let info_read = info.read().unwrap();
|
||||
let mut cur_pos =
|
||||
range.start as u32 + operator_parser.current_position() as u32;
|
||||
ParserState::CodeOperator(_) => {
|
||||
// the body of the function has started
|
||||
fcg.begin_body(&info_read)
|
||||
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
||||
middlewares
|
||||
@ -297,15 +291,31 @@ pub fn read_module<
|
||||
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;
|
||||
// go to other loop
|
||||
break;
|
||||
}
|
||||
ParserState::EndFunctionBody => break,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
cur_pos = parser.current_poisiton() as u32;
|
||||
state = parser.read();
|
||||
}
|
||||
|
||||
cur_pos = range.start as u32 + operator_parser.current_position() as u32;
|
||||
// loop until the function body ends
|
||||
loop {
|
||||
match state {
|
||||
ParserState::Error(err) => return Err(err.into()),
|
||||
ParserState::CodeOperator(op) => {
|
||||
middlewares
|
||||
.run(Some(fcg), Event::Wasm(op), &info_read, cur_pos)
|
||||
.map_err(LoadError::Codegen)?;
|
||||
}
|
||||
ParserState::EndFunctionBody => break,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
cur_pos = parser.current_poisiton() as u32;
|
||||
state = parser.read();
|
||||
}
|
||||
middlewares
|
||||
.run(
|
||||
Some(fcg),
|
||||
@ -314,7 +324,6 @@ pub fn read_module<
|
||||
cur_pos,
|
||||
)
|
||||
.map_err(LoadError::Codegen)?;
|
||||
}
|
||||
|
||||
fcg.finalize()
|
||||
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user