Add new -Z dump-mir-spanview option

Similar to `-Z dump-mir-graphviz`, this adds the option to write
HTML+CSS files that allow users to analyze the spans associated with MIR
elements (by individual statement, just terminator, or overall basic
block).

This PR was split out from PR #76004, and exposes an API for spanview
HTML+CSS files that is also used to analyze code regions chosen for
coverage instrumentation (in a follow-on PR).

Rust compiler MCP rust-lang/compiler-team#278

Relevant issue: #34701 - Implement support for LLVMs code coverage
instrumentation
This commit is contained in:
Rich Kadel
2020-08-29 10:55:46 -07:00
parent 445f34bb14
commit 6b5869a0ae
11 changed files with 739 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ use std::io::{self, Write};
use std::path::{Path, PathBuf};
use super::graphviz::write_mir_fn_graphviz;
use super::spanview::write_mir_fn_spanview;
use crate::transform::MirSource;
use either::Either;
use rustc_data_structures::fx::FxHashMap;
@@ -147,6 +148,16 @@ fn dump_matched_mir_node<'tcx, F>(
write_mir_fn_graphviz(tcx, source.def_id(), body, false, &mut file)?;
};
}
if let Some(spanview) = tcx.sess.opts.debugging_opts.dump_mir_spanview {
let _: io::Result<()> = try {
let mut file =
create_dump_file(tcx, "html", pass_num, pass_name, disambiguator, source)?;
if source.def_id().is_local() {
write_mir_fn_spanview(tcx, source.def_id(), body, spanview, &mut file)?;
}
};
}
}
/// Returns the path to the filename where we should dump a given MIR.