isl_rs/bindings/
access_info.rs1use super::{Context, Error, Flow, LibISLError};
5use libc::uintptr_t;
6
7pub struct AccessInfo {
9 pub ptr: uintptr_t,
10 pub should_free_on_drop: bool,
11}
12
13extern "C" {
14
15 fn isl_access_info_compute_flow(acc: uintptr_t) -> uintptr_t;
16
17 fn isl_access_info_free(acc: uintptr_t) -> uintptr_t;
18
19 fn isl_access_info_get_ctx(acc: uintptr_t) -> uintptr_t;
20
21}
22
23impl AccessInfo {
24 pub fn compute_flow(self) -> Result<Flow, LibISLError> {
26 let acc = self;
27 let isl_rs_ctx = acc.get_ctx();
28 let mut acc = acc;
29 acc.do_not_free_on_drop();
30 let acc = acc.ptr;
31 let isl_rs_result = unsafe { isl_access_info_compute_flow(acc) };
32 let isl_rs_result = Flow { ptr: isl_rs_result,
33 should_free_on_drop: true };
34 let err = isl_rs_ctx.last_error();
35 if err != Error::None_ {
36 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
37 }
38 Ok(isl_rs_result)
39 }
40
41 pub fn free(self) -> Result<AccessInfo, LibISLError> {
43 let acc = self;
44 let isl_rs_ctx = acc.get_ctx();
45 let mut acc = acc;
46 acc.do_not_free_on_drop();
47 let acc = acc.ptr;
48 let isl_rs_result = unsafe { isl_access_info_free(acc) };
49 let isl_rs_result = AccessInfo { ptr: isl_rs_result,
50 should_free_on_drop: true };
51 let err = isl_rs_ctx.last_error();
52 if err != Error::None_ {
53 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
54 }
55 Ok(isl_rs_result)
56 }
57
58 pub fn get_ctx(&self) -> Context {
60 let acc = self;
61 let acc = acc.ptr;
62 let isl_rs_result = unsafe { isl_access_info_get_ctx(acc) };
63 let isl_rs_result = Context { ptr: isl_rs_result,
64 should_free_on_drop: false };
65 isl_rs_result
66 }
67
68 pub fn do_not_free_on_drop(&mut self) {
71 self.should_free_on_drop = false;
72 }
73}
74
75impl Drop for AccessInfo {
76 fn drop(&mut self) {
77 if self.should_free_on_drop {
78 unsafe {
79 isl_access_info_free(self.ptr);
80 }
81 }
82 }
83}