Skip to content

Instantly share code, notes, and snippets.

@nikic
Created January 24, 2023 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikic/145581a29ce951c31e2650ad322359e4 to your computer and use it in GitHub Desktop.
Save nikic/145581a29ce951c31e2650ad322359e4 to your computer and use it in GitHub Desktop.
<?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