Skip to content

Commit

Permalink
Add set_field_at_index for llvm-plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX committed Jan 21, 2024
1 parent 4909eaa commit fe4c1d1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/values/struct_value.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use llvm_sys::core::{LLVMGetNumOperands, LLVMGetOperand};
use llvm_sys::core::{LLVMGetNumOperands, LLVMGetOperand, LLVMSetOperand};

use llvm_sys::prelude::LLVMValueRef;

Expand All @@ -7,7 +7,7 @@ use std::fmt::{self, Display};

use crate::types::StructType;
use crate::values::traits::AsValueRef;
use crate::values::{InstructionValue, Value};
use crate::values::{BasicValue, InstructionValue, Value};

use super::{AnyValue, BasicValueEnum};

Expand Down Expand Up @@ -52,6 +52,17 @@ impl<'ctx> StructValue<'ctx> {
unsafe { Some(BasicValueEnum::new(LLVMGetOperand(self.as_value_ref(), index))) }
}

/// Sets the value of a field belonging to this `StructValue`.
pub fn set_field_at_index<BV: BasicValue<'ctx>>(self, index: u32, val: BV) -> bool {
if index >= self.count_fields() {
return false;
}

unsafe { LLVMSetOperand(self.as_value_ref(), index, val.as_value_ref()) }

true
}

/// Counts the number of fields.
///
/// ```no_run
Expand Down

0 comments on commit fe4c1d1

Please sign in to comment.