parent
5fb2fc1ac5
commit
9acc849e1b
12 changed files with 3001 additions and 4 deletions
@ -0,0 +1,34 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
require dirname(__DIR__) . '/vendor/autoload.php'; |
||||||
|
|
||||||
|
use PhpAot\Php\Encryptor; |
||||||
|
use PhpParser\Error; |
||||||
|
use PhpParser\NodeTraverser; |
||||||
|
use PhpParser\ParserFactory; |
||||||
|
|
||||||
|
define('DEBUG', true); |
||||||
|
|
||||||
|
$traverser = new NodeTraverser; |
||||||
|
$traverser->addVisitor(new \PhpAot\Php\Visitor()); |
||||||
|
|
||||||
|
if (empty($argv[1])) { |
||||||
|
die("php compiler.php [file]\n"); |
||||||
|
} |
||||||
|
|
||||||
|
$code = file_get_contents($argv[1]); |
||||||
|
|
||||||
|
$parser = (new ParserFactory())->createForNewestSupportedVersion(); |
||||||
|
try { |
||||||
|
$ast = $parser->parse($code); |
||||||
|
$stmts = $traverser->traverse($ast); |
||||||
|
$encryptor = new Encryptor($stmts); |
||||||
|
$code = $encryptor->convert(); |
||||||
|
var_dump($code); |
||||||
|
// $translator->save($code, './tmp/hello.cc'); |
||||||
|
// $translator->compileFile('./tmp/hello.cc'); |
||||||
|
} catch (Error $error) { |
||||||
|
echo "Parse error: {$error->getMessage()}\n"; |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,42 @@ |
|||||||
|
<?php |
||||||
|
$dir = '/home/htf/workspace/c/php-8.0.12/ext/standard/'; |
||||||
|
|
||||||
|
$outDir = __DIR__ . '/../config/'; |
||||||
|
|
||||||
|
$funcs = []; |
||||||
|
$files = glob($dir . '*.c'); |
||||||
|
$index = 0; |
||||||
|
foreach ($files as $file) { |
||||||
|
$content = file_get_contents($file); |
||||||
|
preg_match_all('/PHP_FUNCTION\(([a-z0-9_]+)\)/i', $content, $match); |
||||||
|
if (empty($match[1])) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
foreach ($match[1] as $fn) { |
||||||
|
$funcs[] = $fn; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
shuffle($funcs); |
||||||
|
|
||||||
|
$_funcs = []; |
||||||
|
foreach ($funcs as $fn) { |
||||||
|
$_funcs['fn_' . random_int(100000, 999999) . str_pad($index++, 3, '0') . random_int(100, 999)] = $fn; |
||||||
|
} |
||||||
|
|
||||||
|
function dumpVar($file, $var) |
||||||
|
{ |
||||||
|
file_put_contents($file, "<?php\nreturn " . var_export($var, 1) . ";\n");
|
||||||
|
} |
||||||
|
|
||||||
|
dumpVar($outDir . 'functions.php', $_funcs); |
||||||
|
|
||||||
|
$constants = get_defined_constants(); |
||||||
|
$ignore_constants = array_flip(require __DIR__ . '/ignore_constants.php'); |
||||||
|
foreach ($constants as $k => $v) { |
||||||
|
if (isset($ignore_constants[$k])) { |
||||||
|
unset($constants[$k]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
dumpVar($outDir . 'constants.php', $constants); |
||||||
@ -0,0 +1,40 @@ |
|||||||
|
<?php |
||||||
|
return [ |
||||||
|
"PHP_SAPI", |
||||||
|
"PHP_OS", |
||||||
|
"PHP_OS_FAMILY", |
||||||
|
"PHP_ZTS", |
||||||
|
"PHP_MAXPATHLEN", |
||||||
|
"PHP_EOL", |
||||||
|
"PATH_SEPARATOR", |
||||||
|
"DIRECTORY_SEPARATOR", |
||||||
|
"PHP_BINDIR", |
||||||
|
"DEFAULT_INCLUDE_PATH", |
||||||
|
"PHP_LIBDIR", |
||||||
|
"PHP_VERSION", |
||||||
|
"PHP_VERSION_ID", |
||||||
|
'PEAR_INSTALL_DIR', |
||||||
|
'PEAR_EXTENSION_DIR', |
||||||
|
'PHP_EXTENSION_DIR', |
||||||
|
'PHP_PREFIX', |
||||||
|
'PHP_MANDIR', |
||||||
|
'PHP_DATADIR', |
||||||
|
'PHP_SYSCONFDIR', |
||||||
|
'PHP_LOCALSTATEDIR', |
||||||
|
'PHP_CONFIG_FILE_PATH', |
||||||
|
'PHP_CONFIG_FILE_SCAN_DIR', |
||||||
|
'PHP_BINARY', |
||||||
|
'LIBXML_VERSION', |
||||||
|
'LIBXML_DOTTED_VERSION', |
||||||
|
'LIBXML_LOADED_VERSION', |
||||||
|
'OPENSSL_VERSION_TEXT', |
||||||
|
'OPENSSL_VERSION_NUMBER', |
||||||
|
'OPENSSL_DEFAULT_STREAM_CIPHERS', |
||||||
|
'PCRE_VERSION', |
||||||
|
'PCRE_VERSION_MAJOR', |
||||||
|
'PCRE_VERSION_MINOR', |
||||||
|
'PCRE_JIT_SUPPORT', |
||||||
|
'STDIN', |
||||||
|
'STDOUT', |
||||||
|
'STDERR', |
||||||
|
]; |
||||||
@ -0,0 +1 @@ |
|||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,480 @@ |
|||||||
|
<?php |
||||||
|
return array ( |
||||||
|
'fn_268628000406' => 'microtime', |
||||||
|
'fn_446992100118' => 'proc_get_status', |
||||||
|
'fn_670187200134' => 'pack', |
||||||
|
'fn_212140300602' => 'strspn', |
||||||
|
'fn_753418400955' => 'dirname', |
||||||
|
'fn_292876500500' => 'array_udiff_assoc', |
||||||
|
'fn_604825600726' => 'stream_context_set_params', |
||||||
|
'fn_789307700719' => 'call_user_func_array', |
||||||
|
'fn_177275800714' => 'is_callable', |
||||||
|
'fn_742782900797' => 'version_compare', |
||||||
|
'fn_914546100875' => 'glob', |
||||||
|
'fn_835109110163' => 'cosh', |
||||||
|
'fn_214255120422' => 'atan', |
||||||
|
'fn_669705130562' => 'array_column', |
||||||
|
'fn_766607140824' => 'escapeshellarg', |
||||||
|
'fn_453939150520' => 'ftruncate', |
||||||
|
'fn_239496160553' => 'vsprintf', |
||||||
|
'fn_807966170248' => 'headers_sent', |
||||||
|
'fn_742946180180' => 'strripos', |
||||||
|
'fn_514674190217' => 'trim', |
||||||
|
'fn_343211200224' => 'getmyinode', |
||||||
|
'fn_762299210933' => 'error_clear_last', |
||||||
|
'fn_418991220540' => 'chown', |
||||||
|
'fn_231318230857' => 'stream_socket_client', |
||||||
|
'fn_916428240413' => 'ceil', |
||||||
|
'fn_401760250164' => 'stream_select', |
||||||
|
'fn_796719260288' => 'image_type_to_mime_type', |
||||||
|
'fn_713629270678' => 'password_needs_rehash', |
||||||
|
'fn_190101280366' => 'array_merge_recursive', |
||||||
|
'fn_423455290980' => 'fread', |
||||||
|
'fn_737596300131' => 'getmyuid', |
||||||
|
'fn_698830310823' => 'tanh', |
||||||
|
'fn_367721320348' => 'time_sleep_until', |
||||||
|
'fn_441839330115' => 'cos', |
||||||
|
'fn_248720340688' => 'getimagesize', |
||||||
|
'fn_395826350324' => 'strstr', |
||||||
|
'fn_801139360426' => 'is_int', |
||||||
|
'fn_498617370487' => 'strnatcasecmp', |
||||||
|
'fn_830446380410' => 'extract', |
||||||
|
'fn_739403390827' => 'array_unique', |
||||||
|
'fn_933370400691' => 'stream_is_local', |
||||||
|
'fn_110018410541' => 'fpassthru', |
||||||
|
'fn_968807420458' => 'array_diff_uassoc', |
||||||
|
'fn_402412430986' => 'array_intersect_key', |
||||||
|
'fn_502991440134' => 'getlastmod', |
||||||
|
'fn_518489450357' => 'convert_uudecode', |
||||||
|
'fn_972043460578' => 'fprintf', |
||||||
|
'fn_848354470296' => 'log1p', |
||||||
|
'fn_482067480729' => 'mt_rand', |
||||||
|
'fn_353910490827' => 'natsort', |
||||||
|
'fn_455892500890' => 'stream_get_filters', |
||||||
|
'fn_645118510346' => 'getprotobyname', |
||||||
|
'fn_523481520952' => 'disk_free_space', |
||||||
|
'fn_147021530199' => 'substr_compare', |
||||||
|
'fn_482961540112' => 'strcoll', |
||||||
|
'fn_693595550575' => 'strpbrk', |
||||||
|
'fn_801133560379' => 'flush', |
||||||
|
'fn_611248570328' => 'sscanf', |
||||||
|
'fn_739209580612' => 'getopt', |
||||||
|
'fn_232033590338' => 'array_reduce', |
||||||
|
'fn_976203600947' => 'ord', |
||||||
|
'fn_109495610650' => 'array_walk_recursive', |
||||||
|
'fn_837266620691' => 'phpinfo', |
||||||
|
'fn_378209630327' => 'str_pad', |
||||||
|
'fn_203470640974' => 'fgetc', |
||||||
|
'fn_336381650354' => 'min', |
||||||
|
'fn_694628660485' => 'is_null', |
||||||
|
'fn_227405670630' => 'rtrim', |
||||||
|
'fn_515161680400' => 'rsort', |
||||||
|
'fn_702324690392' => 'rename', |
||||||
|
'fn_277415700113' => 'realpath_cache_get', |
||||||
|
'fn_161119710919' => 'dechex', |
||||||
|
'fn_391328720955' => 'explode', |
||||||
|
'fn_592012730335' => 'stream_copy_to_stream', |
||||||
|
'fn_260806740807' => 'md5', |
||||||
|
'fn_153644750450' => 'php_sapi_name', |
||||||
|
'fn_380379760821' => 'array_diff', |
||||||
|
'fn_728615770136' => 'file', |
||||||
|
'fn_178658780585' => 'array_flip', |
||||||
|
'fn_111279790626' => 'php_strip_whitespace', |
||||||
|
'fn_716393800184' => 'addcslashes', |
||||||
|
'fn_373289810599' => 'similar_text', |
||||||
|
'fn_601044820494' => 'usleep', |
||||||
|
'fn_128006830443' => 'natcasesort', |
||||||
|
'fn_380705840279' => 'bin2hex', |
||||||
|
'fn_668833850251' => 'decoct', |
||||||
|
'fn_783296860787' => 'error_get_last', |
||||||
|
'fn_877314870144' => 'print_r', |
||||||
|
'fn_449318880512' => 'linkinfo', |
||||||
|
'fn_714939890342' => 'header', |
||||||
|
'fn_182371900414' => 'syslog', |
||||||
|
'fn_266524910619' => 'max', |
||||||
|
'fn_902621920658' => 'fscanf', |
||||||
|
'fn_889168930589' => 'chroot', |
||||||
|
'fn_853042940887' => 'stream_bucket_append', |
||||||
|
'fn_890924950545' => 'stream_socket_get_name', |
||||||
|
'fn_194760960334' => 'array_pop', |
||||||
|
'fn_742766970643' => 'array_splice', |
||||||
|
'fn_327365980921' => 'array_sum', |
||||||
|
'fn_634987990779' => 'stream_filter_append', |
||||||
|
'fn_111918100549' => 'shuffle', |
||||||
|
'fn_620306101151' => 'get_debug_type', |
||||||
|
'fn_988610102143' => 'acos', |
||||||
|
'fn_943537103904' => 'rad2deg', |
||||||
|
'fn_255204104402' => 'array_merge', |
||||||
|
'fn_115199105128' => 'fflush', |
||||||
|
'fn_386658106653' => 'setlocale', |
||||||
|
'fn_613677107747' => 'stream_socket_enable_crypto', |
||||||
|
'fn_250901108881' => 'unserialize', |
||||||
|
'fn_544619109332' => 'tan', |
||||||
|
'fn_492957110239' => 'uksort', |
||||||
|
'fn_632077111916' => 'utf8_decode', |
||||||
|
'fn_728903112579' => 'array_diff_key', |
||||||
|
'fn_787905113568' => 'stream_resolve_include_path', |
||||||
|
'fn_753419114183' => 'proc_nice', |
||||||
|
'fn_749372115594' => 'is_nan', |
||||||
|
'fn_921462116750' => 'copy', |
||||||
|
'fn_301226117995' => 'mt_srand', |
||||||
|
'fn_548497118441' => 'expm1', |
||||||
|
'fn_549923119715' => 'setrawcookie', |
||||||
|
'fn_530836120592' => 'quoted_printable_encode', |
||||||
|
'fn_798990121646' => 'popen', |
||||||
|
'fn_162074122284' => 'in_array', |
||||||
|
'fn_978081123734' => 'sinh', |
||||||
|
'fn_249220124555' => 'strptime', |
||||||
|
'fn_780423125848' => 'phpversion', |
||||||
|
'fn_393256126551' => 'stream_set_read_buffer', |
||||||
|
'fn_950894127541' => 'stream_socket_accept', |
||||||
|
'fn_314829128893' => 'system', |
||||||
|
'fn_666997129294' => 'str_ireplace', |
||||||
|
'fn_943932130140' => 'substr_count', |
||||||
|
'fn_122517131589' => 'rawurldecode', |
||||||
|
'fn_514569132760' => 'stream_bucket_make_writeable', |
||||||
|
'fn_355194133614' => 'is_scalar', |
||||||
|
'fn_329360134452' => 'unregister_tick_function', |
||||||
|
'fn_507757135378' => 'register_tick_function', |
||||||
|
'fn_271772136265' => 'gethostbyname', |
||||||
|
'fn_752520137148' => 'uasort', |
||||||
|
'fn_561608138525' => 'array_intersect', |
||||||
|
'fn_643620139152' => 'array_search', |
||||||
|
'fn_319906140739' => 'mt_getrandmax', |
||||||
|
'fn_118308141697' => 'array_chunk', |
||||||
|
'fn_804419142832' => 'acosh', |
||||||
|
'fn_250655143914' => 'get_headers', |
||||||
|
'fn_442295144905' => 'metaphone', |
||||||
|
'fn_921009145982' => 'tempnam', |
||||||
|
'fn_544827146439' => 'setcookie', |
||||||
|
'fn_463710147513' => 'link', |
||||||
|
'fn_321884148844' => 'quoted_printable_decode', |
||||||
|
'fn_670819149621' => 'highlight_string', |
||||||
|
'fn_546471150177' => 'connection_status', |
||||||
|
'fn_195279151592' => 'forward_static_call_array', |
||||||
|
'fn_102341152762' => 'crc32', |
||||||
|
'fn_578907153333' => 'array_unshift', |
||||||
|
'fn_132820154945' => 'sin', |
||||||
|
'fn_205967155355' => 'compact', |
||||||
|
'fn_835672156488' => 'assert', |
||||||
|
'fn_813579157559' => 'password_hash', |
||||||
|
'fn_842989158896' => 'levenshtein', |
||||||
|
'fn_597455159834' => 'symlink', |
||||||
|
'fn_118755160747' => 'arsort', |
||||||
|
'fn_588927161362' => 'disk_total_space', |
||||||
|
'fn_742075162378' => 'fputcsv', |
||||||
|
'fn_534538163528' => 'hypot', |
||||||
|
'fn_678023164409' => 'abs', |
||||||
|
'fn_921873165761' => 'proc_terminate', |
||||||
|
'fn_506519166299' => 'fdiv', |
||||||
|
'fn_659077167337' => 'stream_context_set_default', |
||||||
|
'fn_347385168809' => 'krsort', |
||||||
|
'fn_303176169212' => 'strrev', |
||||||
|
'fn_132502170584' => 'md5_file', |
||||||
|
'fn_187180171366' => 'soundex', |
||||||
|
'fn_921128172389' => 'base64_decode', |
||||||
|
'fn_479306173539' => 'intdiv', |
||||||
|
'fn_196323174962' => 'is_resource', |
||||||
|
'fn_408222175391' => 'round', |
||||||
|
'fn_763484176792' => 'stream_get_contents', |
||||||
|
'fn_405388177591' => 'fmod', |
||||||
|
'fn_537701178834' => 'exp', |
||||||
|
'fn_851298179589' => 'getprotobynumber', |
||||||
|
'fn_680387180504' => 'deg2rad', |
||||||
|
'fn_881796181163' => 'ini_get_all', |
||||||
|
'fn_484668182663' => 'stristr', |
||||||
|
'fn_331872183773' => 'pi', |
||||||
|
'fn_951555184758' => 'vfprintf', |
||||||
|
'fn_280942185932' => 'unpack', |
||||||
|
'fn_961555186196' => 'sqrt', |
||||||
|
'fn_434510187334' => 'vprintf', |
||||||
|
'fn_896776188614' => 'array_fill_keys', |
||||||
|
'fn_283041189982' => 'sha1_file', |
||||||
|
'fn_600618190738' => 'get_include_path', |
||||||
|
'fn_621530191192' => 'array_intersect_ukey', |
||||||
|
'fn_750630192398' => 'str_getcsv', |
||||||
|
'fn_984044193571' => 'sort', |
||||||
|
'fn_102858194415' => 'gettimeofday', |
||||||
|
'fn_425897195929' => 'chunk_split', |
||||||
|
'fn_644677196669' => 'random_bytes', |
||||||
|
'fn_387145197643' => 'get_browser', |
||||||
|
'fn_332731198866' => 'password_algos', |
||||||
|
'fn_937498199457' => 'intval', |
||||||
|
'fn_964150200221' => 'str_ends_with', |
||||||
|
'fn_792462201924' => 'html_entity_decode', |
||||||
|
'fn_685571202941' => 'chr', |
||||||
|
'fn_836591203674' => 'ucwords', |
||||||
|
'fn_349303204467' => 'is_bool', |
||||||
|
'fn_709247205476' => 'stream_socket_recvfrom', |
||||||
|
'fn_611876206292' => 'wordwrap', |
||||||
|
'fn_211138207339' => 'boolval', |
||||||
|
'fn_278126208501' => 'error_log', |
||||||
|
'fn_541495209919' => 'octdec', |
||||||
|
'fn_642904210339' => 'stripcslashes', |
||||||
|
'fn_462896211507' => 'iptcembed', |
||||||
|
'fn_722548212154' => 'array_uintersect', |
||||||
|
'fn_517400213771' => 'rewind', |
||||||
|
'fn_962218214129' => 'hrtime', |
||||||
|
'fn_611836215204' => 'ip2long', |
||||||
|
'fn_767927216789' => 'is_iterable', |
||||||
|
'fn_381861217548' => 'nl_langinfo', |
||||||
|
'fn_462520218590' => 'file_get_contents', |
||||||
|
'fn_390151219986' => 'array_key_last', |
||||||
|
'fn_874388220266' => 'ini_set', |
||||||
|
'fn_998783221595' => 'strip_tags', |
||||||
|
'fn_388491222989' => 'move_uploaded_file', |
||||||
|
'fn_498648223595' => 'prev', |
||||||
|
'fn_901288224416' => 'utf8_encode', |
||||||
|
'fn_653360225940' => 'floatval', |
||||||
|
'fn_526788226992' => 'array_replace_recursive', |
||||||
|
'fn_703175227498' => 'stream_filter_remove', |
||||||
|
'fn_308930228347' => 'current', |
||||||
|
'fn_316682229799' => 'headers_list', |
||||||
|
'fn_140762230332' => 'image_type_to_extension', |
||||||
|
'fn_185279231775' => 'getenv', |
||||||
|
'fn_698574232327' => 'array_reverse', |
||||||
|
'fn_255586233378' => 'array_udiff_uassoc', |
||||||
|
'fn_882171234892' => 'memory_get_usage', |
||||||
|
'fn_879977235191' => 'array_pad', |
||||||
|
'fn_951500236183' => 'stream_supports_lock', |
||||||
|
'fn_528642237168' => 'getrusage', |
||||||
|
'fn_238305238577' => 'parse_url', |
||||||
|
'fn_149032239654' => 'putenv', |
||||||
|
'fn_587614240206' => 'stream_set_timeout', |
||||||
|
'fn_814708241489' => 'pclose', |
||||||
|
'fn_752507242578' => 'highlight_file', |
||||||
|
'fn_764151243145' => 'password_get_info', |
||||||
|
'fn_501461244653' => 'chgrp', |
||||||
|
'fn_282365245968' => 'passthru', |
||||||
|
'fn_791162246257' => 'parse_str', |
||||||
|
'fn_823598247548' => 'ftok', |
||||||
|
'fn_523360248836' => 'hexdec', |
||||||
|
'fn_595074249590' => 'memory_get_peak_usage', |
||||||
|
'fn_644107250919' => 'lchown', |
||||||
|
'fn_690375251369' => 'array_map', |
||||||
|
'fn_902910252845' => 'fgets', |
||||||
|
'fn_202432253635' => 'decbin', |
||||||
|
'fn_273254254979' => 'array_change_key_case', |
||||||
|
'fn_808839255250' => 'realpath_cache_size', |
||||||
|
'fn_859147256125' => 'fopen', |
||||||
|
'fn_876531257669' => 'array_shift', |
||||||
|
'fn_365924258423' => 'chmod', |
||||||
|
'fn_912154259766' => 'log10', |
||||||
|
'fn_998515260158' => 'array_udiff', |
||||||
|
'fn_682904261407' => 'closedir', |
||||||
|
'fn_144851262820' => 'dns_check_record', |
||||||
|
'fn_241172263148' => 'gethostname', |
||||||
|
'fn_361325264708' => 'ltrim', |
||||||
|
'fn_502933265944' => 'stream_socket_pair', |
||||||
|
'fn_860459266241' => 'feof', |
||||||
|
'fn_333194267214' => 'serialize', |
||||||
|
'fn_278323268651' => 'printf', |
||||||
|
'fn_403050269942' => 'assert_options', |
||||||
|
'fn_949737270126' => 'opendir', |
||||||
|
'fn_445853271879' => 'strval', |
||||||
|
'fn_938036272880' => 'floor', |
||||||
|
'fn_238940273506' => 'realpath', |
||||||
|
'fn_418690274708' => 'get_html_translation_table', |
||||||
|
'fn_988036275838' => 'stream_set_chunk_size', |
||||||
|
'fn_377276276328' => 'proc_close', |
||||||
|
'fn_832975277922' => 'phpcredits', |
||||||
|
'fn_835996278538' => 'var_export', |
||||||
|
'fn_807712279471' => 'array_filter', |
||||||
|
'fn_658431280980' => 'ini_restore', |
||||||
|
'fn_393788281932' => 'chdir', |
||||||
|
'fn_113349282330' => 'hebrev', |
||||||
|
'fn_314639283744' => 'dir', |
||||||
|
'fn_581482284113' => 'umask', |
||||||
|
'fn_726673285805' => 'dns_get_mx', |
||||||
|
'fn_833375286202' => 'stream_context_get_options', |
||||||
|
'fn_248854287897' => 'array_intersect_uassoc', |
||||||
|
'fn_863894288267' => 'array_combine', |
||||||
|
'fn_566696289341' => 'count_chars', |
||||||
|
'fn_613359290911' => 'htmlspecialchars', |
||||||
|
'fn_634928291512' => 'urldecode', |
||||||
|
'fn_843493292695' => 'array_walk', |
||||||
|
'fn_672572293146' => 'getcwd', |
||||||
|
'fn_944343294715' => 'array_intersect_assoc', |
||||||
|
'fn_785994295246' => 'call_user_func', |
||||||
|
'fn_809978296147' => 'var_dump', |
||||||
|
'fn_631223297932' => 'array_uintersect_uassoc', |
||||||
|
'fn_370210298418' => 'str_rot13', |
||||||
|
'fn_963378299111' => 'tmpfile', |
||||||
|
'fn_300989300489' => 'array_count_values', |
||||||
|
'fn_359251301979' => 'convert_uuencode', |
||||||
|
'fn_673992302291' => 'sleep', |
||||||
|
'fn_912485303377' => 'str_word_count', |
||||||
|
'fn_959600304478' => 'parse_ini_file', |
||||||
|
'fn_540461305519' => 'asort', |
||||||
|
'fn_717340306856' => 'sys_get_temp_dir', |
||||||
|
'fn_367049307457' => 'stream_bucket_prepend', |
||||||
|
'fn_894627308290' => 'getmygid', |
||||||
|
'fn_123902309575' => 'gethostbynamel', |
||||||
|
'fn_871072310627' => 'http_build_query', |
||||||
|
'fn_114830311512' => 'implode', |
||||||
|
'fn_517562312258' => 'flock', |
||||||
|
'fn_464393313481' => 'crypt', |
||||||
|
'fn_341121314298' => 'array_fill', |
||||||
|
'fn_910170315475' => 'unlink', |
||||||
|
'fn_790309316404' => 'substr', |
||||||
|
'fn_716531317159' => 'sha1', |
||||||
|
'fn_169552318784' => 'settype', |
||||||
|
'fn_525665319583' => 'stream_filter_prepend', |
||||||
|
'fn_598343320847' => 'time_nanosleep', |
||||||
|
'fn_312141321224' => 'clearstatcache', |
||||||
|
'fn_885773322944' => 'strtok', |
||||||
|
'fn_720482323999' => 'str_split', |
||||||
|
'fn_884315324209' => 'readdir', |
||||||
|
'fn_363839325167' => 'array_push', |
||||||
|
'fn_754902326438' => 'uniqid', |
||||||
|
'fn_890141327628' => 'strtr', |
||||||
|
'fn_779938328512' => 'get_cfg_var', |
||||||
|
'fn_875126329144' => 'rand', |
||||||
|
'fn_461139330474' => 'htmlentities', |
||||||
|
'fn_348303331730' => 'atan2', |
||||||
|
'fn_159619332206' => 'urlencode', |
||||||
|
'fn_987207333738' => 'stream_context_get_params', |
||||||
|
'fn_445588334162' => 'stream_get_wrappers', |
||||||
|
'fn_493167335595' => 'localeconv', |
||||||
|
'fn_307319336452' => 'getimagesizefromstring', |
||||||
|
'fn_173658337170' => 'count', |
||||||
|
'fn_998426338167' => 'asinh', |
||||||
|
'fn_574064339711' => 'lchgrp', |
||||||
|
'fn_513058340237' => 'pathinfo', |
||||||
|
'fn_541060341655' => 'stripos', |
||||||
|
'fn_346637342151' => 'php_ini_scanned_files', |
||||||
|
'fn_724724343932' => 'str_starts_with', |
||||||
|
'fn_478147344842' => 'iptcparse', |
||||||
|
'fn_627436345167' => 'debug_zval_dump', |
||||||
|
'fn_843128346487' => 'array_rand', |
||||||
|
'fn_509074347341' => 'getservbyport', |
||||||
|
'fn_475471348861' => 'basename', |
||||||
|
'fn_433777349317' => 'readfile', |
||||||
|
'fn_875665350392' => 'stream_context_get_default', |
||||||
|
'fn_231401351328' => 'constant', |
||||||
|
'fn_897967352223' => 'is_countable', |
||||||
|
'fn_600381353896' => 'stream_socket_sendto', |
||||||
|
'fn_648686354216' => 'rawurlencode', |
||||||
|
'fn_366857355457' => 'is_uploaded_file', |
||||||
|
'fn_473091356143' => 'is_float', |
||||||
|
'fn_165533357954' => 'stream_get_transports', |
||||||
|
'fn_237156358360' => 'array_multisort', |
||||||
|
'fn_102783359341' => 'array_diff_ukey', |
||||||
|
'fn_124065360630' => 'get_current_user', |
||||||
|
'fn_433772361960' => 'inet_pton', |
||||||
|
'fn_876845362432' => 'proc_open', |
||||||
|
'fn_696499363557' => 'dl', |
||||||
|
'fn_648804364560' => 'substr_replace', |
||||||
|
'fn_723676365438' => 'inet_ntop', |
||||||
|
'fn_193756366642' => 'atanh', |
||||||
|
'fn_262337367269' => 'usort', |
||||||
|
'fn_615617368558' => 'long2ip', |
||||||
|
'fn_723885369702' => 'number_format', |
||||||
|
'fn_379870370573' => 'gettype', |
||||||
|
'fn_134566371508' => 'fseek', |
||||||
|
'fn_470493372344' => 'forward_static_call', |
||||||
|
'fn_463860373496' => 'ucfirst', |
||||||
|
'fn_466754374622' => 'dns_get_mx', |
||||||
|
'fn_107264375679' => 'fsockopen', |
||||||
|
'fn_479610376250' => 'fclose', |
||||||
|
'fn_973139377619' => 'stream_isatty', |
||||||
|
'fn_963532378121' => 'stream_socket_shutdown', |
||||||
|
'fn_680269379225' => 'get_meta_tags', |
||||||
|
'fn_899645380636' => 'asin', |
||||||
|
'fn_286046381492' => 'closelog', |
||||||
|
'fn_777803382670' => 'register_shutdown_function', |
||||||
|
'fn_843658383330' => 'shell_exec', |
||||||
|
'fn_225733384362' => 'stripslashes', |
||||||
|
'fn_662498385432' => 'str_shuffle', |
||||||
|
'fn_945027386645' => 'scandir', |
||||||
|
'fn_883447387234' => 'array_replace', |
||||||
|
'fn_188286388568' => 'ksort', |
||||||
|
'fn_234493389855' => 'rewinddir', |
||||||
|
'fn_391322390709' => 'fnmatch', |
||||||
|
'fn_802639391768' => 'exec', |
||||||
|
'fn_965630392630' => 'random_int', |
||||||
|
'fn_806623393820' => 'gethostbyaddr', |
||||||
|
'fn_834557394356' => 'dns_get_record', |
||||||
|
'fn_753747395367' => 'stream_bucket_new', |
||||||
|
'fn_308333396888' => 'config_get_hash', |
||||||
|
'fn_122693397687' => 'array_diff_assoc', |
||||||
|
'fn_850310398695' => 'escapeshellcmd', |
||||||
|
'fn_852027399249' => 'nl2br', |
||||||
|
'fn_634138400492' => 'str_replace', |
||||||
|
'fn_978761401682' => 'is_string', |
||||||
|
'fn_908179402243' => 'array_values', |
||||||
|
'fn_246145403862' => 'is_array', |
||||||
|
'fn_375945404859' => 'strpos', |
||||||
|
'fn_491527405466' => 'pfsockopen', |
||||||
|
'fn_932293406676' => 'base64_encode', |
||||||
|
'fn_671335407508' => 'str_contains', |
||||||
|
'fn_343130408317' => 'base_convert', |
||||||
|
'fn_297084409875' => 'is_infinite', |
||||||
|
'fn_550584410765' => 'mail', |
||||||
|
'fn_962465411769' => 'array_keys', |
||||||
|
'fn_584965412679' => 'ignore_user_abort', |
||||||
|
'fn_636165413465' => 'array_product', |
||||||
|
'fn_149040414128' => 'password_verify', |
||||||
|
'fn_279207415557' => 'htmlspecialchars_decode', |
||||||
|
'fn_993372416998' => 'range', |
||||||
|
'fn_189673417819' => 'is_object', |
||||||
|
'fn_644257418726' => 'mkdir', |
||||||
|
'fn_139558419798' => 'touch', |
||||||
|
'fn_151876420211' => 'lcfirst', |
||||||
|
'fn_566271421464' => 'rmdir', |
||||||
|
'fn_939311422338' => 'readlink', |
||||||
|
'fn_127114423996' => 'sapi_windows_vt100_support', |
||||||
|
'fn_763909424838' => 'is_finite', |
||||||
|
'fn_798601425950' => 'array_slice', |
||||||
|
'fn_589227426591' => 'http_response_code', |
||||||
|
'fn_615598427567' => 'openlog', |
||||||
|
'fn_124394428641' => 'php_ini_loaded_file', |
||||||
|
'fn_959188429879' => 'fgetcsv', |
||||||
|
'fn_466149430802' => 'sprintf', |
||||||
|
'fn_364565431656' => 'parse_ini_string', |
||||||
|
'fn_148177432401' => 'array_key_exists', |
||||||
|
'fn_689325433549' => 'dns_get_record', |
||||||
|
'fn_167216434698' => 'sys_getloadavg', |
||||||
|
'fn_950691435206' => 'hex2bin', |
||||||
|
'fn_610152436154' => 'stream_context_set_option', |
||||||
|
'fn_111010437804' => 'set_include_path', |
||||||
|
'fn_444553438827' => 'strrchr', |
||||||
|
'fn_852837439787' => 'stream_set_blocking', |
||||||
|
'fn_927433440248' => 'ftell', |
||||||
|
'fn_834040441473' => 'ini_get', |
||||||
|
'fn_851731442520' => 'php_uname', |
||||||
|
'fn_978046443789' => 'next', |
||||||
|
'fn_342528444864' => 'getservbyname', |
||||||
|
'fn_637095445805' => 'reset', |
||||||
|
'fn_671526446181' => 'addslashes', |
||||||
|
'fn_726412447504' => 'lcg_value', |
||||||
|
'fn_118442448832' => 'bindec', |
||||||
|
'fn_193605449687' => 'dns_check_record', |
||||||
|
'fn_142639450533' => 'stream_set_write_buffer', |
||||||
|
'fn_279645451781' => 'fwrite', |
||||||
|
'fn_559885452761' => 'net_get_interfaces', |
||||||
|
'fn_557156453286' => 'strrpos', |
||||||
|
'fn_989651454633' => 'stream_get_meta_data', |
||||||
|
'fn_953644455686' => 'quotemeta', |
||||||
|
'fn_150968456179' => 'end', |
||||||
|
'fn_532941457482' => 'array_key_first', |
||||||
|
'fn_413255458873' => 'log', |
||||||
|
'fn_551542459309' => 'strtolower', |
||||||
|
'fn_112746460417' => 'key', |
||||||
|
'fn_636571461580' => 'connection_aborted', |
||||||
|
'fn_740491462841' => 'header_remove', |
||||||
|
'fn_827974463454' => 'stream_get_line', |
||||||
|
'fn_387797464718' => 'pow', |
||||||
|
'fn_935752465180' => 'array_uintersect_assoc', |
||||||
|
'fn_528167466136' => 'strnatcmp', |
||||||
|
'fn_839420467511' => 'stream_socket_server', |
||||||
|
'fn_169946468241' => 'strcspn', |
||||||
|
'fn_484993469875' => 'is_numeric', |
||||||
|
'fn_590027470680' => 'getmypid', |
||||||
|
'fn_384043471846' => 'stream_filter_register', |
||||||
|
'fn_808416472868' => 'str_repeat', |
||||||
|
'fn_166553473606' => 'strtoupper', |
||||||
|
'fn_143910474513' => 'stream_context_create', |
||||||
|
'fn_473466475988' => 'file_put_contents', |
||||||
|
'fn_965424476945' => 'fstat', |
||||||
|
); |
||||||
@ -0,0 +1,5 @@ |
|||||||
|
<?php |
||||||
|
$a = __FILE__; |
||||||
|
$b = __DIR__; |
||||||
|
$c = PHP_OS; |
||||||
|
$d = PHP_URL_SCHEME; |
||||||
@ -0,0 +1,2 @@ |
|||||||
|
<?php |
||||||
|
$secure = 'https' === parse_url(wp_login_url(), PHP_URL_SCHEME); |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
function main(int $argc, array $argv): int |
||||||
|
{ |
||||||
|
$a = 1; |
||||||
|
$b = 2; |
||||||
|
$c = 3.12343; |
||||||
|
$d = 'hello'; |
||||||
|
$e = ['hello' => 1, 'world' => 33.43]; |
||||||
|
|
||||||
|
$argc = 999; |
||||||
|
$a = $b * 13; |
||||||
|
|
||||||
|
echo "value:=" . ($a + $b); |
||||||
|
|
||||||
|
$str = str_repeat($d, $b); |
||||||
|
echo $str; |
||||||
|
|
||||||
|
$e2 = array_flip($e); |
||||||
|
var_dump($e2); |
||||||
|
|
||||||
|
return $a * $b; |
||||||
|
} |
||||||
@ -0,0 +1,432 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace PhpAot\Php; |
||||||
|
|
||||||
|
use PhpParser\Node; |
||||||
|
use PhpParser\Node\Expr\Variable; |
||||||
|
use PhpParser\Node\Identifier; |
||||||
|
use PhpParser\PrettyPrinter\Standard; |
||||||
|
|
||||||
|
class Encryptor extends \PhpAot\Core\Translator |
||||||
|
{ |
||||||
|
protected array $stmts; |
||||||
|
protected string $phpxDir = '~/workspace/phpx'; |
||||||
|
protected string $lang = 'PHP'; |
||||||
|
protected array $typeMap = []; |
||||||
|
protected array $headers = [ |
||||||
|
'phpx.h', |
||||||
|
]; |
||||||
|
protected array $encodeMap; |
||||||
|
protected array $decodeMap; |
||||||
|
protected array $constants; |
||||||
|
|
||||||
|
function __construct(array $stmts) |
||||||
|
{ |
||||||
|
$confDir = __DIR__ . '/../../config'; |
||||||
|
$this->stmts = $stmts; |
||||||
|
$this->encodeMap = require $confDir . '/functions.php'; |
||||||
|
$this->decodeMap = array_flip($this->encodeMap); |
||||||
|
$this->constants = require $confDir . '/constants.php'; |
||||||
|
} |
||||||
|
|
||||||
|
function parseHeaders(): string |
||||||
|
{ |
||||||
|
$lines = []; |
||||||
|
foreach ($this->headers as $header) { |
||||||
|
$lines[] = '#include <' . $header . '>'; |
||||||
|
} |
||||||
|
return implode(PHP_EOL, $lines) . PHP_EOL . PHP_EOL; |
||||||
|
} |
||||||
|
|
||||||
|
function setPhpxDir($dir): void |
||||||
|
{ |
||||||
|
$this->phpxDir = $dir; |
||||||
|
} |
||||||
|
|
||||||
|
function convert() |
||||||
|
{ |
||||||
|
$this->parseStmts($this->stmts); |
||||||
|
$prettyPrinter = new Standard; |
||||||
|
return $prettyPrinter->prettyPrintFile($this->stmts); |
||||||
|
} |
||||||
|
|
||||||
|
function save($code, $file) |
||||||
|
{ |
||||||
|
file_put_contents($file, $code); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
function getLine($node): int |
||||||
|
{ |
||||||
|
return $node->getLine(); |
||||||
|
} |
||||||
|
|
||||||
|
function getType($node): string |
||||||
|
{ |
||||||
|
return $node->getType(); |
||||||
|
} |
||||||
|
|
||||||
|
private function parseFunctionDef($v) |
||||||
|
{ |
||||||
|
if ($v->name) { |
||||||
|
$name = $this->parseIdentifier($v->name); |
||||||
|
} else { |
||||||
|
$name = ''; |
||||||
|
} |
||||||
|
|
||||||
|
if ($v->returnType) { |
||||||
|
$return =$this->parseIdentifier($v->returnType); |
||||||
|
} else { |
||||||
|
$return = ''; |
||||||
|
} |
||||||
|
|
||||||
|
if ($v->params) { |
||||||
|
$params = $this->parseParams($v->params); |
||||||
|
} else { |
||||||
|
$params = ''; |
||||||
|
} |
||||||
|
|
||||||
|
$code = $return . ' ' . $name . '(' . $params . ') {' . PHP_EOL; |
||||||
|
$this->indentLevel++; |
||||||
|
$stmts = $this->parseStmts($v->stmts); |
||||||
|
$this->indentLevel--; |
||||||
|
$code .= $stmts; |
||||||
|
$code .= "}"; |
||||||
|
|
||||||
|
return $code; |
||||||
|
} |
||||||
|
|
||||||
|
protected function parseIdentifier($node) |
||||||
|
{ |
||||||
|
$type = $node->getType(); |
||||||
|
switch ($type) { |
||||||
|
case 'Identifier': |
||||||
|
case 'Expr_Variable': |
||||||
|
return $node->name; |
||||||
|
case 'Scalar_Int': |
||||||
|
case 'Scalar_Float': |
||||||
|
return $node->value; |
||||||
|
case 'Scalar_String': |
||||||
|
return '"' . $node->value . '"'; |
||||||
|
case 'Expr_Array': |
||||||
|
return $this->parseArray($node); |
||||||
|
case 'Expr_FuncCall': |
||||||
|
$this->parseFuncCall($node->name); |
||||||
|
break; |
||||||
|
case 'Expr_Ternary': |
||||||
|
case 'Expr_ArrayDimFetch': |
||||||
|
case 'Expr_New': |
||||||
|
case 'Expr_ClassConstFetch': |
||||||
|
case 'Expr_BinaryOp_Identical': |
||||||
|
case 'Expr_BinaryOp_Mul': |
||||||
|
case 'Expr_BinaryOp_Concat': |
||||||
|
case 'Expr_BinaryOp_Plus': |
||||||
|
case 'Expr_Isset': |
||||||
|
case 'Stmt_Switch': |
||||||
|
break; |
||||||
|
default: |
||||||
|
debug($node); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private function parseParams($params) |
||||||
|
{ |
||||||
|
$list = []; |
||||||
|
foreach ($params as $param) { |
||||||
|
$type = $param->type ? $this->parseType($param->type) : ''; |
||||||
|
$name = $param->var ? $this->parseIdentifier($param->var) : ''; |
||||||
|
$list[] = $type . ' ' . $name; |
||||||
|
$this->typeMap[$name] = $type; |
||||||
|
} |
||||||
|
return implode(', ', $list); |
||||||
|
} |
||||||
|
|
||||||
|
private function parseStmts(array $stmts) |
||||||
|
{ |
||||||
|
$lines = []; |
||||||
|
foreach ($stmts as $v) { |
||||||
|
$class = $v->getType(); |
||||||
|
switch ($class) { |
||||||
|
case 'Stmt_Function': |
||||||
|
$lines[] = $this->parseFunctionDef($v); |
||||||
|
break; |
||||||
|
case 'Stmt_Expression': |
||||||
|
$lines[] = $this->parseExpr($v->expr) . ';'; |
||||||
|
break; |
||||||
|
case 'Stmt_Echo': |
||||||
|
$lines[] = $this->parseEcho($v) . ';'; |
||||||
|
break; |
||||||
|
case 'Stmt_Return': |
||||||
|
$this->parseReturn($v); |
||||||
|
break; |
||||||
|
case 'Expr_Include': |
||||||
|
$this->parseInclude($v); |
||||||
|
break; |
||||||
|
case 'Stmt_If': |
||||||
|
$this->parseIf($v); |
||||||
|
break; |
||||||
|
case 'Stmt_Global': |
||||||
|
case 'Stmt_InlineHTML': |
||||||
|
case 'Stmt_Nop': |
||||||
|
case 'Stmt_Switch': |
||||||
|
break; |
||||||
|
default: |
||||||
|
debug($v); |
||||||
|
} |
||||||
|
} |
||||||
|
$code = ''; |
||||||
|
foreach ($lines as $line) { |
||||||
|
$code .= $this->getIndent() . $line . PHP_EOL; |
||||||
|
} |
||||||
|
return $code; |
||||||
|
} |
||||||
|
|
||||||
|
private function parseExpr(mixed $expr) |
||||||
|
{ |
||||||
|
$type = $expr->getType(); |
||||||
|
switch ($type) { |
||||||
|
case 'Expr_Assign': |
||||||
|
return $this->parseAssign($expr); |
||||||
|
case 'Expr_BinaryOp_Plus': |
||||||
|
return $this->parseBinaryOpPlus($expr); |
||||||
|
case 'Expr_BinaryOp_Mul': |
||||||
|
return $this->parseBinaryOpMul($expr); |
||||||
|
case 'Expr_BinaryOp_Concat': |
||||||
|
return $this->parseBinaryOpConcat($expr); |
||||||
|
case 'Expr_FuncCall': |
||||||
|
return $this->parseFuncCall($expr->name); |
||||||
|
case 'Expr_Include': |
||||||
|
return $this->parseInclude($expr->expr); |
||||||
|
case 'Expr_BinaryOp_BooleanAnd': |
||||||
|
return $this->parseBinaryOpBooleanAnd($expr); |
||||||
|
case 'Expr_MethodCall': |
||||||
|
case 'Expr_Isset': |
||||||
|
case 'Expr_Variable': |
||||||
|
case 'Expr_BooleanNot': |
||||||
|
case 'Scalar_String': |
||||||
|
case 'Scalar_MagicConst_File': |
||||||
|
case 'Scalar_MagicConst_Dir': |
||||||
|
break; |
||||||
|
case 'Expr_BinaryOp_NotIdentical': |
||||||
|
$this->parseBinaryOpNotIdentical($expr); |
||||||
|
break; |
||||||
|
case 'Expr_BinaryOp_Identical': |
||||||
|
$this->parseBinaryOpIdentical($expr); |
||||||
|
break; |
||||||
|
case 'Expr_ConstFetch': |
||||||
|
$this->parseConstFetch($expr); |
||||||
|
break; |
||||||
|
default: |
||||||
|
debug($expr); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private function parseAssign(mixed $v) |
||||||
|
{ |
||||||
|
$this->parseExpr($v->var); |
||||||
|
$this->parseExpr($v->expr); |
||||||
|
} |
||||||
|
|
||||||
|
private function parseEcho(mixed $v) |
||||||
|
{ |
||||||
|
return 'php::echo(' . $this->parseExprs($v->exprs) . ')'; |
||||||
|
} |
||||||
|
|
||||||
|
private function parseExprs($exprs) |
||||||
|
{ |
||||||
|
$code = ''; |
||||||
|
foreach ($exprs as $expr) { |
||||||
|
$code .= $this->parseExpr($expr); |
||||||
|
} |
||||||
|
return $code; |
||||||
|
} |
||||||
|
|
||||||
|
private function parseBinaryOpPlus(mixed $expr) |
||||||
|
{ |
||||||
|
$left = $this->parseIdentifier($expr->left); |
||||||
|
$right = $this->parseIdentifier($expr->right); |
||||||
|
|
||||||
|
return $left . ' + ' . $right; |
||||||
|
} |
||||||
|
|
||||||
|
private function parseReturn(mixed $v) |
||||||
|
{ |
||||||
|
return 'return ' . $this->parseExpr($v->expr); |
||||||
|
} |
||||||
|
|
||||||
|
private function parseBinaryOpMul(mixed $expr) |
||||||
|
{ |
||||||
|
$left = $this->parseIdentifier($expr->left); |
||||||
|
$right = $this->parseIdentifier($expr->right); |
||||||
|
|
||||||
|
return $left . ' * ' . $right; |
||||||
|
} |
||||||
|
|
||||||
|
private function detectType($var, $expr) |
||||||
|
{ |
||||||
|
$exprType = $expr->getType(); |
||||||
|
switch ($exprType) { |
||||||
|
case 'Scalar_Int': |
||||||
|
return 'zend_long'; |
||||||
|
case 'Scalar_Float': |
||||||
|
return 'double'; |
||||||
|
case 'Scalar_String': |
||||||
|
return 'php::Variant'; |
||||||
|
case 'Expr_Array': |
||||||
|
return 'php::Array'; |
||||||
|
default: |
||||||
|
debug($expr); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private function parseArray($node) |
||||||
|
{ |
||||||
|
$items = $node->items; |
||||||
|
$list = []; |
||||||
|
$this->indentLevel++; |
||||||
|
foreach ($items as $item) { |
||||||
|
if ($item->key) { |
||||||
|
$list[] = $this->getIndent() . '{ php::Variant(' . $this->parseIdentifier($item->key) . '), php::Variant(' . $this->parseIdentifier($item->value) . ') }'; |
||||||
|
} else { |
||||||
|
$list[] = $this->getIndent() . 'php::Variant(' . $this->parseIdentifier($item->value) . ')'; |
||||||
|
} |
||||||
|
} |
||||||
|
$this->indentLevel--; |
||||||
|
return '{' . PHP_EOL . |
||||||
|
implode(', ' . PHP_EOL, $list) . PHP_EOL . |
||||||
|
$this->getIndent() . |
||||||
|
'}'; |
||||||
|
} |
||||||
|
|
||||||
|
private function parseType($type) |
||||||
|
{ |
||||||
|
$name = $type->name; |
||||||
|
switch ($name) { |
||||||
|
case 'int': |
||||||
|
return 'zend_long'; |
||||||
|
case 'array': |
||||||
|
return 'php::Array'; |
||||||
|
case 'float': |
||||||
|
return 'double'; |
||||||
|
default: |
||||||
|
debug($type); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private function parseIncludes() |
||||||
|
{ |
||||||
|
$list = [ |
||||||
|
$this->phpxDir . '/include', |
||||||
|
]; |
||||||
|
$out = '$(php-config --includes) '; |
||||||
|
foreach ($list as $li) { |
||||||
|
$out .= '-I ' . $li . ' '; |
||||||
|
} |
||||||
|
return $out; |
||||||
|
} |
||||||
|
|
||||||
|
private function parseLdflags() |
||||||
|
{ |
||||||
|
$list = [ |
||||||
|
'$(php-config --prefix)/lib', |
||||||
|
$this->phpxDir . '/lib', |
||||||
|
]; |
||||||
|
$out = ''; |
||||||
|
foreach ($list as $li) { |
||||||
|
$out .= '-L ' . $li . ' '; |
||||||
|
} |
||||||
|
return $out; |
||||||
|
} |
||||||
|
|
||||||
|
private function parseLibs() |
||||||
|
{ |
||||||
|
$list = [ |
||||||
|
'phpx', |
||||||
|
'php', |
||||||
|
]; |
||||||
|
$out = ''; |
||||||
|
foreach ($list as $li) { |
||||||
|
$out .= '-l' . $li . ' '; |
||||||
|
} |
||||||
|
return $out; |
||||||
|
} |
||||||
|
|
||||||
|
public function compileFile($file) |
||||||
|
{ |
||||||
|
$cmd = 'g++ -c ' . $file . ' -o ' . $file . '.o ' . $this->parseIncludes() . $this->parseLdflags() . $this->parseLibs(); |
||||||
|
echo $cmd . PHP_EOL; |
||||||
|
shell_exec($cmd); |
||||||
|
} |
||||||
|
|
||||||
|
private function parseBinaryOpConcat(mixed $expr) |
||||||
|
{ |
||||||
|
$left = $this->parseIdentifier($expr->left); |
||||||
|
$right = $this->parseIdentifier($expr->right); |
||||||
|
|
||||||
|
return $left . ' + ' . $right; |
||||||
|
} |
||||||
|
|
||||||
|
private function parseFuncCall($expr) |
||||||
|
{ |
||||||
|
if (isset($this->decodeMap[$expr->name])) { |
||||||
|
$expr->name = $this->decodeMap[$expr->name]; |
||||||
|
} |
||||||
|
return $expr; |
||||||
|
} |
||||||
|
|
||||||
|
private function parseInclude(mixed $v) |
||||||
|
{ |
||||||
|
return ''; |
||||||
|
} |
||||||
|
|
||||||
|
private function parseIf(mixed $v) |
||||||
|
{ |
||||||
|
$cond = $v->cond; |
||||||
|
$this->parseCond($cond); |
||||||
|
} |
||||||
|
|
||||||
|
private function parseCond(mixed $cond) |
||||||
|
{ |
||||||
|
return $this->parseExpr($cond); |
||||||
|
} |
||||||
|
|
||||||
|
private function parseBinaryOpBooleanAnd(mixed $expr) |
||||||
|
{ |
||||||
|
if (!empty($expr->left)) { |
||||||
|
$this->parseExpr($expr->left); |
||||||
|
} |
||||||
|
if (!empty($expr->right)) { |
||||||
|
$this->parseExpr($expr->right); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private function parseBinaryOpNotIdentical(mixed $expr) |
||||||
|
{ |
||||||
|
if (!empty($expr->left)) { |
||||||
|
$this->parseExpr($expr->left); |
||||||
|
} |
||||||
|
if (!empty($expr->right)) { |
||||||
|
$this->parseExpr($expr->right); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private function parseBinaryOpIdentical(mixed $expr) |
||||||
|
{ |
||||||
|
if (!empty($expr->left)) { |
||||||
|
$this->parseExpr($expr->left); |
||||||
|
} |
||||||
|
if (!empty($expr->right)) { |
||||||
|
$this->parseExpr($expr->right); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private function parseConstFetch(mixed $expr) |
||||||
|
{ |
||||||
|
$name = $expr->name->name; |
||||||
|
if (isset($this->constants[$name])) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
Loading…
Reference in new issue