gccjit_sys 1.3.0

Raw bindings to libgccjit. Companion to the gccjit crate.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
#![allow(non_camel_case_types)]
#![allow(clippy::missing_safety_doc, clippy::too_many_arguments)]

extern crate libc;

#[cfg(feature="dlopen")]
mod dynload;

#[cfg(feature="dlopen")]
use std::ffi::CStr;
use libc::{c_char, c_int, FILE, c_void, c_long, c_double, c_ulong, size_t, ssize_t};

// opaque pointers
pub enum gcc_jit_context {}
pub enum gcc_jit_result {}
pub enum gcc_jit_object {}
pub enum gcc_jit_location {}
pub enum gcc_jit_type {}
pub enum gcc_jit_field {}
pub enum gcc_jit_struct {}
pub enum gcc_jit_function {}
pub enum gcc_jit_block {}
pub enum gcc_jit_rvalue {}
pub enum gcc_jit_lvalue {}
pub enum gcc_jit_param {}
pub enum gcc_jit_case {}
pub enum gcc_jit_function_type {}
pub enum gcc_jit_vector_type {}
pub enum gcc_jit_extended_asm {}
pub enum gcc_jit_target_info {}

#[repr(C)]
pub enum gcc_jit_tls_model {
    GCC_JIT_TLS_MODEL_NONE,
    GCC_JIT_TLS_MODEL_GLOBAL_DYNAMIC,
    GCC_JIT_TLS_MODEL_LOCAL_DYNAMIC,
    GCC_JIT_TLS_MODEL_INITIAL_EXEC,
    GCC_JIT_TLS_MODEL_LOCAL_EXEC,
}

#[repr(C)]
pub enum gcc_jit_str_option {
    GCC_JIT_STR_OPTION_PROGNAME,
    GCC_JIT_STR_OPTION_SPECIAL_CHARS_IN_FUNC_NAMES,
    GCC_JIT_NUM_STR_OPTIONS,
}

#[repr(C)]
pub enum gcc_jit_int_option {
    GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL,
    GCC_JIT_NUM_INT_OPTIONS
}

#[repr(C)]
pub enum gcc_jit_bool_option {
    GCC_JIT_BOOL_OPTION_DEBUGINFO,
    GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE,
    GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE,
    GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE,
    GCC_JIT_BOOL_OPTION_DUMP_SUMMARY,
    GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING,
    GCC_JIT_BOOL_OPTION_SELFCHECK_GC,
    GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES,
    GCC_JIT_NUM_BOOL_OPTIONS
}

#[repr(C)]
pub enum gcc_jit_output_kind {
    GCC_JIT_OUTPUT_KIND_ASSEMBLER,
    GCC_JIT_OUTPUT_KIND_OBJECT_FILE,
    GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY,
    GCC_JIT_OUTPUT_KIND_EXECUTABLE
}

#[repr(C)]
pub enum gcc_jit_types {
    GCC_JIT_TYPE_VOID,
    /* "void *". */
    GCC_JIT_TYPE_VOID_PTR,
    /* C++'s bool type; also C99's "_Bool" type, aka "bool" if using
    stdbool.h. */
    GCC_JIT_TYPE_BOOL,
    /* Various integer types. */
    /* C's "char" (of some signedness) and the variants where the
    signedness is specified. */
    GCC_JIT_TYPE_CHAR,
    GCC_JIT_TYPE_SIGNED_CHAR,
    GCC_JIT_TYPE_UNSIGNED_CHAR,
    /* C's "short" and "unsigned short". */
    GCC_JIT_TYPE_SHORT, /* signed */
    GCC_JIT_TYPE_UNSIGNED_SHORT,
    /* C's "int" and "unsigned int". */
    GCC_JIT_TYPE_INT, /* signed */
    GCC_JIT_TYPE_UNSIGNED_INT,
    /* C's "long" and "unsigned long". */
    GCC_JIT_TYPE_LONG, /* signed */
    GCC_JIT_TYPE_UNSIGNED_LONG,
    /* C99's "long long" and "unsigned long long". */
    GCC_JIT_TYPE_LONG_LONG, /* signed */
    GCC_JIT_TYPE_UNSIGNED_LONG_LONG,

    /* Floating-point types */
    GCC_JIT_TYPE_FLOAT,
    GCC_JIT_TYPE_DOUBLE,
    GCC_JIT_TYPE_LONG_DOUBLE,
    /* C type: (const char *). */
    GCC_JIT_TYPE_CONST_CHAR_PTR,
    /* The C "size_t" type. */
    GCC_JIT_TYPE_SIZE_T,
    /* C type: (FILE *) */
    GCC_JIT_TYPE_FILE_PTR,
    /* Complex numbers. */
    GCC_JIT_TYPE_COMPLEX_FLOAT,
    GCC_JIT_TYPE_COMPLEX_DOUBLE,
    GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE,

    GCC_JIT_TYPE_UINT8_T,
    GCC_JIT_TYPE_UINT16_T,
    GCC_JIT_TYPE_UINT32_T,
    GCC_JIT_TYPE_UINT64_T,
    GCC_JIT_TYPE_UINT128_T,
    GCC_JIT_TYPE_INT8_T,
    GCC_JIT_TYPE_INT16_T,
    GCC_JIT_TYPE_INT32_T,
    GCC_JIT_TYPE_INT64_T,
    GCC_JIT_TYPE_INT128_T,

    GCC_JIT_TYPE_BFLOAT16,
    GCC_JIT_TYPE_FLOAT16,
    GCC_JIT_TYPE_FLOAT32,
    GCC_JIT_TYPE_FLOAT64,
    GCC_JIT_TYPE_FLOAT128,
}

