px_llvm_codegen_utils_core/
lib.rs

1use std::ffi::CStr;
2use std::marker::PhantomData;
3use std::mem::{replace, take, MaybeUninit};
4use std::sync::{Arc, Mutex};
5use std::thread::LocalKey;
6use std::thread_local;
7
8use nonempty::NonEmpty;
9use typenum::Same;
10mod private {
11    pub trait Sealed {}
12}
13
14pub trait Ctx<'a>: Clone + private::Sealed + 'a {}
15pub trait Mod<'a>: Clone + private::Sealed + 'a {
16    type Ctx<'b>: Ctx<'b>
17    where
18        Self: 'b;
19    fn ctx<'b: 'a>(&'b self) -> Self::Ctx<'b>;
20    fn create_mod<'b, 'c, 'd>(a: &'b CStr, ctx: &'c Self::Ctx<'d>) -> Self
21    where
22        'a: 'b + 'c + 'd;
23}
24pub trait Value<'a>: Clone + private::Sealed + 'a {
25    type Tag: 'a;
26    type Kind: for<'b> ValueKind<Val<'a, Self::Tag> = Self, Mod<'b> = Self::Mod<'b>>;
27    type Mod<'b>: Mod<'b>;
28    fn r#mod<'b: 'a>(&'b self) -> Self::Mod<'b>;
29}
30pub trait ValueKind: private::Sealed {
31    type Mod<'a>: Mod<'a>;
32    type Val<'a, K: 'a>: for<'b> Value<'a, Tag = K, Kind = Self, Mod<'b> = Self::Mod<'b>>
33    where
34        K: 'a;
35    type Func<'a>: for<'b> Func<'a, Kind = Self, Mod<'b> = Self::Mod<'b>>;
36    type Ty<'a>: Ty<'a>;
37    fn const_int<'a>(ty: Self::Ty<'a>, n: u64, sext: bool) -> Self::Val<'a, Normal>;
38    fn function<'a, 'b, 'c, 'd: 'a + 'b + 'c>(
39        r#mod: Self::Mod<'a>,
40        name: &'b CStr,
41        ty: Self::Ty<'c>,
42    ) -> Self::Func<'d>;
43}
44pub trait Func<'a>: Clone + private::Sealed + Value<'a, Tag = FuncTag> + 'a {}
45pub trait BB<'a>: Clone + private::Sealed + 'a {
46    type Func<'b>: Func<'b>
47    where
48        'a: 'b,
49        Self: 'b;
50    fn new<'b, 'c>(f: Self::Func<'b>, name: &'c CStr) -> Self
51    where
52        'a: 'b + 'c;
53}
54macro_rules! rest {
55    ($llvm:ident as [$i:ident ($(($l:lifetime) @ $e:ident : $t:ty as |$v:ident|$b:expr),*)]) => {
56        $(let $e= match $e{$v => $b});*;
57        paste::paste!{
58
59        }
60    };
61}
62macro_rules! inst {
63    (($l2:lifetime)@ [$($a:tt)*] => $($b:tt)*) => {
64        inst!(($l2) @ $($a)* => $($b)* => [$($a)*]);
65    };
66    (($l2:lifetime)@ $i:ident ($(($($l:lifetime),*) @ $e:ident : $t:ty as |$v:ident|$b:expr),*) =>  $($llvm:ident )? => $stuff:tt) => {
67        paste::paste!{
68            #[allow(unreachable_code,unused_variables)]
69            fn $i<'b,$($($l),*),*,'res:  $($($l +)* )* 'b>(&'b self, $($e: $t),*) -> <Self::ValKind<'a,'a> as ValueKind>::Val<'res,Normal> where $($($l2 : $l),*),*{
70
71                let builder = |(),$($e : $t),*| -> std::convert::Infallible{
72                    panic!("abstract method used")
73                };
74                let ptr = ();
75                let leaked = |a: std::convert::Infallible,b: Normal| match a{};
76                let mark: Result<std::convert::Infallible,()> = Err(());
77                // macro_rules! shim{
78                //     () => {
79
80                //     };
81                // }
82                $(
83                    rest!($llvm as $stuff);
84                    let builder = $llvm::core::[<LLVMBuild $i >];
85                    let ptr = self.ptr();
86                    let leaked = |a,b|unsafe{crate::LLHandle::leaked(a,b)};
87                    let mark: Result<(),std::convert::Infallible> = Ok(());
88
89                    // shim!()
90                )?;
91
92                let res = unsafe{
93                    builder(ptr,$($e),*)
94                };
95                leaked(res,Normal)
96            }
97        }
98    };
99}
100macro_rules! insts {
101    (($l2:lifetime)@{[$($t0:tt)*], $([$($t:tt)*],)*} => $(<$llvm:ident>)?) => {
102        inst!(($l2)@[$($t0)*] => $($llvm)?);
103        insts!(($l2)@{$([$($t)*],)*} => $(<$llvm>)?);
104    };
105    (($l2:lifetime)@{} => $(<$llvm:ident>)?) => {
106
107    };
108}
109#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Debug)]
110#[non_exhaustive]
111pub enum ICmp {
112    Eq,
113    Lt,
114    Lts,
115}
116macro_rules! default_insts {
117    ($l2:lifetime @ $($llvm:ident)?) => {
118        insts!(($l2) @ {
119            [Alloca (('ty) @ ty: Self::Ty<'ty> as |x|x.ptr(), ('name) @ name : &'name CStr as |x|x.as_ptr())],
120            [Load2 (('ty) @ ty: Self::Ty<'ty> as |x|x.ptr(), ('ptr) @ pointer: <Self::ValKind<'a,'a> as ValueKind>::Val<'ptr,Normal> as |x|x.ptr(), ('name) @ name : &'name CStr as |x|x.as_ptr())],
121            [StructGEP2 (('ty) @ ty: Self::Ty<'ty> as |x|x.ptr(), ('ptr) @ pointer: <Self::ValKind<'a,'a> as ValueKind>::Val<'ptr,Normal> as |x|x.ptr(), ('idx) @ idx: &'idx u32 as |x|*x, ('name) @ name : &'name CStr as |x|x.as_ptr())],
122
123            [Store (('val) @ value: <Self::ValKind<'a,'a> as ValueKind>::Val<'val,Normal> as |x|x.ptr(), ('ptr) @ pointer: <Self::ValKind<'a,'a> as ValueKind>::Val<'ptr,Normal> as |x|x.ptr())],
124            [Add (('lhs) @ lhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'lhs,Normal> as |x|x.ptr(), ('rhs) @ rhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'rhs,Normal> as |x|x.ptr(), ('name) @ name : &'name CStr as |x|x.as_ptr())],
125            [And (('lhs) @ lhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'lhs,Normal> as |x|x.ptr(), ('rhs) @ rhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'rhs,Normal> as |x|x.ptr(), ('name) @ name : &'name CStr as |x|x.as_ptr())],
126            [Neg (('lhs) @ lhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'lhs,Normal> as |x|x.ptr(),  ('name) @ name : &'name CStr as |x|x.as_ptr())],
127      [  Not (('lhs) @ lhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'lhs,Normal> as |x|x.ptr(), ('name) @ name : &'name CStr as |x|x.as_ptr())],
128      [ TruncOrBitCast (('lhs) @ lhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'lhs,Normal> as |x|x.ptr(),('ty) @ ty: Self::Ty<'ty> as |x|x.ptr(), ('name) @ name : &'name CStr as |x|x.as_ptr())],
129      [Mul (('lhs) @ lhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'lhs,Normal> as |x|x.ptr(), ('rhs) @ rhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'rhs,Normal> as |x|x.ptr(), ('name) @ name : &'name CStr as |x|x.as_ptr())],
130      [Or (('lhs) @ lhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'lhs,Normal> as |x|x.ptr(), ('rhs) @ rhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'rhs,Normal> as |x|x.ptr(), ('name) @ name : &'name CStr as |x|x.as_ptr())],
131     [ Sub (('lhs) @ lhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'lhs,Normal> as |x|x.ptr(), ('rhs) @ rhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'rhs,Normal> as |x|x.ptr(), ('name) @ name : &'name CStr as |x|x.as_ptr())],
132     [Xor (('lhs) @ lhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'lhs,Normal> as |x|x.ptr(), ('rhs) @ rhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'rhs,Normal> as |x|x.ptr(), ('name) @ name : &'name CStr as |x|x.as_ptr())],
133         [ICmp (('op) @ op: crate::ICmp as |a|a.into(),('lhs) @ lhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'lhs,Normal> as |x|x.ptr(), ('rhs) @ rhs: <Self::ValKind<'a,'a> as ValueKind>::Val<'rhs,Normal> as |x|x.ptr(), ('name) @ name : &'name CStr as |x|x.as_ptr())],
134
135     [ Br (('dest) @ dest: Self::BB<'dest,'a,'a> as |x|x.ptr())],
136     [CondBr (('cond) @ r#if: <Self::ValKind<'a,'a> as ValueKind>::Val<'cond,Normal> as |x|x.ptr(), ('then) @ then: Self::BB<'then,'a,'a> as |x|x.ptr(),('e) @ r#else: Self::BB<'e,'a,'a> as |x|x.ptr())],
137        } => $(<$llvm>)?);
138    };
139}
140pub trait Ty<'a>: Clone + private::Sealed + 'a {
141    type Ctx<'b>: Ctx<'b>
142    where
143        Self: 'b;
144    fn int_ty(ctx: Self::Ctx<'a>, size: u32) -> Self;
145    fn ptr_ty(ctx: Self::Ctx<'a>, address_space: u32) -> Self;
146    fn struct_ty(ctx: Self::Ctx<'a>, fields: impl Iterator<Item = Self>, packed: bool) -> Self;
147    fn fun_ty(self, params: impl Iterator<Item = Self>) -> Self;
148}
149pub trait Builder<'a>: Clone + private::Sealed + 'a {
150    type BB<'b, 'e, 'd>: BB<'b, Func<'b>: Value<'b, Kind = Self::ValKind<'e, 'd>>>
151    where
152        Self: 'b,
153        'a: 'b,
154        Self: 'e,
155        Self: 'd;
156    type ValKind<'d, 'b>: ValueKind<Ty<'d> = Self::Ty<'d>, Mod<'b> = Self::Mod<'b>>
157    where
158        Self: 'd,
159        Self: 'b;
160    // type InternalValShim<'b: 'a, 'd, 'e, K: 'b>: Value<'b, Tag = K>
161    //     + Same<Output = <Self::ValKind<'d, 'e> as ValueKind>::Val<'b, K>>
162    // where
163    //     Self: 'd,
164    //     Self: 'e;
165    // type Val<'b: 'a, K: 'b>: Value<'b, Tag = K>
166    //     + for<'d, 'e> Into<Self::InternalValShim<'b, 'd, 'e, K>>
167    //     + for<'d, 'e> From<Self::InternalValShim<'b, 'd, 'e, K>>;
168    // type Val<'b, K: 'b>: Value<'b, Tag = K>
169    //     + for<'d, 'e> Same<Output = <Self::ValKind<'d, 'e> as ValueKind>::Val<'b, K>>;
170    type Mod<'b>: Mod<'b, Ctx<'b> = Self::Ctx<'b>>
171    where
172        Self: 'b;
173    type Ty<'b>: Ty<'b>
174    where
175        Self: 'b;
176    type Ctx<'b>: Ctx<'b>
177    where
178        Self: 'b;
179    fn new_in_ctx(ctx: Self::Ctx<'a>) -> Self;
180    fn r#continue<'b, 'c>(&'b self, bb: Self::BB<'c, '_, '_>)
181    where
182        'a: 'b + 'c;
183    fn call<'b, 'c, 'd, 'e, 'f, 'h, 'i, 'g: 'a + 'b + 'c + 'd + 'e + 'f + 'h + 'i>(
184        &'b self,
185        resty: Self::Ty<'c>,
186        r#fn: <Self::ValKind<'_, '_> as ValueKind>::Val<'d, Normal>,
187        args: impl Iterator<Item = <Self::ValKind<'h, 'i> as ValueKind>::Val<'e, Normal>>,
188        name: &'f CStr,
189    ) -> <Self::ValKind<'_, '_> as ValueKind>::Val<'g, Normal>
190    where
191        Self: 'h + 'i;
192    fn gep2<'b, 'c, 'd, 'e, 'f, 'h, 'i, 'g: 'a + 'b + 'c + 'd + 'e + 'f + 'h + 'i>(
193        &'b self,
194        resty: Self::Ty<'c>,
195        ptr: <Self::ValKind<'_, '_> as ValueKind>::Val<'d, Normal>,
196        args: impl Iterator<Item = <Self::ValKind<'h, 'i> as ValueKind>::Val<'e, Normal>>,
197        name: &'f CStr,
198    ) -> <Self::ValKind<'_, '_> as ValueKind>::Val<'g, Normal>
199    where
200        Self: 'h + 'i;
201    default_insts!('a @ );
202}
203pub struct LLHandle<'a, K, T>(Arc<LLShim<'a, K, T>>);
204impl<'a, K, T> Clone for LLHandle<'a, K, T> {
205    fn clone(&self) -> Self {
206        Self(self.0.clone())
207    }
208}
209impl<'a, K, T> LLHandle<'a, K, T> {
210    pub unsafe fn from_raw_parts(ptr: *mut T, dropper: fn(*mut T, K), key: K) -> Self {
211        LLHandle(Arc::new(LLShim {
212            val: ptr,
213            dropper: dropper,
214            key: MaybeUninit::new(key),
215            phantom: PhantomData,
216        }))
217    }
218    pub unsafe fn leaked(ptr: *mut T, key: K) -> Self {
219        unsafe { Self::from_raw_parts(ptr, |_, _| {}, key) }
220    }
221    pub fn ptr(&self) -> *mut T {
222        return self.0.val;
223    }
224    pub fn key(&self) -> &K {
225        return unsafe { self.0.key.assume_init_ref() };
226    }
227}
228pub struct LLShim<'a, K, T> {
229    val: *mut T,
230    key: MaybeUninit<K>,
231    dropper: fn(*mut T, K),
232    phantom: PhantomData<&'a T>,
233}
234impl<'a, K, T> Drop for LLShim<'a, K, T> {
235    fn drop(&mut self) {
236        (self.dropper)(self.val, unsafe {
237            replace(&mut self.key, MaybeUninit::uninit()).assume_init()
238        })
239    }
240}
241macro_rules! seal {
242    ($(<$($generics:lifetime),*> => $t:ty),* $(,)?) => {
243        $(impl<$($generics),*> private::Sealed for $t{})*
244    };
245}
246pub struct Normal;
247pub struct FuncTag;
248macro_rules! impls {
249    ($l:ident {}) => {
250        const _: () = {
251            use $l as llvm_sys;
252            seal!(
253             <'a>  =>   crate::LLHandle<'a,Normal,llvm_sys::LLVMContext>,
254              <'a>  =>  crate::LLHandle<'a,Normal,llvm_sys::LLVMModule>,
255               <> =>  llvm_sys::LLVMValue,
256              <'a>  =>  crate::LLHandle<'a,Normal,llvm_sys::LLVMBasicBlock>,
257              <'a>  =>  crate::LLHandle<'a,Normal,llvm_sys::LLVMBuilder>,
258              <'a>  =>  crate::LLHandle<'a,Normal,llvm_sys::LLVMType>,
259            );
260            impl From<crate::ICmp> for llvm_sys::LLVMIntPredicate{
261                fn from(a: crate::ICmp) -> Self{
262                    match a{
263                        crate::ICmp::Eq => llvm_sys::LLVMIntPredicate::LLVMIntEQ,
264                        crate ::ICmp::Lt => llvm_sys::LLVMIntPredicate::LLVMIntULT,
265                        crate ::ICmp::Lts => llvm_sys::LLVMIntPredicate::LLVMIntSLT,
266                    }
267                }
268            }
269            impl<'a, K> private::Sealed for crate::LLHandle<'a, K, llvm_sys::LLVMValue> {}
270            impl<'a, K: 'a> crate::Value<'a> for crate::LLHandle<'a, K, llvm_sys::LLVMValue> {
271                type Tag = K;
272                type Kind = llvm_sys::LLVMValue;
273                type Mod<'b> = crate::LLHandle<'b, Normal, llvm_sys::LLVMModule>;
274                fn r#mod<'b: 'a>(&'b self) -> Self::Mod<'b> {
275                    let ptr = self.ptr();
276                    let ptr = unsafe { llvm_sys::core::LLVMGetGlobalParent(ptr) };
277                    unsafe { crate::LLHandle::leaked(ptr, Normal) }
278                }
279            }
280            impl<'a> crate::Ty<'a> for crate::LLHandle<'a, Normal, llvm_sys::LLVMType> {
281                type Ctx<'b>
282                    = crate::LLHandle<'b, Normal, llvm_sys::LLVMContext>
283                where
284                    Self: 'b;
285                fn int_ty(ctx: Self::Ctx<'a>, size: u32) -> Self {
286                    let ptr = ctx.ptr();
287                    let ptr = unsafe { llvm_sys::core::LLVMIntTypeInContext(ptr, size) };
288                    unsafe { LLHandle::leaked(ptr, Normal) }
289                }
290                fn ptr_ty(ctx: Self::Ctx<'a>, address_space: u32) -> Self {
291                    let ptr = ctx.ptr();
292                    let ptr =
293                        unsafe { llvm_sys::core::LLVMPointerTypeInContext(ptr, address_space) };
294                    unsafe { LLHandle::leaked(ptr, Normal) }
295                }
296                fn fun_ty(self, params: impl Iterator<Item = Self>) -> Self {
297                    let ptr = self.ptr();
298                    let mut args = params.map(|p| p.ptr()).collect::<Vec<_>>();
299                    let ptr = unsafe {
300                        llvm_sys::core::LLVMFunctionType(
301                            ptr,
302                            args.as_mut_ptr(),
303                            args.len().try_into().unwrap(),
304                            0,
305                        )
306                    };
307                    unsafe { LLHandle::leaked(ptr, Normal) }
308                }
309                fn struct_ty(ctx: Self::Ctx<'a>, fields: impl Iterator<Item = Self>, packed: bool) -> Self{
310                    let mut fields = fields.map(|p| p.ptr()).collect::<Vec<_>>();
311                    let ptr = unsafe{
312                        llvm_sys::core::LLVMStructTypeInContext(ctx.ptr(),fields.as_mut_ptr(),fields.len().try_into().unwrap(),if packed{1}else{0})
313                    };
314                    unsafe { LLHandle::leaked(ptr, Normal) }
315                }
316            }
317            impl crate::ValueKind for llvm_sys::LLVMValue {
318                type Val<'a, K: 'a> = crate::LLHandle<'a, K, llvm_sys::LLVMValue>;
319                type Mod<'a> = crate::LLHandle<'a, Normal, llvm_sys::LLVMModule>;
320                type Func<'a> = crate::LLHandle<'a, FuncTag, llvm_sys::LLVMValue>;
321                type Ty<'a> = crate::LLHandle<'a, Normal, llvm_sys::LLVMType>;
322                fn const_int<'a>(ty: Self::Ty<'a>, n: u64, sext: bool) -> Self::Val<'a, Normal> {
323                    let ptr = ty.ptr();
324                    let ptr =
325                        unsafe { llvm_sys::core::LLVMConstInt(ptr, n, if sext { 1 } else { 0 }) };
326                    unsafe { crate::LLHandle::leaked(ptr, Normal) }
327                }
328                fn function<'a, 'b, 'c, 'd: 'a + 'b + 'c>(
329                    r#mod: Self::Mod<'a>,
330                    name: &'b CStr,
331                    ty: Self::Ty<'c>,
332                ) -> Self::Func<'d> {
333                    let ptr = unsafe {
334                        llvm_sys::core::LLVMAddFunction(r#mod.ptr(), name.as_ptr(), ty.ptr())
335                    };
336                    unsafe { crate::LLHandle::leaked(ptr, FuncTag) }
337                }
338            }
339            impl<'a> crate::Ctx<'a> for crate::LLHandle<'a, Normal, llvm_sys::LLVMContext> {}
340            impl<'a> crate::Mod<'a> for crate::LLHandle<'a, Normal, llvm_sys::LLVMModule> {
341                type Ctx<'b>
342                    = crate::LLHandle<'b, Normal, llvm_sys::LLVMContext>
343                where
344                    Self: 'b;
345                fn ctx<'b: 'a>(&'b self) -> Self::Ctx<'b> {
346                    let ptr = self.ptr();
347                    let ptr = unsafe { llvm_sys::core::LLVMGetModuleContext(ptr) };
348                    unsafe { crate::LLHandle::leaked(ptr, Normal) }
349                }
350                fn create_mod<'b, 'c, 'd>(a: &'b CStr, ctx: &'c Self::Ctx<'d>) -> Self
351                where
352                    'a: 'b + 'c + 'd,
353                {
354                    let ptr = ctx.ptr();
355                    let ptr = unsafe {
356                        llvm_sys::core::LLVMModuleCreateWithNameInContext(a.as_ptr(), ptr)
357                    };
358                    unsafe {
359                        crate::LLHandle::from_raw_parts(
360                            ptr,
361                            |a, _| llvm_sys::core::LLVMDisposeModule(a),
362                            Normal,
363                        )
364                    }
365                }
366            }
367            impl<'a> crate::Func<'a> for crate::LLHandle<'a, FuncTag, llvm_sys::LLVMValue> {}
368            impl<'a> crate::BB<'a> for crate::LLHandle<'a, Normal, llvm_sys::LLVMBasicBlock> {
369                type Func<'b>
370                    = crate::LLHandle<'b, FuncTag, llvm_sys::LLVMValue>
371                where
372                    'a: 'b,
373                    Self: 'b;
374                fn new<'b, 'c>(f: Self::Func<'b>, name: &'c CStr) -> Self
375                where
376                    'a: 'b + 'c,
377                {
378                    let ptr = f.ptr();
379                    let ptr = unsafe { llvm_sys::core::LLVMAppendBasicBlock(ptr, name.as_ptr()) };
380                    unsafe { crate::LLHandle::leaked(ptr, Normal) }
381                }
382            }
383            impl<'a> crate::Builder<'a> for crate::LLHandle<'a, Normal, llvm_sys::LLVMBuilder> {
384                type BB<'b,'e,'d>
385                    = crate::LLHandle<'b, Normal, llvm_sys::LLVMBasicBlock>
386                where
387                    Self: 'b,
388                    'a: 'b, Self: 'e, Self: 'd;
389                type ValKind<'d, 'b> = llvm_sys::LLVMValue  where
390                Self: 'd,
391                Self: 'b;
392                // type InternalValShim<'b: 'a, 'd, 'e, K: 'b> = crate::LLHandle<'b,K,llvm_sys::LLVMValue> where K: Sized, K: 'b, Self: 'd, Self: 'e;
393                // type Val<'b: 'a,K: 'b> = crate::LLHandle<'b,K,llvm_sys::LLVMValue> where K: Sized, K: 'b;
394                type Ty<'b>
395                    = crate::LLHandle<'b, Normal, llvm_sys::LLVMType>
396                where
397                    Self: 'b;
398                type Ctx<'b>
399                    = crate::LLHandle<'b, Normal, llvm_sys::LLVMContext>
400                where
401                    Self: 'b;
402                type Mod<'b> = crate::LLHandle<'b, Normal, llvm_sys::LLVMModule> where Self: 'b;
403                fn new_in_ctx(ctx: Self::Ctx<'a>) -> Self {
404                    let ptr = ctx.ptr();
405                    let ptr = unsafe { llvm_sys::core::LLVMCreateBuilderInContext(ptr) };
406                    unsafe {
407                        crate::LLHandle::from_raw_parts(
408                            ptr,
409                            |a, _| llvm_sys::core::LLVMDisposeBuilder(a),
410                            Normal,
411                        )
412                    }
413                }
414                fn r#continue<'b, 'c>(&'b self, bb: Self::BB<'c,'a,'a>)
415                where
416                    'a: 'b + 'c,
417                {
418                    unsafe { llvm_sys::core::LLVMPositionBuilderAtEnd(self.ptr(), bb.ptr()) }
419                }
420                fn call<'b, 'c, 'd, 'e, 'f,'h,'i, 'g: 'a + 'b + 'c + 'd + 'e + 'f + 'h + 'i>(
421                    &'b self,
422                    resty: Self::Ty<'c>,
423                    r#fn: <Self::ValKind<'a,'a> as ValueKind>::Val<'d, Normal>,
424                    args: impl Iterator<Item = <Self::ValKind<'h,'i> as ValueKind>::Val<'e, Normal>>,
425                    name: &'f CStr,
426                ) -> <Self::ValKind<'_,'_> as ValueKind>::Val<'g, Normal> where 'a: 'h + 'i, Self: 'c{
427                    let ptr = self.ptr();
428                    let resty = resty.ptr();
429                    let Fn = r#fn.ptr();
430                    let mut args = args.map(|a| a.ptr()).collect::<Vec<_>>();
431                    let res = unsafe {
432                        llvm_sys::core::LLVMBuildCall2(
433                            ptr,
434                            resty,
435                            Fn,
436                            args.as_mut_ptr(),
437                            args.len().try_into().unwrap(),
438                            name.as_ptr(),
439                        )
440                    };
441                    unsafe { crate::LLHandle::leaked(res, Normal) }
442                }
443                fn gep2<'b, 'c, 'd, 'e, 'f, 'h, 'i, 'g: 'a + 'b + 'c + 'd + 'e + 'f + 'h + 'i>(
444                    &'b self,
445                    resty: Self::Ty<'c>,
446                    ptr2: <Self::ValKind<'_, '_> as ValueKind>::Val<'d, Normal>,
447                    args: impl Iterator<Item = <Self::ValKind<'h, 'i> as ValueKind>::Val<'e, Normal>>,
448                    name: &'f CStr,
449                ) -> <Self::ValKind<'_, '_> as ValueKind>::Val<'g, Normal>
450                where
451                    Self: 'h + 'i{
452                        let ptr = self.ptr();
453                        let resty = resty.ptr();
454                        let Fn = ptr2.ptr();
455                        let mut args = args.map(|a| a.ptr()).collect::<Vec<_>>();
456                        let res = unsafe {
457                            llvm_sys::core::LLVMBuildGEP2(
458                                ptr,
459                                resty,
460                                Fn,
461                                args.as_mut_ptr(),
462                                args.len().try_into().unwrap(),
463                                name.as_ptr(),
464                            )
465                        };
466                        unsafe { crate::LLHandle::leaked(res, Normal) }
467                    }
468                default_insts!('a @ llvm_sys);
469            }
470        };
471    };
472}
473
474llvm_codegen_utils_version_macros::vers!({} impls);