diff --git a/c2rust-analyze/src/analyze.rs b/c2rust-analyze/src/analyze.rs index 9aad495302..8b586cdce1 100644 --- a/c2rust-analyze/src/analyze.rs +++ b/c2rust-analyze/src/analyze.rs @@ -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(); @@ -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); // ---------------------------------- diff --git a/c2rust-analyze/src/main.rs b/c2rust-analyze/src/main.rs index fd3befdd8e..3f751031c0 100644 --- a/c2rust-analyze/src/main.rs +++ b/c2rust-analyze/src/main.rs @@ -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) { @@ -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); }