Update LLVM backend to wasmparser 0.51.3

This commit is contained in:
Mark McCaskey
2020-02-26 13:07:31 -08:00
parent 21fd95d760
commit 0a92d9c65e
3 changed files with 65 additions and 74 deletions

View File

@ -37,7 +37,7 @@ use wasmer_runtime_core::{
codegen::*,
memory::MemoryType,
module::{ModuleInfo, ModuleInner},
parse::wp_type_to_type,
parse::{wp_type_to_type, LoadError},
structures::{Map, TypedIndex},
types::{
FuncIndex, FuncSig, GlobalIndex, LocalOrImport, MemoryIndex, SigIndex, TableIndex, Type,
@ -670,7 +670,7 @@ fn resolve_memory_ptr<'ctx>(
memarg: &MemoryImmediate,
ptr_ty: PointerType<'ctx>,
value_size: usize,
) -> Result<PointerValue<'ctx>, BinaryReaderError> {
) -> Result<PointerValue<'ctx>, CodegenError> {
// Look up the memory base (as pointer) and bounds (as unsigned integer).
let memory_cache = ctx.memory(MemoryIndex::new(0), intrinsics, module.clone());
let (mem_base, mem_bound, minimum, _maximum) = match memory_cache {
@ -1200,9 +1200,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
* https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#control-flow-instructions
***************************/
Operator::Block { ty } => {
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
message: "not currently in a block",
offset: -1isize as usize,
let current_block = builder.get_insert_block().ok_or(CodegenError {
message: "not currently in a block".to_string(),
})?;
let end_block = context.append_basic_block(function, "end");
@ -1276,9 +1275,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
Operator::Br { relative_depth } => {
let frame = state.frame_at_depth(relative_depth)?;
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
message: "not currently in a block",
offset: -1isize as usize,
let current_block = builder.get_insert_block().ok_or(CodegenError {
message: "not currently in a block".to_string(),
})?;
let value_len = if frame.is_loop() {
@ -1308,9 +1306,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
let cond = state.pop1()?;
let frame = state.frame_at_depth(relative_depth)?;
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
message: "not currently in a block",
offset: -1isize as usize,
let current_block = builder.get_insert_block().ok_or(CodegenError {
message: "not currently in a block".to_string(),
})?;
let value_len = if frame.is_loop() {
@ -1340,9 +1337,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
builder.position_at_end(&else_block);
}
Operator::BrTable { ref table } => {
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
message: "not currently in a block",
offset: -1isize as usize,
let current_block = builder.get_insert_block().ok_or(CodegenError {
message: "not currently in a block".to_string(),
})?;
let (label_depths, default_depth) = table.read_table()?;
@ -1366,7 +1362,7 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
.iter()
.enumerate()
.map(|(case_index, &depth)| {
let frame_result: Result<&ControlFrame, BinaryReaderError> =
let frame_result: Result<&ControlFrame, CodegenError> =
state.frame_at_depth(depth);
let frame = match frame_result {
Ok(v) => v,
@ -1390,9 +1386,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
state.reachable = false;
}
Operator::If { ty } => {
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
message: "not currently in a block",
offset: -1isize as usize,
let current_block = builder.get_insert_block().ok_or(CodegenError {
message: "not currently in a block".to_string(),
})?;
let if_then_block = context.append_basic_block(function, "if_then");
let if_else_block = context.append_basic_block(function, "if_else");
@ -1431,9 +1426,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
Operator::Else => {
if state.reachable {
let frame = state.frame_at_depth(0)?;
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
message: "not currently in a block",
offset: -1isize as usize,
let current_block = builder.get_insert_block().ok_or(CodegenError {
message: "not currently in a block".to_string(),
})?;
for phi in frame.phis().to_vec().iter().rev() {
@ -1465,9 +1459,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
Operator::End => {
let frame = state.pop_frame()?;
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
message: "not currently in a block",
offset: -1isize as usize,
let current_block = builder.get_insert_block().ok_or(CodegenError {
message: "not currently in a block".to_string(),
})?;
if state.reachable {
@ -1524,9 +1517,8 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
}
}
Operator::Return => {
let current_block = builder.get_insert_block().ok_or(BinaryReaderError {
message: "not currently in a block",
offset: -1isize as usize,
let current_block = builder.get_insert_block().ok_or(CodegenError {
message: "not currently in a block".to_string(),
})?;
let frame = state.outermost_frame()?;
@ -8611,6 +8603,14 @@ impl From<BinaryReaderError> for CodegenError {
}
}
impl From<LoadError> for CodegenError {
fn from(other: LoadError) -> CodegenError {
CodegenError {
message: format!("{:?}", other),
}
}
}
impl Drop for LLVMModuleCodeGenerator<'_> {
fn drop(&mut self) {
// Ensure that all members of the context are dropped before we drop the context.