Coder Social home page Coder Social logo

jit's Introduction

PHP Jit Compiler

Configuration

$llvm = \Serafim\Jit\Compiler::fromLibrary('/path/to/llvm.so');
$llvm->target(new \Serafim\Jit\Target\X86Target());

Example

use Serafim\Jit\Compiler;
use Serafim\Jit\ImportFunction;
use Serafim\Jit\Target\X86Target;

$llvm = Compiler::fromLibrary('/path/to/llvm.so');
$llvm->target(new X86Target());

$entry = $llvm->entry(
    #[ImportFunction(name: 'get_int', type: 'int')]
    #[ImportFunction(name: 'add_five', type: 'int', args: ['int'])]
    fn()=> <<<'asm'
    define i32 @get_int() {
        ret i32 42
    }
    
    define i32 @add_five(i32) #0 {
        %2 = alloca i32, align 4
        store i32 %0, i32* %2, align 4
        %3 = load i32, i32* %2, align 4
        %4 = add nsw i32 %3, 5
        ret i32 %4
    }
    asm
);

echo $entry->get_int() . "\n"; // 42
echo $entry->add_five(5) . "\n"; // 5 + 5

Example #2: Compile Sources

/** @var \Serafim\Jit\Compiler $llvm */
$entry = $llvm->compile(<<<'asm'
    define i32 @get_int() { ... }
    define i32 @add_five(i32) #0 { ... }
asm);

$get_int = $entry->getFunction('get_int', 'int');
$add_five = $entry->getFunction('add_five', 'int', ['int']);

Example #3: Compile File

/** @var \Serafim\Jit\Compiler $llvm */
$entry = $llvm->file(__DIR__ . '/path/to/file.ll');

jit's People

Contributors

serafimarts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.