protected function execute(InputInterface $input, OutputInterface $output) { $jit = Jit::getInstance(); $compiler = new Compiler(); $ir = ''; foreach ($input->getArgument('files') as $file) { $ir .= "\n" . $jit->getFileIr($file); } $name = $input->getArgument("name"); $lname = strtolower($name); $files = $compiler->compile(trim($ir), $name); $dir = $this->makeTempDir(); foreach ($files as $fname => $file) { file_put_contents($dir . '/' . $fname, $file); } $opt = $input->getOption("optimize") ? "-O3" : ""; $command = "(cd {$dir}; phpize && CFLAGS=\"\$CFLAGS {$opt}\" ./configure && make)"; passthru($command, $retval); if ($retval) { throw new \RuntimeException("There was an error: {$retval}"); } rename("{$dir}/modules/{$lname}.so", getcwd() . "/{$lname}.so"); echo "\nGenerated {$lname}.so\n"; }
- $1 $8 $9 var $10 long recurse $9 $10 var $11 numeric + $7 $10 $11 return $11 return end ENDIR; /** * Compile the function using the JITFU extension! * * This is extremely cheap, since no analysis needs to happen. All that happens is the IR * is turned into JIT-Fu instructions (which are then compiled by libjit). */ $func = Jit::getInstance()->compileIrJitFu($ir, 'fibo'); /** * Now let's benchmark the two implementations! * * If you don't have JitFu installed, then both should be equal. */ benchmark("fibo", "PHP"); benchmark($func, "ReckiCT"); /** * A very light weight benchmark tool, which runs the code 100,000 times. * * @param callable $func The function to benchmark * @param string $label The label of the test, for output * * @return void */
/** * @covers ::getInstance * @covers ::__construct * @covers ::compileIrJitFu */ public function testCompileIrJitFuWithoutExt() { $ir = <<<'EOF' function ReckiCT\test long param $1 long begin return $1 end EOF; $jit = Jit::getInstance(); $r = new \ReflectionProperty($jit, 'jitfucompiler'); $r->setAccessible(true); $r->setValue($jit, null); $func = $jit->compileIrJitFu($ir, __NAMESPACE__ . '\\test'); $this->assertEquals(__NAMESPACE__ . '\\test', $func); }