Skip to content

Commit

Permalink
Add get_name to values
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX authored and TheDan64 committed Feb 7, 2024
1 parent e060023 commit 34e989c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/values/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::values::{
};

use std::convert::TryFrom;
use std::ffi::CStr;
use std::fmt::{self, Display};

use super::AnyValue;
Expand Down Expand Up @@ -231,6 +232,18 @@ impl<'ctx> BasicValueEnum<'ctx> {
}
}

/// Get the name of the `BasicValueEnum`.
pub fn get_name(&self) -> &CStr {
match self {
BasicValueEnum::ArrayValue(v) => v.get_name(),
BasicValueEnum::IntValue(v) => v.get_name(),
BasicValueEnum::FloatValue(v) => v.get_name(),
BasicValueEnum::PointerValue(v) => v.get_name(),
BasicValueEnum::StructValue(v) => v.get_name(),
BasicValueEnum::VectorValue(v) => v.get_name(),
}
}

/// Set name of the `BasicValueEnum`.
pub fn set_name(&self, name: &str) {
match self {
Expand Down
6 changes: 6 additions & 0 deletions src/values/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use llvm_sys::prelude::LLVMValueRef;
#[llvm_versions(12.0..=latest)]
use llvm_sys::core::LLVMIsPoison;

use std::ffi::CStr;
use std::fmt::Debug;

use crate::support::LLVMString;
Expand Down Expand Up @@ -109,6 +110,11 @@ pub unsafe trait BasicValue<'ctx>: AnyValue<'ctx> {
unsafe { Value::new(self.as_value_ref()).get_first_use() }
}

/// Get the name of a `BasicValue`.
fn get_name(&self) -> &CStr {
unsafe { Value::new(self.as_value_ref()).get_name() }
}

/// Sets the name of a `BasicValue`. If the value is a constant, this is a noop.
fn set_name(&self, name: &str) {
unsafe { Value::new(self.as_value_ref()).set_name(name) }
Expand Down

0 comments on commit 34e989c

Please sign in to comment.