Skip to content

Commit

Permalink
impl AnyValue & BasicValue for GlobalValue as they are always Pointer…
Browse files Browse the repository at this point in the history
…Values.

Fixes rust-lang#26
  • Loading branch information
TheDan64 committed Nov 21, 2017
1 parent 7895037 commit b26b894
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/values/global_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::ffi::{CString, CStr};

use {GlobalVisibility, ThreadLocalMode, DLLStorageClass};
use values::traits::AsValueRef;
use values::{BasicValueEnum, BasicValue, Value};
use values::{BasicValueEnum, BasicValue, PointerValue, Value};

// REVIEW: GlobalValues may always be PointerValues, in which case we can
// simplify from BasicValueEnum down to PointerValue
// REVIEW: GlobalValues are always PointerValues. With SubTypes, we should
// compress this into a PointerValue<Global> type
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct GlobalValue {
global_value: Value,
Expand Down Expand Up @@ -189,6 +189,10 @@ impl GlobalValue {
pub unsafe fn delete(self) {
LLVMDeleteGlobal(self.as_value_ref())
}

pub fn as_pointer_value(&self) -> PointerValue {
PointerValue::new(self.as_value_ref())
}
}

impl AsValueRef for GlobalValue {
Expand Down
6 changes: 3 additions & 3 deletions src/values/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use llvm_sys::prelude::LLVMValueRef;

use std::fmt::Debug;

use values::{ArrayValue, AggregateValueEnum, StructValue, BasicValueEnum, AnyValueEnum, IntValue, FloatValue, PointerValue, PhiValue, VectorValue, FunctionValue, InstructionValue};
use values::{ArrayValue, AggregateValueEnum, GlobalValue, StructValue, BasicValueEnum, AnyValueEnum, IntValue, FloatValue, PointerValue, PhiValue, VectorValue, FunctionValue, InstructionValue};

// This is an ugly privacy hack so that Type can stay private to this module
// and so that super traits using this trait will be not be implementable
Expand Down Expand Up @@ -47,5 +47,5 @@ pub trait AnyValue: AsValueRef + Debug {
}

trait_value_set! {AggregateValue: ArrayValue, AggregateValueEnum, StructValue}
trait_value_set! {AnyValue: AnyValueEnum, BasicValueEnum, AggregateValueEnum, ArrayValue, IntValue, FloatValue, PhiValue, PointerValue, FunctionValue, StructValue, VectorValue, InstructionValue}
trait_value_set! {BasicValue: ArrayValue, BasicValueEnum, AggregateValueEnum, IntValue, FloatValue, StructValue, PointerValue, VectorValue}
trait_value_set! {AnyValue: AnyValueEnum, BasicValueEnum, AggregateValueEnum, ArrayValue, IntValue, FloatValue, GlobalValue, PhiValue, PointerValue, FunctionValue, StructValue, VectorValue, InstructionValue}
trait_value_set! {BasicValue: ArrayValue, BasicValueEnum, AggregateValueEnum, IntValue, FloatValue, GlobalValue, StructValue, PointerValue, VectorValue}
2 changes: 2 additions & 0 deletions tests/test_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use self::inkwell::values::{MetadataValue, FIRST_CUSTOM_METADATA_KIND_ID};

use std::ffi::CString;

// TODO: Test GlobalValues used as PointerValues

#[test]
fn test_linkage() {
let context = Context::create();
Expand Down

0 comments on commit b26b894

Please sign in to comment.