Skip to content

Commit 833e5f6

Browse files
committed
analyze: unify similar metrics scripts
1 parent 08fb475 commit 833e5f6

File tree

5 files changed

+118
-169
lines changed

5 files changed

+118
-169
lines changed

c2rust-analyze/scripts/pointwise_try_build.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ set -euo pipefail
44
echo
55

66
f=$1
7-
shift 1
7+
mode=$2
8+
shift 2
89
flags=( "$@" )
910
echo "f=$f"
11+
echo "mode=$mode"
1012

1113
name=${f%%.*.rs}
1214
name=${name##**/}
@@ -21,7 +23,22 @@ filter_errors() {
2123
{ grep -v -e '^aborting due to ' -e '^call to unsafe function is unsafe ' || true; }
2224
}
2325

24-
sed -i -e "/fn $func\\>/s/\\<unsafe //" $f
26+
case "$mode" in
27+
pointwise)
28+
sed -i -e "/fn $func\\>/s/\\<unsafe //" $f
29+
;;
30+
unmodified)
31+
d="$(dirname "$f")"
32+
f="$d/${name}_safe_${func}.rs"
33+
cp "$d/$name.rs" "$f"
34+
sed -i -e "/fn $func\\>/s/\\<unsafe //" $f
35+
;;
36+
*)
37+
echo "unsupported mode $mode" 1>&2
38+
exit 1
39+
;;
40+
esac
41+
2542
rustc --error-format json --emit metadata --crate-name $name "$f" "${flags[@]}" 2>rustc-$func.json || true
2643
num_lines="$(cat rustc-$func.json | filter_errors | wc -l)"
2744
echo "got $num_lines errors for $func"

c2rust-analyze/scripts/pointwise_try_build_unmodified.sh

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Run pointwise metrics on lighttpd_rust_amalgamated.
5+
6+
if [[ $# -ne 1 ]]; then
7+
echo "Usage: $0 <path/to/lighttpd_rust_amalgamated/>"
8+
exit 1
9+
fi
10+
11+
SCRIPT_DIR="$(dirname "$0")"
12+
13+
# Get the path to lighttpd_rust_amalgamated
14+
MODULE_DIR="$1"
15+
shift 1
16+
17+
# Find the sysroot directory of rustc
18+
SYSROOT="$(rustc --print sysroot)"
19+
20+
# Find the necessary rlibs
21+
extern() {
22+
local name=$1
23+
local rlib=$(find "$MODULE_DIR/target/debug/deps" -name "lib${name}*.rlib" -print -quit)
24+
echo >&2 "found rlib for $name: $rlib"
25+
echo --extern $name=$rlib
26+
}
27+
28+
now=$(date +%Y%m%d-%H%M%S)
29+
30+
31+
# Set $rustc_flags and run the analysis as appropriate for the target project.
32+
# $rustc_flags is also used below for `pointwise_try_build.sh`.
33+
project="$(basename "$MODULE_DIR")"
34+
case "$project" in
35+
lighttpd_*)
36+
rustc_flags=(
37+
--edition 2021
38+
--crate-type rlib
39+
#--sysroot "$SYSROOT"
40+
-L "dependency=$MODULE_DIR/target/debug/deps"
41+
$(extern c2rust_bitfields)
42+
$(extern libc)
43+
-A warnings
44+
)
45+
46+
C2RUST_ANALYZE_NO_CARGO=1 \
47+
C2RUST_ANALYZE_REWRITE_MODE=pointwise \
48+
C2RUST_ANALYZE_USE_MANUAL_SHIMS=1 \
49+
cargo run --bin c2rust-analyze --release -- "$MODULE_DIR/src/main.rs" \
50+
--crate-name "$(basename "$MODULE_DIR")" \
51+
"${rustc_flags[@]}" \
52+
|& tee pointwise-lighttpd-analyze-$now.log \
53+
|| true
54+
55+
;;
56+
57+
cfs_*)
58+
: cargo run --bin c2rust-analyze --release -- \
59+
--rewrite-mode pointwise --use-manual-shims -- \
60+
build --manifest-path "$MODULE_DIR/Cargo.toml" \
61+
|& tee pointwise-cfs-analyze-$now.log \
62+
|| true
63+
64+
rustc_flags=(
65+
--edition 2021
66+
--crate-type rlib
67+
#--sysroot "$SYSROOT"
68+
-L "dependency=$MODULE_DIR/target/debug/deps"
69+
$(extern c2rust_bitfields)
70+
$(extern f128)
71+
$(extern libc)
72+
$(extern memoffset)
73+
-A warnings
74+
)
75+
76+
;;
77+
78+
*)
79+
echo "unsupported project $project" 1>&2
80+
exit 1
81+
esac
82+
83+
84+
# Try to compile each function separately.
85+
86+
pointwise_log_file=pointwise-lighttpd-pointwise-$now.log
87+
for f in "$MODULE_DIR"/src/main.*.rs; do
88+
"$SCRIPT_DIR/pointwise_try_build.sh" "$f" pointwise "${rustc_flags[@]}" || true
89+
done |& tee "$pointwise_log_file"
90+
91+
unmodified_log_file=pointwise-lighttpd-unmodified-$now.log
92+
for f in "$MODULE_DIR"/src/main.*.rs; do
93+
"$SCRIPT_DIR/pointwise_try_build.sh" "$f" unmodified "${rustc_flags[@]}" || true
94+
done |& tee "$unmodified_log_file"
95+
96+
echo
97+
echo
98+
99+
python3 "$SCRIPT_DIR/pointwise_metrics.py" "$pointwise_log_file" "$unmodified_log_file"

c2rust-analyze/scripts/run_pointwise_metrics_cfs.sh

Lines changed: 0 additions & 65 deletions
This file was deleted.

c2rust-analyze/scripts/run_pointwise_metrics_lighttpd.sh

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)