GCCJIT - Perl bindings for GCCJIT library


    use GCCJIT qw/:constants/;
    use GCCJIT::Context;

    my $ctxt = GCCJIT::Context->acquire();
    my $int_type = $ctxt->get_type(GCC_JIT_TYPE_INT);

    my $param_i = $ctxt->new_param(undef, $int_type, "i");
    my $func = $ctxt->new_function(undef, GCC_JIT_FUNCTION_EXPORTED,
        $int_type, "square", [ $param_i ], 0);

    my $block = $func->new_block("my new block");

    my $expr = $ctxt->new_binary_op(undef, GCC_JIT_BINARY_OP_MULT,
        $int_type, $param_i->as_rvalue(), $param_i->as_rvalue());

    $block->end_with_return(undef, $expr);

    my $result = $ctxt->compile();
    my $raw_ptr = $result->get_code("square");

    use FFI::Raw;
    my $ffi = FFI::Raw->new_from_ptr($raw_ptr, FFI::Raw::int, FFI::Raw::int);
    say $ffi->(4);


This package provides bindings for libgccjit, an embeddable compiler backend based on GCC. There are two packages in this distribution:

GCCJIT, this package, provides direct bindings to the C API of libgccjit.

GCCJIT::Context provides a more succinct, object-oriented view of the same API.

Where gccjit functions expects an array and its length as two arguments, GCCJIT variant takes a single array reference instead.


This package does not export anything by default. Exportable are all gccjit constants and functions, and following tags:


Exports all libgccjit constants.


Exports raw libgccjit functions (use GCCJIT::Context wrappers instead).


Exports everything.


Online documentation for GCCJIT library:

GCCJIT project wiki page:


Vickenty Fesunov <>


Copyright (C) 2015 by Vickenty Fesunov.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <>.