Add stub methods to MCStreamer for emitting Win64 exception-handling
[oota-llvm.git] / include / llvm / Analysis / DIBuilder.h
1 //===--- llvm/Analysis/DIBuilder.h - Debug Information Builder --*- C++ -*-===//
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 file defines a DIBuilder that is useful for creating debugging 
11 // information entries in LLVM IR form.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_ANALYSIS_DIBUILDER_H
16 #define LLVM_ANALYSIS_DIBUILDER_H
17
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/StringRef.h"
21
22 namespace llvm {
23   class BasicBlock;
24   class Instruction;
25   class Function;
26   class Module;
27   class Value;
28   class LLVMContext;
29   class MDNode;
30   class StringRef;
31   class DIDescriptor;
32   class DIFile;
33   class DIEnumerator;
34   class DIType;
35   class DIArray;
36   class DIGlobalVariable;
37   class DINameSpace;
38   class DIVariable;
39   class DISubrange;
40   class DILexicalBlock;
41   class DISubprogram;
42   class DITemplateTypeParameter;
43   class DITemplateValueParameter;
44
45   class DIBuilder {
46     private:
47     Module &M;
48     LLVMContext & VMContext;
49     MDNode *TheCU;
50
51     Function *DeclareFn;     // llvm.dbg.declare
52     Function *ValueFn;       // llvm.dbg.value
53
54     DIBuilder(const DIBuilder &);       // DO NOT IMPLEMENT
55     void operator=(const DIBuilder &);  // DO NOT IMPLEMENT
56
57     public:
58     explicit DIBuilder(Module &M);
59     const MDNode *getCU() { return TheCU; }
60     enum ComplexAddrKind { OpPlus=1, OpDeref };
61
62     /// createCompileUnit - A CompileUnit provides an anchor for all debugging
63     /// information generated during this instance of compilation.
64     /// @param Lang     Source programming language, eg. dwarf::DW_LANG_C99
65     /// @param File     File name
66     /// @param Dir      Directory
67     /// @param Producer String identify producer of debugging information. 
68     ///                 Usuall this is a compiler version string.
69     /// @param isOptimized A boolean flag which indicates whether optimization
70     ///                    is ON or not.
71     /// @param Flags    This string lists command line options. This string is 
72     ///                 directly embedded in debug info output which may be used
73     ///                 by a tool analyzing generated debugging information.
74     /// @param RV       This indicates runtime version for languages like 
75     ///                 Objective-C.
76     void createCompileUnit(unsigned Lang, StringRef File, StringRef Dir, 
77                            StringRef Producer,
78                            bool isOptimized, StringRef Flags, unsigned RV);
79
80     /// createFile - Create a file descriptor to hold debugging information
81     /// for a file.
82     DIFile createFile(StringRef Filename, StringRef Directory);
83                            
84     /// createEnumerator - Create a single enumerator value.
85     DIEnumerator createEnumerator(StringRef Name, uint64_t Val);
86
87     /// createBasicType - Create debugging information entry for a basic 
88     /// type.
89     /// @param Name        Type name.
90     /// @param SizeInBits  Size of the type.
91     /// @param AlignInBits Type alignment.
92     /// @param Encoding    DWARF encoding code, e.g. dwarf::DW_ATE_float.
93     DIType createBasicType(StringRef Name, uint64_t SizeInBits, 
94                            uint64_t AlignInBits, unsigned Encoding);
95
96     /// createQualifiedType - Create debugging information entry for a qualified
97     /// type, e.g. 'const int'.
98     /// @param Tag         Tag identifing type, e.g. dwarf::TAG_volatile_type
99     /// @param FromTy      Base Type.
100     DIType createQualifiedType(unsigned Tag, DIType FromTy);
101
102     /// createPointerType - Create debugging information entry for a pointer.
103     /// @param PointeeTy   Type pointed by this pointer.
104     /// @param SizeInBits  Size.
105     /// @param AlignInBits Alignment. (optional)
106     /// @param Name        Pointer type name. (optional)
107     DIType createPointerType(DIType PointeeTy, uint64_t SizeInBits,
108                              uint64_t AlignInBits = 0, 
109                              StringRef Name = StringRef());
110
111     /// createReferenceType - Create debugging information entry for a c++
112     /// style reference.
113     DIType createReferenceType(DIType RTy);
114
115     /// createTypedef - Create debugging information entry for a typedef.
116     /// @param Ty          Original type.
117     /// @param Name        Typedef name.
118     /// @param File        File where this type is defined.
119     /// @param LineNo      Line number.
120     DIType createTypedef(DIType Ty, StringRef Name, DIFile File, 
121                          unsigned LineNo);
122
123     /// createFriend - Create debugging information entry for a 'friend'.
124     DIType createFriend(DIType Ty, DIType FriendTy);
125
126     /// createInheritance - Create debugging information entry to establish
127     /// inheritance relationship between two types.
128     /// @param Ty           Original type.
129     /// @param BaseTy       Base type. Ty is inherits from base.
130     /// @param BaseOffset   Base offset.
131     /// @param Flags        Flags to describe inheritance attribute, 
132     ///                     e.g. private
133     DIType createInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset,
134                              unsigned Flags);
135
136     /// createMemberType - Create debugging information entry for a member.
137     /// @param Name         Member name.
138     /// @param File         File where this member is defined.
139     /// @param LineNo       Line number.
140     /// @param SizeInBits   Member size.
141     /// @param AlignInBits  Member alignment.
142     /// @param OffsetInBits Member offset.
143     /// @param Flags        Flags to encode member attribute, e.g. private
144     /// @param Ty           Parent type.
145     DIType createMemberType(StringRef Name, DIFile File,
146                             unsigned LineNo, uint64_t SizeInBits, 
147                             uint64_t AlignInBits, uint64_t OffsetInBits, 
148                             unsigned Flags, DIType Ty);
149
150     /// createObjCIVar - Create debugging information entry for Objective-C
151     /// instance variable.
152     /// @param Name         Member name.
153     /// @param File         File where this member is defined.
154     /// @param LineNo       Line number.
155     /// @param SizeInBits   Member size.
156     /// @param AlignInBits  Member alignment.
157     /// @param OffsetInBits Member offset.
158     /// @param Flags        Flags to encode member attribute, e.g. private
159     /// @param Ty           Parent type.
160     /// @param PropertyName Name of the Objective C property assoicated with
161     ///                     this ivar.
162     /// @param GetterName   Name of the Objective C property getter selector.
163     /// @param SetterName   Name of the Objective C property setter selector.
164     /// @param PropertyAttributes Objective C property attributes.
165     DIType createObjCIVar(StringRef Name, DIFile File,
166                           unsigned LineNo, uint64_t SizeInBits, 
167                           uint64_t AlignInBits, uint64_t OffsetInBits, 
168                           unsigned Flags, DIType Ty,
169                           StringRef PropertyName = StringRef(),
170                           StringRef PropertyGetterName = StringRef(),
171                           StringRef PropertySetterName = StringRef(),
172                           unsigned PropertyAttributes = 0);
173
174     /// createClassType - Create debugging information entry for a class.
175     /// @param Scope        Scope in which this class is defined.
176     /// @param Name         class name.
177     /// @param File         File where this member is defined.
178     /// @param LineNo       Line number.
179     /// @param SizeInBits   Member size.
180     /// @param AlignInBits  Member alignment.
181     /// @param OffsetInBits Member offset.
182     /// @param Flags        Flags to encode member attribute, e.g. private
183     /// @param Elements     class members.
184     /// @param VTableHolder Debug info of the base class that contains vtable
185     ///                     for this type. This is used in 
186     ///                     DW_AT_containing_type. See DWARF documentation
187     ///                     for more info.
188     /// @param TemplateParms Template type parameters.
189     DIType createClassType(DIDescriptor Scope, StringRef Name, DIFile File,
190                            unsigned LineNumber, uint64_t SizeInBits,
191                            uint64_t AlignInBits, uint64_t OffsetInBits,
192                            unsigned Flags, DIType DerivedFrom, 
193                            DIArray Elements, MDNode *VTableHolder = 0,
194                            MDNode *TemplateParms = 0);
195
196     /// createStructType - Create debugging information entry for a struct.
197     /// @param Scope        Scope in which this struct is defined.
198     /// @param Name         Struct name.
199     /// @param File         File where this member is defined.
200     /// @param LineNo       Line number.
201     /// @param SizeInBits   Member size.
202     /// @param AlignInBits  Member alignment.
203     /// @param Flags        Flags to encode member attribute, e.g. private
204     /// @param Elements     Struct elements.
205     /// @param RunTimeLang  Optional parameter, Objective-C runtime version.
206     DIType createStructType(DIDescriptor Scope, StringRef Name, DIFile File,
207                             unsigned LineNumber, uint64_t SizeInBits,
208                             uint64_t AlignInBits, unsigned Flags,
209                             DIArray Elements, unsigned RunTimeLang = 0);
210
211     /// createUnionType - Create debugging information entry for an union.
212     /// @param Scope        Scope in which this union is defined.
213     /// @param Name         Union name.
214     /// @param File         File where this member is defined.
215     /// @param LineNo       Line number.
216     /// @param SizeInBits   Member size.
217     /// @param AlignInBits  Member alignment.
218     /// @param Flags        Flags to encode member attribute, e.g. private
219     /// @param Elements     Union elements.
220     /// @param RunTimeLang  Optional parameter, Objective-C runtime version.
221     DIType createUnionType(DIDescriptor Scope, StringRef Name, DIFile File,
222                            unsigned LineNumber, uint64_t SizeInBits,
223                            uint64_t AlignInBits, unsigned Flags,
224                            DIArray Elements, unsigned RunTimeLang = 0);
225
226     /// createTemplateTypeParameter - Create debugging information for template
227     /// type parameter.
228     /// @param Scope        Scope in which this type is defined.
229     /// @param Name         Type parameter name.
230     /// @param Ty           Parameter type.
231     /// @param File         File where this type parameter is defined.
232     /// @param LineNo       Line number.
233     /// @param ColumnNo     Column Number.
234     DITemplateTypeParameter
235     createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
236                                 MDNode *File = 0, unsigned LineNo = 0,
237                                 unsigned ColumnNo = 0);
238
239     /// createTemplateValueParameter - Create debugging information for template
240     /// value parameter.
241     /// @param Scope        Scope in which this type is defined.
242     /// @param Name         Value parameter name.
243     /// @param Ty           Parameter type.
244     /// @param Value        Constant parameter value.
245     /// @param File         File where this type parameter is defined.
246     /// @param LineNo       Line number.
247     /// @param ColumnNo     Column Number.
248     DITemplateValueParameter
249     createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
250                                  uint64_t Value,
251                                  MDNode *File = 0, unsigned LineNo = 0,
252                                  unsigned ColumnNo = 0);
253
254     /// createArrayType - Create debugging information entry for an array.
255     /// @param Size         Array size.
256     /// @param AlignInBits  Alignment.
257     /// @param Ty           Element type.
258     /// @param Subscripts   Subscripts.
259     DIType createArrayType(uint64_t Size, uint64_t AlignInBits, 
260                            DIType Ty, DIArray Subscripts);
261
262     /// createVectorType - Create debugging information entry for a vector type.
263     /// @param Size         Array size.
264     /// @param AlignInBits  Alignment.
265     /// @param Ty           Element type.
266     /// @param Subscripts   Subscripts.
267     DIType createVectorType(uint64_t Size, uint64_t AlignInBits, 
268                             DIType Ty, DIArray Subscripts);
269
270     /// createEnumerationType - Create debugging information entry for an 
271     /// enumeration.
272     /// @param Scope        Scope in which this enumeration is defined.
273     /// @param Name         Union name.
274     /// @param File         File where this member is defined.
275     /// @param LineNo       Line number.
276     /// @param SizeInBits   Member size.
277     /// @param AlignInBits  Member alignment.
278     /// @param Elements     Enumeration elements.
279     DIType createEnumerationType(DIDescriptor Scope, StringRef Name, 
280                                  DIFile File, unsigned LineNumber, 
281                                  uint64_t SizeInBits, 
282                                  uint64_t AlignInBits, DIArray Elements);
283
284     /// createSubroutineType - Create subroutine type.
285     /// @param File          File in which this subroutine is defined.
286     /// @param ParamterTypes An array of subroutine parameter types. This
287     ///                      includes return type at 0th index.
288     DIType createSubroutineType(DIFile File, DIArray ParameterTypes);
289
290     /// createArtificialType - Create a new DIType with "artificial" flag set.
291     DIType createArtificialType(DIType Ty);
292
293     /// createTemporaryType - Create a temporary forward-declared type.
294     DIType createTemporaryType();
295     DIType createTemporaryType(DIFile F);
296
297     /// retainType - Retain DIType in a module even if it is not referenced 
298     /// through debug info anchors.
299     void retainType(DIType T);
300
301     /// createUnspecifiedParameter - Create unspeicified type descriptor
302     /// for a subroutine type.
303     DIDescriptor createUnspecifiedParameter();
304
305     /// getOrCreateArray - Get a DIArray, create one if required.
306     DIArray getOrCreateArray(ArrayRef<Value *> Elements);
307
308     /// getOrCreateSubrange - Create a descriptor for a value range.  This
309     /// implicitly uniques the values returned.
310     DISubrange getOrCreateSubrange(int64_t Lo, int64_t Hi);
311
312     /// createGlobalVariable - Create a new descriptor for the specified global.
313     /// @param Name        Name of the variable.
314     /// @param File        File where this variable is defined.
315     /// @param LineNo      Line number.
316     /// @param Ty          Variable Type.
317     /// @param isLocalToUnit Boolean flag indicate whether this variable is
318     ///                      externally visible or not.
319     /// @param Val         llvm::Value of the variable.
320     DIGlobalVariable
321     createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
322                          DIType Ty, bool isLocalToUnit, llvm::Value *Val);
323
324
325     /// createStaticVariable - Create a new descriptor for the specified 
326     /// variable.
327     /// @param Conext      Variable scope. 
328     /// @param Name        Name of the variable.
329     /// @param LinakgeName Mangled  name of the variable.
330     /// @param File        File where this variable is defined.
331     /// @param LineNo      Line number.
332     /// @param Ty          Variable Type.
333     /// @param isLocalToUnit Boolean flag indicate whether this variable is
334     ///                      externally visible or not.
335     /// @param Val         llvm::Value of the variable.
336     DIGlobalVariable
337     createStaticVariable(DIDescriptor Context, StringRef Name, 
338                          StringRef LinkageName, DIFile File, unsigned LineNo, 
339                          DIType Ty, bool isLocalToUnit, llvm::Value *Val);
340
341
342     /// createLocalVariable - Create a new descriptor for the specified 
343     /// local variable.
344     /// @param Tag         Dwarf TAG. Usually DW_TAG_auto_variable or
345     ///                    DW_TAG_arg_variable.
346     /// @param Scope       Variable scope.
347     /// @param Name        Variable name.
348     /// @param File        File where this variable is defined.
349     /// @param LineNo      Line number.
350     /// @param Ty          Variable Type
351     /// @param AlwaysPreserve Boolean. Set to true if debug info for this
352     ///                       variable should be preserved in optimized build.
353     /// @param Flags          Flags, e.g. artificial variable.
354     /// @param ArgNo       If this variable is an arugment then this argument's
355     ///                    number. 1 indicates 1st argument.
356     DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
357                                    StringRef Name,
358                                    DIFile File, unsigned LineNo,
359                                    DIType Ty, bool AlwaysPreserve = false,
360                                    unsigned Flags = 0,
361                                    unsigned ArgNo = 0);
362
363
364     /// createComplexVariable - Create a new descriptor for the specified
365     /// variable which has a complex address expression for its address.
366     /// @param Tag         Dwarf TAG. Usually DW_TAG_auto_variable or
367     ///                    DW_TAG_arg_variable.
368     /// @param Scope       Variable scope.
369     /// @param Name        Variable name.
370     /// @param File        File where this variable is defined.
371     /// @param LineNo      Line number.
372     /// @param Ty          Variable Type
373     /// @param Addr        An array of complex address operations.
374     /// @param ArgNo       If this variable is an arugment then this argument's
375     ///                    number. 1 indicates 1st argument.
376     DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
377                                      StringRef Name, DIFile F, unsigned LineNo,
378                                      DIType Ty, ArrayRef<Value *> Addr,
379                                      unsigned ArgNo = 0);
380
381     /// createFunction - Create a new descriptor for the specified subprogram.
382     /// See comments in DISubprogram for descriptions of these fields.
383     /// @param Scope         Function scope.
384     /// @param Name          Function name.
385     /// @param LinkageName   Mangled function name.
386     /// @param File          File where this variable is defined.
387     /// @param LineNo        Line number.
388     /// @param Ty            Function type.
389     /// @param isLocalToUnit True if this function is not externally visible..
390     /// @param isDefinition  True if this is a function definition.
391     /// @param Flags         e.g. is this function prototyped or not.
392     ///                      This flags are used to emit dwarf attributes.
393     /// @param isOptimized   True if optimization is ON.
394     /// @param Fn            llvm::Function pointer.
395     /// @param TParam        Function template parameters.
396     DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
397                                 StringRef LinkageName,
398                                 DIFile File, unsigned LineNo,
399                                 DIType Ty, bool isLocalToUnit,
400                                 bool isDefinition,
401                                 unsigned Flags = 0,
402                                 bool isOptimized = false,
403                                 Function *Fn = 0,
404                                 MDNode *TParam = 0,
405                                 MDNode *Decl = 0);
406
407     /// createMethod - Create a new descriptor for the specified C++ method.
408     /// See comments in DISubprogram for descriptions of these fields.
409     /// @param Scope         Function scope.
410     /// @param Name          Function name.
411     /// @param LinkageName   Mangled function name.
412     /// @param File          File where this variable is defined.
413     /// @param LineNo        Line number.
414     /// @param Ty            Function type.
415     /// @param isLocalToUnit True if this function is not externally visible..
416     /// @param isDefinition  True if this is a function definition.
417     /// @param Virtuality    Attributes describing virtualness. e.g. pure 
418     ///                      virtual function.
419     /// @param VTableIndex   Index no of this method in virtual table.
420     /// @param VTableHolder  Type that holds vtable.
421     /// @param Flags         e.g. is this function prototyped or not.
422     ///                      This flags are used to emit dwarf attributes.
423     /// @param isOptimized   True if optimization is ON.
424     /// @param Fn            llvm::Function pointer.
425     /// @param TParam        Function template parameters.
426     DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
427                               StringRef LinkageName,
428                               DIFile File, unsigned LineNo,
429                               DIType Ty, bool isLocalToUnit,
430                               bool isDefinition,
431                               unsigned Virtuality = 0, unsigned VTableIndex = 0,
432                               MDNode *VTableHolder = 0,
433                               unsigned Flags = 0,
434                               bool isOptimized = false,
435                               Function *Fn = 0,
436                               MDNode *TParam = 0);
437
438     /// createNameSpace - This creates new descriptor for a namespace
439     /// with the specified parent scope.
440     /// @param Scope       Namespace scope
441     /// @param Name        Name of this namespace
442     /// @param File        Source file
443     /// @param LineNo      Line number
444     DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
445                                 DIFile File, unsigned LineNo);
446
447
448     /// createLexicalBlock - This creates a descriptor for a lexical block
449     /// with the specified parent context.
450     /// @param Scope       Parent lexical scope.
451     /// @param File        Source file
452     /// @param Line        Line number
453     /// @param Col         Column number
454     DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
455                                       unsigned Line, unsigned Col);
456
457     /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
458     /// @param Storage     llvm::Value of the variable
459     /// @param VarInfo     Variable's debug info descriptor.
460     /// @param InsertAtEnd Location for the new intrinsic.
461     Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
462                                BasicBlock *InsertAtEnd);
463
464     /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
465     /// @param Storage      llvm::Value of the variable
466     /// @param VarInfo      Variable's debug info descriptor.
467     /// @param InsertBefore Location for the new intrinsic.
468     Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
469                                Instruction *InsertBefore);
470
471
472     /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
473     /// @param Val          llvm::Value of the variable
474     /// @param Offset       Offset
475     /// @param VarInfo      Variable's debug info descriptor.
476     /// @param InsertAtEnd Location for the new intrinsic.
477     Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
478                                          DIVariable VarInfo, 
479                                          BasicBlock *InsertAtEnd);
480     
481     /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
482     /// @param Val          llvm::Value of the variable
483     /// @param Offset       Offset
484     /// @param VarInfo      Variable's debug info descriptor.
485     /// @param InsertBefore Location for the new intrinsic.
486     Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
487                                          DIVariable VarInfo, 
488                                          Instruction *InsertBefore);
489
490   };
491 } // end namespace llvm
492
493 #endif