1 //===-- llvm/Support/DebugInfoBuilder.h - -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the DebugInfoBuilder class, which is
11 // a helper class used to construct source level debugging information.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_DEBUGINFOBUILDER_H
16 #define LLVM_SUPPORT_DEBUGINFOBUILDER_H
18 #include <llvm/Module.h>
36 /// Helper class used to construct source-level debugging information.
38 /// The helper contains a notion of "current context", which is a
39 /// DWARF descriptor object representing the scope (module, class,
40 /// function, etc.) that currently encloses the definitions being
43 /// Initially, you should call setModule() to specify the target
44 /// module. Descriptors which are generated will be inserted into
45 /// this module. This also generates the initial set of anchor
46 /// descriptors, if they have not already been created for the module.
48 /// Next, you should call createCompileUnitDescriptor() to create
49 /// the descriptor for the current compilation unit. This method
50 /// sets the current context to the newly created descriptor.
52 /// Once that has been done, you can then create descriptors for
53 /// global definitions (functions, variables, etc.). You can use
54 /// setContext() to modify the current context. setContext() returns
55 /// a reference to the previous context, allowing easy restoration
56 /// of the previous context.
57 class DebugInfoBuilder {
60 PointerType * anyPtrType; // Pointer to empty struct
61 StructType * anchorType;
62 GlobalVariable * compileUnit;
63 GlobalVariable * context;
64 GlobalVariable * compileUnitAnchor;
65 GlobalVariable * globalVariableAnchor;
66 GlobalVariable * subprogramAnchor;
67 GlobalVariable * compileUnitDescriptor;
69 // Create an anchor with the specified tag.
70 GlobalVariable * createAnchor(unsigned anchorTag, const char * anchorName);
72 // Calculate alignement for primitive types.
73 unsigned getBasicAlignment(unsigned sizeInBits);
75 // Calculate the size of the specified LLVM type.
76 Constant * getSize(const Type * type);
78 // Calculate the alignment of the specified LLVM type.
79 Constant * getAlignment(const Type * type);
85 /// Return the type defined by llvm.dbg.anchor.type
86 StructType * getAnchorType() const { return anchorType; }
88 /// Set the reference to the module where we will insert debugging
89 /// information. Also defines the debug info types for the module and
90 /// creates the initial anchors. Also changes the current context to the
91 // global context for that module.
92 void setModule(Module * m);
94 /// Emit a compile unit descriptor. This should be done once for each
95 /// module before any other debug descriptors are created. This also
96 /// changes the current context to the global context for the compile unit.
97 GlobalVariable * createCompileUnitDescriptor(
99 const sys::Path & srcPath,
100 const std::string & producer);
102 /// Set a new context, returning the previous context. The context is the
103 /// debug descriptor representing the current scope (module, function,
105 GlobalVariable * setContext(GlobalVariable * ctx) {
106 GlobalVariable * prev = context;
111 /// Emit a subprogram descriptor in the current context.
112 GlobalVariable * createSubProgramDescriptor(
113 const std::string & name, // Name of the subprogram
114 const std::string & qualName, // Fully-qualified name
115 unsigned line, // Line number
116 GlobalVariable * typeDesc, // Type descriptor
117 bool isInternalScoped, // True if internal to module.
118 bool isDefined); // True if defined in this module.
120 /// Create a type descriptor for a primitive type.
121 GlobalVariable * createBasicTypeDescriptor(
125 unsigned alignmentInBits,
126 unsigned offsetInBits,
127 unsigned typeEncoding);
129 /// Create a type descriptor for an integer type
130 GlobalVariable * createIntegerTypeDescriptor(
131 std::string & name, const IntegerType * type, bool isSigned);
133 /// Create a type descriptor for an character type
134 GlobalVariable * createCharacterTypeDescriptor(
135 std::string & name, const IntegerType * type, bool isSigned);
137 /// Create a type descriptor for an floating-point type
138 GlobalVariable * createFloatTypeDescriptor(std::string & name,
141 /// Create a type descriptor for a pointer type.
142 GlobalVariable * createPointerTypeDescriptor(
143 std::string & name, // Name of the type
144 GlobalVariable * referenceType, // Descriptor for what is pointed to
145 const PointerType * type, // LLVM type of the pointer
146 unsigned line); // Line number of definition (0 if none)