Skip to content

Add support for multiple integers value for attribute and NonNull #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions gccjit_sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ pub enum gcc_jit_fn_attribute
GCC_JIT_FN_ATTRIBUTE_PURE,
GCC_JIT_FN_ATTRIBUTE_CONST,
GCC_JIT_FN_ATTRIBUTE_WEAK,
GCC_JIT_FN_ATTRIBUTE_NONNULL,
}

#[cfg(feature="master")]
Expand Down Expand Up @@ -619,6 +620,9 @@ extern {
#[cfg(feature="master")]
pub fn gcc_jit_function_add_string_attribute(func: *mut gcc_jit_function, attribute: gcc_jit_fn_attribute, value: *const c_char);

#[cfg(feature="master")]
pub fn gcc_jit_function_add_integer_array_attribute(func: *mut gcc_jit_function, attribute: gcc_jit_fn_attribute, value: *const c_int, length: size_t);

#[cfg(feature="master")]
pub fn gcc_jit_lvalue_add_attribute(variable: *mut gcc_jit_lvalue, attribute: gcc_jit_variable_attribute, value: *const c_char);

Expand Down
27 changes: 26 additions & 1 deletion src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub enum FnAttribute<'a> {
Pure,
Const,
Weak,
NonNull(Vec<i32>),
}

#[cfg(feature="master")]
Expand All @@ -78,6 +79,7 @@ impl<'a> FnAttribute<'a> {
| FnAttribute::Pure
| FnAttribute::Const
| FnAttribute::Weak => AttributeValue::None,
FnAttribute::NonNull(ref value) => AttributeValue::IntArray(value),
}
}

Expand All @@ -95,6 +97,7 @@ impl<'a> FnAttribute<'a> {
FnAttribute::Pure => gccjit_sys::gcc_jit_fn_attribute::GCC_JIT_FN_ATTRIBUTE_PURE,
FnAttribute::Const => gccjit_sys::gcc_jit_fn_attribute::GCC_JIT_FN_ATTRIBUTE_CONST,
FnAttribute::Weak => gccjit_sys::gcc_jit_fn_attribute::GCC_JIT_FN_ATTRIBUTE_WEAK,
FnAttribute::NonNull(_) => gccjit_sys::gcc_jit_fn_attribute::GCC_JIT_FN_ATTRIBUTE_NONNULL,
}
}
}
Expand Down Expand Up @@ -208,7 +211,29 @@ impl<'ctx> Function<'ctx> {
pub fn add_attribute<'a>(&self, attribute: FnAttribute<'a>) {
let value = attribute.get_value();
match value {
AttributeValue::Int(_) => unimplemented!(),
AttributeValue::Int(value) => {
// Basically the same as `IntArray` but for only one element.
let value = &[value];
unsafe {
gccjit_sys::gcc_jit_function_add_integer_array_attribute(
self.ptr,
attribute.as_sys(),
value.as_ptr(),
value.len() as _,
);
}

}
AttributeValue::IntArray(value) => {
unsafe {
gccjit_sys::gcc_jit_function_add_integer_array_attribute(
self.ptr,
attribute.as_sys(),
value.as_ptr(),
value.len() as _,
);
}
}
AttributeValue::None => {
unsafe {
gccjit_sys::gcc_jit_function_add_attribute(self.ptr, attribute.as_sys());
Expand Down
4 changes: 3 additions & 1 deletion src/lvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub enum AttributeValue<'a> {
Int(i32),
None,
String(&'a str),
IntArray(&'a [i32]),
}

#[cfg(feature="master")]
Expand All @@ -51,7 +52,7 @@ pub enum VarAttribute {
impl VarAttribute {
fn get_value(&self) -> AttributeValue {
match *self {
VarAttribute::Visibility(visibility) => AttributeValue::String(visibility.as_str()),
Self::Visibility(visibility) => AttributeValue::String(visibility.as_str()),
}
}

Expand Down Expand Up @@ -221,6 +222,7 @@ impl<'ctx> LValue<'ctx> {
let value = attribute.get_value();
match value {
AttributeValue::Int(_) => unimplemented!(),
AttributeValue::IntArray(_) => unimplemented!(),
AttributeValue::None => unimplemented!(),
AttributeValue::String(string) => {
let cstr = CString::new(string).unwrap();
Expand Down