mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-22 05:01:33 +00:00
Refactor func_count in parser
This commit is contained in:
@ -92,7 +92,8 @@ pub fn read_module<
|
|||||||
|
|
||||||
let mut namespace_builder = Some(StringTableBuilder::new());
|
let mut namespace_builder = Some(StringTableBuilder::new());
|
||||||
let mut name_builder = Some(StringTableBuilder::new());
|
let mut name_builder = Some(StringTableBuilder::new());
|
||||||
let mut func_count: usize = ::std::usize::MAX;
|
let mut func_count: usize = 0;
|
||||||
|
let mut mcg_info_fed = false;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
use wasmparser::ParserState;
|
use wasmparser::ParserState;
|
||||||
@ -196,9 +197,9 @@ pub fn read_module<
|
|||||||
info.write().unwrap().start_func = Some(FuncIndex::new(start_index as usize));
|
info.write().unwrap().start_func = Some(FuncIndex::new(start_index as usize));
|
||||||
}
|
}
|
||||||
ParserState::BeginFunctionBody { .. } => {
|
ParserState::BeginFunctionBody { .. } => {
|
||||||
let id = func_count.wrapping_add(1);
|
let id = func_count;
|
||||||
func_count = id;
|
if !mcg_info_fed {
|
||||||
if func_count == 0 {
|
mcg_info_fed = true;
|
||||||
info.write().unwrap().namespace_table =
|
info.write().unwrap().namespace_table =
|
||||||
namespace_builder.take().unwrap().finish();
|
namespace_builder.take().unwrap().finish();
|
||||||
info.write().unwrap().name_table = name_builder.take().unwrap().finish();
|
info.write().unwrap().name_table = name_builder.take().unwrap().finish();
|
||||||
@ -279,6 +280,7 @@ pub fn read_module<
|
|||||||
.map_err(|x| LoadError::Codegen(x))?;
|
.map_err(|x| LoadError::Codegen(x))?;
|
||||||
fcg.finalize()
|
fcg.finalize()
|
||||||
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
||||||
|
func_count = func_count.wrapping_add(1);
|
||||||
}
|
}
|
||||||
ParserState::BeginActiveElementSectionEntry(table_index) => {
|
ParserState::BeginActiveElementSectionEntry(table_index) => {
|
||||||
let table_index = TableIndex::new(table_index as usize);
|
let table_index = TableIndex::new(table_index as usize);
|
||||||
@ -370,7 +372,7 @@ pub fn read_module<
|
|||||||
}
|
}
|
||||||
ParserState::EndWasm => {
|
ParserState::EndWasm => {
|
||||||
// TODO Consolidate with BeginFunction body if possible
|
// TODO Consolidate with BeginFunction body if possible
|
||||||
if func_count == ::std::usize::MAX {
|
if !mcg_info_fed {
|
||||||
info.write().unwrap().namespace_table =
|
info.write().unwrap().namespace_table =
|
||||||
namespace_builder.take().unwrap().finish();
|
namespace_builder.take().unwrap().finish();
|
||||||
info.write().unwrap().name_table = name_builder.take().unwrap().finish();
|
info.write().unwrap().name_table = name_builder.take().unwrap().finish();
|
||||||
|
Reference in New Issue
Block a user