Fix LLVM refactor unreachable depth

This commit is contained in:
Brandon Fish 2019-05-05 13:56:02 -05:00
parent 31acf81762
commit e1138a553b

View File

@ -2525,7 +2525,7 @@ pub struct LLVMFunctionCodeGenerator {
// value_stack: Vec<(Location, LocalOrTemp)>, // value_stack: Vec<(Location, LocalOrTemp)>,
// control_stack: Vec<ControlFrame>, // control_stack: Vec<ControlFrame>,
// machine: Machine, // machine: Machine,
// unreachable_depth: usize, unreachable_depth: usize,
} }
impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator { impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
@ -2675,29 +2675,24 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
let signatures = &self.signatures; let signatures = &self.signatures;
let mut ctx = self.ctx.as_mut().unwrap(); let mut ctx = self.ctx.as_mut().unwrap();
let mut unreachable_depth = 0;
if !state.reachable { if !state.reachable {
match *op { match *op {
Operator::Block { ty: _ } | Operator::Loop { ty: _ } | Operator::If { ty: _ } => { Operator::Block { ty: _ } | Operator::Loop { ty: _ } | Operator::If { ty: _ } => {
unreachable_depth += 1; self.unreachable_depth += 1;
// continue;
return Ok(()); return Ok(());
} }
Operator::Else => { Operator::Else => {
if unreachable_depth != 0 { if self.unreachable_depth != 0 {
// continue;
return Ok(()); return Ok(());
} }
} }
Operator::End => { Operator::End => {
if unreachable_depth != 0 { if self.unreachable_depth != 0 {
unreachable_depth -= 1; self.unreachable_depth -= 1;
// continue;
return Ok(()); return Ok(());
} }
} }
_ => { _ => {
// continue;
return Ok(()); return Ok(());
} }
} }
@ -4781,6 +4776,7 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
::std::mem::transmute::<&Intrinsics, &'static Intrinsics>(&self.intrinsics) ::std::mem::transmute::<&Intrinsics, &'static Intrinsics>(&self.intrinsics)
}, },
ctx: None, ctx: None,
unreachable_depth: 0,
}; };
self.functions.push(code); self.functions.push(code);
Ok(self.functions.last_mut().unwrap()) Ok(self.functions.last_mut().unwrap())