-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#421 removed a lot of the simple error/cleanup `goto`s in C. This re-transpiles those functions and merges the new versions back in with the relooper state machines now removed. I only re-transpiled and merged back functions used by the `dav1d` binary (the others aren't as important). I also included the `retranspile.sh` script I used to help with this, as we may want to do this again for something (e.x. more `goto`s, upstream changes to `dav1d`, etc.). Also, some upstream changes weren't made, but these were minor, such as redundant `as` casts and type annotations. It'll be easier to do these in bulk later (and the reason they were only done sporadically before was because the code was so heavily indented due to the state machines).
- Loading branch information
Showing
5 changed files
with
3,333 additions
and
4,813 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# How to Re-Transpile `fn`s After Changes to the C code | ||
|
||
1. Make your changes to the C code. | ||
2. Run `./retranspile.sh transpile` to actually re-transpile. | ||
3. For each `fn` `${fn_name}`, | ||
1. Copy `fn ${fn_name}` and any new callees to `retranspile/${fn_name}.fn.new`. | ||
4. Run `./retranspile.sh stash`, `stash`ing all of the re-transpile changes. | ||
5. For each `fn` `${fn_name}`, | ||
1. Run `./retranspile.sh fn-diff ${fn_name}`, saving `fn ${fn_name}`'s diff | ||
(it unfortunately shows a lot extra, too) | ||
from the `initial-transpile` to `retranspile/${fn_name}.fn.diff`. | ||
2. Replace the existing `fn` with the new version. | ||
3. Patch back the changes in `retranspile/${fn_name}.fn.diff`, probably manually. | ||
4. Run `./retranspile.sh commit ${fn_name}`, committing the re-transpiled changes. | ||
6. Run `./retranspile.sh cleanup ${fn_name}` to cleanup intermediate files for `${fn_name}`, | ||
or just `./retranspile.sh cleanup` to cleanup them all. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euox pipefail | ||
|
||
mkdir -p retranspile/ | ||
|
||
transpile() { | ||
local c2rust_dir="../c2rust-for-rav1d" | ||
local c2rust="${c2rust_dir}/target/release/c2rust" | ||
|
||
if [[ ! -x "${c2rust}" ]]; then | ||
rm -rf "${c2rust_dir}" | ||
# need this specific branch, so just build our own copy of c2rust | ||
git clone \ | ||
--branch perl/c11_atomics \ | ||
--depth 1 \ | ||
https://github.com/immunant/c2rust.git "${c2rust_dir}" | ||
(cd "${c2rust_dir}" | ||
cargo build --release | ||
) | ||
fi | ||
|
||
export CC=clang | ||
rm -rf build | ||
mkdir build | ||
meson setup build \ | ||
--reconfigure \ | ||
-Dtest_rust=false \ | ||
-Denable_asm=false \ | ||
"-Dbitdepths=['8','16']" | ||
bear -- ninja -C build tools/dav1d | ||
"${c2rust}" transpile compile_commands.json --binary dav1d --overwrite-existing | ||
} | ||
|
||
stash() { | ||
git add . | ||
git stash push -m 'retranspiled dav1d' | ||
} | ||
|
||
fn-diff() { | ||
local fn_name="$1" | ||
git diff "initial-transpile-fmt..$(git branch --show-current)" \ | ||
--ignore-space-change \ | ||
-G"[^ ] fn ${fn_name}" \ | ||
> "retranspile/${fn_name}.fn.diff" | ||
delta < "retranspile/${fn_name}.fn.diff" | ||
} | ||
|
||
commit() { | ||
local fn_name="$1" | ||
git commit -m "\`fn ${fn_name}\`: Re-transpile." | ||
} | ||
|
||
cleanup() { | ||
local fn_name="${1:-*}" | ||
rm -rf retranspile/${fn_name}.fn.* | ||
rmdir --ignore-fail-on-non-empty retranspile/ | ||
} | ||
|
||
"${@}" |
Oops, something went wrong.