Skip to content

Commit 15cf0bf

Browse files
Add support for IntArray and for NonNull function attribute
1 parent 0b158c6 commit 15cf0bf

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

gccjit_sys/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ pub enum gcc_jit_fn_attribute
270270
GCC_JIT_FN_ATTRIBUTE_PURE,
271271
GCC_JIT_FN_ATTRIBUTE_CONST,
272272
GCC_JIT_FN_ATTRIBUTE_WEAK,
273+
GCC_JIT_FN_ATTRIBUTE_NONNULL,
273274
}
274275

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

623+
#[cfg(feature="master")]
624+
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);
625+
622626
#[cfg(feature="master")]
623627
pub fn gcc_jit_lvalue_add_attribute(variable: *mut gcc_jit_lvalue, attribute: gcc_jit_variable_attribute, value: *const c_char);
624628

src/function.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub enum FnAttribute<'a> {
6161
Pure,
6262
Const,
6363
Weak,
64+
NonNull(Vec<i32>),
6465
}
6566

6667
#[cfg(feature="master")]
@@ -78,6 +79,7 @@ impl<'a> FnAttribute<'a> {
7879
| FnAttribute::Pure
7980
| FnAttribute::Const
8081
| FnAttribute::Weak => AttributeValue::None,
82+
FnAttribute::NonNull(ref value) => AttributeValue::IntArray(value),
8183
}
8284
}
8385

@@ -95,6 +97,7 @@ impl<'a> FnAttribute<'a> {
9597
FnAttribute::Pure => gccjit_sys::gcc_jit_fn_attribute::GCC_JIT_FN_ATTRIBUTE_PURE,
9698
FnAttribute::Const => gccjit_sys::gcc_jit_fn_attribute::GCC_JIT_FN_ATTRIBUTE_CONST,
9799
FnAttribute::Weak => gccjit_sys::gcc_jit_fn_attribute::GCC_JIT_FN_ATTRIBUTE_WEAK,
100+
FnAttribute::NonNull(_) => gccjit_sys::gcc_jit_fn_attribute::GCC_JIT_FN_ATTRIBUTE_NONNULL,
98101
}
99102
}
100103
}
@@ -208,7 +211,29 @@ impl<'ctx> Function<'ctx> {
208211
pub fn add_attribute<'a>(&self, attribute: FnAttribute<'a>) {
209212
let value = attribute.get_value();
210213
match value {
211-
AttributeValue::Int(_) => unimplemented!(),
214+
AttributeValue::Int(value) => {
215+
// Basically the same as `IntArray` but for only one element.
216+
let value = &[value];
217+
unsafe {
218+
gccjit_sys::gcc_jit_function_add_integer_array_attribute(
219+
self.ptr,
220+
attribute.as_sys(),
221+
value.as_ptr(),
222+
value.len() as _,
223+
);
224+
}
225+
226+
}
227+
AttributeValue::IntArray(value) => {
228+
unsafe {
229+
gccjit_sys::gcc_jit_function_add_integer_array_attribute(
230+
self.ptr,
231+
attribute.as_sys(),
232+
value.as_ptr(),
233+
value.len() as _,
234+
);
235+
}
236+
}
212237
AttributeValue::None => {
213238
unsafe {
214239
gccjit_sys::gcc_jit_function_add_attribute(self.ptr, attribute.as_sys());

src/lvalue.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub enum AttributeValue<'a> {
3939
Int(i32),
4040
None,
4141
String(&'a str),
42+
IntArray(&'a [i32]),
4243
}
4344

4445
#[cfg(feature="master")]
@@ -51,7 +52,7 @@ pub enum VarAttribute {
5152
impl VarAttribute {
5253
fn get_value(&self) -> AttributeValue {
5354
match *self {
54-
VarAttribute::Visibility(visibility) => AttributeValue::String(visibility.as_str()),
55+
Self::Visibility(visibility) => AttributeValue::String(visibility.as_str()),
5556
}
5657
}
5758

@@ -221,6 +222,7 @@ impl<'ctx> LValue<'ctx> {
221222
let value = attribute.get_value();
222223
match value {
223224
AttributeValue::Int(_) => unimplemented!(),
225+
AttributeValue::IntArray(_) => unimplemented!(),
224226
AttributeValue::None => unimplemented!(),
225227
AttributeValue::String(string) => {
226228
let cstr = CString::new(string).unwrap();

0 commit comments

Comments
 (0)