diff --git a/cranelift/src/wasm.rs b/cranelift/src/wasm.rs index 1e900537ff..057c167fbc 100644 --- a/cranelift/src/wasm.rs +++ b/cranelift/src/wasm.rs @@ -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 { diff --git a/lib/codegen/src/dominator_tree.rs b/lib/codegen/src/dominator_tree.rs index c8dec582aa..ba066fe496 100644 --- a/lib/codegen/src/dominator_tree.rs +++ b/lib/codegen/src/dominator_tree.rs @@ -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). // diff --git a/lib/codegen/src/preopt.rs b/lib/codegen/src/preopt.rs index b96c3d9531..e252659d35 100644 --- a/lib/codegen/src/preopt.rs +++ b/lib/codegen/src/preopt.rs @@ -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; + } } } _ => {} diff --git a/lib/wasm/src/module_translator.rs b/lib/wasm/src/module_translator.rs index 5010aba87f..907a92660b 100644 --- a/lib/wasm/src/module_translator.rs +++ b/lib/wasm/src/module_translator.rs @@ -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(()) }