Vickenty Fesunov

NAME

GCCJIT - Perl bindings for GCCJIT library

SYNOPSIS

    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);

DESCRIPTION

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.

EXPORTS

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

:constants

Exports all libgccjit constants.

:raw_api

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

:all

Exports everything.

SEE ALSO

Online documentation for GCCJIT library: https://gcc.gnu.org/onlinedocs/gcc-5.2.0/jit/

GCCJIT project wiki page: https://gcc.gnu.org/wiki/JIT

AUTHOR

Vickenty Fesunov <cpan-gccjit@setattr.net>

COPYRIGHT AND LICENSE

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 <http://www.gnu.org/licenses/>.