Skip to content

Commit

Permalink
analyze: implement --rewrite-mode pointwise
Browse files Browse the repository at this point in the history
  • Loading branch information
spernsteiner committed Apr 15, 2024
1 parent e2b3ea3 commit a015ff3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 11 additions & 5 deletions c2rust-analyze/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,9 @@ fn run(tcx: TyCtxt) {
// Load the list of fixed defs early, so any errors are reported immediately.
let fixed_defs = get_fixed_defs(tcx).unwrap();

let rewrite_pointwise = true;
let rewrite_pointwise = env::var("C2RUST_ANALYZE_REWRITE_MODE")
.ok()
.map_or(false, |val| val == "pointwise");

let mut gacx = GlobalAnalysisCtxt::new(tcx);
let mut func_info = HashMap::new();
Expand Down Expand Up @@ -1686,13 +1688,17 @@ fn run2<'tcx>(
"alongside" => {
update_files = rewrite::UpdateFiles::Alongside;
}
"pointwise" => {
let pointwise_fn_ldid = pointwise_fn_ldid.expect(
"C2RUST_ANALYZE_REWRITE_MODE=pointwise, \
but pointwise_fn_ldid is unset?",
);
let pointwise_fn_name = tcx.item_name(pointwise_fn_ldid.to_def_id());
update_files = rewrite::UpdateFiles::AlongsidePointwise(pointwise_fn_name);
}
_ => panic!("bad value {:?} for C2RUST_ANALYZE_REWRITE_MODE", val),
}
}
if let Some(pointwise_fn_ldid) = pointwise_fn_ldid {
let pointwise_fn_name = tcx.item_name(pointwise_fn_ldid.to_def_id());
update_files = rewrite::UpdateFiles::AlongsidePointwise(pointwise_fn_name);
}
rewrite::apply_rewrites(tcx, all_rewrites, annotations, update_files);

// ----------------------------------
Expand Down
4 changes: 4 additions & 0 deletions c2rust-analyze/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ enum RewriteMode {
/// Save rewritten code to a separate file alongside each source file.
#[value(name = "alongside")]
Alongside,
/// Rewrite each function separately, and write the results for each to a separate file.
#[value(name = "pointwise")]
Pointwise,
}

fn exit_with_status(status: ExitStatus) {
Expand Down Expand Up @@ -445,6 +448,7 @@ fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> {
RewriteMode::None => "none",
RewriteMode::InPlace => "inplace",
RewriteMode::Alongside => "alongside",
RewriteMode::Pointwise => "pointwise",
};
cmd.env("C2RUST_ANALYZE_REWRITE_MODE", val);
}
Expand Down

0 comments on commit a015ff3

Please sign in to comment.