Adds coverage graphviz

This commit is contained in:
Rich Kadel
2020-10-22 20:28:16 -07:00
parent b5020648fe
commit 3291d28e9a
9 changed files with 657 additions and 10 deletions

View File

@@ -1,3 +1,7 @@
use super::debug;
use debug::DebugCounters;
use rustc_middle::mir::coverage::*;
/// Manages the counter and expression indexes/IDs to generate `CoverageKind` components for MIR
@@ -6,6 +10,7 @@ pub(crate) struct CoverageCounters {
function_source_hash: u64,
next_counter_id: u32,
num_expressions: u32,
pub debug_counters: DebugCounters,
}
impl CoverageCounters {
@@ -14,24 +19,46 @@ impl CoverageCounters {
function_source_hash,
next_counter_id: CounterValueReference::START.as_u32(),
num_expressions: 0,
debug_counters: DebugCounters::new(),
}
}
pub fn make_counter(&mut self) -> CoverageKind {
CoverageKind::Counter {
/// Activate the `DebugCounters` data structures, to provide additional debug formatting
/// features when formating `CoverageKind` (counter) values.
pub fn enable_debug(&mut self) {
self.debug_counters.enable();
}
pub fn make_counter<F>(&mut self, debug_block_label_fn: F) -> CoverageKind
where
F: Fn() -> Option<String>,
{
let counter = CoverageKind::Counter {
function_source_hash: self.function_source_hash,
id: self.next_counter(),
};
if self.debug_counters.is_enabled() {
self.debug_counters.add_counter(&counter, (debug_block_label_fn)());
}
counter
}
pub fn make_expression(
pub fn make_expression<F>(
&mut self,
lhs: ExpressionOperandId,
op: Op,
rhs: ExpressionOperandId,
) -> CoverageKind {
debug_block_label_fn: F,
) -> CoverageKind
where
F: Fn() -> Option<String>,
{
let id = self.next_expression();
CoverageKind::Expression { id, lhs, op, rhs }
let expression = CoverageKind::Expression { id, lhs, op, rhs };
if self.debug_counters.is_enabled() {
self.debug_counters.add_counter(&expression, (debug_block_label_fn)());
}
expression
}
/// Counter IDs start from one and go up.