| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include <filesystem> | ||
| 6 | #include <stack> | ||
| 7 | |||
| 8 | #include <llvm/IR/DIBuilder.h> | ||
| 9 | |||
| 10 | namespace spice::compiler { | ||
| 11 | |||
| 12 | // Forward declarations | ||
| 13 | class IRGenerator; | ||
| 14 | class SymbolTableEntry; | ||
| 15 | class QualType; | ||
| 16 | class Function; | ||
| 17 | class Struct; | ||
| 18 | class ASTNode; | ||
| 19 | struct CodeLoc; | ||
| 20 | |||
| 21 | class DebugInfoGenerator { | ||
| 22 | public: | ||
| 23 | // Constructors | ||
| 24 |
1/2✓ Branch 3 → 4 taken 906 times.
✗ Branch 3 → 6 not taken.
|
906 | explicit DebugInfoGenerator(IRGenerator *irGenerator) : irGenerator(irGenerator) {} |
| 25 | |||
| 26 | // Public methods | ||
| 27 | void initialize(const std::string &sourceFileName, std::filesystem::path sourceFileDir); | ||
| 28 | void generateFunctionDebugInfo(llvm::Function *llvmFunction, const Function *spiceFunc, bool isLambda = false); | ||
| 29 | void concludeFunctionDebugInfo(); | ||
| 30 | void pushLexicalBlock(const ASTNode *node); | ||
| 31 | void popLexicalBlock(); | ||
| 32 | llvm::DICompositeType *generateCaptureStructDebugInfo(const Function *spiceFunc); | ||
| 33 | void generateGlobalVarDebugInfo(llvm::GlobalVariable *global, const SymbolTableEntry *globalEntry); | ||
| 34 | void generateGlobalStringDebugInfo(llvm::GlobalVariable *global, const std::string &name, size_t length, | ||
| 35 | const CodeLoc &codeLoc) const; | ||
| 36 | void generateLocalVarDebugInfo(const std::string &varName, llvm::Value *address, size_t argNumber = SIZE_MAX); | ||
| 37 | void setSourceLocation(const CodeLoc &codeLoc); | ||
| 38 | void setSourceLocation(const ASTNode *node); | ||
| 39 | void finalize() const; | ||
| 40 | |||
| 41 | private: | ||
| 42 | // Private members | ||
| 43 | IRGenerator *irGenerator; | ||
| 44 | std::unique_ptr<llvm::DIBuilder> diBuilder; | ||
| 45 | llvm::DICompileUnit *compileUnit = nullptr; | ||
| 46 | llvm::DIFile *diFile = nullptr; | ||
| 47 | std::stack<llvm::DIScope *> lexicalBlocks; | ||
| 48 | std::unordered_map<size_t, llvm::DICompositeType *> structTypeCache; | ||
| 49 | unsigned int pointerWidth = 0; | ||
| 50 | // Debug types | ||
| 51 | llvm::DIType *doubleTy = nullptr; | ||
| 52 | llvm::DIType *intTy = nullptr; | ||
| 53 | llvm::DIType *uIntTy = nullptr; | ||
| 54 | llvm::DIType *shortTy = nullptr; | ||
| 55 | llvm::DIType *uShortTy = nullptr; | ||
| 56 | llvm::DIType *longTy = nullptr; | ||
| 57 | llvm::DIType *uLongTy = nullptr; | ||
| 58 | llvm::DIType *byteTy = nullptr; | ||
| 59 | llvm::DIType *charTy = nullptr; | ||
| 60 | llvm::DIType *stringTy = nullptr; | ||
| 61 | llvm::DIType *boolTy = nullptr; | ||
| 62 | llvm::DIType *voidTy = nullptr; | ||
| 63 | llvm::DICompositeType *fatPtrTy = nullptr; | ||
| 64 | |||
| 65 | // Private methods | ||
| 66 | [[nodiscard]] llvm::DIType *getDITypeForQualType(const ASTNode *node, const QualType &ty); | ||
| 67 | }; | ||
| 68 | |||
| 69 | } // namespace spice::compiler | ||
| 70 |