Skip to content

Commit

Permalink
Add get_value_type to GlobalValue
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Lambein committed Apr 3, 2024
1 parent 71c80e5 commit 2f63a42
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/values/global_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use std::fmt::{self, Display};
#[llvm_versions(7.0..=latest)]
use crate::comdat::Comdat;
use crate::module::Linkage;
use crate::types::AnyTypeEnum;
use crate::values::traits::AsValueRef;
#[llvm_versions(8.0..=latest)]
use crate::values::MetadataValue;
Expand Down Expand Up @@ -295,6 +296,10 @@ impl<'ctx> GlobalValue<'ctx> {
pub fn set_linkage(self, linkage: Linkage) {
unsafe { LLVMSetLinkage(self.as_value_ref(), linkage.into()) }
}

pub fn get_value_type(self) -> AnyTypeEnum<'ctx> {
unsafe { AnyTypeEnum::new(llvm_sys::core::LLVMGlobalGetValueType(self.as_value_ref())) }
}
}

unsafe impl AsValueRef for GlobalValue<'_> {
Expand Down
3 changes: 2 additions & 1 deletion tests/all/test_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use inkwell::attributes::AttributeLoc;
use inkwell::comdat::ComdatSelectionKind;
use inkwell::context::Context;
use inkwell::module::Linkage::*;
use inkwell::types::{BasicType, StringRadix, VectorType};
use inkwell::types::{AnyTypeEnum, BasicType, StringRadix, VectorType};
use inkwell::values::{AnyValue, BasicValue, InstructionOpcode::*, FIRST_CUSTOM_METADATA_KIND_ID};
use inkwell::{AddressSpace, DLLStorageClass, GlobalVisibility, ThreadLocalMode};

Expand Down Expand Up @@ -883,6 +883,7 @@ fn test_globals() {
assert_eq!(global.get_dll_storage_class(), DLLStorageClass::default());
assert_eq!(global.get_visibility(), GlobalVisibility::default());
assert_eq!(global.get_linkage(), External);
assert_eq!(global.get_value_type(), AnyTypeEnum::IntType(i8_type));
assert_eq!(module.get_first_global().unwrap(), global);
assert_eq!(module.get_last_global().unwrap(), global);
assert_eq!(module.get_global("my_global").unwrap(), global);
Expand Down

0 comments on commit 2f63a42

Please sign in to comment.