diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index ca6b3e78..b0d0fd56 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -158,8 +158,9 @@ class CompilerBase extends \PhpAot\Core\Translator protected string $cxxflags = ''; protected string $ldflags = ''; protected int $floatPrecision = 17; - protected bool $debugInfo = true; - protected bool $printBacktraceOnError = true; + protected bool $debugInfo = false; + protected bool $formatCode = false; + protected bool $printBacktraceOnError = false; protected bool $noLiteralStrings = false; protected string $file; protected string $dir; @@ -2064,8 +2065,12 @@ class CompilerBase extends \PhpAot\Core\Translator { $cmd .= ' ' . $this->parseIncludes(); $cmd .= ' -O' . $this->optimizeLevel; - $cmd .= ' -g'; + + if ($this->debugInfo) { + $cmd .= ' -g'; + } $cmd .= ' -Wall'; + if ($this->enableProfiler) { $cmd .= ' -lprofiler'; $cmd .= ' -DPPROF_ON=1'; @@ -3628,6 +3633,9 @@ class CompilerBase extends \PhpAot\Core\Translator protected function formatCppCode(string $file): void { + if (!$this->formatCode) { + return; + } $cmd = 'cd ' . $this->rootPath . ' && clang-format -i ' . $file; $this->climate->info('format: ' . $this->getRelativePath($file)); $this->climate->comment($cmd); diff --git a/src/Php/Translator.php b/src/Php/Translator.php index ec9074bb..03e02e3f 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -79,19 +79,23 @@ class Translator extends Preprocessor $this->showVersion(); $climate->br(); + global $argv; + $cmd = $argv[0]; + $climate->bold('USAGE:'); - $climate->tab()->out('./bin/compiler.php [options]'); + $climate->tab()->out($cmd . ' [options]'); $climate->br(); $climate->bold('ARGUMENTS:'); - $climate->tab()->out(' Input PHP file/directory to compile'); + $climate->tab()->out(' Input PHP file/directory/project.yml to compile'); $climate->br(); $climate->bold('OPTIONS:'); $climate->tab()->out('-O Optimization level (0-3, default: 0)'); $climate->tab()->out('-p, --profile Enable performance profiling'); + $climate->tab()->out('-d, --debug-info Enable debug info'); $climate->tab()->out('-o, --output Output binary name (default: input basename)'); - $climate->tab()->out('-v, --verbose Verbose output'); + $climate->tab()->out('-v, --version Show version'); $climate->tab()->out('-h, --help Show this help message'); $climate->tab()->out('-f, --force Force compile even if cache exists'); $climate->tab()->out('-m, --mode Compilation mode, -m bin(binary) or -m ext(extension), default: bin'); @@ -100,11 +104,11 @@ class Translator extends Preprocessor $climate->br(); $climate->bold('EXAMPLES:'); - $climate->tab()->out('./bin/compiler.php examples/hello.php'); - $climate->tab()->out('./bin/compiler.php examples/bench.php -O2'); - $climate->tab()->out('./bin/compiler.php examples/bench.php -O2 '); - $climate->tab()->out('./bin/compiler.php examples/extension -O2 -o myapp -m ext'); - $climate->tab()->out('./bin/compiler.php examples/app.php -O3 -o myapp -v'); + $climate->tab()->out($cmd . ' hello.php'); + $climate->tab()->out($cmd . ' bench.php -O2'); + $climate->tab()->out($cmd . ' project/config.yml -O2'); + $climate->tab()->out($cmd . ' my-ext/ -O2 -o myapp -m ext'); + $climate->tab()->out($cmd . ' app.php -O3 -o myapp -v'); $climate->br(); } @@ -179,7 +183,7 @@ class Translator extends Preprocessor { $realpath = realpath($path); if ($realpath === false) { - exit("path not exists: {$path}\n"); + $this->error("path not exists: {$path}"); } $path = $realpath; diff --git a/src/compiler-build.php b/src/compiler-build.php index 772b951b..0396000d 100644 --- a/src/compiler-build.php +++ b/src/compiler-build.php @@ -8,16 +8,17 @@ function main(int $argc, array $argv): void require ROOT_PATH . '/vendor/autoload.php'; - if (empty($argv[1])) { - die("php compiler.php [file]\n"); - } - global $translator; - $path = $argv[1]; $translator = new Translator(ROOT_PATH); + if (empty($argv[1])) { + $translator->showUsage(); + exit(0); + } + $translator->setIndent(' '); // 扫描所有 PHP 文件,预处理 + $path = $argv[1]; $files = $translator->prepare($path); // 生成 C++ 文件 $sourceFiles = $translator->convert($files);