1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #ifndef LLVM_CLANG_LIB_CODEGEN_COVERAGEMAPPINGGEN_H |
14 | #define LLVM_CLANG_LIB_CODEGEN_COVERAGEMAPPINGGEN_H |
15 | |
16 | #include "clang/Basic/LLVM.h" |
17 | #include "clang/Basic/SourceLocation.h" |
18 | #include "clang/Lex/PPCallbacks.h" |
19 | #include "llvm/ADT/DenseMap.h" |
20 | #include "llvm/IR/GlobalValue.h" |
21 | #include "llvm/Support/raw_ostream.h" |
22 | |
23 | namespace clang { |
24 | |
25 | class LangOptions; |
26 | class SourceManager; |
27 | class FileEntry; |
28 | class Preprocessor; |
29 | class Decl; |
30 | class Stmt; |
31 | |
32 | |
33 | |
34 | |
35 | class CoverageSourceInfo : public PPCallbacks { |
36 | std::vector<SourceRange> SkippedRanges; |
37 | public: |
38 | ArrayRef<SourceRange> getSkippedRanges() const { return SkippedRanges; } |
39 | |
40 | void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override; |
41 | }; |
42 | |
43 | namespace CodeGen { |
44 | |
45 | class CodeGenModule; |
46 | |
47 | |
48 | |
49 | class CoverageMappingModuleGen { |
50 | CodeGenModule &CGM; |
51 | CoverageSourceInfo &SourceInfo; |
52 | llvm::SmallDenseMap<const FileEntry *, unsigned, 8> FileEntries; |
53 | std::vector<llvm::Constant *> FunctionRecords; |
54 | std::vector<llvm::Constant *> FunctionNames; |
55 | llvm::StructType *FunctionRecordTy; |
56 | std::vector<std::string> CoverageMappings; |
57 | |
58 | public: |
59 | CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo) |
60 | : CGM(CGM), SourceInfo(SourceInfo), FunctionRecordTy(nullptr) {} |
61 | |
62 | CoverageSourceInfo &getSourceInfo() const { |
63 | return SourceInfo; |
64 | } |
65 | |
66 | |
67 | |
68 | void addFunctionMappingRecord(llvm::GlobalVariable *FunctionName, |
69 | StringRef FunctionNameValue, |
70 | uint64_t FunctionHash, |
71 | const std::string &CoverageMapping, |
72 | bool IsUsed = true); |
73 | |
74 | |
75 | void emit(); |
76 | |
77 | |
78 | |
79 | unsigned getFileID(const FileEntry *File); |
80 | }; |
81 | |
82 | |
83 | |
84 | class CoverageMappingGen { |
85 | CoverageMappingModuleGen &CVM; |
86 | SourceManager &SM; |
87 | const LangOptions &LangOpts; |
88 | llvm::DenseMap<const Stmt *, unsigned> *CounterMap; |
89 | |
90 | public: |
91 | CoverageMappingGen(CoverageMappingModuleGen &CVM, SourceManager &SM, |
92 | const LangOptions &LangOpts) |
93 | : CVM(CVM), SM(SM), LangOpts(LangOpts), CounterMap(nullptr) {} |
94 | |
95 | CoverageMappingGen(CoverageMappingModuleGen &CVM, SourceManager &SM, |
96 | const LangOptions &LangOpts, |
97 | llvm::DenseMap<const Stmt *, unsigned> *CounterMap) |
98 | : CVM(CVM), SM(SM), LangOpts(LangOpts), CounterMap(CounterMap) {} |
99 | |
100 | |
101 | |
102 | |
103 | void emitCounterMapping(const Decl *D, llvm::raw_ostream &OS); |
104 | |
105 | |
106 | |
107 | void emitEmptyMapping(const Decl *D, llvm::raw_ostream &OS); |
108 | }; |
109 | |
110 | } |
111 | } |
112 | |
113 | #endif |
114 | |