-
-
Save nikic/145581a29ce951c31e2650ad322359e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = $argv[1]; | |
if (!is_file($file)) { | |
throw new Exception("Could not find file $file"); | |
} | |
$orig = file_get_contents($file); | |
$named = `build/bin/opt -passes=instnamer -S -o - < $file`; | |
$regex = <<<'REGEX' | |
/ | |
define.*@(?<name>[\w.]+)\([^{]+ | |
(?<curly> | |
\{ | |
[^{}]* | |
(?: (?&curly) [^{}]* )* | |
\} | |
) | |
/x | |
REGEX; | |
if (!preg_match_all($regex, $named, $matches, PREG_SET_ORDER)) { | |
throw new Exception("Failed to match"); | |
} | |
$newFuncs = []; | |
foreach ($matches as $match) { | |
$newFuncs[$match['name']] = $match[0]; | |
} | |
$new = preg_replace_callback($regex, function($match) use($newFuncs) { | |
$name = $match['name']; | |
if (!isset($newFuncs[$name])) { | |
throw new Exception("Missing new function for @$name"); | |
} | |
return $newFuncs[$name]; | |
}, $orig); | |
file_put_contents($file, $new); | |
if (str_contains($new, 'update_test_checks')) { | |
echo `./update_test_checks.sh $file`; | |
} else if (str_contains($new, 'update_llc_test_checks')) { | |
echo `./update_llc_test_checks.sh $file`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment