f2119c2c3de5a35c5b2a6f6527c2d5f6fa512dd6
[oota-llvm.git] / include / llvm / CodeGen / MachineDebugInfo.h
1 //===-- llvm/CodeGen/MachineDebugInfo.h -------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by James M. Laskey and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Collect debug information for a module.  This information should be in a
11 // neutral form that can be used by different debugging schemes.
12 //
13 // The organization of information is primarily clustered around the source
14 // compile units.  The main exception is source line correspondence where
15 // inlining may interleave code from various compile units.
16 //
17 // The following information can be retrieved from the MachineDebugInfo.
18 //
19 //  -- Source directories - Directories are uniqued based on their canonical
20 //     string and assigned a sequential numeric ID (base 1.)
21 //  -- Source files - Files are also uniqued based on their name and directory
22 //     ID.  A file ID is sequential number (base 1.)
23 //  -- Source line coorespondence - A vector of file ID, line#, column# triples.
24 //     A DEBUG_LOCATION instruction is generated  by the DAG Legalizer
25 //     corresponding to each entry in the source line list.  This allows a debug
26 //     emitter to generate labels referenced by debug information tables.
27 //
28 //===----------------------------------------------------------------------===//
29
30 #ifndef LLVM_CODEGEN_MACHINEDEBUGINFO_H
31 #define LLVM_CODEGEN_MACHINEDEBUGINFO_H
32
33 #include "llvm/Support/Dwarf.h"
34 #include "llvm/ADT/UniqueVector.h"
35 #include "llvm/GlobalValue.h"
36 #include "llvm/Pass.h"
37 #include "llvm/User.h"
38
39 #include <string>
40 #include <set>
41
42 namespace llvm {
43
44 //===----------------------------------------------------------------------===//
45 // Forward declarations.
46 class Constant;
47 class DebugInfoDesc;
48 class GlobalVariable;
49 class Module;
50 class PointerType;
51 class StructType;
52
53 //===----------------------------------------------------------------------===//
54 // Debug info constants.
55
56 enum {
57   LLVMDebugVersion = 1,                 // Current version of debug information.
58   DIInvalid = ~0U,                      // Invalid result indicator.
59   
60   // DebugInfoDesc type identifying tags.
61   DI_TAG_anchor = 0,
62   DI_TAG_compile_unit,
63   DI_TAG_global_variable,
64   DI_TAG_subprogram,
65   DI_TAG_basictype,
66   DI_TAG_typedef
67 };
68
69 //===----------------------------------------------------------------------===//
70 /// DIVisitor - Subclasses of this class apply steps to each of the fields in
71 /// the supplied DebugInfoDesc.
72 class DIVisitor {
73 public:
74   DIVisitor() {}
75   virtual ~DIVisitor() {}
76
77   /// ApplyToFields - Target the visitor to each field of the debug information
78   /// descriptor.
79   void ApplyToFields(DebugInfoDesc *DD);
80   
81   /// Apply - Subclasses override each of these methods to perform the
82   /// appropriate action for the type of field.
83   virtual void Apply(int &Field) = 0;
84   virtual void Apply(unsigned &Field) = 0;
85   virtual void Apply(uint64_t &Field) = 0;
86   virtual void Apply(bool &Field) = 0;
87   virtual void Apply(std::string &Field) = 0;
88   virtual void Apply(DebugInfoDesc *&Field) = 0;
89   virtual void Apply(GlobalVariable *&Field) = 0;
90 };
91
92 //===----------------------------------------------------------------------===//
93 /// DebugInfoDesc - This class is the base class for debug info descriptors.
94 ///
95 class DebugInfoDesc {
96 private:
97   unsigned Tag;                         // Content indicator.  Dwarf values are
98                                         // used but that does not limit use to
99                                         // Dwarf writers.
100   
101 protected:
102   DebugInfoDesc(unsigned T) : Tag(T) {}
103   
104 public:
105   virtual ~DebugInfoDesc() {}
106
107   // Accessors
108   unsigned getTag()          const { return Tag; }
109   
110   /// TagFromGlobal - Returns the Tag number from a debug info descriptor
111   /// GlobalVariable.  Return DIIValid if operand is not an unsigned int.
112   static unsigned TagFromGlobal(GlobalVariable *GV);
113
114   /// DescFactory - Create an instance of debug info descriptor based on Tag.
115   /// Return NULL if not a recognized Tag.
116   static DebugInfoDesc *DescFactory(unsigned Tag);
117   
118   /// getLinkage - get linkage appropriate for this type of descriptor.
119   ///
120   virtual GlobalValue::LinkageTypes getLinkage() const;
121     
122   //===--------------------------------------------------------------------===//
123   // Subclasses should supply the following static methods.
124   
125   // Implement isa/cast/dyncast.
126   static bool classof(const DebugInfoDesc *)  { return true; }
127   
128   //===--------------------------------------------------------------------===//
129   // Subclasses should supply the following virtual methods.
130   
131   /// ApplyToFields - Target the vistor to the fields of the descriptor.
132   ///
133   virtual void ApplyToFields(DIVisitor *Visitor);
134
135   /// getDescString - Return a string used to compose global names and labels.
136   ///
137   virtual const char *getDescString() const = 0;
138   
139   /// getTypeString - Return a string used to label this descriptor's type.
140   ///
141   virtual const char *getTypeString() const = 0;
142   
143 #ifndef NDEBUG
144   virtual void dump() = 0;
145 #endif
146 };
147
148
149 //===----------------------------------------------------------------------===//
150 /// AnchorDesc - Descriptors of this class act as markers for identifying
151 /// descriptors of certain groups.
152 class AnchorDesc : public DebugInfoDesc {
153 private:  
154   std::string Name;                     // Anchor type string.
155   
156 public:
157   AnchorDesc()
158   : DebugInfoDesc(DI_TAG_anchor)
159   , Name("")
160   {}
161   AnchorDesc(const std::string &N)
162   : DebugInfoDesc(DI_TAG_anchor)
163   , Name(N)
164   {}
165   
166   // Accessors
167   const std::string &getName() const { return Name; }
168
169   // Implement isa/cast/dyncast.
170   static bool classof(const AnchorDesc *) { return true; }
171   static bool classof(const DebugInfoDesc *D) {
172     return D->getTag() == DI_TAG_anchor;
173   }
174
175   /// getLinkage - get linkage appropriate for this type of descriptor.
176   ///
177   virtual GlobalValue::LinkageTypes getLinkage() const;
178
179   /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
180   ///
181   virtual void ApplyToFields(DIVisitor *Visitor);
182
183   /// getDescString - Return a string used to compose global names and labels.
184   ///
185   virtual const char *getDescString() const;
186     
187   /// getTypeString - Return a string used to label this descriptor's type.
188   ///
189   virtual const char *getTypeString() const;
190     
191 #ifndef NDEBUG
192   virtual void dump();
193 #endif
194 };
195
196 //===----------------------------------------------------------------------===//
197 /// AnchoredDesc - This class manages anchors for a variety of top level
198 /// descriptors.
199 class AnchoredDesc : public DebugInfoDesc {
200 private:  
201   AnchorDesc *Anchor;                   // Anchor for all descriptors of the
202                                         // same type.
203
204 protected:
205
206   AnchoredDesc(unsigned T);
207
208 public:  
209   // Accessors.
210   AnchorDesc *getAnchor() const { return Anchor; }
211   void setAnchor(AnchorDesc *A) { Anchor = A; }
212
213   //===--------------------------------------------------------------------===//
214   // Subclasses should supply the following virtual methods.
215   
216   /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
217   ///
218   virtual void ApplyToFields(DIVisitor *Visitor);
219 };
220
221 //===----------------------------------------------------------------------===//
222 /// CompileUnitDesc - This class packages debug information associated with a 
223 /// source/header file.
224 class CompileUnitDesc : public AnchoredDesc {
225 private:  
226   unsigned DebugVersion;                // LLVM debug version when produced.
227   unsigned Language;                    // Language number (ex. DW_LANG_C89.)
228   std::string FileName;                 // Source file name.
229   std::string Directory;                // Source file directory.
230   std::string Producer;                 // Compiler string.
231   
232 public:
233   CompileUnitDesc();
234   
235   // Accessors
236   unsigned getDebugVersion()              const { return DebugVersion; }
237   unsigned getLanguage()                  const { return Language; }
238   const std::string &getFileName()        const { return FileName; }
239   const std::string &getDirectory()       const { return Directory; }
240   const std::string &getProducer()        const { return Producer; }
241   void setLanguage(unsigned L)                  { Language = L; }
242   void setFileName(const std::string &FN)       { FileName = FN; }
243   void setDirectory(const std::string &D)       { Directory = D; }
244   void setProducer(const std::string &P)        { Producer = P; }
245   
246   // FIXME - Need translation unit getter/setter.
247
248   // Implement isa/cast/dyncast.
249   static bool classof(const CompileUnitDesc *) { return true; }
250   static bool classof(const DebugInfoDesc *D) {
251     return D->getTag() == DI_TAG_compile_unit;
252   }
253   
254   /// DebugVersionFromGlobal - Returns the version number from a compile unit
255   /// GlobalVariable.  Return DIIValid if operand is not an unsigned int.
256   static unsigned DebugVersionFromGlobal(GlobalVariable *GV);
257   
258   /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
259   ///
260   virtual void ApplyToFields(DIVisitor *Visitor);
261
262   /// getDescString - Return a string used to compose global names and labels.
263   ///
264   virtual const char *getDescString() const;
265     
266   /// getTypeString - Return a string used to label this descriptor's type.
267   ///
268   virtual const char *getTypeString() const;
269   
270   /// getAnchorString - Return a string used to label this descriptor's anchor.
271   ///
272   virtual const char *getAnchorString() const;
273     
274 #ifndef NDEBUG
275   virtual void dump();
276 #endif
277 };
278
279 //===----------------------------------------------------------------------===//
280 /// TypeDesc - This class packages debug information associated with a type.
281 ///
282 class TypeDesc : public DebugInfoDesc {
283 private:
284   DebugInfoDesc *Context;               // Context debug descriptor.
285   std::string Name;                     // Type name.
286   uint64_t Size;                        // Type size.
287
288 protected:
289   TypeDesc(unsigned T);
290
291 public:
292   // Accessors
293   DebugInfoDesc *getContext()                const { return Context; }
294   const std::string &getName()               const { return Name; }
295   uint64_t getSize()                         const { return Size; }
296   void setContext(DebugInfoDesc *C)                { Context = C; }
297   void setName(const std::string &N)               { Name = N; }
298   void setSize(uint64_t S)                         { Size = S; }
299   
300   /// ApplyToFields - Target the visitor to the fields of the  TypeDesc.
301   ///
302   virtual void ApplyToFields(DIVisitor *Visitor);
303
304   /// getDescString - Return a string used to compose global names and labels.
305   ///
306   virtual const char *getDescString() const;
307
308   /// getTypeString - Return a string used to label this descriptor's type.
309   ///
310   virtual const char *getTypeString() const;
311   
312 #ifndef NDEBUG
313   virtual void dump();
314 #endif
315 };
316
317 //===----------------------------------------------------------------------===//
318 /// BasicTypeDesc - This class packages debug information associated with a
319 /// basic type (eg. int, bool, double.)
320 class BasicTypeDesc : public TypeDesc {
321 private:
322   unsigned Encoding;                    // Type encoding.
323   
324 public:
325   BasicTypeDesc();
326   
327   // Accessors
328   unsigned getEncoding()                     const { return Encoding; }
329   void setEncoding(unsigned E)                     { Encoding = E; }
330
331   // Implement isa/cast/dyncast.
332   static bool classof(const BasicTypeDesc *)  { return true; }
333   static bool classof(const DebugInfoDesc *D) {
334     return D->getTag() == DI_TAG_basictype;
335   }
336   
337   /// ApplyToFields - Target the visitor to the fields of the  BasicTypeDesc.
338   ///
339   virtual void ApplyToFields(DIVisitor *Visitor);
340
341 #ifndef NDEBUG
342   virtual void dump();
343 #endif
344 };
345
346
347 //===----------------------------------------------------------------------===//
348 /// TypedefDesc - This class packages debug information associated with a
349 /// derived typedef.
350 class TypedefDesc : public TypeDesc {
351 private:
352   TypeDesc *FromType;                   // Type derived from.
353   CompileUnitDesc *File;                // Declared compile unit.
354   int Line;                             // Declared line#.
355
356 public:
357   TypedefDesc();
358   
359   // Accessors
360   TypeDesc *getFromType()                    const { return FromType; }
361   CompileUnitDesc *getFile()                 const { return File; }
362   int getLine()                              const { return Line; }
363   void setFromType(TypeDesc *F)                    { FromType = F; }
364   void setFile(CompileUnitDesc *U)                 { File = U; }
365   void setLine(int L)                              { Line = L; }
366
367   // Implement isa/cast/dyncast.
368   static bool classof(const TypedefDesc *)  { return true; }
369   static bool classof(const DebugInfoDesc *D) {
370     return D->getTag() == DI_TAG_typedef;
371   }
372   
373   /// ApplyToFields - Target the visitor to the fields of the  TypedefDesc.
374   ///
375   virtual void ApplyToFields(DIVisitor *Visitor);
376
377 #ifndef NDEBUG
378   virtual void dump();
379 #endif
380 };
381
382 //===----------------------------------------------------------------------===//
383 /// GlobalDesc - This class is the base descriptor for global functions and
384 /// variables.
385 class GlobalDesc : public AnchoredDesc {
386 private:
387   DebugInfoDesc *Context;               // Context debug descriptor.
388   std::string Name;                     // Global name.
389   TypeDesc *TyDesc;                     // Type debug descriptor.
390   bool IsStatic;                        // Is the global a static.
391   bool IsDefinition;                    // Is the global defined in context.
392   
393 protected:
394   GlobalDesc(unsigned T);
395
396 public:
397   // Accessors
398   DebugInfoDesc *getContext()                const { return Context; }
399   const std::string &getName()               const { return Name; }
400   TypeDesc *getTypeDesc()                    const { return TyDesc; }
401   bool isStatic()                            const { return IsStatic; }
402   bool isDefinition()                        const { return IsDefinition; }
403   void setContext(DebugInfoDesc *C)                { Context = C; }
404   void setName(const std::string &N)               { Name = N; }
405   void setTypeDesc(TypeDesc *T)                    { TyDesc = T; }
406   void setIsStatic(bool IS)                        { IsStatic = IS; }
407   void setIsDefinition(bool ID)                    { IsDefinition = ID; }
408
409   /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
410   ///
411   virtual void ApplyToFields(DIVisitor *Visitor);
412 };
413
414 //===----------------------------------------------------------------------===//
415 /// GlobalVariableDesc - This class packages debug information associated with a
416 /// GlobalVariable.
417 class GlobalVariableDesc : public GlobalDesc {
418 private:
419   GlobalVariable *Global;               // llvm global.
420   unsigned Line;                        // Source line number.
421   
422 public:
423   GlobalVariableDesc();
424
425   // Accessors.
426   GlobalVariable *getGlobalVariable()        const { return Global; }
427   unsigned getLine()                         const { return Line; }
428   void setGlobalVariable(GlobalVariable *GV)       { Global = GV; }
429   void setLine(unsigned L)                         { Line = L; }
430  
431   // Implement isa/cast/dyncast.
432   static bool classof(const GlobalVariableDesc *)  { return true; }
433   static bool classof(const DebugInfoDesc *D) {
434     return D->getTag() == DI_TAG_global_variable; 
435   }
436   
437   /// ApplyToFields - Target the visitor to the fields of the
438   /// GlobalVariableDesc.
439   virtual void ApplyToFields(DIVisitor *Visitor);
440
441   /// getDescString - Return a string used to compose global names and labels.
442   ///
443   virtual const char *getDescString() const;
444
445   /// getTypeString - Return a string used to label this descriptor's type.
446   ///
447   virtual const char *getTypeString() const;
448   
449   /// getAnchorString - Return a string used to label this descriptor's anchor.
450   ///
451   virtual const char *getAnchorString() const;
452     
453 #ifndef NDEBUG
454   virtual void dump();
455 #endif
456 };
457
458 //===----------------------------------------------------------------------===//
459 /// SubprogramDesc - This class packages debug information associated with a
460 /// subprogram/function.
461 class SubprogramDesc : public GlobalDesc {
462 private:
463   // FIXME - Other attributes
464   
465 public:
466   SubprogramDesc();
467   
468   // Accessors
469   // FIXME - Other getters/setters.
470   
471   // Implement isa/cast/dyncast.
472   static bool classof(const SubprogramDesc *)  { return true; }
473   static bool classof(const DebugInfoDesc *D) {
474     return D->getTag() == DI_TAG_subprogram;
475   }
476   
477   /// ApplyToFields - Target the visitor to the fields of the  SubprogramDesc.
478   ///
479   virtual void ApplyToFields(DIVisitor *Visitor);
480
481   /// getDescString - Return a string used to compose global names and labels.
482   ///
483   virtual const char *getDescString() const;
484
485   /// getTypeString - Return a string used to label this descriptor's type.
486   ///
487   virtual const char *getTypeString() const;
488   
489   /// getAnchorString - Return a string used to label this descriptor's anchor.
490   ///
491   virtual const char *getAnchorString() const;
492     
493 #ifndef NDEBUG
494   virtual void dump();
495 #endif
496 };
497
498 //===----------------------------------------------------------------------===//
499 /// DIDeserializer - This class is responsible for casting GlobalVariables
500 /// into DebugInfoDesc objects.
501 class DIDeserializer {
502 private:
503   unsigned DebugVersion;                // Version of debug information in use.
504   std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs;
505                                         // Previously defined gloabls.
506   
507 public:
508   DIDeserializer() : DebugVersion(LLVMDebugVersion) {}
509   ~DIDeserializer() {}
510   
511   // Accessors
512   unsigned getDebugVersion() const { return DebugVersion; }
513   
514   /// Deserialize - Reconstitute a GlobalVariable into it's component
515   /// DebugInfoDesc objects.
516   DebugInfoDesc *Deserialize(Value *V);
517   DebugInfoDesc *Deserialize(GlobalVariable *GV);
518 };
519
520 //===----------------------------------------------------------------------===//
521 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
522 /// into GlobalVariables.
523 class DISerializer {
524 private:
525   Module *M;                            // Definition space module.
526   PointerType *StrPtrTy;                // A "sbyte *" type.  Created lazily.
527   PointerType *EmptyStructPtrTy;        // A "{ }*" type.  Created lazily.
528   std::map<unsigned, StructType *> TagTypes;
529                                         // Types per Tag.  Created lazily.
530   std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
531                                         // Previously defined descriptors.
532   std::map<const std::string, Constant *> StringCache;
533                                         // Previously defined strings.
534                                           
535 public:
536   DISerializer()
537   : M(NULL)
538   , StrPtrTy(NULL)
539   , EmptyStructPtrTy(NULL)
540   , TagTypes()
541   , DescGlobals()
542   , StringCache()
543   {}
544   ~DISerializer() {}
545   
546   // Accessors
547   Module *getModule()        const { return M; };
548   void setModule(Module *module)  { M = module; }
549
550   /// getStrPtrType - Return a "sbyte *" type.
551   ///
552   const PointerType *getStrPtrType();
553   
554   /// getEmptyStructPtrType - Return a "{ }*" type.
555   ///
556   const PointerType *getEmptyStructPtrType();
557   
558   /// getTagType - Return the type describing the specified descriptor (via
559   /// tag.)
560   const StructType *getTagType(DebugInfoDesc *DD);
561   
562   /// getString - Construct the string as constant string global.
563   ///
564   Constant *getString(const std::string &String);
565   
566   /// Serialize - Recursively cast the specified descriptor into a
567   /// GlobalVariable so that it can be serialized to a .bc or .ll file.
568   GlobalVariable *Serialize(DebugInfoDesc *DD);
569 };
570
571 //===----------------------------------------------------------------------===//
572 /// DIVerifier - This class is responsible for verifying the given network of
573 /// GlobalVariables are valid as DebugInfoDesc objects.
574 class DIVerifier {
575 private:
576   unsigned DebugVersion;                // Version of debug information in use.
577   std::set<GlobalVariable *> Visited;   // Tracks visits during recursion.
578   std::map<unsigned, unsigned> Counts;  // Count of fields per Tag type.
579
580   /// markVisited - Return true if the GlobalVariable hase been "seen" before.
581   /// Mark markVisited otherwise.
582   bool markVisited(GlobalVariable *GV);
583   
584 public:
585   DIVerifier() : DebugVersion(LLVMDebugVersion) {}
586   ~DIVerifier() {}
587   
588   /// Verify - Return true if the GlobalVariable appears to be a valid
589   /// serialization of a DebugInfoDesc.
590   bool Verify(Value *V);
591   bool Verify(GlobalVariable *GV);
592 };
593
594 //===----------------------------------------------------------------------===//
595 /// SourceLineInfo - This class is used to record source line correspondence.
596 ///
597 class SourceLineInfo {
598 private:
599   unsigned Line;                        // Source line number.
600   unsigned Column;                      // Source column.
601   unsigned SourceID;                    // Source ID number.
602
603 public:
604   SourceLineInfo(unsigned L, unsigned C, unsigned S)
605   : Line(L), Column(C), SourceID(S) {}
606   
607   // Accessors
608   unsigned getLine()     const { return Line; }
609   unsigned getColumn()   const { return Column; }
610   unsigned getSourceID() const { return SourceID; }
611 };
612
613 //===----------------------------------------------------------------------===//
614 /// SourceFileInfo - This class is used to track source information.
615 ///
616 class SourceFileInfo {
617 private:
618   unsigned DirectoryID;                 // Directory ID number.
619   std::string Name;                     // File name (not including directory.)
620   
621 public:
622   SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
623             
624   // Accessors
625   unsigned getDirectoryID()    const { return DirectoryID; }
626   const std::string &getName() const { return Name; }
627
628   /// operator== - Used by UniqueVector to locate entry.
629   ///
630   bool operator==(const SourceFileInfo &SI) const {
631     return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
632   }
633
634   /// operator< - Used by UniqueVector to locate entry.
635   ///
636   bool operator<(const SourceFileInfo &SI) const {
637     return getDirectoryID() < SI.getDirectoryID() ||
638           (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
639   }
640 };
641
642 //===----------------------------------------------------------------------===//
643 /// MachineDebugInfo - This class contains debug information specific to a
644 /// module.  Queries can be made by different debugging schemes and reformated
645 /// for specific use.
646 ///
647 class MachineDebugInfo : public ImmutablePass {
648 private:
649   // Use the same serializer/deserializer/verifier for the module.
650   DIDeserializer DR;
651
652   // CompileUnits - Uniquing vector for compile units.
653   UniqueVector<CompileUnitDesc *> CompileUnits;
654   
655   // Directories - Uniquing vector for directories.
656   UniqueVector<std::string> Directories;
657                                          
658   // SourceFiles - Uniquing vector for source files.
659   UniqueVector<SourceFileInfo> SourceFiles;
660
661   // Lines - List of of source line correspondence.
662   std::vector<SourceLineInfo *> Lines;
663
664 public:
665   MachineDebugInfo();
666   ~MachineDebugInfo();
667   
668   /// doInitialization - Initialize the debug state for a new module.
669   ///
670   bool doInitialization();
671   
672   /// doFinalization - Tear down the debug state after completion of a module.
673   ///
674   bool doFinalization();
675   
676   /// getDescFor - Convert a Value to a debug information descriptor.
677   ///
678   // FIXME - use new Value type when available.
679   DebugInfoDesc *getDescFor(Value *V);
680   
681   /// Verify - Verify that a Value is debug information descriptor.
682   ///
683   bool Verify(Value *V);
684   
685   /// AnalyzeModule - Scan the module for global debug information.
686   ///
687   void AnalyzeModule(Module &M);
688   
689   /// hasInfo - Returns true if valid debug info is present.
690   ///
691   bool hasInfo() const { return !CompileUnits.empty(); }
692   
693   /// RecordLabel - Records location information and associates it with a
694   /// debug label.  Returns a unique label ID used to generate a label and 
695   /// provide correspondence to the source line list.
696   unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source) {
697     Lines.push_back(new SourceLineInfo(Line, Column, Source));
698     return Lines.size();
699   }
700   
701   /// RecordSource - Register a source file with debug info. Returns an source
702   /// ID.
703   unsigned RecordSource(const std::string &Directory,
704                         const std::string &Source) {
705     unsigned DirectoryID = Directories.insert(Directory);
706     return SourceFiles.insert(SourceFileInfo(DirectoryID, Source));
707   }
708   unsigned RecordSource(const CompileUnitDesc *CompileUnit) {
709     return RecordSource(CompileUnit->getDirectory(),
710                         CompileUnit->getFileName());
711   }
712   
713   /// getDirectories - Return the UniqueVector of std::string representing
714   /// directories.
715   const UniqueVector<std::string> &getDirectories() const {
716     return Directories;
717   }
718   
719   /// getSourceFiles - Return the UniqueVector of source files. 
720   ///
721   const UniqueVector<SourceFileInfo> &getSourceFiles() const {
722     return SourceFiles;
723   }
724   
725   /// getSourceLines - Return a vector of source lines.  Vector index + 1
726   /// equals label ID.
727   const std::vector<SourceLineInfo *> &getSourceLines() const {
728     return Lines;
729   }
730   
731   /// SetupCompileUnits - Set up the unique vector of compile units.
732   ///
733   void SetupCompileUnits(Module &M);
734
735   /// getCompileUnits - Return a vector of debug compile units.
736   ///
737   const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
738   
739   /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
740   /// named GlobalVariable.
741   std::vector<GlobalVariable*>
742   getGlobalVariablesUsing(Module &M, const std::string &RootName);
743
744   /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
745   ///
746   template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
747     T Desc;
748     std::vector<GlobalVariable *> Globals =
749                              getGlobalVariablesUsing(M, Desc.getAnchorString());
750     std::vector<T *> AnchoredDescs;
751     for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
752       AnchoredDescs.push_back(cast<T>(DR.Deserialize(Globals[i])));
753     }
754
755     return AnchoredDescs;
756   }
757
758 }; // End class MachineDebugInfo
759
760 } // End llvm namespace
761
762 #endif