Skip to content

Commit

Permalink
Fix rmc codegen to check for no-codegen option (rust-lang#601)
Browse files Browse the repository at this point in the history
RMC code generation was creating artifacts even if rustc was run with
-Z no-codegen. I changed the codegen to check for this option before
writing the json files.

This issue was uncovered by my change to move the rmc flags to
rmc-rustc. This script is used during compiletest. In the check stage,
the test runs rustc with --no-codegen.
  • Loading branch information
celinval authored and tedinski committed Oct 29, 2021
1 parent a60612d commit 3ec6882
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions compiler/rustc_codegen_rmc/src/compiler_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl CodegenBackend for GotocCodegenBackend {

fn link(
&self,
_sess: &Session,
sess: &Session,
codegen_results: Box<dyn Any>,
outputs: &OutputFilenames,
) -> Result<(), ErrorReported> {
Expand All @@ -157,18 +157,21 @@ impl CodegenBackend for GotocCodegenBackend {
.downcast::<GotocCodegenResult>()
.expect("in link: codegen_results is not a GotocCodegenResult");

// "path.o"
let base_filename = outputs.path(OutputType::Object);
// No output should be generated if user selected no_codegen.
if !sess.opts.debugging_opts.no_codegen && sess.opts.output_types.should_codegen() {
// "path.o"
let base_filename = outputs.path(OutputType::Object);

let symtab_filename = base_filename.with_extension("symtab.json");
debug!("output to {:?}", symtab_filename);
let mut out_file = ::std::fs::File::create(&symtab_filename).unwrap();
write!(out_file, "{}", result.symtab.to_irep().to_json().pretty().to_string()).unwrap();
let symtab_filename = base_filename.with_extension("symtab.json");
debug!("output to {:?}", symtab_filename);
let mut out_file = ::std::fs::File::create(&symtab_filename).unwrap();
write!(out_file, "{}", result.symtab.to_irep().to_json().pretty().to_string()).unwrap();

let type_map_filename = base_filename.with_extension("type_map.json");
debug!("type_map to {:?}", type_map_filename);
let mut out_file = ::std::fs::File::create(&type_map_filename).unwrap();
write!(out_file, "{}", result.type_map.to_json().pretty().to_string()).unwrap();
let type_map_filename = base_filename.with_extension("type_map.json");
debug!("type_map to {:?}", type_map_filename);
let mut out_file = ::std::fs::File::create(&type_map_filename).unwrap();
write!(out_file, "{}", result.type_map.to_json().pretty().to_string()).unwrap();
}

Ok(())
}
Expand Down

0 comments on commit 3ec6882

Please sign in to comment.