#[repr(C)]
pub enum gcc_jit_function_kind {
    /* Function is defined by the client code and visible
       by name outside of the JIT. */
    GCC_JIT_FUNCTION_EXPORTED,
    /* Function is defined by the client code, but is invisible
       outside of the JIT. Analogous to a "static" function. */
    GCC_JIT_FUNCTION_INTERNAL,
    /* Function is not defined by the client code; we're merely
       referring to it. Analogous to using an "extern" function from a
       header file. */
    GCC_JIT_FUNCTION_IMPORTED,
    /* Function is only ever inlined into other functions, and is
       invisible outside of the JIT.
       Analogous to prefixing with "inline" and adding
       __attribute__((always_inline)).
       Inlining will only occur when the optimization level is
       above 0; when optimization is off, this is essentially the
       same as GCC_JIT_FUNCTION_INTERNAL. */
    GCC_JIT_FUNCTION_ALWAYS_INLINE
}

#[repr(C)]
pub enum gcc_jit_global_kind
{
    /* Global is defined by the client code and visible
       by name outside of this JIT context via gcc_jit_result_get_global. */
    GCC_JIT_GLOBAL_EXPORTED,
    /* Global is defined by the client code, but is invisible
       outside of this JIT context. Analogous to a "static" global. */
    GCC_JIT_GLOBAL_INTERNAL,
    /* Global is not defined by the client code; we're merely
       referring to it. Analogous to using an "extern" global from a
       header file. */
    GCC_JIT_GLOBAL_IMPORTED
}

#[repr(C)]
pub enum gcc_jit_unary_op
{
    /* Negate an arithmetic value; analogous to:
       -(EXPR)
       in C. */
    GCC_JIT_UNARY_OP_MINUS,
    /* Bitwise negation of an integer value (one's complement); analogous
       to:
       ~(EXPR)
       in C. */
    GCC_JIT_UNARY_OP_BITWISE_NEGATE,
    /* Logical negation of an arithmetic or pointer value; analogous to:
       !(EXPR)
       in C. */
    GCC_JIT_UNARY_OP_LOGICAL_NEGATE,
    /* Absolute value of an arithmetic expression; analogous to:
       abs (EXPR)
       in C. */
    GCC_JIT_UNARY_OP_ABS
}

#[repr(C)]
pub enum gcc_jit_binary_op
{
    /* Addition of arithmetic values; analogous to:
    (EXPR_A) + (EXPR_B)
    in C.
    For pointer addition, use gcc_jit_context_new_array_access. */
    GCC_JIT_BINARY_OP_PLUS,
    /* Subtraction of arithmetic values; analogous to:
    (EXPR_A) - (EXPR_B)
    in C. */
    GCC_JIT_BINARY_OP_MINUS,
    /* Multiplication of a pair of arithmetic values; analogous to:
    (EXPR_A) * (EXPR_B)
    in C. */
    GCC_JIT_BINARY_OP_MULT,
    /* Quotient of division of arithmetic values; analogous to:
    (EXPR_A) / (EXPR_B)
    in C.
    The result type affects the kind of division: if the result type is
    integer-based, then the result is truncated towards zero, whereas
    a floating-point result type indicates floating-point division. */
    GCC_JIT_BINARY_OP_DIVIDE,
    /* Remainder of division of arithmetic values; analogous to:
    (EXPR_A) % (EXPR_B)
    in C. */
    GCC_JIT_BINARY_OP_MODULO,
    /* Bitwise AND; analogous to:
    (EXPR_A) & (EXPR_B)
    in C. */
    GCC_JIT_BINARY_OP_BITWISE_AND,
    /* Bitwise exclusive OR; analogous to:
    (EXPR_A) ^ (EXPR_B)
    in C. */
    GCC_JIT_BINARY_OP_BITWISE_XOR,
    /* Bitwise inclusive OR; analogous to:
    (EXPR_A) | (EXPR_B)
    in C. */
    GCC_JIT_BINARY_OP_BITWISE_OR,
    /* Logical AND; analogous to:
    (EXPR_A) && (EXPR_B)
    in C. */
    GCC_JIT_BINARY_OP_LOGICAL_AND,
    /* Logical OR; analogous to:
    (EXPR_A) || (EXPR_B)
    in C. */
    GCC_JIT_BINARY_OP_LOGICAL_OR,
    /* Left shift; analogous to:
    (EXPR_A) << (EXPR_B)
    in C. */
    GCC_JIT_BINARY_OP_LSHIFT,
    /* Right shift; analogous to:
    (EXPR_A) >> (EXPR_B)
    in C. */
    GCC_JIT_BINARY_OP_RSHIFT
}

#[repr(C)]
pub enum gcc_jit_comparison
{
    /* (EXPR_A) == (EXPR_B). */
    GCC_JIT_COMPARISON_EQ,
    /* (EXPR_A) != (EXPR_B). */
    GCC_JIT_COMPARISON_NE,
    /* (EXPR_A) < (EXPR_B). */
    GCC_JIT_COMPARISON_LT,
    /* (EXPR_A) <=(EXPR_B). */
    GCC_JIT_COMPARISON_LE,
    /* (EXPR_A) > (EXPR_B). */
    GCC_JIT_COMPARISON_GT,
    /* (EXPR_A) >= (EXPR_B). */
    GCC_JIT_COMPARISON_GE
}

