inkwell::attributes

Struct Attribute

Source
pub struct Attribute { /* private fields */ }
Expand description

Functions, function parameters, and return types can have Attributes to indicate how they should be treated by optimizations and code generation.

Implementations§

Source§

impl Attribute

Source

pub unsafe fn new(attribute: LLVMAttributeRef) -> Self

Creates a new Attribute from a raw pointer.

Source

pub fn as_mut_ptr(&self) -> LLVMAttributeRef

Acquires the underlying raw pointer belonging to this Attribute type.

Source

pub fn is_enum(self) -> bool

Determines whether or not an Attribute is an enum. This method will likely be removed in the future in favor of Attributes being generically defined.

§Example
use inkwell::context::Context;

let context = Context::create();
let enum_attribute = context.create_enum_attribute(0, 10);

assert!(enum_attribute.is_enum());
Source

pub fn is_string(self) -> bool

Determines whether or not an Attribute is a string. This method will likely be removed in the future in favor of Attributes being generically defined.

§Example
use inkwell::context::Context;

let context = Context::create();
let string_attribute = context.create_string_attribute("my_key_123", "my_val");

assert!(string_attribute.is_string());
Source

pub fn is_type(self) -> bool

Available on crate features llvm12-0 or llvm13-0 or llvm14-0 or llvm15-0 or llvm16-0 or llvm17-0 or llvm18-0 only.

Determines whether or not an Attribute is a type attribute. This method will likely be removed in the future in favor of Attributes being generically defined.

§Example
use inkwell::context::Context;
use inkwell::attributes::Attribute;

let context = Context::create();
let kind_id = Attribute::get_named_enum_kind_id("sret");
let type_attribute = context.create_type_attribute(
    kind_id,
    context.i32_type().into(),
);

assert!(type_attribute.is_type());
Source

pub fn get_named_enum_kind_id(name: &str) -> u32

Gets the enum kind id associated with a builtin name.

§Example
use inkwell::attributes::Attribute;

// This kind id doesn't exist:
assert_eq!(Attribute::get_named_enum_kind_id("foobar"), 0);

// These are real kind ids:
assert_eq!(Attribute::get_named_enum_kind_id("align"), 1);
assert_eq!(Attribute::get_named_enum_kind_id("builtin"), 5);
Source

pub fn get_enum_kind_id(self) -> u32

Available on crate features llvm12-0 or llvm13-0 or llvm14-0 or llvm15-0 or llvm16-0 or llvm17-0 or llvm18-0 only.

Gets the kind id associated with an enum Attribute.

§Example
use inkwell::context::Context;

let context = Context::create();
let enum_attribute = context.create_enum_attribute(0, 10);

assert_eq!(enum_attribute.get_enum_kind_id(), 0);

This function also works for type Attributes.

use inkwell::context::Context;
use inkwell::attributes::Attribute;
use inkwell::types::AnyType;

let context = Context::create();
let kind_id = Attribute::get_named_enum_kind_id("sret");
let any_type = context.i32_type().as_any_type_enum();
let type_attribute = context.create_type_attribute(
    kind_id,
    any_type,
);

assert_eq!(type_attribute.get_enum_kind_id(), kind_id);
Source

pub fn get_last_enum_kind_id() -> u32

Gets the last enum kind id associated with builtin names.

§Example
use inkwell::attributes::Attribute;

assert_eq!(Attribute::get_last_enum_kind_id(), 56);
Source

pub fn get_enum_value(self) -> u64

Gets the value associated with an enum Attribute.

§Example
use inkwell::context::Context;

let context = Context::create();
let enum_attribute = context.create_enum_attribute(0, 10);

assert_eq!(enum_attribute.get_enum_value(), 10);
Source

pub fn get_string_kind_id(&self) -> &CStr

Gets the string kind id associated with a string attribute.

§Example
use inkwell::context::Context;

let context = Context::create();
let string_attribute = context.create_string_attribute("my_key", "my_val");

assert_eq!(string_attribute.get_string_kind_id().to_str(), Ok("my_key"));
Source

pub fn get_string_value(&self) -> &CStr

Gets the string value associated with a string attribute.

§Example
use inkwell::context::Context;

let context = Context::create();
let string_attribute = context.create_string_attribute("my_key", "my_val");

assert_eq!(string_attribute.get_string_value().to_str(), Ok("my_val"));
Source

pub fn get_type_value(&self) -> AnyTypeEnum<'_>

Available on crate features llvm12-0 or llvm13-0 or llvm14-0 or llvm15-0 or llvm16-0 or llvm17-0 or llvm18-0 only.

Gets the type associated with a type attribute.

§Example
use inkwell::context::Context;
use inkwell::attributes::Attribute;
use inkwell::types::AnyType;

let context = Context::create();
let kind_id = Attribute::get_named_enum_kind_id("sret");
let any_type = context.i32_type().as_any_type_enum();
let type_attribute = context.create_type_attribute(
    kind_id,
    any_type,
);

assert!(type_attribute.is_type());
assert_eq!(type_attribute.get_type_value(), any_type);
assert_ne!(type_attribute.get_type_value(), context.i64_type().as_any_type_enum());

Trait Implementations§

Source§

impl Clone for Attribute

Source§

fn clone(&self) -> Attribute

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Attribute

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Attribute

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Attribute

Source§

impl Eq for Attribute

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.