Skip to content

Commit

Permalink
Refactor BlockExt trait methods (#680)
Browse files Browse the repository at this point in the history
* Refactor BlockExt trait methods

* fix clippy
  • Loading branch information
tcoratger authored Jun 11, 2024
1 parent 1eb7588 commit 6b86c98
Showing 1 changed file with 37 additions and 49 deletions.
86 changes: 37 additions & 49 deletions src/block_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,16 @@ impl<'ctx> BlockExt<'ctx> for Block<'ctx> {
T: Into<BigInt>,
{
let ty = IntegerType::new(context, bits).into();
Ok(self
.append_operation(
ods::arith::constant(
context,
ty,
Attribute::parse(context, &format!("{} : {}", value.into(), ty))
.ok_or(Error::ParseAttributeError)?,
location,
)
.into(),
self.append_op_result(
ods::arith::constant(
context,
ty,
Attribute::parse(context, &format!("{} : {}", value.into(), ty))
.ok_or(Error::ParseAttributeError)?,
location,
)
.result(0)?
.into())
.into(),
)
}

fn const_int_from_type<T>(
Expand All @@ -165,19 +162,16 @@ impl<'ctx> BlockExt<'ctx> for Block<'ctx> {
where
T: Into<BigInt>,
{
Ok(self
.append_operation(
ods::arith::constant(
context,
ty,
Attribute::parse(context, &format!("{} : {}", value.into(), ty))
.ok_or(Error::ParseAttributeError)?,
location,
)
.into(),
self.append_op_result(
ods::arith::constant(
context,
ty,
Attribute::parse(context, &format!("{} : {}", value.into(), ty))
.ok_or(Error::ParseAttributeError)?,
location,
)
.result(0)?
.into())
.into(),
)
}

fn extract_value(
Expand All @@ -188,19 +182,16 @@ impl<'ctx> BlockExt<'ctx> for Block<'ctx> {
value_type: Type<'ctx>,
index: usize,
) -> Result<Value<'ctx, '_>, Error> {
Ok(self
.append_operation(
ods::llvm::extractvalue(
context,
value_type,
container,
DenseI64ArrayAttribute::new(context, &[index.try_into().unwrap()]).into(),
location,
)
.into(),
self.append_op_result(
ods::llvm::extractvalue(
context,
value_type,
container,
DenseI64ArrayAttribute::new(context, &[index.try_into().unwrap()]).into(),
location,
)
.result(0)?
.into())
.into(),
)
}

fn insert_value(
Expand All @@ -211,20 +202,17 @@ impl<'ctx> BlockExt<'ctx> for Block<'ctx> {
value: Value<'ctx, '_>,
index: usize,
) -> Result<Value<'ctx, '_>, Error> {
Ok(self
.append_operation(
ods::llvm::insertvalue(
context,
container.r#type(),
container,
value,
DenseI64ArrayAttribute::new(context, &[index.try_into().unwrap()]).into(),
location,
)
.into(),
self.append_op_result(
ods::llvm::insertvalue(
context,
container.r#type(),
container,
value,
DenseI64ArrayAttribute::new(context, &[index.try_into().unwrap()]).into(),
location,
)
.result(0)?
.into())
.into(),
)
}

fn insert_values<'block>(
Expand Down

0 comments on commit 6b86c98

Please sign in to comment.