Fixed coverage map issues; better aligned with LLVM APIs
Found some problems with the coverage map encoding when testing with more than one counter per function. While debugging, I realized some better ways to structure the Rust implementation of the coverage mapping generator. I refactored somewhat, resulting in less code overall, expanded coverage of LLVM Coverage Map capabilities, and much closer alignment with LLVM data structures, APIs, and naming. This should be easier to follow and easier to maintain.
This commit is contained in:
parent
c4e173472b
commit
12ddd6073a
13 changed files with 612 additions and 600 deletions
|
@ -8,60 +8,6 @@
|
|||
|
||||
using namespace llvm;
|
||||
|
||||
extern "C" SmallVectorTemplateBase<coverage::CounterExpression>
|
||||
*LLVMRustCoverageSmallVectorCounterExpressionCreate() {
|
||||
return new SmallVector<coverage::CounterExpression, 32>();
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustCoverageSmallVectorCounterExpressionDispose(
|
||||
SmallVectorTemplateBase<coverage::CounterExpression> *Vector) {
|
||||
delete Vector;
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustCoverageSmallVectorCounterExpressionAdd(
|
||||
SmallVectorTemplateBase<coverage::CounterExpression> *Expressions,
|
||||
coverage::CounterExpression::ExprKind Kind,
|
||||
unsigned LeftIndex,
|
||||
unsigned RightIndex) {
|
||||
auto LHS = coverage::Counter::getCounter(LeftIndex);
|
||||
auto RHS = coverage::Counter::getCounter(RightIndex);
|
||||
Expressions->push_back(coverage::CounterExpression { Kind, LHS, RHS });
|
||||
}
|
||||
|
||||
extern "C" SmallVectorTemplateBase<coverage::CounterMappingRegion>
|
||||
*LLVMRustCoverageSmallVectorCounterMappingRegionCreate() {
|
||||
return new SmallVector<coverage::CounterMappingRegion, 32>();
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustCoverageSmallVectorCounterMappingRegionDispose(
|
||||
SmallVectorTemplateBase<coverage::CounterMappingRegion> *Vector) {
|
||||
delete Vector;
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustCoverageSmallVectorCounterMappingRegionAdd(
|
||||
SmallVectorTemplateBase<coverage::CounterMappingRegion> *MappingRegions,
|
||||
unsigned Index,
|
||||
unsigned FileID,
|
||||
unsigned LineStart,
|
||||
unsigned ColumnStart,
|
||||
unsigned LineEnd,
|
||||
unsigned ColumnEnd) {
|
||||
auto Counter = coverage::Counter::getCounter(Index);
|
||||
MappingRegions->push_back(coverage::CounterMappingRegion::makeRegion(
|
||||
Counter, FileID, LineStart,
|
||||
ColumnStart, LineEnd, ColumnEnd));
|
||||
|
||||
// FIXME(richkadel): As applicable, implement additional CounterMappingRegion types using the
|
||||
// static method alternatives to `coverage::CounterMappingRegion::makeRegion`:
|
||||
//
|
||||
// makeExpansion(unsigned FileID, unsigned ExpandedFileID, unsigned LineStart,
|
||||
// unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) {
|
||||
// makeSkipped(unsigned FileID, unsigned LineStart, unsigned ColumnStart,
|
||||
// unsigned LineEnd, unsigned ColumnEnd) {
|
||||
// makeGapRegion(Counter Count, unsigned FileID, unsigned LineStart,
|
||||
// unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) {
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer(
|
||||
const char* const Filenames[],
|
||||
size_t FilenamesLen,
|
||||
|
@ -79,13 +25,15 @@ extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer(
|
|||
extern "C" void LLVMRustCoverageWriteMappingToBuffer(
|
||||
const unsigned *VirtualFileMappingIDs,
|
||||
unsigned NumVirtualFileMappingIDs,
|
||||
const SmallVectorImpl<coverage::CounterExpression> *Expressions,
|
||||
SmallVectorImpl<coverage::CounterMappingRegion> *MappingRegions,
|
||||
const coverage::CounterExpression *Expressions,
|
||||
unsigned NumExpressions,
|
||||
coverage::CounterMappingRegion *MappingRegions,
|
||||
unsigned NumMappingRegions,
|
||||
RustStringRef BufferOut) {
|
||||
auto CoverageMappingWriter = coverage::CoverageMappingWriter(
|
||||
makeArrayRef(VirtualFileMappingIDs, NumVirtualFileMappingIDs),
|
||||
makeArrayRef(*Expressions),
|
||||
MutableArrayRef<coverage::CounterMappingRegion> { *MappingRegions });
|
||||
makeArrayRef(VirtualFileMappingIDs, NumVirtualFileMappingIDs),
|
||||
makeArrayRef(Expressions, NumExpressions),
|
||||
makeMutableArrayRef(MappingRegions, NumMappingRegions));
|
||||
RawRustStringOstream OS(BufferOut);
|
||||
CoverageMappingWriter.write(OS);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue