Add TranslationState::in_unreachable_code().

Move an unreachable code test and sanity check into this method.
This commit is contained in:
Jakob Stoklund Olesen
2017-09-05 11:46:08 -07:00
parent 6f864f2926
commit 2671cbb092
2 changed files with 11 additions and 5 deletions

View File

@@ -118,11 +118,7 @@ pub fn translate_function_body(
let parser_state = parser.read();
match *parser_state {
ParserState::CodeOperator(ref op) => {
debug_assert!(
state.phantom_unreachable_stack_depth == 0 ||
state.real_unreachable_stack_depth > 0
);
if state.real_unreachable_stack_depth > 0 {
if state.in_unreachable_code() {
translate_unreachable_operator(op, &mut builder, &mut state)
} else {
translate_operator(

View File

@@ -200,4 +200,14 @@ impl TranslationState {
reachable: false,
});
}
/// Test if the translation state is currently in unreachable code.
pub fn in_unreachable_code(&self) -> bool {
if self.real_unreachable_stack_depth > 0 {
true
} else {
debug_assert_eq!(self.phantom_unreachable_stack_depth, 0, "in reachable code");
false
}
}
}