coverage: Store expression operands as BcbCounter
This commit is contained in:
parent
9105c57b7f
commit
1a3a54c513
@ -35,6 +35,13 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct BcbExpression {
|
||||||
|
lhs: BcbCounter,
|
||||||
|
op: Op,
|
||||||
|
rhs: BcbCounter,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) enum CounterIncrementSite {
|
pub(super) enum CounterIncrementSite {
|
||||||
Node { bcb: BasicCoverageBlock },
|
Node { bcb: BasicCoverageBlock },
|
||||||
@ -58,7 +65,7 @@ pub(super) struct CoverageCounters {
|
|||||||
bcb_edge_counters: FxHashMap<(BasicCoverageBlock, BasicCoverageBlock), BcbCounter>,
|
bcb_edge_counters: FxHashMap<(BasicCoverageBlock, BasicCoverageBlock), BcbCounter>,
|
||||||
/// Table of expression data, associating each expression ID with its
|
/// Table of expression data, associating each expression ID with its
|
||||||
/// corresponding operator (+ or -) and its LHS/RHS operands.
|
/// corresponding operator (+ or -) and its LHS/RHS operands.
|
||||||
expressions: IndexVec<ExpressionId, Expression>,
|
expressions: IndexVec<ExpressionId, BcbExpression>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CoverageCounters {
|
impl CoverageCounters {
|
||||||
@ -90,8 +97,7 @@ fn make_counter(&mut self, site: CounterIncrementSite) -> BcbCounter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn make_expression(&mut self, lhs: BcbCounter, op: Op, rhs: BcbCounter) -> BcbCounter {
|
fn make_expression(&mut self, lhs: BcbCounter, op: Op, rhs: BcbCounter) -> BcbCounter {
|
||||||
let expression = Expression { lhs: lhs.as_term(), op, rhs: rhs.as_term() };
|
let id = self.expressions.push(BcbExpression { lhs, op, rhs });
|
||||||
let id = self.expressions.push(expression);
|
|
||||||
BcbCounter::Expression { id }
|
BcbCounter::Expression { id }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +172,21 @@ pub(super) fn bcb_nodes_with_coverage_expressions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn into_expressions(self) -> IndexVec<ExpressionId, Expression> {
|
pub(super) fn into_expressions(self) -> IndexVec<ExpressionId, Expression> {
|
||||||
self.expressions
|
let old_len = self.expressions.len();
|
||||||
|
let expressions = self
|
||||||
|
.expressions
|
||||||
|
.into_iter()
|
||||||
|
.map(|BcbExpression { lhs, op, rhs }| Expression {
|
||||||
|
lhs: lhs.as_term(),
|
||||||
|
op,
|
||||||
|
rhs: rhs.as_term(),
|
||||||
|
})
|
||||||
|
.collect::<IndexVec<ExpressionId, _>>();
|
||||||
|
|
||||||
|
// Expression IDs are indexes into this vector, so make sure we didn't
|
||||||
|
// accidentally invalidate them by changing its length.
|
||||||
|
assert_eq!(old_len, expressions.len());
|
||||||
|
expressions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user