Misc refactorings when looking at the wasm code;

This commit is contained in:
Benjamin Bouvier
2018-07-12 19:59:06 +02:00
committed by Dan Gohman
parent c068721964
commit 03159a9200
4 changed files with 28 additions and 50 deletions

View File

@@ -141,8 +141,8 @@ fn handle_module(
let num_func_imports = dummy_environ.get_num_func_imports(); let num_func_imports = dummy_environ.get_num_func_imports();
let mut total_module_code_size = 0; let mut total_module_code_size = 0;
let mut context = Context::new();
for (def_index, func) in dummy_environ.info.function_bodies.iter().enumerate() { for (def_index, func) in dummy_environ.info.function_bodies.iter().enumerate() {
let mut context = Context::new();
context.func = func.clone(); context.func = func.clone();
let func_index = num_func_imports + def_index; let func_index = num_func_imports + def_index;
@@ -180,6 +180,8 @@ fn handle_module(
println!("{}", context.func.display(fisa.isa)); println!("{}", context.func.display(fisa.isa));
vprintln!(flag_verbose, ""); vprintln!(flag_verbose, "");
} }
context.clear();
} }
if !flag_check_translation && flag_print_size { if !flag_check_translation && flag_print_size {

View File

@@ -271,7 +271,7 @@ impl DominatorTree {
// //
// There are two ways of viewing the CFG as a graph: // There are two ways of viewing the CFG as a graph:
// //
// 1. Each EBB is a node, with outgoing edges for all the branches in the EBB> // 1. Each EBB is a node, with outgoing edges for all the branches in the EBB.
// 2. Each basic block is a node, with outgoing edges for the single branch at the end of // 2. Each basic block is a node, with outgoing edges for the single branch at the end of
// the BB. (An EBB is a linear sequence of basic blocks). // the BB. (An EBB is a linear sequence of basic blocks).
// //

View File

@@ -517,25 +517,19 @@ fn simplify(pos: &mut FuncCursor, inst: Inst) {
.. ..
} => { } => {
// Fold away a redundant `bint`. // Fold away a redundant `bint`.
let maybe = { let condition_def = {
let args = pos.func.dfg.inst_args(inst); let args = pos.func.dfg.inst_args(inst);
if let ValueDef::Result(def_inst, _) = pos.func.dfg.value_def(args[0]) { pos.func.dfg.value_def(args[0])
if let InstructionData::Unary {
opcode: Opcode::Bint,
arg: bool_val,
} = pos.func.dfg[def_inst]
{
Some(bool_val)
} else {
None
}
} else {
None
}
}; };
if let Some(bool_val) = maybe { if let ValueDef::Result(def_inst, _) = condition_def {
let args = pos.func.dfg.inst_args_mut(inst); if let InstructionData::Unary {
args[0] = bool_val; opcode: Opcode::Bint,
arg: bool_val,
} = pos.func.dfg[def_inst]
{
let args = pos.func.dfg.inst_args_mut(inst);
args[0] = bool_val;
}
} }
} }
_ => {} _ => {}

View File

@@ -94,10 +94,19 @@ pub fn translate_module<'data>(
ParserState::BeginSection { ParserState::BeginSection {
code: SectionCode::Code, code: SectionCode::Code,
.. ..
} => { } => loop {
// The code section begins match *parser.read() {
break; ParserState::BeginFunctionBody { .. } => {}
} ParserState::EndSection => break,
ParserState::Error(e) => return Err(WasmError::from_binary_reader_error(e)),
ref s => panic!("wrong content in code section: {:?}", s),
}
let mut reader = parser.create_binary_reader();
let size = reader.bytes_remaining();
environ.define_function_body(reader
.read_bytes(size)
.map_err(WasmError::from_binary_reader_error)?)?;
},
ParserState::EndSection => { ParserState::EndSection => {
next_input = ParserInput::Default; next_input = ParserInput::Default;
} }
@@ -119,31 +128,4 @@ pub fn translate_module<'data>(
_ => panic!("wrong content in the preamble"), _ => panic!("wrong content in the preamble"),
}; };
} }
// At this point we've entered the code section
loop {
match *parser.read() {
ParserState::BeginFunctionBody { .. } => {}
ParserState::EndSection => break,
ParserState::Error(e) => return Err(WasmError::from_binary_reader_error(e)),
ref s => panic!("wrong content in code section: {:?}", s),
}
let mut reader = parser.create_binary_reader();
let size = reader.bytes_remaining();
environ.define_function_body(reader
.read_bytes(size)
.map_err(WasmError::from_binary_reader_error)?)?;
}
loop {
match *parser.read() {
ParserState::BeginSection {
code: SectionCode::Data,
..
} => {
parse_data_section(&mut parser, environ)?;
}
ParserState::EndWasm => break,
_ => (),
}
}
Ok(())
} }