Add support for emitting code with a single return at the end. (#153)

This also enables testing of the wasmtests tests.

This also updates for wabt updating to the official "wat" filename
extension, as opposed to "wast".
This commit is contained in:
Dan Gohman
2017-09-12 13:27:36 -07:00
committed by GitHub
parent 2e046d68ce
commit 1ab207b93c
15 changed files with 154 additions and 38 deletions

View File

@@ -329,8 +329,20 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
}
}
Operator::Return => {
let return_count = state.control_stack[0].return_values().len();
builder.ins().return_(state.peekn(return_count));
let (return_count, br_destination) = {
let frame = &mut state.control_stack[0];
frame.set_reachable();
let return_count = frame.return_values().len();
(return_count, frame.br_destination())
};
{
let args = state.peekn(return_count);
if environ.flags().return_at_end() {
builder.ins().jump(br_destination, args);
} else {
builder.ins().return_(args);
}
}
state.popn(return_count);
state.real_unreachable_stack_depth = 1;
}