llir/values/instruction/
extract_value.rs1use llvm_sys::core::*;
2use llvm_sys::prelude::LLVMValueRef;
3use std::marker::PhantomData;
4
5use crate::types::*;
6use crate::values::*;
7use crate::*;
8
9#[derive(Copy, Clone, PartialEq, Eq, Hash)]
11pub struct ExtractValueInstruction<'ctx>(LLVMValueRef, PhantomData<&'ctx ()>);
12
13impl_instr_debug!(ExtractValueInstruction);
14
15impl_as_operand_for_instr!(ExtractValueInstruction);
16
17impl_send_sync!(ExtractValueInstruction);
18
19impl<'ctx> GetType<'ctx> for ExtractValueInstruction<'ctx> {}
20
21impl<'ctx> GetDebugMetadata<'ctx> for ExtractValueInstruction<'ctx> {}
22
23impl<'ctx> InstructionDebugLoc for ExtractValueInstruction<'ctx> {}
24
25impl<'ctx> InstructionTrait<'ctx> for ExtractValueInstruction<'ctx> {}
26
27impl<'ctx> ExtractValueInstruction<'ctx> {
28 pub fn aggregate(&self) -> Operand<'ctx> {
30 Operand::from_llvm(unsafe { LLVMGetOperand(self.0, 0) })
31 }
32
33 pub fn aggregate_type(&self) -> Type<'ctx> {
35 self.aggregate().get_type()
36 }
37
38 pub fn num_indices(&self) -> usize {
40 unsafe { LLVMGetNumIndices(self.0) as usize }
41 }
42
43 pub fn indices(&self) -> Vec<u32> {
45 let num_indices = self.num_indices();
46 let mut indices = vec![0; num_indices];
47 unsafe {
48 let raw_indices = LLVMGetIndices(self.0);
49 for i in 0..num_indices {
50 indices[i] = *raw_indices.offset(i as isize) as u32;
51 }
52 }
53 return indices;
54 }
55}
56
57impl<'ctx> ValueOpcode for ExtractValueInstruction<'ctx> {
58 fn opcode(&self) -> Opcode {
59 Opcode::ExtractValue
60 }
61}
62
63impl<'ctx> AsInstruction<'ctx> for ExtractValueInstruction<'ctx> {
64 fn as_instruction(&self) -> Instruction<'ctx> {
65 Instruction::ExtractValue(*self)
66 }
67}
68
69impl_positional_value_ref!(ExtractValueInstruction, 0);
70
71impl_positional_from_llvm_value!(ExtractValueInstruction);