#[cfg(feature="master")]
#[repr(C)]
pub enum gcc_jit_fn_attribute
{
    GCC_JIT_FN_ATTRIBUTE_ALIAS,
    GCC_JIT_FN_ATTRIBUTE_ALWAYS_INLINE,
    GCC_JIT_FN_ATTRIBUTE_INLINE,
    GCC_JIT_FN_ATTRIBUTE_NOINLINE,
    GCC_JIT_FN_ATTRIBUTE_TARGET,
    GCC_JIT_FN_ATTRIBUTE_USED,
    GCC_JIT_FN_ATTRIBUTE_VISIBILITY,
    GCC_JIT_FN_ATTRIBUTE_COLD,
    GCC_JIT_FN_ATTRIBUTE_RETURNS_TWICE,
    GCC_JIT_FN_ATTRIBUTE_PURE,
    GCC_JIT_FN_ATTRIBUTE_CONST,
    GCC_JIT_FN_ATTRIBUTE_WEAK,
    GCC_JIT_FN_ATTRIBUTE_NONNULL,
    GCC_JIT_FN_ATTRIBUTE_ARM_CMSE_NONSECURE_CALL,
    GCC_JIT_FN_ATTRIBUTE_ARM_CMSE_NONSECURE_ENTRY,
    GCC_JIT_FN_ATTRIBUTE_ARM_PCS,
    GCC_JIT_FN_ATTRIBUTE_AVR_INTERRUPT,
    GCC_JIT_FN_ATTRIBUTE_AVR_NOBLOCK,
    GCC_JIT_FN_ATTRIBUTE_AVR_SIGNAL,
    GCC_JIT_FN_ATTRIBUTE_GCN_AMDGPU_HSA_KERNEL,
    GCC_JIT_FN_ATTRIBUTE_MSP430_INTERRUPT,
    GCC_JIT_FN_ATTRIBUTE_NVPTX_KERNEL,
    GCC_JIT_FN_ATTRIBUTE_RISCV_INTERRUPT,
    GCC_JIT_FN_ATTRIBUTE_X86_FAST_CALL,
    GCC_JIT_FN_ATTRIBUTE_X86_INTERRUPT,
    GCC_JIT_FN_ATTRIBUTE_X86_MS_ABI,
    GCC_JIT_FN_ATTRIBUTE_X86_STDCALL,
    GCC_JIT_FN_ATTRIBUTE_X86_SYSV_ABI,
    GCC_JIT_FN_ATTRIBUTE_X86_THIS_CALL,
}

#[cfg(feature="master")]
#[repr(C)]
pub enum gcc_jit_variable_attribute
{
    GCC_JIT_VARIABLE_ATTRIBUTE_VISIBILITY,
    GCC_JIT_VARIABLE_ATTRIBUTE_WEAK,
}

