diff --git a/Cargo.toml b/Cargo.toml index ea6a8b26de..7a0bc97ee6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -156,7 +156,6 @@ llvm-sys-181 = { package = "llvm-sys", version = "181.2.0", optional = true } llvm-sys-191 = { package = "llvm-sys", version = "191.0.0", optional = true } llvm-sys-201 = { package = "llvm-sys", version = "201.0.0", optional = true } -either = "1.5" libc = "0.2" once_cell = "1.16" thiserror = "2.0.11" diff --git a/examples/kaleidoscope/implementation_typed_pointers.rs b/examples/kaleidoscope/implementation_typed_pointers.rs index 7249442a06..48842cacd8 100644 --- a/examples/kaleidoscope/implementation_typed_pointers.rs +++ b/examples/kaleidoscope/implementation_typed_pointers.rs @@ -971,7 +971,7 @@ impl<'a, 'ctx> Compiler<'a, 'ctx> { .build_call(fun, &[lhs.into(), rhs.into()], "tmpbin") .unwrap() .try_as_basic_value() - .left() + .basic() { Some(value) => Ok(value.into_float_value()), None => Err("Invalid call produced."), @@ -1001,7 +1001,7 @@ impl<'a, 'ctx> Compiler<'a, 'ctx> { .build_call(fun, argsv.as_slice(), "tmp") .unwrap() .try_as_basic_value() - .left() + .basic() { Some(value) => Ok(value.into_float_value()), None => Err("Invalid call produced."), diff --git a/src/basic_block.rs b/src/basic_block.rs index da41ee85c3..91cc3affb2 100644 --- a/src/basic_block.rs +++ b/src/basic_block.rs @@ -506,7 +506,7 @@ impl<'ctx> BasicBlock<'ctx> { /// /// bb1.replace_all_uses_with(&bb2); /// - /// assert_eq!(branch_inst.get_operand(0).unwrap().right().unwrap(), bb2); + /// assert_eq!(branch_inst.get_operand(0).unwrap().unwrap_block(), bb2); /// ``` pub fn replace_all_uses_with(self, other: &BasicBlock<'ctx>) { let value = unsafe { LLVMBasicBlockAsValue(self.basic_block) }; diff --git a/src/builder.rs b/src/builder.rs index 29d3f69ad4..5d6e649207 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -242,8 +242,7 @@ impl<'ctx> Builder<'ctx> { /// /// let ret_val = builder.build_call(fn_value, &[i32_arg.into(), md_string.into()], "call").unwrap() /// .try_as_basic_value() - /// .left() - /// .unwrap(); + /// .unwrap_basic(); /// /// builder.build_return(Some(&ret_val)).unwrap(); /// ``` @@ -320,8 +319,7 @@ impl<'ctx> Builder<'ctx> { /// /// let ret_val = builder.build_call(fn_value, &[i32_arg.into(), md_string.into()], "call").unwrap() /// .try_as_basic_value() - /// .left() - /// .unwrap(); + /// .unwrap_basic(); /// /// builder.build_return(Some(&ret_val)).unwrap(); /// ``` @@ -367,7 +365,7 @@ impl<'ctx> Builder<'ctx> { /// ) /// .unwrap() /// .try_as_basic_value() - /// .unwrap_left(); + /// .unwrap_basic(); /// builder.build_return(Some(&ret_val)).unwrap(); /// /// # module.verify().unwrap(); @@ -413,8 +411,7 @@ impl<'ctx> Builder<'ctx> { /// let function_pointer = fn_value.as_global_value().as_pointer_value(); /// let ret_val = builder.build_indirect_call(fn_value.get_type(), function_pointer, &[i32_arg.into(), md_string.into()], "call").unwrap() /// .try_as_basic_value() - /// .left() - /// .unwrap(); + /// .unwrap_basic(); /// /// builder.build_return(Some(&ret_val)).unwrap(); /// ``` @@ -585,7 +582,7 @@ impl<'ctx> Builder<'ctx> { /// builder.position_at_end(then_block); /// /// // in the then_block, the `call_site` value is defined and can be used - /// let result = call_site.try_as_basic_value().left().unwrap(); + /// let result = call_site.try_as_basic_value().unwrap_basic(); /// /// builder.build_return(Some(&result)).unwrap(); /// } @@ -707,7 +704,7 @@ impl<'ctx> Builder<'ctx> { /// builder.position_at_end(then_block); /// /// // in the then_block, the `call_site` value is defined and can be used - /// let result = call_site.try_as_basic_value().left().unwrap(); + /// let result = call_site.try_as_basic_value().unwrap_basic(); /// /// builder.build_return(Some(&result)).unwrap(); /// } @@ -1068,7 +1065,7 @@ impl<'ctx> Builder<'ctx> { /// builder.position_at_end(then_block); /// /// // in the then_block, the `call_site` value is defined and can be used - /// let result = call_site.try_as_basic_value().left().unwrap(); + /// let result = call_site.try_as_basic_value().unwrap_basic(); /// /// builder.build_return(Some(&result)).unwrap(); /// } diff --git a/src/execution_engine.rs b/src/execution_engine.rs index 0de13a79ef..c6c43eaea2 100644 --- a/src/execution_engine.rs +++ b/src/execution_engine.rs @@ -166,7 +166,7 @@ impl<'ctx> ExecutionEngine<'ctx> { /// /// let argf = ft.const_float(64.); /// let call_site_value = builder.build_call(extf, &[argf.into(), argf.into()], "retv").unwrap(); - /// let retv = call_site_value.try_as_basic_value().left().unwrap().into_float_value(); + /// let retv = call_site_value.try_as_basic_value().unwrap_basic().into_float_value(); /// /// builder.build_return(Some(&retv)).unwrap(); /// diff --git a/src/lib.rs b/src/lib.rs index 3788bf4a86..ba9d5a0d80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,7 +78,6 @@ use llvm_sys::{ use llvm_sys::LLVMInlineAsmDialect; -pub use either::Either; pub use error::Error; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; diff --git a/src/values/basic_value_use.rs b/src/values/basic_value_use.rs index e847c9f004..72ec3f582e 100644 --- a/src/values/basic_value_use.rs +++ b/src/values/basic_value_use.rs @@ -1,7 +1,3 @@ -use either::{ - Either, - Either::{Left, Right}, -}; use llvm_sys::core::{LLVMGetNextUse, LLVMGetUsedValue, LLVMGetUser, LLVMIsABasicBlock, LLVMValueAsBasicBlock}; use llvm_sys::prelude::LLVMUseRef; @@ -10,6 +6,87 @@ use std::marker::PhantomData; use crate::basic_block::BasicBlock; use crate::values::{AnyValueEnum, BasicValueEnum}; +/// Either [BasicValueEnum] or [BasicBlock]. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum Operand<'ctx> { + Value(BasicValueEnum<'ctx>), + Block(BasicBlock<'ctx>), +} + +impl<'ctx> Operand<'ctx> { + /// Determines if the [Operand] is a [BasicValueEnum]. + #[inline] + #[must_use] + pub fn is_value(self) -> bool { + matches!(self, Self::Value(_)) + } + + /// Determines if the [Operand] is a [BasicBlock]. + #[inline] + #[must_use] + pub fn is_block(self) -> bool { + matches!(self, Self::Block(_)) + } + + /// If the [Operand] is a [BasicValueEnum], map it into [Option::Some]. + #[inline] + #[must_use] + pub fn value(self) -> Option> { + match self { + Self::Value(value) => Some(value), + _ => None, + } + } + + /// If the [Operand] is a [BasicBlock], map it into [Option::Some]. + #[inline] + #[must_use] + pub fn block(self) -> Option> { + match self { + Self::Block(block) => Some(block), + _ => None, + } + } + + /// Expect [BasicValueEnum], panic with the message if it is not. + #[inline] + #[must_use] + #[track_caller] + pub fn expect_value(self, msg: &str) -> BasicValueEnum<'ctx> { + match self { + Self::Value(value) => value, + _ => panic!("{msg}"), + } + } + + /// Expect [BasicBlock], panic with the message if it is not. + #[inline] + #[must_use] + #[track_caller] + pub fn expect_block(self, msg: &str) -> BasicBlock<'ctx> { + match self { + Self::Block(block) => block, + _ => panic!("{msg}"), + } + } + + /// Unwrap [BasicValueEnum]. Will panic if it is not. + #[inline] + #[must_use] + #[track_caller] + pub fn unwrap_value(self) -> BasicValueEnum<'ctx> { + self.expect_value("Called unwrap_value() on UsedValue::Block.") + } + + /// Unwrap [BasicBlock]. Will panic if it is not. + #[inline] + #[must_use] + #[track_caller] + pub fn unwrap_block(self) -> BasicBlock<'ctx> { + self.expect_block("Called unwrap_block() on UsedValue::Value.") + } +} + /// A usage of a `BasicValue` in another value. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct BasicValueUse<'ctx>(LLVMUseRef, PhantomData<&'ctx ()>); @@ -160,18 +237,18 @@ impl<'ctx> BasicValueUse<'ctx> { /// let free_instruction = builder.build_free(arg1).unwrap(); /// let return_instruction = builder.build_return(None).unwrap(); /// - /// let free_operand0 = free_instruction.get_operand(0).unwrap().left().unwrap(); + /// let free_operand0 = free_instruction.get_operand(0).unwrap().unwrap_value(); /// let free_operand0_instruction = free_operand0.as_instruction_value().unwrap(); /// let bitcast_use_value = free_operand0_instruction /// .get_first_use() /// .unwrap() /// .get_used_value() - /// .left() + /// .value() /// .unwrap(); /// /// assert_eq!(bitcast_use_value, free_operand0); /// ``` - pub fn get_used_value(self) -> Either, BasicBlock<'ctx>> { + pub fn get_used_value(self) -> Operand<'ctx> { let used_value = unsafe { LLVMGetUsedValue(self.0) }; let is_basic_block = unsafe { !LLVMIsABasicBlock(used_value).is_null() }; @@ -179,9 +256,9 @@ impl<'ctx> BasicValueUse<'ctx> { if is_basic_block { let bb = unsafe { BasicBlock::new(LLVMValueAsBasicBlock(used_value)) }; - Right(bb.expect("BasicBlock should always be valid")) + Operand::Block(bb.expect("BasicBlock should always be valid")) } else { - unsafe { Left(BasicValueEnum::new(used_value)) } + unsafe { Operand::Value(BasicValueEnum::new(used_value)) } } } } diff --git a/src/values/call_site_value.rs b/src/values/call_site_value.rs index 212e29f274..f2070a81c2 100644 --- a/src/values/call_site_value.rs +++ b/src/values/call_site_value.rs @@ -1,7 +1,5 @@ use std::fmt::{self, Display}; -use either::Either; - use llvm_sys::core::LLVMGetCalledFunctionType; use llvm_sys::core::{ LLVMGetCalledValue, LLVMGetInstructionCallConv, LLVMGetTypeKind, LLVMIsTailCall, LLVMSetInstrParamAlignment, @@ -20,6 +18,87 @@ use crate::values::{AsValueRef, BasicValueEnum, FunctionValue, InstructionValue, use super::{AnyValue, InstructionOpcode}; +/// Either [BasicValueEnum] or [InstructionValue]. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum ValueKind<'ctx> { + Basic(BasicValueEnum<'ctx>), + Instruction(InstructionValue<'ctx>), +} + +impl<'ctx> ValueKind<'ctx> { + /// Determines if the [ValueKind] is a [BasicValueEnum]. + #[inline] + #[must_use] + pub fn is_basic(self) -> bool { + matches!(self, Self::Basic(_)) + } + + /// Determines if the [ValueKind] is an [InstructionValue]. + #[inline] + #[must_use] + pub fn is_instruction(self) -> bool { + matches!(self, Self::Instruction(_)) + } + + /// If the [ValueKind] is a [BasicValueEnum], map it into [Option::Some]. + #[inline] + #[must_use] + pub fn basic(self) -> Option> { + match self { + Self::Basic(value) => Some(value), + _ => None, + } + } + + /// If the [ValueKind] is an [InstructionValue], map it into [Option::Some]. + #[inline] + #[must_use] + pub fn instruction(self) -> Option> { + match self { + Self::Instruction(inst) => Some(inst), + _ => None, + } + } + + /// Expect [BasicValueEnum], panic with the message if it is not. + #[inline] + #[must_use] + #[track_caller] + pub fn expect_basic(self, msg: &str) -> BasicValueEnum<'ctx> { + match self { + Self::Basic(value) => value, + _ => panic!("{msg}"), + } + } + + /// Expect [InstructionValue], panic with the message if it is not. + #[inline] + #[must_use] + #[track_caller] + pub fn expect_instruction(self, msg: &str) -> InstructionValue<'ctx> { + match self { + Self::Instruction(inst) => inst, + _ => panic!("{msg}"), + } + } + + /// Unwrap [BasicValueEnum]. Will panic if it is not. + #[inline] + #[must_use] + #[track_caller] + pub fn unwrap_basic(self) -> BasicValueEnum<'ctx> { + self.expect_basic("Called unwrap_basic() on ValueKind::Instruction.") + } + + /// Unwrap [InstructionValue]. Will panic if it is not. + #[inline] + #[must_use] + #[track_caller] + pub fn unwrap_instruction(self) -> InstructionValue<'ctx> { + self.expect_instruction("Called unwrap_instruction() on ValueKind::Basic.") + } +} + /// A value resulting from a function call. It may have function attributes applied to it. /// /// This struct may be removed in the future in favor of an `InstructionValue` type. @@ -160,13 +239,13 @@ impl<'ctx> CallSiteValue<'ctx> { /// /// let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap(); /// - /// assert!(call_site_value.try_as_basic_value().is_right()); + /// assert!(call_site_value.try_as_basic_value().is_instruction()); /// ``` - pub fn try_as_basic_value(self) -> Either, InstructionValue<'ctx>> { + pub fn try_as_basic_value(self) -> ValueKind<'ctx> { unsafe { match LLVMGetTypeKind(LLVMTypeOf(self.as_value_ref())) { - LLVMTypeKind::LLVMVoidTypeKind => Either::Right(InstructionValue::new(self.as_value_ref())), - _ => Either::Left(BasicValueEnum::new(self.as_value_ref())), + LLVMTypeKind::LLVMVoidTypeKind => ValueKind::Instruction(InstructionValue::new(self.as_value_ref())), + _ => ValueKind::Basic(BasicValueEnum::new(self.as_value_ref())), } } } diff --git a/src/values/callable_value.rs b/src/values/callable_value.rs index 2595b76ba5..a65c5427b3 100644 --- a/src/values/callable_value.rs +++ b/src/values/callable_value.rs @@ -1,4 +1,3 @@ -use either::Either; use std::convert::TryFrom; use std::fmt::{self, Display}; @@ -11,6 +10,95 @@ use llvm_sys::prelude::LLVMTypeRef; use llvm_sys::prelude::LLVMValueRef; use llvm_sys::LLVMTypeKind; +/// Either [FunctionValue] or [PointerValue]. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub(crate) enum CallableValueEnum<'ctx> { + Function(FunctionValue<'ctx>), + Pointer(PointerValue<'ctx>), +} + +impl<'ctx> CallableValueEnum<'ctx> { + /// Determines if [CallableValueEnum] is a [FunctionValue]. + #[allow(unused)] + #[inline] + #[must_use] + pub fn is_function(self) -> bool { + matches!(self, Self::Function(_)) + } + + /// Determines if [CallableValueEnum] is a [PointerValue]. + #[allow(unused)] + #[inline] + #[must_use] + pub fn is_pointer(self) -> bool { + matches!(self, Self::Pointer(_)) + } + + /// If the [CallableValueEnum] is a [FunctionValue], map it into [Option::Some]. + #[allow(unused)] + #[inline] + #[must_use] + pub fn function(self) -> Option> { + match self { + Self::Function(function) => Some(function), + _ => None, + } + } + + /// If the [CallableValueEnum] is a [PointerValue], map it into [Option::Some]. + #[allow(unused)] + #[inline] + #[must_use] + pub fn pointer(self) -> Option> { + match self { + Self::Pointer(pointer) => Some(pointer), + _ => None, + } + } + + /// Expect [FunctionValue], panic with the message if it is not. + #[allow(unused)] + #[inline] + #[must_use] + #[track_caller] + pub fn expect_function(self, msg: &str) -> FunctionValue<'ctx> { + match self { + Self::Function(function) => function, + _ => panic!("{msg}"), + } + } + + /// Expect [PointerValue], panic with the message if it is not. + #[allow(unused)] + #[inline] + #[must_use] + #[track_caller] + pub fn expect_pointer(self, msg: &str) -> PointerValue<'ctx> { + match self { + Self::Pointer(pointer) => pointer, + _ => panic!("{msg}"), + } + } + + /// Unwrap [FunctionValue]. Will panic if it is not. + #[allow(unused)] + #[inline] + #[must_use] + #[track_caller] + pub fn unwrap_function(self) -> FunctionValue<'ctx> { + self.expect_function("Called unwrap_function() on CallableValueEnum::Pointer.") + } + + /// Unwrap [PointerValue]. Will panic if it is not. + #[allow(unused)] + #[inline] + #[must_use] + #[track_caller] + pub fn unwrap_pointer(self) -> PointerValue<'ctx> { + self.expect_pointer("Called unwrap_pointer() on CallableValueEnum::Function.") + } +} + /// A value that can be called with the [`build_call`] instruction. /// /// In practice, the `F : Into>` bound of [`build_call`] means it is @@ -36,8 +124,7 @@ use llvm_sys::LLVMTypeKind; /// /// let ret_val = builder.build_call(fn_value, &[i32_arg.into()], "call").unwrap() /// .try_as_basic_value() -/// .left() -/// .unwrap(); +/// .unwrap_basic(); /// /// builder.build_return(Some(&ret_val)).unwrap(); /// ``` @@ -71,21 +158,18 @@ use llvm_sys::LLVMTypeKind; /// /// let ret_val = builder.build_call(callable_value, &[i32_arg.into()], "call").unwrap() /// .try_as_basic_value() -/// .left() -/// .unwrap(); +/// .unwrap_basic(); /// /// builder.build_return(Some(&ret_val)).unwrap(); /// ``` #[derive(Debug)] -pub struct CallableValue<'ctx>(Either, PointerValue<'ctx>>); +pub struct CallableValue<'ctx>(CallableValueEnum<'ctx>); unsafe impl AsValueRef for CallableValue<'_> { fn as_value_ref(&self) -> LLVMValueRef { - use either::Either::*; - match self.0 { - Left(function) => function.as_value_ref(), - Right(pointer) => pointer.as_value_ref(), + CallableValueEnum::Function(function) => function.as_value_ref(), + CallableValueEnum::Pointer(pointer) => pointer.as_value_ref(), } } } @@ -94,11 +178,9 @@ unsafe impl<'ctx> AnyValue<'ctx> for CallableValue<'ctx> {} unsafe impl AsTypeRef for CallableValue<'_> { fn as_type_ref(&self) -> LLVMTypeRef { - use either::Either::*; - match self.0 { - Left(function) => function.get_type().as_type_ref(), - Right(pointer) => pointer.get_type().get_element_type().as_type_ref(), + CallableValueEnum::Function(function) => function.get_type().as_type_ref(), + CallableValueEnum::Pointer(pointer) => pointer.get_type().get_element_type().as_type_ref(), } } } @@ -117,7 +199,7 @@ impl CallableValue<'_> { impl<'ctx> From> for CallableValue<'ctx> { fn from(value: FunctionValue<'ctx>) -> Self { - Self(Either::Left(value)) + Self(CallableValueEnum::Function(value)) } } @@ -131,7 +213,7 @@ impl<'ctx> TryFrom> for CallableValue<'ctx> { let is_a_fn_ptr = matches!(ty_kind, LLVMTypeKind::LLVMFunctionTypeKind); if is_a_fn_ptr { - Ok(Self(Either::Right(value))) + Ok(Self(CallableValueEnum::Pointer(value))) } else { Err(()) } diff --git a/src/values/instruction_value.rs b/src/values/instruction_value.rs index c100ccfa49..430a2fb556 100644 --- a/src/values/instruction_value.rs +++ b/src/values/instruction_value.rs @@ -1,7 +1,3 @@ -use either::{ - Either, - Either::{Left, Right}, -}; #[llvm_versions(14..)] use llvm_sys::core::LLVMGetGEPSourceElementType; use llvm_sys::core::{ @@ -21,11 +17,11 @@ use llvm_sys::LLVMOpcode; use std::{ffi::CStr, fmt, fmt::Display}; -use crate::error::AlignmentError; use crate::values::{BasicValue, BasicValueEnum, BasicValueUse, MetadataValue, Value}; #[llvm_versions(10..)] use crate::AtomicRMWBinOp; use crate::{basic_block::BasicBlock, types::AnyTypeEnum}; +use crate::{error::AlignmentError, values::basic_value_use::Operand}; use crate::{types::BasicTypeEnum, values::traits::AsValueRef}; use crate::{AtomicOrdering, FloatPredicate, IntPredicate}; @@ -663,7 +659,7 @@ impl<'ctx> InstructionValue<'ctx> { /// 3) Function call has two: i8 pointer %1 argument, and the free function itself /// 4) Void return has zero: void is not a value and does not count as an operand /// even though the return instruction can take values. - pub fn get_operand(self, index: u32) -> Option, BasicBlock<'ctx>>> { + pub fn get_operand(self, index: u32) -> Option> { let num_operands = self.get_num_operands(); if index >= num_operands { @@ -678,7 +674,7 @@ impl<'ctx> InstructionValue<'ctx> { /// # Safety /// /// The index must be less than [InstructionValue::get_num_operands]. - pub unsafe fn get_operand_unchecked(self, index: u32) -> Option, BasicBlock<'ctx>>> { + pub unsafe fn get_operand_unchecked(self, index: u32) -> Option> { let operand = unsafe { LLVMGetOperand(self.as_value_ref(), index) }; if operand.is_null() { @@ -690,9 +686,9 @@ impl<'ctx> InstructionValue<'ctx> { if is_basic_block { let bb = unsafe { BasicBlock::new(LLVMValueAsBasicBlock(operand)) }; - Some(Right(bb.expect("BasicBlock should always be valid"))) + Some(Operand::Block(bb.expect("BasicBlock should always be valid"))) } else { - Some(Left(unsafe { BasicValueEnum::new(operand) })) + Some(Operand::Value(unsafe { BasicValueEnum::new(operand) })) } } @@ -737,7 +733,7 @@ impl<'ctx> InstructionValue<'ctx> { /// // This will produce invalid IR: /// free_instruction.set_operand(0, f32_val); /// - /// assert_eq!(free_instruction.get_operand(0).unwrap().left().unwrap(), f32_val); + /// assert_eq!(free_instruction.get_operand(0).unwrap().unwrap_value(), f32_val); /// ``` pub fn set_operand>(self, index: u32, val: BV) -> bool { let num_operands = self.get_num_operands(); @@ -1040,7 +1036,7 @@ pub struct OperandIter<'ctx> { } impl<'ctx> Iterator for OperandIter<'ctx> { - type Item = Option, BasicBlock<'ctx>>>; + type Item = Option>; fn next(&mut self) -> Option { if self.i < self.count { diff --git a/tests/all/test_basic_block.rs b/tests/all/test_basic_block.rs index 39ad35fa85..44b957e3ce 100644 --- a/tests/all/test_basic_block.rs +++ b/tests/all/test_basic_block.rs @@ -185,7 +185,7 @@ fn test_rauw() { bb1.replace_all_uses_with(&bb1); // no-op bb1.replace_all_uses_with(&bb2); - assert_eq!(branch_inst.get_operand(0).unwrap().right().unwrap(), bb2); + assert_eq!(branch_inst.get_operand(0).unwrap().unwrap_block(), bb2); } #[test] diff --git a/tests/all/test_builder.rs b/tests/all/test_builder.rs index 932b0191fd..9c69dcd158 100644 --- a/tests/all/test_builder.rs +++ b/tests/all/test_builder.rs @@ -35,7 +35,7 @@ fn test_build_call() { assert!(pi2_call_site.is_tail_call()); - let pi2 = pi2_call_site.try_as_basic_value().left().unwrap(); + let pi2 = pi2_call_site.try_as_basic_value().unwrap_basic(); builder.build_return(Some(&pi2)).unwrap(); @@ -134,7 +134,7 @@ fn test_build_invoke_cleanup_resume() { { builder.position_at_end(then_block); - let result = call_site.try_as_basic_value().left().unwrap(); + let result = call_site.try_as_basic_value().unwrap_basic(); builder.build_return(Some(&result)).unwrap(); } @@ -208,7 +208,7 @@ fn test_build_invoke_catch_all() { { builder.position_at_end(then_block); - let pi2 = pi2_call_site.try_as_basic_value().left().unwrap(); + let pi2 = pi2_call_site.try_as_basic_value().unwrap_basic(); builder.build_return(Some(&pi2)).unwrap(); } @@ -286,7 +286,7 @@ fn landing_pad_filter() { { builder.position_at_end(then_block); - let pi2 = pi2_call_site.try_as_basic_value().left().unwrap(); + let pi2 = pi2_call_site.try_as_basic_value().unwrap_basic(); builder.build_return(Some(&pi2)).unwrap(); } diff --git a/tests/all/test_instruction_values.rs b/tests/all/test_instruction_values.rs index 3b120742e9..61fae5e93d 100644 --- a/tests/all/test_instruction_values.rs +++ b/tests/all/test_instruction_values.rs @@ -47,8 +47,8 @@ fn test_operands() { let store_operand0 = store_instruction.get_operand(0).unwrap(); let store_operand1 = store_instruction.get_operand(1).unwrap(); - assert_eq!(store_operand0.left().unwrap(), f32_val); // f32 const - assert_eq!(store_operand1.left().unwrap(), arg1); // f32* arg1 + assert_eq!(store_operand0.unwrap_value(), f32_val); // f32 const + assert_eq!(store_operand1.unwrap_value(), arg1); // f32* arg1 assert!(store_instruction.get_operand(2).is_none()); assert!(store_instruction.get_operand(3).is_none()); assert!(store_instruction.get_operand(4).is_none()); @@ -57,12 +57,12 @@ fn test_operands() { let store_operand0 = store_operands.next().unwrap().unwrap(); let store_operand1 = store_operands.next().unwrap().unwrap(); - assert_eq!(store_operand0.left().unwrap(), f32_val); // f32 const - assert_eq!(store_operand1.left().unwrap(), arg1); // f32* arg1 + assert_eq!(store_operand0.unwrap_value(), f32_val); // f32 const + assert_eq!(store_operand1.unwrap_value(), arg1); // f32* arg1 assert!(store_operands.next().is_none()); - let free_operand0 = free_instruction.get_operand(0).unwrap().left().unwrap(); - let free_operand1 = free_instruction.get_operand(1).unwrap().left().unwrap(); + let free_operand0 = free_instruction.get_operand(0).unwrap().unwrap_value(); + let free_operand1 = free_instruction.get_operand(1).unwrap().unwrap_value(); assert!(free_operand0.is_pointer_value()); // (implicitly casted) i8* arg1 assert!(free_operand1.is_pointer_value()); // Free function ptr @@ -72,7 +72,7 @@ fn test_operands() { let free_operand0_instruction = free_operand0.as_instruction_value().unwrap(); assert_eq!(free_operand0_instruction.get_opcode(), BitCast); - assert_eq!(free_operand0_instruction.get_operand(0).unwrap().left().unwrap(), arg1); + assert_eq!(free_operand0_instruction.get_operand(0).unwrap().unwrap_value(), arg1); assert!(free_operand0_instruction.get_operand(1).is_none()); assert!(free_operand0_instruction.get_operand(2).is_none()); @@ -104,9 +104,8 @@ fn test_operands() { .get_first_use() .unwrap() .get_used_value() - .left() - .unwrap(); - let free_call_param = free_instruction.get_operand(0).unwrap().left().unwrap(); + .unwrap_value(); + let free_call_param = free_instruction.get_operand(0).unwrap().unwrap_value(); assert_eq!(bit_cast_use_value, free_call_param); @@ -137,8 +136,8 @@ fn test_operands() { store_operand_use1.get_user().into_instruction_value(), store_instruction ); - assert_eq!(store_operand_use0.get_used_value().left().unwrap(), f32_val); - assert_eq!(store_operand_use1.get_used_value().left().unwrap(), arg1); + assert_eq!(store_operand_use0.get_used_value().value().unwrap(), f32_val); + assert_eq!(store_operand_use1.get_used_value().value().unwrap(), arg1); assert!(store_instruction.get_operand_use(2).is_none()); assert!(store_instruction.get_operand_use(3).is_none()); @@ -163,8 +162,8 @@ fn test_operands() { store_operand_use1.get_user().into_instruction_value(), store_instruction ); - assert_eq!(store_operand_use0.get_used_value().left().unwrap(), f32_val); - assert_eq!(store_operand_use1.get_used_value().left().unwrap(), arg1); + assert_eq!(store_operand_use0.get_used_value().value().unwrap(), f32_val); + assert_eq!(store_operand_use1.get_used_value().value().unwrap(), arg1); assert!(store_operand_uses.next().is_none()); let free_operand_use0 = free_instruction.get_operand_use(0).unwrap(); @@ -195,13 +194,13 @@ fn test_basic_block_operand() { builder.position_at_end(basic_block); let branch_instruction = builder.build_unconditional_branch(basic_block2).unwrap(); - let bb_operand = branch_instruction.get_operand(0).unwrap().right().unwrap(); + let bb_operand = branch_instruction.get_operand(0).unwrap().unwrap_block(); assert_eq!(bb_operand, basic_block2); let bb_operand_use = branch_instruction.get_operand_use(0).unwrap(); - assert_eq!(bb_operand_use.get_used_value().right().unwrap(), basic_block2); + assert_eq!(bb_operand_use.get_used_value().block().unwrap(), basic_block2); builder.position_at_end(basic_block2); builder.build_return(None).unwrap(); diff --git a/tests/all/test_values.rs b/tests/all/test_values.rs index 65c7364e8f..3526b48d18 100644 --- a/tests/all/test_values.rs +++ b/tests/all/test_values.rs @@ -91,7 +91,7 @@ fn test_call_site_tail_call_attributes() { assert!(!call_site.is_tail_call()); assert_eq!(call_site.get_tail_call_kind(), LLVMTailCallKindNone); assert_eq!( - call_site.try_as_basic_value().right().unwrap().get_tail_call_kind(), + call_site.try_as_basic_value().unwrap_instruction().get_tail_call_kind(), Some(LLVMTailCallKindNone) );