GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 1 / 0 / 1
Functions: -% 0 / 0 / 0
Branches: 35.7% 15 / 0 / 42

src/irgenerator/DebugInfoGenerator.h
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #pragma once
4
5 #include <filesystem>
6 #include <stack>
7 #include <unordered_map>
8
9 #include <ast/ASTNodes.h>
10 #include <util/GlobalDefinitions.h>
11
12 #include <llvm/IR/DIBuilder.h>
13
14 namespace spice::compiler {
15
16 // Forward declarations
17 class IRGenerator;
18 class SymbolTableEntry;
19 class QualType;
20 class Function;
21 class Struct;
22 struct CodeLoc;
23
24 class DebugInfoGenerator {
25 public:
26 // Constructors
27 explicit DebugInfoGenerator(IRGenerator *irGenerator);
28
29 // Public methods
30 void initialize(const std::string &sourceFileName, std::filesystem::path sourceFileDir);
31 void generateFunctionDebugInfo(llvm::Function *llvmFunction, const Function *spiceFunc, bool isLambda = false);
32 void concludeFunctionDebugInfo();
33 void pushLexicalBlock(const ASTNode *node);
34 void popLexicalBlock();
35 llvm::DICompositeType *generateCaptureStructDebugInfo(const Function *spiceFunc);
36 void generateGlobalVarDebugInfo(llvm::GlobalVariable *global, const SymbolTableEntry *globalEntry);
37 void generateGlobalStringDebugInfo(llvm::GlobalVariable *global, const std::string &name, size_t length,
38 const CodeLoc &codeLoc) const;
39 void generateLocalVarDebugInfo(const std::string &varName, llvm::Value *address, size_t argNumber = SIZE_MAX);
40 void setSourceLocation(const CodeLoc &codeLoc);
41
15/42
✓ Branch 5 → 6 taken 75462 times.
✗ Branch 5 → 19 not taken.
✗ Branch 5 → 117 not taken.
✗ Branch 5 → 244 not taken.
✓ Branch 7 → 8 taken 39268 times.
✗ Branch 7 → 34 not taken.
✗ Branch 7 → 50 not taken.
✗ Branch 7 → 54 not taken.
✗ Branch 7 → 64 not taken.
✗ Branch 7 → 66 not taken.
✗ Branch 7 → 104 not taken.
✓ Branch 8 → 9 taken 113444 times.
✗ Branch 8 → 27 not taken.
✓ Branch 15 → 16 taken 147898 times.
✗ Branch 15 → 88 not taken.
✓ Branch 57 → 58 taken 58 times.
✗ Branch 57 → 162 not taken.
✗ Branch 57 → 170 not taken.
✗ Branch 57 → 224 not taken.
✓ Branch 66 → 67 taken 6 times.
✗ Branch 66 → 157 not taken.
✓ Branch 82 → 83 taken 588 times.
✗ Branch 82 → 252 not taken.
✗ Branch 85 → 86 not taken.
✗ Branch 85 → 164 not taken.
✓ Branch 86 → 87 taken 1072 times.
✗ Branch 86 → 162 not taken.
✓ Branch 98 → 99 taken 11207 times.
✗ Branch 98 → 211 not taken.
✓ Branch 119 → 120 taken 21857 times.
✗ Branch 119 → 162 not taken.
✗ Branch 119 → 198 not taken.
✓ Branch 120 → 121 taken 22119 times.
✗ Branch 120 → 298 not taken.
✓ Branch 121 → 122 taken 41 times.
✗ Branch 121 → 170 not taken.
✓ Branch 151 → 152 taken 16 times.
✗ Branch 151 → 224 not taken.
✓ Branch 154 → 155 taken 588 times.
✗ Branch 154 → 252 not taken.
✓ Branch 164 → 165 taken 35680 times.
✗ Branch 164 → 279 not taken.
597005 ALWAYS_INLINE void setSourceLocation(const ASTNode *node) { setSourceLocation(node->codeLoc); }
42 void finalize() const;
43
44 private:
45 // Private members
46 IRGenerator *irGenerator;
47 std::unique_ptr<llvm::DIBuilder> diBuilder;
48 llvm::DICompileUnit *compileUnit = nullptr;
49 llvm::DIFile *diFile = nullptr;
50 std::stack<llvm::DIScope *> lexicalBlocks;
51 std::unordered_map<size_t, llvm::DICompositeType *> structTypeCache;
52 unsigned int pointerWidth = 0;
53 // Debug types
54 llvm::DIType *doubleTy = nullptr;
55 llvm::DIType *intTy = nullptr;
56 llvm::DIType *uIntTy = nullptr;
57 llvm::DIType *shortTy = nullptr;
58 llvm::DIType *uShortTy = nullptr;
59 llvm::DIType *longTy = nullptr;
60 llvm::DIType *uLongTy = nullptr;
61 llvm::DIType *byteTy = nullptr;
62 llvm::DIType *charTy = nullptr;
63 llvm::DIType *stringTy = nullptr;
64 llvm::DIType *boolTy = nullptr;
65 llvm::DIType *voidTy = nullptr;
66 llvm::DICompositeType *fatPtrTy = nullptr;
67
68 // Private methods
69 [[nodiscard]] llvm::DIType *getDITypeForQualType(const ASTNode *node, const QualType &ty);
70 };
71
72 } // namespace spice::compiler
73