Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1 | //===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is the source level debug info generator for llvm translation. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CLANG_CODEGEN_CGDEBUGINFO_H |
| 15 | #define CLANG_CODEGEN_CGDEBUGINFO_H |
| 16 | |
| 17 | #include "clang/Basic/SourceLocation.h" |
| 18 | #include <map> |
| 19 | #include <vector> |
| 20 | |
| 21 | |
| 22 | namespace llvm { |
| 23 | class Function; |
| 24 | class IRBuilder; |
| 25 | class DISerializer; |
| 26 | class CompileUnitDesc; |
| 27 | class BasicBlock; |
| 28 | class AnchorDesc; |
| 29 | class DebugInfoDesc; |
| 30 | class Value; |
| 31 | } |
| 32 | |
| 33 | namespace clang { |
| 34 | namespace CodeGen { |
| 35 | class CodeGenModule; |
| 36 | |
| 37 | /// DebugInfo - This class gathers all debug information during compilation and |
| 38 | /// is responsible for emitting to llvm globals or pass directly to the backend. |
| 39 | class CGDebugInfo { |
| 40 | private: |
| 41 | CodeGenModule *M; |
| 42 | llvm::DISerializer *SR; |
| 43 | SourceLocation CurLoc; |
| 44 | SourceLocation PrevLoc; |
| 45 | |
| 46 | /// CompileUnitCache - Cache of previously constructed CompileUnits. |
| 47 | std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache; |
Eli Friedman | 9bc7c8d | 2008-05-22 01:40:10 +0000 | [diff] [blame^] | 48 | std::vector<llvm::DebugInfoDesc*> DebugAllocationList; |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 49 | |
| 50 | llvm::Function *StopPointFn; |
| 51 | llvm::AnchorDesc *CompileUnitAnchor; |
Eli Friedman | 9bc7c8d | 2008-05-22 01:40:10 +0000 | [diff] [blame^] | 52 | llvm::AnchorDesc *SubProgramAnchor; |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 53 | llvm::Function *RegionStartFn; |
| 54 | llvm::Function *RegionEndFn; |
Eli Friedman | 9bc7c8d | 2008-05-22 01:40:10 +0000 | [diff] [blame^] | 55 | llvm::Function *FuncStartFn; |
| 56 | llvm::Value *CurFuncDesc; |
| 57 | |
| 58 | /// getOrCreateCompileUnit - Get the compile unit from the cache or create a |
| 59 | /// new one if necessary. |
| 60 | llvm::CompileUnitDesc *getOrCreateCompileUnit(SourceLocation loc); |
| 61 | |
| 62 | /// getCastValueFor - Return a llvm representation for a given debug |
| 63 | /// information descriptor cast to an empty struct pointer. |
| 64 | llvm::Value *getCastValueFor(llvm::DebugInfoDesc *DD); |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 65 | |
| 66 | public: |
| 67 | CGDebugInfo(CodeGenModule *m); |
| 68 | ~CGDebugInfo(); |
| 69 | |
| 70 | void setLocation(SourceLocation loc) { CurLoc = loc; }; |
| 71 | |
| 72 | /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of |
| 73 | /// source line. |
| 74 | void EmitStopPoint(llvm::Function *Fn, llvm::IRBuilder &Builder); |
| 75 | |
Eli Friedman | 9bc7c8d | 2008-05-22 01:40:10 +0000 | [diff] [blame^] | 76 | /// EmitFunctionStart - Emit a call to llvm.dbg.func.start to indicate start |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 77 | /// of a new block. |
Eli Friedman | 9bc7c8d | 2008-05-22 01:40:10 +0000 | [diff] [blame^] | 78 | void EmitFunctionStart(llvm::Function *Fn, llvm::IRBuilder &Builder); |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 79 | |
Eli Friedman | 9bc7c8d | 2008-05-22 01:40:10 +0000 | [diff] [blame^] | 80 | /// EmitFunctionEnd - Emit call to llvm.dbg.region.end to indicate end of a |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 81 | /// block. |
Eli Friedman | 9bc7c8d | 2008-05-22 01:40:10 +0000 | [diff] [blame^] | 82 | void EmitFunctionEnd(llvm::Function *Fn, llvm::IRBuilder &Builder); |
Sanjiv Gupta | 40e56a1 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 83 | }; |
| 84 | } // namespace CodeGen |
| 85 | } // namespace clang |
| 86 | |
| 87 | #endif |