, BuilderError> {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
+ // LLVMBuildArrayMalloc segfaults if ty is unsized
if !ty.is_sized() {
- return Err("Cannot build array malloc call for an unsized type");
+ return Err(BuilderError::AlignmentError(
+ "Cannot build array malloc call for an unsized type",
+ ));
}
let c_string = to_c_str(name);
@@ -1464,8 +1640,11 @@ impl<'ctx> Builder<'ctx> {
}
// SubType: (&self, ptr: PointerValue
) -> InstructionValue {
- pub fn build_free(&self, ptr: PointerValue<'ctx>) -> InstructionValue<'ctx> {
- unsafe { InstructionValue::new(LLVMBuildFree(self.builder, ptr.as_value_ref())) }
+ pub fn build_free(&self, ptr: PointerValue<'ctx>) -> Result, BuilderError> {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
+ unsafe { Ok(InstructionValue::new(LLVMBuildFree(self.builder, ptr.as_value_ref()))) }
}
pub fn insert_instruction(&self, instruction: &InstructionValue<'ctx>, name: Option<&str>) {
@@ -1488,51 +1667,79 @@ impl<'ctx> Builder<'ctx> {
// TODO: Possibly make this generic over sign via struct metadata or subtypes
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
// if I::sign() == Unsigned { LLVMBuildUDiv() } else { LLVMBuildSDiv() }
- pub fn build_int_unsigned_div>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_int_unsigned_div>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildUDiv(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// TODO: Possibly make this generic over sign via struct metadata or subtypes
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_int_signed_div>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_int_signed_div>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildSDiv(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// TODO: Possibly make this generic over sign via struct metadata or subtypes
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_int_exact_signed_div>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_int_exact_signed_div>(
+ &self,
+ lhs: T,
+ rhs: T,
+ name: &str,
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value =
unsafe { LLVMBuildExactSDiv(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// TODO: Possibly make this generic over sign via struct metadata or subtypes
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_int_unsigned_rem>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_int_unsigned_rem>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildURem(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// TODO: Possibly make this generic over sign via struct metadata or subtypes
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_int_signed_rem>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_int_signed_rem>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildSRem(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
- pub fn build_int_s_extend>(&self, int_value: T, int_type: T::BaseType, name: &str) -> T {
+ pub fn build_int_s_extend>(
+ &self,
+ int_value: T,
+ int_type: T::BaseType,
+ name: &str,
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildSExt(
@@ -1543,7 +1750,7 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// REVIEW: Does this need vector support?
@@ -1552,7 +1759,10 @@ impl<'ctx> Builder<'ctx> {
ptr_val: PointerValue<'ctx>,
ptr_type: PointerType<'ctx>,
name: &str,
- ) -> PointerValue<'ctx> {
+ ) -> Result, BuilderError> {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildAddrSpaceCast(
@@ -1563,7 +1773,7 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { PointerValue::new(value) }
+ unsafe { Ok(PointerValue::new(value)) }
}
/// Builds a bitcast instruction. A bitcast reinterprets the bits of one value
@@ -1589,20 +1799,23 @@ impl<'ctx> Builder<'ctx> {
///
/// builder.position_at_end(entry);
///
- /// builder.build_bitcast(i32_arg, f32_type, "i32tof32");
- /// builder.build_return(None);
+ /// builder.build_bitcast(i32_arg, f32_type, "i32tof32").unwrap();
+ /// builder.build_return(None).unwrap();
///
/// assert!(module.verify().is_ok());
/// ```
- pub fn build_bitcast(&self, val: V, ty: T, name: &str) -> BasicValueEnum<'ctx>
+ pub fn build_bitcast(&self, val: V, ty: T, name: &str) -> Result, BuilderError>
where
T: BasicType<'ctx>,
V: BasicValue<'ctx>,
{
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildBitCast(self.builder, val.as_value_ref(), ty.as_type_ref(), c_string.as_ptr()) };
- unsafe { BasicValueEnum::new(value) }
+ unsafe { Ok(BasicValueEnum::new(value)) }
}
pub fn build_int_s_extend_or_bit_cast>(
@@ -1610,7 +1823,10 @@ impl<'ctx> Builder<'ctx> {
int_value: T,
int_type: T::BaseType,
name: &str,
- ) -> T {
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildSExtOrBitCast(
@@ -1621,10 +1837,18 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
- pub fn build_int_z_extend>(&self, int_value: T, int_type: T::BaseType, name: &str) -> T {
+ pub fn build_int_z_extend>(
+ &self,
+ int_value: T,
+ int_type: T::BaseType,
+ name: &str,
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildZExt(
@@ -1635,7 +1859,7 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
pub fn build_int_z_extend_or_bit_cast>(
@@ -1643,7 +1867,10 @@ impl<'ctx> Builder<'ctx> {
int_value: T,
int_type: T::BaseType,
name: &str,
- ) -> T {
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildZExtOrBitCast(
@@ -1654,10 +1881,18 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
- pub fn build_int_truncate>(&self, int_value: T, int_type: T::BaseType, name: &str) -> T {
+ pub fn build_int_truncate>(
+ &self,
+ int_value: T,
+ int_type: T::BaseType,
+ name: &str,
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
@@ -1669,7 +1904,7 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
pub fn build_int_truncate_or_bit_cast>(
@@ -1677,7 +1912,10 @@ impl<'ctx> Builder<'ctx> {
int_value: T,
int_type: T::BaseType,
name: &str,
- ) -> T {
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
@@ -1689,14 +1927,17 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
- pub fn build_float_rem>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_float_rem>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildFRem(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// REVIEW: Consolidate these two casts into one via subtypes
@@ -1705,7 +1946,11 @@ impl<'ctx> Builder<'ctx> {
float: T,
int_type: >::MathConvType,
name: &str,
- ) -> <>::MathConvType as IntMathType<'ctx>>::ValueType {
+ ) -> Result<<>::MathConvType as IntMathType<'ctx>>::ValueType, BuilderError>
+ {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildFPToUI(
@@ -1716,7 +1961,7 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { <::MathConvType as IntMathType>::ValueType::new(value) }
+ unsafe { Ok(<::MathConvType as IntMathType>::ValueType::new(value)) }
}
pub fn build_float_to_signed_int>(
@@ -1724,7 +1969,11 @@ impl<'ctx> Builder<'ctx> {
float: T,
int_type: >::MathConvType,
name: &str,
- ) -> <>::MathConvType as IntMathType<'ctx>>::ValueType {
+ ) -> Result<<>::MathConvType as IntMathType<'ctx>>::ValueType, BuilderError>
+ {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildFPToSI(
@@ -1735,7 +1984,7 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { <::MathConvType as IntMathType>::ValueType::new(value) }
+ unsafe { Ok(<::MathConvType as IntMathType>::ValueType::new(value)) }
}
// REVIEW: Consolidate these two casts into one via subtypes
@@ -1744,7 +1993,11 @@ impl<'ctx> Builder<'ctx> {
int: T,
float_type: >::MathConvType,
name: &str,
- ) -> <>::MathConvType as FloatMathType<'ctx>>::ValueType {
+ ) -> Result<<>::MathConvType as FloatMathType<'ctx>>::ValueType, BuilderError>
+ {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildUIToFP(
@@ -1755,7 +2008,7 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { <::MathConvType as FloatMathType>::ValueType::new(value) }
+ unsafe { Ok(<::MathConvType as FloatMathType>::ValueType::new(value)) }
}
pub fn build_signed_int_to_float>(
@@ -1763,7 +2016,11 @@ impl<'ctx> Builder<'ctx> {
int: T,
float_type: >::MathConvType,
name: &str,
- ) -> <>::MathConvType as FloatMathType<'ctx>>::ValueType {
+ ) -> Result<<>::MathConvType as FloatMathType<'ctx>>::ValueType, BuilderError>
+ {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildSIToFP(
@@ -1774,10 +2031,18 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { <::MathConvType as FloatMathType>::ValueType::new(value) }
+ unsafe { Ok(<::MathConvType as FloatMathType>::ValueType::new(value)) }
}
- pub fn build_float_trunc>(&self, float: T, float_type: T::BaseType, name: &str) -> T {
+ pub fn build_float_trunc>(
+ &self,
+ float: T,
+ float_type: T::BaseType,
+ name: &str,
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildFPTrunc(
@@ -1788,10 +2053,18 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
- pub fn build_float_ext>(&self, float: T, float_type: T::BaseType, name: &str) -> T {
+ pub fn build_float_ext>(
+ &self,
+ float: T,
+ float_type: T::BaseType,
+ name: &str,
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildFPExt(
@@ -1802,10 +2075,18 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
- pub fn build_float_cast>(&self, float: T, float_type: T::BaseType, name: &str) -> T {
+ pub fn build_float_cast>(
+ &self,
+ float: T,
+ float_type: T::BaseType,
+ name: &str,
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildFPCast(
@@ -1816,11 +2097,19 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// SubType: (&self, lhs: &IntValue, rhs: &IntType, name: &str) -> IntValue {
- pub fn build_int_cast>(&self, int: T, int_type: T::BaseType, name: &str) -> T {
+ pub fn build_int_cast>(
+ &self,
+ int: T,
+ int_type: T::BaseType,
+ name: &str,
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildIntCast(
@@ -1831,7 +2120,7 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
/// Like `build_int_cast`, but respects the signedness of the type being cast to.
@@ -1842,7 +2131,10 @@ impl<'ctx> Builder<'ctx> {
int_type: T::BaseType,
is_signed: bool,
name: &str,
- ) -> T {
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
LLVMBuildIntCast2(
@@ -1854,72 +2146,93 @@ impl<'ctx> Builder<'ctx> {
)
};
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
- pub fn build_float_div>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_float_div>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildFDiv(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_int_add>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_int_add>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildAdd(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
- // REVIEW: Possibly incorperate into build_int_add via flag param
+ // REVIEW: Possibly incorporate into build_int_add via flag param
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_int_nsw_add>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_int_nsw_add>(&self, lhs: T, rhs: T, name: &str) -> Result {
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildNSWAdd(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
- // REVIEW: Possibly incorperate into build_int_add via flag param
+ // REVIEW: Possibly incorporate into build_int_add via flag param
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_int_nuw_add>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_int_nuw_add>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildNUWAdd(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// SubType: (&self, lhs: &FloatValue, rhs: &FloatValue, name: &str) -> FloatValue {
- pub fn build_float_add>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_float_add>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildFAdd(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_xor>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_xor>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildXor(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_and>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_and>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildAnd(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_or>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_or>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildOr(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
/// Builds an `IntValue` containing the result of a logical left shift instruction.
@@ -1961,15 +2274,18 @@ impl<'ctx> Builder<'ctx> {
///
/// builder.position_at_end(entry_block);
///
- /// let shift = builder.build_left_shift(value, n, "left_shift"); // value << n
+ /// let shift = builder.build_left_shift(value, n, "left_shift").unwrap(); // value << n
///
- /// builder.build_return(Some(&shift));
+ /// builder.build_return(Some(&shift)).unwrap();
/// ```
- pub fn build_left_shift>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_left_shift>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildShl(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
/// Builds an `IntValue` containing the result of a right shift instruction.
@@ -2032,11 +2348,20 @@ impl<'ctx> Builder<'ctx> {
///
/// // Whether or not your right shift is sign extended (true) or logical (false) depends
/// // on the boolean input parameter:
- /// let shift = builder.build_right_shift(value, n, false, "right_shift"); // value >> n
+ /// let shift = builder.build_right_shift(value, n, false, "right_shift").unwrap(); // value >> n
///
- /// builder.build_return(Some(&shift));
+ /// builder.build_return(Some(&shift)).unwrap();
/// ```
- pub fn build_right_shift>(&self, lhs: T, rhs: T, sign_extend: bool, name: &str) -> T {
+ pub fn build_right_shift>(
+ &self,
+ lhs: T,
+ rhs: T,
+ sign_extend: bool,
+ name: &str,
+ ) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe {
if sign_extend {
@@ -2046,74 +2371,98 @@ impl<'ctx> Builder<'ctx> {
}
};
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_int_sub>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_int_sub>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildSub(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
- // REVIEW: Possibly incorperate into build_int_sub via flag param
- pub fn build_int_nsw_sub>(&self, lhs: T, rhs: T, name: &str) -> T {
+ // REVIEW: Possibly incorporate into build_int_sub via flag param
+ pub fn build_int_nsw_sub>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildNSWSub(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
- // REVIEW: Possibly incorperate into build_int_sub via flag param
+ // REVIEW: Possibly incorporate into build_int_sub via flag param
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_int_nuw_sub>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_int_nuw_sub>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildNUWSub(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// SubType: (&self, lhs: &FloatValue, rhs: &FloatValue, name: &str) -> FloatValue {
- pub fn build_float_sub>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_float_sub>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildFSub(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_int_mul>(&self, lhs: T, rhs: T, name: &str) -> T {
+ pub fn build_int_mul>(&self, lhs: T, rhs: T, name: &str) -> Result {
+ if self.positioned.get() != PositionState::Set {
+ return Err(BuilderError::UnsetPosition);
+ }
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildMul(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) };
- unsafe { T::new(value) }
+ unsafe { Ok(T::new(value)) }
}
- // REVIEW: Possibly incorperate into build_int_mul via flag param
+ // REVIEW: Possibly incorporate into build_int_mul via flag param
// SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue {
- pub fn build_int_nsw_mul