|
1 | 1 | #![allow(non_camel_case_types)]
|
2 | 2 | #![allow(non_upper_case_globals)]
|
3 | 3 |
|
4 |
| -use crate::coverageinfo::CounterMappingRegion; |
| 4 | +use rustc_codegen_ssa::coverageinfo::map as coverage_map; |
5 | 5 |
|
6 | 6 | use super::debuginfo::{
|
7 | 7 | DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,
|
@@ -652,6 +652,155 @@ pub struct Linker<'a>(InvariantOpaque<'a>);
|
652 | 652 | pub type DiagnosticHandler = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
|
653 | 653 | pub type InlineAsmDiagHandler = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint);
|
654 | 654 |
|
| 655 | +pub mod coverageinfo { |
| 656 | + use super::coverage_map; |
| 657 | + |
| 658 | + /// Aligns with [llvm::coverage::CounterMappingRegion::RegionKind](https://github.com/rust-lang/llvm-project/blob/rustc/10.0-2020-05-05/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L205-L221) |
| 659 | + #[derive(Copy, Clone, Debug)] |
| 660 | + #[repr(C)] |
| 661 | + pub enum RegionKind { |
| 662 | + /// A CodeRegion associates some code with a counter |
| 663 | + CodeRegion = 0, |
| 664 | + |
| 665 | + /// An ExpansionRegion represents a file expansion region that associates |
| 666 | + /// a source range with the expansion of a virtual source file, such as |
| 667 | + /// for a macro instantiation or #include file. |
| 668 | + ExpansionRegion = 1, |
| 669 | + |
| 670 | + /// A SkippedRegion represents a source range with code that was skipped |
| 671 | + /// by a preprocessor or similar means. |
| 672 | + SkippedRegion = 2, |
| 673 | + |
| 674 | + /// A GapRegion is like a CodeRegion, but its count is only set as the |
| 675 | + /// line execution count when its the only region in the line. |
| 676 | + GapRegion = 3, |
| 677 | + } |
| 678 | + |
| 679 | + /// This struct provides LLVM's representation of a "CoverageMappingRegion", encoded into the |
| 680 | + /// coverage map, in accordance with the |
| 681 | + /// [LLVM Code Coverage Mapping Format](https://github.com/rust-lang/llvm-project/blob/llvmorg-8.0.0/llvm/docs/CoverageMappingFormat.rst#llvm-code-coverage-mapping-format). |
| 682 | + /// The struct composes fields representing the `Counter` type and value(s) (injected counter |
| 683 | + /// ID, or expression type and operands), the source file (an indirect index into a "filenames |
| 684 | + /// array", encoded separately), and source location (start and end positions of the represented |
| 685 | + /// code region). |
| 686 | + /// |
| 687 | + /// Aligns with [llvm::coverage::CounterMappingRegion](https://github.com/rust-lang/llvm-project/blob/rustc/10.0-2020-05-05/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L223-L226) |
| 688 | + /// Important: The Rust struct layout (order and types of fields) must match its C++ |
| 689 | + /// counterpart. |
| 690 | + #[derive(Copy, Clone, Debug)] |
| 691 | + #[repr(C)] |
| 692 | + pub struct CounterMappingRegion { |
| 693 | + /// The counter type and type-dependent counter data, if any. |
| 694 | + counter: coverage_map::Counter, |
| 695 | + |
| 696 | + /// An indirect reference to the source filename. In the LLVM Coverage Mapping Format, the |
| 697 | + /// file_id is an index into a function-specific `virtual_file_mapping` array of indexes |
| 698 | + /// that, in turn, are used to look up the filename for this region. |
| 699 | + file_id: u32, |
| 700 | + |
| 701 | + /// If the `RegionKind` is an `ExpansionRegion`, the `expanded_file_id` can be used to find |
| 702 | + /// the mapping regions created as a result of macro expansion, by checking if their file id |
| 703 | + /// matches the expanded file id. |
| 704 | + expanded_file_id: u32, |
| 705 | + |
| 706 | + /// 1-based starting line of the mapping region. |
| 707 | + start_line: u32, |
| 708 | + |
| 709 | + /// 1-based starting column of the mapping region. |
| 710 | + start_col: u32, |
| 711 | + |
| 712 | + /// 1-based ending line of the mapping region. |
| 713 | + end_line: u32, |
| 714 | + |
| 715 | + /// 1-based ending column of the mapping region. If the high bit is set, the current |
| 716 | + /// mapping region is a gap area. |
| 717 | + end_col: u32, |
| 718 | + |
| 719 | + kind: RegionKind, |
| 720 | + } |
| 721 | + |
| 722 | + impl CounterMappingRegion { |
| 723 | + pub fn code_region( |
| 724 | + counter: coverage_map::Counter, |
| 725 | + file_id: u32, |
| 726 | + start_line: u32, |
| 727 | + start_col: u32, |
| 728 | + end_line: u32, |
| 729 | + end_col: u32, |
| 730 | + ) -> Self { |
| 731 | + Self { |
| 732 | + counter, |
| 733 | + file_id, |
| 734 | + expanded_file_id: 0, |
| 735 | + start_line, |
| 736 | + start_col, |
| 737 | + end_line, |
| 738 | + end_col, |
| 739 | + kind: RegionKind::CodeRegion, |
| 740 | + } |
| 741 | + } |
| 742 | + |
| 743 | + pub fn expansion_region( |
| 744 | + file_id: u32, |
| 745 | + expanded_file_id: u32, |
| 746 | + start_line: u32, |
| 747 | + start_col: u32, |
| 748 | + end_line: u32, |
| 749 | + end_col: u32, |
| 750 | + ) -> Self { |
| 751 | + Self { |
| 752 | + counter: coverage_map::Counter::zero(), |
| 753 | + file_id, |
| 754 | + expanded_file_id, |
| 755 | + start_line, |
| 756 | + start_col, |
| 757 | + end_line, |
| 758 | + end_col, |
| 759 | + kind: RegionKind::ExpansionRegion, |
| 760 | + } |
| 761 | + } |
| 762 | + |
| 763 | + pub fn skipped_region( |
| 764 | + file_id: u32, |
| 765 | + start_line: u32, |
| 766 | + start_col: u32, |
| 767 | + end_line: u32, |
| 768 | + end_col: u32, |
| 769 | + ) -> Self { |
| 770 | + Self { |
| 771 | + counter: coverage_map::Counter::zero(), |
| 772 | + file_id, |
| 773 | + expanded_file_id: 0, |
| 774 | + start_line, |
| 775 | + start_col, |
| 776 | + end_line, |
| 777 | + end_col, |
| 778 | + kind: RegionKind::SkippedRegion, |
| 779 | + } |
| 780 | + } |
| 781 | + |
| 782 | + pub fn gap_region( |
| 783 | + counter: coverage_map::Counter, |
| 784 | + file_id: u32, |
| 785 | + start_line: u32, |
| 786 | + start_col: u32, |
| 787 | + end_line: u32, |
| 788 | + end_col: u32, |
| 789 | + ) -> Self { |
| 790 | + Self { |
| 791 | + counter, |
| 792 | + file_id, |
| 793 | + expanded_file_id: 0, |
| 794 | + start_line, |
| 795 | + start_col, |
| 796 | + end_line, |
| 797 | + end_col: ((1 as u32) << 31) | end_col, |
| 798 | + kind: RegionKind::GapRegion, |
| 799 | + } |
| 800 | + } |
| 801 | + } |
| 802 | +} |
| 803 | + |
655 | 804 | pub mod debuginfo {
|
656 | 805 | use super::{InvariantOpaque, Metadata};
|
657 | 806 | use bitflags::bitflags;
|
@@ -1646,9 +1795,9 @@ extern "C" {
|
1646 | 1795 | pub fn LLVMRustCoverageWriteMappingToBuffer(
|
1647 | 1796 | VirtualFileMappingIDs: *const c_uint,
|
1648 | 1797 | NumVirtualFileMappingIDs: c_uint,
|
1649 |
| - Expressions: *const rustc_codegen_ssa::coverageinfo::map::CounterExpression, |
| 1798 | + Expressions: *const coverage_map::CounterExpression, |
1650 | 1799 | NumExpressions: c_uint,
|
1651 |
| - MappingRegions: *mut CounterMappingRegion, |
| 1800 | + MappingRegions: *mut coverageinfo::CounterMappingRegion, |
1652 | 1801 | NumMappingRegions: c_uint,
|
1653 | 1802 | BufferOut: &RustString,
|
1654 | 1803 | );
|
|
0 commit comments