Misc refactorings when looking at the wasm code;
This commit is contained in:
committed by
Dan Gohman
parent
c068721964
commit
03159a9200
@@ -141,8 +141,8 @@ fn handle_module(
|
||||
|
||||
let num_func_imports = dummy_environ.get_num_func_imports();
|
||||
let mut total_module_code_size = 0;
|
||||
let mut context = Context::new();
|
||||
for (def_index, func) in dummy_environ.info.function_bodies.iter().enumerate() {
|
||||
let mut context = Context::new();
|
||||
context.func = func.clone();
|
||||
|
||||
let func_index = num_func_imports + def_index;
|
||||
@@ -180,6 +180,8 @@ fn handle_module(
|
||||
println!("{}", context.func.display(fisa.isa));
|
||||
vprintln!(flag_verbose, "");
|
||||
}
|
||||
|
||||
context.clear();
|
||||
}
|
||||
|
||||
if !flag_check_translation && flag_print_size {
|
||||
|
||||
@@ -271,7 +271,7 @@ impl DominatorTree {
|
||||
//
|
||||
// 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
|
||||
// the BB. (An EBB is a linear sequence of basic blocks).
|
||||
//
|
||||
|
||||
@@ -517,25 +517,19 @@ fn simplify(pos: &mut FuncCursor, inst: Inst) {
|
||||
..
|
||||
} => {
|
||||
// Fold away a redundant `bint`.
|
||||
let maybe = {
|
||||
let condition_def = {
|
||||
let args = pos.func.dfg.inst_args(inst);
|
||||
if let ValueDef::Result(def_inst, _) = 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
|
||||
}
|
||||
pos.func.dfg.value_def(args[0])
|
||||
};
|
||||
if let Some(bool_val) = maybe {
|
||||
let args = pos.func.dfg.inst_args_mut(inst);
|
||||
args[0] = bool_val;
|
||||
if let ValueDef::Result(def_inst, _) = condition_def {
|
||||
if let InstructionData::Unary {
|
||||
opcode: Opcode::Bint,
|
||||
arg: bool_val,
|
||||
} = pos.func.dfg[def_inst]
|
||||
{
|
||||
let args = pos.func.dfg.inst_args_mut(inst);
|
||||
args[0] = bool_val;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -94,10 +94,19 @@ pub fn translate_module<'data>(
|
||||
ParserState::BeginSection {
|
||||
code: SectionCode::Code,
|
||||
..
|
||||
} => {
|
||||
// The code section begins
|
||||
break;
|
||||
}
|
||||
} => 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)?)?;
|
||||
},
|
||||
ParserState::EndSection => {
|
||||
next_input = ParserInput::Default;
|
||||
}
|
||||
@@ -119,31 +128,4 @@ pub fn translate_module<'data>(
|
||||
_ => 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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user