macro_rules! extern_maybe_dlopen {
    ($($(#[cfg($attr_name:ident = $attr_value:expr)])? fn $func_name:ident ($($arg:ident : $arg_type:ty),*) $(-> $return_type:ty)? ;)*) => {
        #[cfg(not(feature="dlopen"))]
        #[link(name = "gccjit")]
        extern "C" {
            $(
            $(#[cfg($attr_name=$attr_value)])?
            pub fn $func_name($($arg: $arg_type),*) $(-> $return_type)?;
            )*
        }

        pub struct Libgccjit {
            #[cfg(feature="dlopen")]
            _lib: dynload::Library,
            $(
            #[cfg(feature="dlopen")]
            $(#[cfg($attr_name=$attr_value)])?
            $func_name: unsafe extern "C" fn($($arg_type),*) $(-> $return_type)?,
            )*
        }

        impl Libgccjit {
            #[cfg(not(feature="dlopen"))]
            #[allow(clippy::new_without_default)]
            pub const fn new() -> Self {
                Self {
                }
            }

            #[cfg(feature="dlopen")]
            pub unsafe fn open(path: &CStr) -> Result<Self, String> {
                let lib = unsafe { dynload::Library::open(path)? };

                Ok(Self {
                    $(
                    $(#[cfg($attr_name=$attr_value)])?
                    $func_name: unsafe { std::mem::transmute::<*mut (), unsafe extern "C" fn($($arg_type),*) $(-> $return_type)?>(
                        lib.get(CStr::from_bytes_with_nul_unchecked(concat!(stringify!($func_name), "\0").as_bytes()))?
                    )},
                    )*
                    _lib: lib,
                })
            }

            $(
            #[inline]
            $(#[cfg($attr_name=$attr_value)])?
            pub unsafe fn $func_name(&self, $($arg: $arg_type),*) $(-> $return_type)? {
                #[cfg(feature="dlopen")]
                unsafe { (self.$func_name)($($arg),*) }

                #[cfg(not(feature="dlopen"))]
                unsafe { $func_name($($arg),*) }
            }
            )*
        }
    };
}

extern_maybe_dlopen! {
    // context operations
    fn gcc_jit_context_acquire() -> *mut gcc_jit_context;
    fn gcc_jit_context_release(ctx: *mut gcc_jit_context);
    fn gcc_jit_context_set_str_option(ctx: *mut gcc_jit_context,
                                          option: gcc_jit_str_option,
                                          value: *const c_char);
    fn gcc_jit_context_set_int_option(ctx: *mut gcc_jit_context,
                                          option: gcc_jit_int_option,
                                          value: c_int);
    fn gcc_jit_context_set_bool_option(ctx: *mut gcc_jit_context,
                                           option: gcc_jit_bool_option,
                                           value: c_int);
    fn gcc_jit_context_set_bool_allow_unreachable_blocks(ctx: *mut gcc_jit_context,
                                                             value: c_int);
    fn gcc_jit_context_compile(ctx: *mut gcc_jit_context) -> *mut gcc_jit_result;
    fn gcc_jit_context_compile_to_file(ctx: *mut gcc_jit_context,
                                           kind: gcc_jit_output_kind,
                                           path: *const c_char);
    fn gcc_jit_context_dump_to_file(ctx: *mut gcc_jit_context,
                                        path: *const c_char,
                                        update_locations: c_int);
    fn gcc_jit_context_set_logfile(ctx: *mut gcc_jit_context,
                                       file: *mut FILE,
                                       flags: c_int,
                                       verbosity: c_int);
    fn gcc_jit_context_get_first_error(ctx: *mut gcc_jit_context) -> *const c_char;
    fn gcc_jit_context_get_last_error(ctx: *mut gcc_jit_context) -> *const c_char;

    // result operations
    fn gcc_jit_result_get_code(result: *mut gcc_jit_result,
                                   funcname: *const c_char) -> *mut c_void;
    fn gcc_jit_result_get_global(result: *mut gcc_jit_result,
                                     globalname: *const c_char) ->  *mut c_void;
    fn gcc_jit_result_release(result: *mut gcc_jit_result);

    // object operations. gcc_jit_object is the root of a C++ inheritence
    // hierarchy, but this is a C API.
    fn gcc_jit_object_get_context(obj: *mut gcc_jit_object) -> *mut gcc_jit_context;
    fn gcc_jit_object_get_debug_string(obj: *mut gcc_jit_object) -> *const c_char;

    fn gcc_jit_context_new_location(ctx: *mut gcc_jit_context,
                                        filename: *const c_char,
                                        line: c_int,
                                        col: c_int) -> *mut gcc_jit_location;

    // upcast operator for location
    fn gcc_jit_location_as_object(loc: *mut gcc_jit_location) -> *mut gcc_jit_object;

    fn gcc_jit_type_as_object(ty: *mut gcc_jit_type) -> *mut gcc_jit_object;

    fn gcc_jit_context_get_type(ctx: *mut gcc_jit_context,
                                    ty: gcc_jit_types) -> *mut gcc_jit_type;
    fn gcc_jit_context_get_int_type(ctx: *mut gcc_jit_context,
                                        num_bytes: c_int,
                                        is_signed: c_int) -> *mut gcc_jit_type;
    fn gcc_jit_type_get_pointer(ty: *mut gcc_jit_type) -> *mut gcc_jit_type;
    fn gcc_jit_type_get_const(ty: *mut gcc_jit_type) -> *mut gcc_jit_type;
    fn gcc_jit_type_get_volatile(ty: *mut gcc_jit_type) -> *mut gcc_jit_type;
    #[cfg(feature="master")]
    fn gcc_jit_type_get_restrict(ty: *mut gcc_jit_type) -> *mut gcc_jit_type;
    fn gcc_jit_context_new_array_type(ctx: *mut gcc_jit_context,
                                          loc: *mut gcc_jit_location,
                                          ty: *mut gcc_jit_type,
                                          num_elements: c_ulong) -> *mut gcc_jit_type;
    // struct handling
    fn gcc_jit_context_new_field(ctx: *mut gcc_jit_context,
                                     loc: *mut gcc_jit_location,
                                     ty: *mut gcc_jit_type,
                                     name: *const c_char) -> *mut gcc_jit_field;
    fn gcc_jit_field_as_object(field: *mut gcc_jit_field) -> *mut gcc_jit_object;
    fn gcc_jit_context_new_struct_type(ctx: *mut gcc_jit_context,
                                           loc: *mut gcc_jit_location,
                                           name: *const c_char,
                                           num_fields: c_int,
                                           fields: *mut *mut gcc_jit_field) -> *mut gcc_jit_struct;

    fn gcc_jit_context_new_opaque_struct(ctx: *mut gcc_jit_context,
                                             loc: *mut gcc_jit_location,
                                             name: *const c_char) -> *mut gcc_jit_struct;

    fn gcc_jit_struct_as_type(struct_: *mut gcc_jit_struct) -> *mut gcc_jit_type;

    fn gcc_jit_struct_set_fields(struct_: *mut gcc_jit_struct,
                                     loc: *mut gcc_jit_location,
                                     num_fields: c_int,
                                     fields: *mut *mut gcc_jit_field);
    fn gcc_jit_context_new_union_type(ctx: *mut gcc_jit_context,
                                          loc: *mut gcc_jit_location,
                                          name: *const c_char,
                                          num_fields: c_int,
                                          fields: *mut *mut gcc_jit_field) -> *mut gcc_jit_type;

    fn gcc_jit_context_new_function_ptr_type(ctx: *mut gcc_jit_context,
                                                 loc: *mut gcc_jit_location,
                                                 ret_ty: *mut gcc_jit_type,
                                                 num_params: c_int,
                                                 param_tys: *mut *mut gcc_jit_type,
                                                 is_variadic: c_int) -> *mut gcc_jit_type;

    // constructing functions
    fn gcc_jit_context_new_param(ctx: *mut gcc_jit_context,
                                     loc: *mut gcc_jit_location,
                                     ty: *mut gcc_jit_type,
                                     name: *const c_char) -> *mut gcc_jit_param;
    fn gcc_jit_param_as_object(param: *mut gcc_jit_param) -> *mut gcc_jit_object;
    fn gcc_jit_param_as_lvalue(param: *mut gcc_jit_param) -> *mut gcc_jit_lvalue;
    fn gcc_jit_param_as_rvalue(param: *mut gcc_jit_param) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_new_function(ctx: *mut gcc_jit_context,
                                        loc: *mut gcc_jit_location,
                                        kind: gcc_jit_function_kind,
                                        return_ty: *mut gcc_jit_type,
                                        name: *const c_char,
                                        num_params: c_int,
                                        param: *mut *mut gcc_jit_param,
                                        is_variadic: c_int) -> *mut gcc_jit_function;
    fn gcc_jit_context_get_builtin_function(ctx: *mut gcc_jit_context,
                                                name: *const c_char) -> *mut gcc_jit_function;
    fn gcc_jit_function_as_object(func: *mut gcc_jit_function) -> *mut gcc_jit_object;

    fn gcc_jit_function_get_param(func: *mut gcc_jit_function,
                                      idx: c_int) -> *mut gcc_jit_param;
    fn gcc_jit_function_dump_to_dot(func: *mut gcc_jit_function,
                                        path: *const c_char);
    fn gcc_jit_function_new_block(func: *mut gcc_jit_function,
                                      name: *const c_char) -> *mut gcc_jit_block;
    fn gcc_jit_block_as_object(block: *mut gcc_jit_block) -> *mut gcc_jit_object;
    fn gcc_jit_block_get_function(block: *mut gcc_jit_block) -> *mut gcc_jit_function;

    fn gcc_jit_context_new_global(ctx: *mut gcc_jit_context,
                                      loc: *mut gcc_jit_location,
                                      kind: gcc_jit_global_kind,
                                      ty: *mut gcc_jit_type,
                                      name: *const c_char) -> *mut gcc_jit_lvalue;
    fn gcc_jit_lvalue_as_object(lvalue: *mut gcc_jit_lvalue) -> *mut gcc_jit_object;
    fn gcc_jit_lvalue_as_rvalue(lvalue: *mut gcc_jit_lvalue) -> *mut gcc_jit_rvalue;
    fn gcc_jit_rvalue_as_object(rvalue: *mut gcc_jit_rvalue) -> *mut gcc_jit_object;
    fn gcc_jit_rvalue_get_type(rvalue: *mut gcc_jit_rvalue) -> *mut gcc_jit_type;

    fn gcc_jit_context_new_rvalue_from_int(ctx: *mut gcc_jit_context,
                                               ty: *mut gcc_jit_type,
                                               value: c_int) ->  *mut gcc_jit_rvalue;
    fn gcc_jit_context_new_rvalue_from_long(ctx: *mut gcc_jit_context,
                                                ty: *mut gcc_jit_type,
                                                value: c_long) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_zero(ctx: *mut gcc_jit_context,
                                ty: *mut gcc_jit_type) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_one(ctx: *mut gcc_jit_context,
                               ty: *mut gcc_jit_type) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_new_rvalue_from_double(ctx: *mut gcc_jit_context,
                                                  ty: *mut gcc_jit_type,
                                                  value: c_double) -> *mut gcc_jit_rvalue;

    fn gcc_jit_context_new_rvalue_from_ptr(ctx: *mut gcc_jit_context,
                                               ty: *mut gcc_jit_type,
                                               value: *mut c_void) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_null(ctx: *mut gcc_jit_context,
                                ty: *mut gcc_jit_type) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_new_string_literal(ctx: *mut gcc_jit_context,
                                              value: *const c_char) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_new_unary_op(ctx: *mut gcc_jit_context,
                                        loc: *mut gcc_jit_location,
                                        op: gcc_jit_unary_op,
                                        ty: *mut gcc_jit_type,
                                        rvalue: *mut gcc_jit_rvalue) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_new_binary_op(ctx: *mut gcc_jit_context,
                                         loc: *mut gcc_jit_location,
                                         op: gcc_jit_binary_op,
                                         ty: *mut gcc_jit_type,
                                         left: *mut gcc_jit_rvalue,
                                         right: *mut gcc_jit_rvalue) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_new_comparison(ctx: *mut gcc_jit_context,
                                          loc: *mut gcc_jit_location,
                                          op: gcc_jit_comparison,
                                          left: *mut gcc_jit_rvalue,
                                          right: *mut gcc_jit_rvalue) -> *mut gcc_jit_rvalue;

    fn gcc_jit_context_new_call(ctx: *mut gcc_jit_context,
                                    loc: *mut gcc_jit_location,
                                    func: *mut gcc_jit_function,
                                    num_args: c_int,
                                    args: *mut *mut gcc_jit_rvalue) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_new_call_through_ptr(ctx: *mut gcc_jit_context,
                                                loc: *mut gcc_jit_location,
                                                fun_ptr: *mut gcc_jit_rvalue,
                                                num_args: c_int,
                                                args: *mut *mut gcc_jit_rvalue) -> *mut gcc_jit_rvalue;

    fn gcc_jit_context_new_cast(ctx: *mut gcc_jit_context,
                                    loc: *mut gcc_jit_location,
                                    rvalue: *mut gcc_jit_rvalue,
                                    ty: *mut gcc_jit_type) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_new_array_access(ctx: *mut gcc_jit_context,
                                            loc: *mut gcc_jit_location,
                                            ptr: *mut gcc_jit_rvalue,
                                            idx: *mut gcc_jit_rvalue) -> *mut gcc_jit_lvalue;

    fn gcc_jit_lvalue_access_field(struct_or_union: *mut gcc_jit_lvalue,
                                       loc: *mut gcc_jit_location,
                                       field: *mut gcc_jit_field) -> *mut gcc_jit_lvalue;

    fn gcc_jit_rvalue_access_field(struct_or_union: *mut gcc_jit_rvalue,
                                       loc: *mut gcc_jit_location,
                                       field: *mut gcc_jit_field) -> *mut gcc_jit_rvalue;
    fn gcc_jit_rvalue_dereference_field(ptr: *mut gcc_jit_rvalue,
                                            loc: *mut gcc_jit_location,
                                            field: *mut gcc_jit_field) -> *mut gcc_jit_lvalue;
    fn gcc_jit_rvalue_dereference(ptr: *mut gcc_jit_rvalue,
                                      loc: *mut gcc_jit_location) -> *mut gcc_jit_lvalue;
    fn gcc_jit_lvalue_get_address(lvalue: *mut gcc_jit_lvalue,
                                      loc: *mut gcc_jit_location) -> *mut gcc_jit_rvalue;
    fn gcc_jit_function_new_local(func: *mut gcc_jit_function,
                                      loc: *mut gcc_jit_location,
                                      ty: *mut gcc_jit_type,
                                      name: *const c_char) -> *mut gcc_jit_lvalue;
    fn gcc_jit_block_add_eval(block: *mut gcc_jit_block,
                                  loc: *mut gcc_jit_location,
                                  rvalue: *mut gcc_jit_rvalue);
    fn gcc_jit_block_add_assignment(block: *mut gcc_jit_block,
                                        loc: *mut gcc_jit_location,
                                        lvalue: *mut gcc_jit_lvalue,
                                        rvalue: *mut gcc_jit_rvalue);
    fn gcc_jit_block_add_assignment_op(block: *mut gcc_jit_block,
                                           loc: *mut gcc_jit_location,
                                           lvalue: *mut gcc_jit_lvalue,
                                           op: gcc_jit_binary_op,
                                           rvalue: *mut gcc_jit_rvalue);
    fn gcc_jit_block_add_comment(block: *mut gcc_jit_block,
                                     loc: *mut gcc_jit_location,
                                     msg: *const c_char);
    fn gcc_jit_block_end_with_conditional(block: *mut gcc_jit_block,
                                              loc: *mut gcc_jit_location,
                                              cond: *mut gcc_jit_rvalue,
                                              on_true: *mut gcc_jit_block,
                                              on_false: *mut gcc_jit_block);
    fn gcc_jit_block_end_with_jump(block: *mut gcc_jit_block,
                                       loc: *mut gcc_jit_location,
                                       target: *mut gcc_jit_block);
    fn gcc_jit_block_end_with_return(block: *mut gcc_jit_block,
                                         loc: *mut gcc_jit_location,
                                         ret: *mut gcc_jit_rvalue);
    fn gcc_jit_block_end_with_void_return(block: *mut gcc_jit_block,
                                              loc: *mut gcc_jit_location);
    fn gcc_jit_context_new_child_context(parent: *mut gcc_jit_context) -> *mut gcc_jit_context;
    fn gcc_jit_context_dump_reproducer_to_file(parent: *mut gcc_jit_context,
                                                   path: *const c_char);

    fn gcc_jit_context_new_case(ctxt: *mut gcc_jit_context, min_value: *mut gcc_jit_rvalue, max_value: *mut gcc_jit_rvalue, dest_block: *mut gcc_jit_block) -> *mut gcc_jit_case;
    fn gcc_jit_block_end_with_switch(block: *mut gcc_jit_block, loc: *mut gcc_jit_location, expr: *mut gcc_jit_rvalue, default_block: *mut gcc_jit_block, num_cases: c_int, cases: *mut *mut gcc_jit_case);
    fn gcc_jit_case_as_object(case_: *mut gcc_jit_case) -> *mut gcc_jit_object;

    fn gcc_jit_function_get_address(fun: *mut gcc_jit_function, loc: *mut gcc_jit_location) ->  *mut gcc_jit_rvalue;

    fn gcc_jit_type_get_vector(typ: *mut gcc_jit_type, num_units:  size_t) -> *mut gcc_jit_type;
    fn gcc_jit_context_new_rvalue_from_vector(ctxt: *mut gcc_jit_context, loc: *mut gcc_jit_location, vec_type: *mut gcc_jit_type, num_elements: size_t, elements: *mut *mut gcc_jit_rvalue) ->  *mut gcc_jit_rvalue;

    fn gcc_jit_context_add_command_line_option(ctxt: *mut gcc_jit_context, optname: *const c_char);
    fn gcc_jit_context_add_driver_option(ctxt: *mut gcc_jit_context, optname: *const c_char);

    fn gcc_jit_type_get_aligned(typ: *mut gcc_jit_type, alignment_in_bytes: size_t) ->  *mut gcc_jit_type;

    fn gcc_jit_function_get_return_type(func: *mut gcc_jit_function) -> *mut gcc_jit_type;
    fn gcc_jit_function_get_param_count(func: *mut gcc_jit_function) -> ssize_t;

    fn gcc_jit_type_dyncast_array(typ: *mut gcc_jit_type) -> *mut gcc_jit_type;
    fn gcc_jit_type_is_bool(typ: *mut gcc_jit_type) -> c_int;
    fn gcc_jit_type_is_integral(typ: *mut gcc_jit_type) -> c_int;
    #[cfg(feature = "master")]
    fn gcc_jit_type_is_floating_point(typ: *mut gcc_jit_type) -> c_int;
    fn gcc_jit_type_unqualified(typ: *mut gcc_jit_type) -> *mut gcc_jit_type;
    fn gcc_jit_type_is_pointer(typ: *mut gcc_jit_type) -> *mut gcc_jit_type;
    fn gcc_jit_type_dyncast_function_ptr_type(typ: *mut gcc_jit_type) -> *mut gcc_jit_function_type;
    fn gcc_jit_function_type_get_return_type(function_type: *mut gcc_jit_function_type) -> *mut gcc_jit_type;
    fn gcc_jit_function_type_get_param_count(function_type: *mut gcc_jit_function_type) -> ssize_t;
    fn gcc_jit_type_dyncast_vector(typ: *mut gcc_jit_type) -> *mut gcc_jit_vector_type;
    fn gcc_jit_function_type_get_param_type(function_type: *mut gcc_jit_function_type, index: c_int) -> *mut gcc_jit_type;
    fn gcc_jit_vector_type_get_num_units(vector_type: *mut gcc_jit_vector_type) -> ssize_t;
    fn gcc_jit_vector_type_get_element_type(vector_type: *mut gcc_jit_vector_type) -> *mut gcc_jit_type;
    fn gcc_jit_struct_get_field(struct_type: *mut gcc_jit_struct, index: c_int) -> *mut gcc_jit_field;
    fn gcc_jit_type_is_struct(typ: *mut gcc_jit_type) -> *mut gcc_jit_struct;
    fn gcc_jit_struct_get_field_count(struct_type: *mut gcc_jit_struct) -> ssize_t;

    fn gcc_jit_global_set_initializer(global: *mut gcc_jit_lvalue, blob: *const c_void, num_bytes: size_t) -> *mut gcc_jit_lvalue;

    fn gcc_jit_block_end_with_extended_asm_goto(block: *mut gcc_jit_block, loc: *mut gcc_jit_location, asm_template: *const c_char, num_goto_blocks: c_int, goto_blocks: *mut *mut gcc_jit_block, fallthrough_block: *mut gcc_jit_block) -> *mut gcc_jit_extended_asm;
    fn gcc_jit_extended_asm_as_object(ext_asm: *mut gcc_jit_extended_asm) -> *mut gcc_jit_object;
    fn gcc_jit_extended_asm_set_volatile_flag(ext_asm: *mut gcc_jit_extended_asm, flag: c_int);
    fn gcc_jit_extended_asm_set_inline_flag(ext_asm: *mut gcc_jit_extended_asm, flag: c_int);
    fn gcc_jit_extended_asm_add_output_operand(ext_asm: *mut gcc_jit_extended_asm, asm_symbolic_name: *const c_char, constraint: *const c_char, dest: *mut gcc_jit_lvalue);
    fn gcc_jit_extended_asm_add_input_operand(ext_asm: *mut gcc_jit_extended_asm, asm_symbolic_name: *const c_char, constraint: *const c_char, src: *mut gcc_jit_rvalue);
    fn gcc_jit_extended_asm_add_clobber(ext_asm: *mut gcc_jit_extended_asm, victim: *const c_char);
    fn gcc_jit_context_add_top_level_asm(ctxt: *mut gcc_jit_context, loc: *mut gcc_jit_location, asm_stmts: *const c_char);
    fn gcc_jit_block_add_extended_asm(block: *mut gcc_jit_block, loc: *mut gcc_jit_location, asm_template: *const c_char) -> *mut gcc_jit_extended_asm;

    fn gcc_jit_lvalue_set_tls_model(lvalue: *mut gcc_jit_lvalue, model: gcc_jit_tls_model);
    fn gcc_jit_lvalue_set_link_section(lvalue: *mut gcc_jit_lvalue, name: *const c_char);

    fn gcc_jit_context_new_bitcast(ctxt: *mut gcc_jit_context, loc: *mut gcc_jit_location, rvalue: *mut gcc_jit_rvalue, type_: *mut gcc_jit_type) -> *mut gcc_jit_rvalue;

    fn gcc_jit_lvalue_set_register_name(lvalue: *mut gcc_jit_lvalue, reg_name: *const c_char);

    fn gcc_jit_context_new_struct_constructor(ctxt: *mut gcc_jit_context, loc: *mut gcc_jit_location, typ: *mut gcc_jit_type, num_values: c_int, fields: *mut *mut gcc_jit_field, values: *mut *mut gcc_jit_rvalue) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_new_union_constructor(ctxt: *mut gcc_jit_context, loc: *mut gcc_jit_location, typ: *mut gcc_jit_type, field: *mut gcc_jit_field, value: *mut gcc_jit_rvalue) -> *mut gcc_jit_rvalue;
    fn gcc_jit_context_new_array_constructor(ctxt: *mut gcc_jit_context, loc: *mut gcc_jit_location, typ: *mut gcc_jit_type, arr_length: c_int, values: *mut *mut gcc_jit_rvalue) -> *mut gcc_jit_rvalue;
    fn gcc_jit_global_set_initializer_rvalue(global: *mut gcc_jit_lvalue, init_value: *mut gcc_jit_rvalue) -> *mut gcc_jit_lvalue;

    fn gcc_jit_type_get_size(typ: *mut gcc_jit_type) -> ssize_t;
    fn gcc_jit_compatible_types(ltype: *mut gcc_jit_type, rtype: *mut gcc_jit_type) -> bool;

    fn gcc_jit_context_set_bool_print_errors_to_stderr(ctxt: *mut gcc_jit_context, enabled: c_int);

    fn gcc_jit_lvalue_set_alignment(lvalue: *mut gcc_jit_lvalue, alignment: c_int);
    fn gcc_jit_lvalue_get_alignment(lvalue: *mut gcc_jit_lvalue) -> c_int;

    #[cfg(feature="master")]
    fn gcc_jit_context_get_target_builtin_function(ctxt: *mut gcc_jit_context, name: *const c_char) -> *mut gcc_jit_function;

    #[cfg(feature="master")]
    fn gcc_jit_context_new_rvalue_vector_perm(ctxt: *mut gcc_jit_context, loc: *mut gcc_jit_location, elements1: *mut gcc_jit_rvalue, elements2: *mut gcc_jit_rvalue, mask: *mut gcc_jit_rvalue) -> *mut gcc_jit_rvalue;
    #[cfg(feature="master")]
    fn gcc_jit_context_new_vector_access(ctxt: *mut gcc_jit_context, loc: *mut gcc_jit_location, vector: *mut gcc_jit_rvalue, index: *mut gcc_jit_rvalue) -> *mut gcc_jit_lvalue;

    #[cfg(feature="master")]
    fn gcc_jit_type_set_packed(typ: *mut gcc_jit_type);

    #[cfg(feature="master")]
    fn gcc_jit_context_convert_vector(ctxt: *mut gcc_jit_context, loc: *mut gcc_jit_location, vector: *mut gcc_jit_rvalue, type_: *mut gcc_jit_type) -> *mut gcc_jit_rvalue;

    #[cfg(feature="master")]
    fn gcc_jit_global_set_readonly(global: *mut gcc_jit_lvalue);

    #[cfg(feature="master")]
    fn gcc_jit_function_add_attribute(func: *mut gcc_jit_function, attribute: gcc_jit_fn_attribute);

    #[cfg(feature="master")]
    fn gcc_jit_function_add_string_attribute(func: *mut gcc_jit_function, attribute: gcc_jit_fn_attribute, value: *const c_char);

    #[cfg(feature="master")]
    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")]
    fn gcc_jit_lvalue_add_string_attribute(variable: *mut gcc_jit_lvalue, attribute: gcc_jit_variable_attribute, value: *const c_char);

    #[cfg(feature="master")]
    fn gcc_jit_block_add_try_catch(block: *mut gcc_jit_block, loc: *mut gcc_jit_location, try_block: *mut gcc_jit_block, catch_block: *mut gcc_jit_block);

    #[cfg(feature="master")]
    fn gcc_jit_block_add_try_finally(block: *mut gcc_jit_block, loc: *mut gcc_jit_location, try_block: *mut gcc_jit_block, finally_block: *mut gcc_jit_block);

    #[cfg(feature="master")]
    fn gcc_jit_function_set_personality_function(func: *mut gcc_jit_function, personality_func: *mut gcc_jit_function);

    #[cfg(feature="master")]
    fn gcc_jit_set_global_personality_function_name(name: *const c_char);

    #[cfg(feature="master")]
    fn gcc_jit_context_get_target_info(ctxt: *mut gcc_jit_context) -> *mut gcc_jit_target_info;

    #[cfg(feature="master")]
    fn gcc_jit_target_info_release(info: *mut gcc_jit_target_info);

    #[cfg(feature="master")]
    fn gcc_jit_target_info_cpu_supports(info: *mut gcc_jit_target_info, feature: *const c_char) -> c_int;

    #[cfg(feature="master")]
    fn gcc_jit_target_info_arch(info: *mut gcc_jit_target_info) -> *const c_char;

    #[cfg(feature="master")]
    fn gcc_jit_target_info_supports_target_dependent_type(info: *mut gcc_jit_target_info, ty: gcc_jit_types) -> c_int;

    #[cfg(feature="master")]
    fn gcc_jit_context_new_sizeof(ctxt: *mut gcc_jit_context, typ: *mut gcc_jit_type) -> *mut gcc_jit_rvalue;

    #[cfg(feature="master")]
    fn gcc_jit_context_set_output_ident(ctxt: *mut gcc_jit_context, output_ident: *const c_char);

    fn gcc_jit_version_major() -> c_int;
    fn gcc_jit_version_minor() -> c_int;
    fn gcc_jit_version_patchlevel() -> c_int;

    #[cfg(feature="master")]
    fn gcc_jit_function_new_temp(func: *mut gcc_jit_function, loc: *mut gcc_jit_location, ty: *mut gcc_jit_type) -> *mut gcc_jit_lvalue;

    #[cfg(feature="master")]
    fn gcc_jit_rvalue_set_location(rvalue: *mut gcc_jit_rvalue,
                                       loc: *mut gcc_jit_location);

    #[cfg(feature="master")]
    fn gcc_jit_context_new_alignof(ctxt: *mut gcc_jit_context, typ: *mut gcc_jit_type) -> *mut gcc_jit_rvalue;

    #[cfg(feature="master")]
    fn gcc_jit_rvalue_set_type(rvalue: *mut gcc_jit_rvalue, new_type: *mut gcc_jit_type);

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

    #[cfg(feature="master")]
    fn gcc_jit_lvalue_get_name(lvalue: *mut gcc_jit_lvalue) -> *const c_char;

    #[cfg(feature="master")]
    fn gcc_jit_lvalue_set_name(lvalue: *mut gcc_jit_lvalue, new_name: *const c_char);

    #[cfg(feature="master")]
    fn gcc_jit_is_lto_supported() -> bool;

    #[cfg(feature="master")]
    fn gcc_jit_type_set_addressable(typ: *mut gcc_jit_type);

    #[cfg(feature="master")]
    fn gcc_jit_set_lang_name(lang_name: *const c_char);

    #[cfg(feature="master")]
    fn gcc_jit_context_set_filename(ctx: *mut gcc_jit_context, filename: *const c_char);

    #[cfg(feature="master")]
    fn gcc_jit_context_new_array_type_u64(ctx: *mut gcc_jit_context,
                                          loc: *mut gcc_jit_location,
                                          ty: *mut gcc_jit_type,
                                          num_elements: u64) -> *mut gcc_jit_type;
}