Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
jubianchi committed May 31, 2021
1 parent e5e51b9 commit bb73126
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 102 deletions.
36 changes: 18 additions & 18 deletions lib/compiler-llvm/src/abi/aarch64_systemv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ impl Abi for Aarch64SystemV {
[] => (
intrinsics.void_ty.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -97,8 +97,8 @@ impl Abi for Aarch64SystemV {
(
type_to_llvm(intrinsics, single_value)?.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -110,8 +110,8 @@ impl Abi for Aarch64SystemV {
(
context.struct_type(&[f32_ty, f32_ty], false).fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -123,8 +123,8 @@ impl Abi for Aarch64SystemV {
(
context.struct_type(&[f64_ty, f64_ty], false).fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -138,8 +138,8 @@ impl Abi for Aarch64SystemV {
.struct_type(&[f32_ty, f32_ty, f32_ty], false)
.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -153,8 +153,8 @@ impl Abi for Aarch64SystemV {
.struct_type(&[f32_ty, f32_ty, f32_ty, f32_ty], false)
.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -176,8 +176,8 @@ impl Abi for Aarch64SystemV {
[32, 32] => (
intrinsics.i64_ty.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -192,8 +192,8 @@ impl Abi for Aarch64SystemV {
| [32, 32, 32, 32] => (
intrinsics.i64_ty.array_type(2).fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand Down Expand Up @@ -225,8 +225,8 @@ impl Abi for Aarch64SystemV {
(
intrinsics.void_ty.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand Down
44 changes: 22 additions & 22 deletions lib/compiler-llvm/src/abi/x86_64_systemv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ impl Abi for X86_64SystemV {
[] => (
intrinsics.void_ty.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -112,8 +112,8 @@ impl Abi for X86_64SystemV {
(
type_to_llvm(intrinsics, single_value)?.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -130,8 +130,8 @@ impl Abi for X86_64SystemV {
(
context.struct_type(&basic_types, false).fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -141,8 +141,8 @@ impl Abi for X86_64SystemV {
[32, 32] if sig.results()[0] == Type::F32 && sig.results()[1] == Type::F32 => (
intrinsics.f32_ty.vec_type(2).fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -151,8 +151,8 @@ impl Abi for X86_64SystemV {
[32, 32] => (
intrinsics.i64_ty.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -169,8 +169,8 @@ impl Abi for X86_64SystemV {
)
.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -187,8 +187,8 @@ impl Abi for X86_64SystemV {
)
.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -205,8 +205,8 @@ impl Abi for X86_64SystemV {
)
.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -223,8 +223,8 @@ impl Abi for X86_64SystemV {
)
.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand All @@ -249,8 +249,8 @@ impl Abi for X86_64SystemV {
)
.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand Down Expand Up @@ -278,8 +278,8 @@ impl Abi for X86_64SystemV {
(
intrinsics.void_ty.fn_type(
param_types
.map(|v| v.unwrap().into())
.collect::<Vec<BasicMetadataTypeEnum>>()
.map(|v| v.map(Into::into))
.collect::<Result<Vec<BasicMetadataTypeEnum>, _>>()?
.as_slice(),
false,
),
Expand Down
81 changes: 19 additions & 62 deletions lib/compiler-llvm/src/translator/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2229,7 +2229,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
func,
params
.iter()
.map(|v| (*v).into())
.copied()
.map(Into::into)
.collect::<Vec<BasicMetadataValueEnum>>()
.as_slice(),
"",
Expand Down Expand Up @@ -2520,7 +2521,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
typed_func_ptr,
params
.iter()
.map(|v| (*v).into())
.copied()
.map(Into::into)
.collect::<Vec<BasicMetadataValueEnum>>()
.as_slice(),
"indirect_call",
Expand Down Expand Up @@ -10935,14 +10937,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
}
Operator::MemoryInit { segment, mem } => {
let (dest, src, len) = self.state.pop3()?;
let mem = self
.intrinsics
.i32_ty
.const_int(mem.into(), false);
let segment = self
.intrinsics
.i32_ty
.const_int(segment.into(), false);
let mem = self.intrinsics.i32_ty.const_int(mem.into(), false);
let segment = self.intrinsics.i32_ty.const_int(segment.into(), false);
self.builder.build_call(
self.intrinsics.memory_init,
&[
Expand All @@ -10957,10 +10953,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
);
}
Operator::DataDrop { segment } => {
let segment = self
.intrinsics
.i32_ty
.const_int(segment.into(), false);
let segment = self.intrinsics.i32_ty.const_int(segment.into(), false);
self.builder.build_call(
self.intrinsics.data_drop,
&[vmctx.as_basic_value_enum().into(), segment.into()],
Expand All @@ -10980,10 +10973,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
};

let (dest_pos, src_pos, len) = self.state.pop3()?;
let src_index = self
.intrinsics
.i32_ty
.const_int(src.into(), false);
let src_index = self.intrinsics.i32_ty.const_int(src.into(), false);
self.builder.build_call(
memory_copy,
&[
Expand All @@ -11007,10 +10997,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
};

let (dst, val, len) = self.state.pop3()?;
let mem_index = self
.intrinsics
.i32_ty
.const_int(mem.into(), false);
let mem_index = self.intrinsics.i32_ty.const_int(mem.into(), false);
self.builder.build_call(
memory_fill,
&[
Expand Down Expand Up @@ -11058,10 +11045,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
self.state.push1(value);
}
Operator::TableGet { table } => {
let table_index = self
.intrinsics
.i32_ty
.const_int(table.into(), false);
let table_index = self.intrinsics.i32_ty.const_int(table.into(), false);
let elem = self.state.pop1()?;
let table_get = if let Some(_) = self
.wasm_module
Expand Down Expand Up @@ -11096,10 +11080,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
self.state.push1(value);
}
Operator::TableSet { table } => {
let table_index = self
.intrinsics
.i32_ty
.const_int(table.into(), false);
let table_index = self.intrinsics.i32_ty.const_int(table.into(), false);
let (elem, value) = self.state.pop2()?;
let value = self
.builder
Expand Down Expand Up @@ -11128,14 +11109,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
src_table,
} => {
let (dst, src, len) = self.state.pop3()?;
let dst_table = self
.intrinsics
.i32_ty
.const_int(dst_table as u64, false);
let src_table = self
.intrinsics
.i32_ty
.const_int(src_table as u64, false);
let dst_table = self.intrinsics.i32_ty.const_int(dst_table as u64, false);
let src_table = self.intrinsics.i32_ty.const_int(src_table as u64, false);
self.builder.build_call(
self.intrinsics.table_copy,
&[
Expand All @@ -11151,14 +11126,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
}
Operator::TableInit { segment, table } => {
let (dst, src, len) = self.state.pop3()?;
let segment = self
.intrinsics
.i32_ty
.const_int(segment as u64, false);
let table = self
.intrinsics
.i32_ty
.const_int(table as u64, false);
let segment = self.intrinsics.i32_ty.const_int(segment as u64, false);
let table = self.intrinsics.i32_ty.const_int(table as u64, false);
self.builder.build_call(
self.intrinsics.table_init,
&[
Expand All @@ -11173,21 +11142,15 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
);
}
Operator::ElemDrop { segment } => {
let segment = self
.intrinsics
.i32_ty
.const_int(segment as u64, false);
let segment = self.intrinsics.i32_ty.const_int(segment as u64, false);
self.builder.build_call(
self.intrinsics.elem_drop,
&[self.ctx.basic().into(), segment.into()],
"",
);
}
Operator::TableFill { table } => {
let table = self
.intrinsics
.i32_ty
.const_int(table as u64, false);
let table = self.intrinsics.i32_ty.const_int(table as u64, false);
let (start, elem, len) = self.state.pop3()?;
let elem = self
.builder
Expand Down Expand Up @@ -11217,10 +11180,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
} else {
(self.intrinsics.imported_table_grow, table)
};
let table_index = self
.intrinsics
.i32_ty
.const_int(table_index as u64, false);
let table_index = self.intrinsics.i32_ty.const_int(table_index as u64, false);
let size = self
.builder
.build_call(
Expand All @@ -11247,10 +11207,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
} else {
(self.intrinsics.imported_table_size, table)
};
let table_index = self
.intrinsics
.i32_ty
.const_int(table_index as u64, false);
let table_index = self.intrinsics.i32_ty.const_int(table_index as u64, false);
let size = self
.builder
.build_call(
Expand Down

0 comments on commit bb73126

Please sign in to comment.