From 34e989c698d6c88ef07bea4e3fe0e1b25cf66ed8 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Mon, 5 Feb 2024 20:29:23 -0800 Subject: [PATCH] Add get_name to values Signed-off-by: Alex Saveau --- src/values/enums.rs | 13 +++++++++++++ src/values/traits.rs | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/src/values/enums.rs b/src/values/enums.rs index 875a547347c..969b499e73d 100644 --- a/src/values/enums.rs +++ b/src/values/enums.rs @@ -10,6 +10,7 @@ use crate::values::{ }; use std::convert::TryFrom; +use std::ffi::CStr; use std::fmt::{self, Display}; use super::AnyValue; @@ -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 { diff --git a/src/values/traits.rs b/src/values/traits.rs index 47084670538..e4fd3b669ea 100644 --- a/src/values/traits.rs +++ b/src/values/traits.rs @@ -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; @@ -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) }