TypePHP 编译器 https://swoole.com/aot/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

26 lines
678 B

#!/usr/bin/env php
<?php
require __DIR__ . '/bootstrap.php';
use PhpAot\Php\Translator;
if (empty($argv[1])) {
die("php compiler.php [file]\n");
}
try {
$file = $argv[1];
$translator = new Translator(ROOT_PATH);
$translator->setIndent(' ');
$code = $translator->convert($file);
$info = pathinfo($file);
$cppFile = './tmp/' . $info['filename'] . '.cc';
$translator->save($code, $cppFile);
$translator->compileFile($cppFile);
$objectFile = './tmp/' . $info['filename'] . '.cc.o';
$translator->compileBinary($info['filename'], $objectFile);
} catch (Error $error) {
echo "Parse error: {$error->getMessage()}\n";
return;
}