1 //===-- llvm/CodeGen/MachineDebugInfoDesc.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 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_MACHINEDEBUGINFODESC_H
15 #define LLVM_CODEGEN_MACHINEDEBUGINFODESC_H
17 #include "llvm/GlobalValue.h"
18 #include "llvm/Support/DataTypes.h"
23 //===----------------------------------------------------------------------===//
24 // Forward declarations.
28 //===----------------------------------------------------------------------===//
29 // Debug info description constants.
32 LLVMDebugVersion = (6 << 16), // Current version of debug information.
33 LLVMDebugVersion5 = (5 << 16), // Constant for version 5.
34 LLVMDebugVersion4 = (4 << 16), // Constant for version 4.
35 LLVMDebugVersionMask = 0xffff0000 // Mask for version number.
38 //===----------------------------------------------------------------------===//
39 /// DebugInfoDesc - This class is the base class for debug info descriptors.
42 // Content indicator. Dwarf values are used but that does not limit use to
46 explicit DebugInfoDesc(unsigned T) : Tag(T | LLVMDebugVersion) {}
48 virtual ~DebugInfoDesc();
51 unsigned getTag() const { return Tag & ~LLVMDebugVersionMask; }
52 unsigned getVersion() const { return Tag & LLVMDebugVersionMask; }
53 void setTag(unsigned T) { Tag = T | LLVMDebugVersion; }
55 /// TagFromGlobal - Returns the tag number from a debug info descriptor
56 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
57 static unsigned TagFromGlobal(GlobalVariable *GV);
59 /// VersionFromGlobal - Returns the version number from a debug info
60 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
62 static unsigned VersionFromGlobal(GlobalVariable *GV);
64 /// DescFactory - Create an instance of debug info descriptor based on Tag.
65 /// Return NULL if not a recognized Tag.
66 static DebugInfoDesc *DescFactory(unsigned Tag);
68 /// getLinkage - get linkage appropriate for this type of descriptor.
70 virtual GlobalValue::LinkageTypes getLinkage() const;
72 //===--------------------------------------------------------------------===//
73 // Subclasses should supply the following virtual methods.
75 /// ApplyToFields - Target the vistor to the fields of the descriptor.
77 virtual void ApplyToFields(DIVisitor *Visitor);
79 /// getDescString - Return a string used to compose global names and labels.
81 virtual const char *getDescString() const = 0;
83 /// getTypeString - Return a string used to label this descriptor's type.
85 virtual const char *getTypeString() const = 0;
88 virtual void dump() = 0;
91 //===--------------------------------------------------------------------===//
92 // Subclasses should supply the following static methods.
94 // Implement isa/cast/dyncast.
95 static bool classof(const DebugInfoDesc *) { return true; }
98 //===----------------------------------------------------------------------===//
99 /// AnchorDesc - Descriptors of this class act as markers for identifying
100 /// descriptors of certain groups.
102 class AnchorDesc : public DebugInfoDesc {
103 // Tag number of descriptors anchored by this object.
107 explicit AnchorDesc(AnchoredDesc *D);
110 unsigned getAnchorTag() const { return AnchorTag; }
112 /// getLinkage - get linkage appropriate for this type of descriptor.
114 virtual GlobalValue::LinkageTypes getLinkage() const;
116 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
118 virtual void ApplyToFields(DIVisitor *Visitor);
120 /// getDescString - Return a string used to compose global names and labels.
122 virtual const char *getDescString() const;
124 /// getTypeString - Return a string used to label this descriptor's type.
126 virtual const char *getTypeString() const {
127 return "llvm.dbg.anchor.type";
134 // Implement isa/cast/dyncast.
135 static bool classof(const AnchorDesc *) { return true; }
136 static bool classof(const DebugInfoDesc *D);
139 //===----------------------------------------------------------------------===//
140 /// AnchoredDesc - This class manages anchors for a variety of top level
142 class AnchoredDesc : public DebugInfoDesc {
143 // Anchor for all descriptors of the same type.
144 DebugInfoDesc *Anchor;
146 explicit AnchoredDesc(unsigned T);
149 AnchorDesc *getAnchor() const { return static_cast<AnchorDesc *>(Anchor); }
150 void setAnchor(AnchorDesc *A) { Anchor = static_cast<DebugInfoDesc *>(A); }
152 //===--------------------------------------------------------------------===//
153 // Subclasses should supply the following virtual methods.
155 /// getAnchorString - Return a string used to label descriptor's anchor.
157 virtual const char *getAnchorString() const = 0;
159 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
161 virtual void ApplyToFields(DIVisitor *Visitor);
164 //===----------------------------------------------------------------------===//
165 /// CompileUnitDesc - This class packages debug information associated with a
166 /// source/header file.
167 class CompileUnitDesc : public AnchoredDesc {
168 unsigned Language; // Language number (ex. DW_LANG_C89.)
169 std::string FileName; // Source file name.
170 std::string Directory; // Source file directory.
171 std::string Producer; // Compiler string.
176 unsigned getLanguage() const { return Language; }
177 const std::string &getFileName() const { return FileName; }
178 const std::string &getDirectory() const { return Directory; }
179 const std::string &getProducer() const { return Producer; }
180 void setLanguage(unsigned L) { Language = L; }
181 void setFileName(const std::string &FN) { FileName = FN; }
182 void setDirectory(const std::string &D) { Directory = D; }
183 void setProducer(const std::string &P) { Producer = P; }
185 // FIXME - Need translation unit getter/setter.
187 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
189 virtual void ApplyToFields(DIVisitor *Visitor);
191 /// getDescString - Return a string used to compose global names and labels.
193 virtual const char *getDescString() const {
194 return "llvm.dbg.compile_unit";
197 /// getTypeString - Return a string used to label this descriptor's type.
199 virtual const char *getTypeString() const {
200 return "llvm.dbg.compile_unit.type";
203 /// getAnchorString - Return a string used to label this descriptor's anchor.
205 const char *getAnchorString() const {
206 return "llvm.dbg.compile_units";
213 // Implement isa/cast/dyncast.
214 static bool classof(const CompileUnitDesc *) { return true; }
215 static bool classof(const DebugInfoDesc *D);
218 //===----------------------------------------------------------------------===//
219 /// TypeDesc - This class packages debug information associated with a type.
221 class TypeDesc : public DebugInfoDesc {
223 FlagPrivate = 1 << 0,
224 FlagProtected = 1 << 1
226 DebugInfoDesc *Context; // Context debug descriptor.
227 std::string Name; // Type name (may be empty.)
228 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
229 unsigned Line; // Defined line# (may be zero.)
230 uint64_t Size; // Type bit size (may be zero.)
231 uint64_t Align; // Type bit alignment (may be zero.)
232 uint64_t Offset; // Type bit offset (may be zero.)
233 unsigned Flags; // Miscellaneous flags.
235 explicit TypeDesc(unsigned T);
238 DebugInfoDesc *getContext() const { return Context; }
239 const std::string &getName() const { return Name; }
240 CompileUnitDesc *getFile() const {
241 return static_cast<CompileUnitDesc *>(File);
243 unsigned getLine() const { return Line; }
244 uint64_t getSize() const { return Size; }
245 uint64_t getAlign() const { return Align; }
246 uint64_t getOffset() const { return Offset; }
247 bool isPrivate() const {
248 return (Flags & FlagPrivate) != 0;
250 bool isProtected() const {
251 return (Flags & FlagProtected) != 0;
253 void setContext(DebugInfoDesc *C) { Context = C; }
254 void setName(const std::string &N) { Name = N; }
255 void setFile(CompileUnitDesc *U) {
256 File = static_cast<DebugInfoDesc *>(U);
258 void setLine(unsigned L) { Line = L; }
259 void setSize(uint64_t S) { Size = S; }
260 void setAlign(uint64_t A) { Align = A; }
261 void setOffset(uint64_t O) { Offset = O; }
262 void setIsPrivate() { Flags |= FlagPrivate; }
263 void setIsProtected() { Flags |= FlagProtected; }
265 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
267 virtual void ApplyToFields(DIVisitor *Visitor);
269 /// getDescString - Return a string used to compose global names and labels.
271 virtual const char *getDescString() const {
272 return "llvm.dbg.type";
275 /// getTypeString - Return a string used to label this descriptor's type.
277 virtual const char *getTypeString() const {
278 return "llvm.dbg.type.type";
286 //===----------------------------------------------------------------------===//
287 /// BasicTypeDesc - This class packages debug information associated with a
288 /// basic type (eg. int, bool, double.)
289 class BasicTypeDesc : public TypeDesc {
290 unsigned Encoding; // Type encoding.
295 unsigned getEncoding() const { return Encoding; }
296 void setEncoding(unsigned E) { Encoding = E; }
298 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
300 virtual void ApplyToFields(DIVisitor *Visitor);
302 /// getDescString - Return a string used to compose global names and labels.
304 virtual const char *getDescString() const {
305 return "llvm.dbg.basictype";
308 /// getTypeString - Return a string used to label this descriptor's type.
310 virtual const char *getTypeString() const {
311 return "llvm.dbg.basictype.type";
318 // Implement isa/cast/dyncast.
319 static bool classof(const BasicTypeDesc *) { return true; }
320 static bool classof(const DebugInfoDesc *D);
323 //===----------------------------------------------------------------------===//
324 /// DerivedTypeDesc - This class packages debug information associated with a
325 /// derived types (eg., typedef, pointer, reference.)
326 class DerivedTypeDesc : public TypeDesc {
327 DebugInfoDesc *FromType; // Type derived from.
329 explicit DerivedTypeDesc(unsigned T);
332 TypeDesc *getFromType() const {
333 return static_cast<TypeDesc *>(FromType);
335 void setFromType(TypeDesc *F) {
336 FromType = static_cast<DebugInfoDesc *>(F);
339 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
341 virtual void ApplyToFields(DIVisitor *Visitor);
343 /// getDescString - Return a string used to compose global names and labels.
345 virtual const char *getDescString() const {
346 return "llvm.dbg.derivedtype";
349 /// getTypeString - Return a string used to label this descriptor's type.
351 virtual const char *getTypeString() const {
352 return "llvm.dbg.derivedtype.type";
359 // Implement isa/cast/dyncast.
360 static bool classof(const DerivedTypeDesc *) { return true; }
361 static bool classof(const DebugInfoDesc *D);
364 //===----------------------------------------------------------------------===//
365 /// CompositeTypeDesc - This class packages debug information associated with a
366 /// array/struct types (eg., arrays, struct, union, enums.)
367 class CompositeTypeDesc : public DerivedTypeDesc {
368 std::vector<DebugInfoDesc *> Elements; // Information used to compose type.
370 explicit CompositeTypeDesc(unsigned T);
373 std::vector<DebugInfoDesc *> &getElements() { return Elements; }
375 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
377 virtual void ApplyToFields(DIVisitor *Visitor);
379 /// getDescString - Return a string used to compose global names and labels.
381 virtual const char *getDescString() const {
382 return "llvm.dbg.compositetype";
385 /// getTypeString - Return a string used to label this descriptor's type.
387 virtual const char *getTypeString() const {
388 return "llvm.dbg.compositetype.type";
395 // Implement isa/cast/dyncast.
396 static bool classof(const CompositeTypeDesc *) { return true; }
397 static bool classof(const DebugInfoDesc *D);
400 //===----------------------------------------------------------------------===//
401 /// SubrangeDesc - This class packages debug information associated with integer
403 class SubrangeDesc : public DebugInfoDesc {
404 int64_t Lo; // Low value of range.
405 int64_t Hi; // High value of range.
410 int64_t getLo() const { return Lo; }
411 int64_t getHi() const { return Hi; }
412 void setLo(int64_t L) { Lo = L; }
413 void setHi(int64_t H) { Hi = H; }
415 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
417 virtual void ApplyToFields(DIVisitor *Visitor);
419 /// getDescString - Return a string used to compose global names and labels.
421 virtual const char *getDescString() const {
422 return "llvm.dbg.subrange";
425 /// getTypeString - Return a string used to label this descriptor's type.
427 virtual const char *getTypeString() const {
428 return "llvm.dbg.subrange.type";
435 // Implement isa/cast/dyncast.
436 static bool classof(const SubrangeDesc *) { return true; }
437 static bool classof(const DebugInfoDesc *D);
440 //===----------------------------------------------------------------------===//
441 /// EnumeratorDesc - This class packages debug information associated with
442 /// named integer constants.
443 class EnumeratorDesc : public DebugInfoDesc {
444 std::string Name; // Enumerator name.
445 int64_t Value; // Enumerator value.
450 const std::string &getName() const { return Name; }
451 int64_t getValue() const { return Value; }
452 void setName(const std::string &N) { Name = N; }
453 void setValue(int64_t V) { Value = V; }
455 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
457 virtual void ApplyToFields(DIVisitor *Visitor);
459 /// getDescString - Return a string used to compose global names and labels.
461 virtual const char *getDescString() const {
462 return "llvm.dbg.enumerator";
465 /// getTypeString - Return a string used to label this descriptor's type.
467 virtual const char *getTypeString() const {
468 return "llvm.dbg.enumerator.type";
475 // Implement isa/cast/dyncast.
476 static bool classof(const EnumeratorDesc *) { return true; }
477 static bool classof(const DebugInfoDesc *D);
480 //===----------------------------------------------------------------------===//
481 /// VariableDesc - This class packages debug information associated with a
482 /// subprogram variable.
484 class VariableDesc : public DebugInfoDesc {
485 DebugInfoDesc *Context; // Context debug descriptor.
486 std::string Name; // Type name (may be empty.)
487 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
488 unsigned Line; // Defined line# (may be zero.)
489 DebugInfoDesc *TyDesc; // Type of variable.
491 explicit VariableDesc(unsigned T);
494 DebugInfoDesc *getContext() const { return Context; }
495 const std::string &getName() const { return Name; }
496 CompileUnitDesc *getFile() const {
497 return static_cast<CompileUnitDesc *>(File);
499 unsigned getLine() const { return Line; }
500 TypeDesc *getType() const {
501 return static_cast<TypeDesc*>(TyDesc);
503 void setContext(DebugInfoDesc *C) { Context = C; }
504 void setName(const std::string &N) { Name = N; }
505 void setFile(CompileUnitDesc *U) {
506 File = static_cast<DebugInfoDesc *>(U);
508 void setLine(unsigned L) { Line = L; }
509 void setType(TypeDesc *T) {
510 TyDesc = static_cast<DebugInfoDesc *>(T);
513 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
515 virtual void ApplyToFields(DIVisitor *Visitor);
517 /// getDescString - Return a string used to compose global names and labels.
519 virtual const char *getDescString() const {
520 return "llvm.dbg.variable";
523 /// getTypeString - Return a string used to label this descriptor's type.
525 virtual const char *getTypeString() const {
526 return "llvm.dbg.variable.type";
533 // Implement isa/cast/dyncast.
534 static bool classof(const VariableDesc *) { return true; }
535 static bool classof(const DebugInfoDesc *D);
538 //===----------------------------------------------------------------------===//
539 /// GlobalDesc - This class is the base descriptor for global functions and
541 class GlobalDesc : public AnchoredDesc {
542 DebugInfoDesc *Context; // Context debug descriptor.
543 std::string Name; // Global name.
544 std::string FullName; // Fully qualified name.
545 std::string LinkageName; // Name for binding to MIPS linkage.
546 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
547 unsigned Line; // Defined line# (may be zero.)
548 DebugInfoDesc *TyDesc; // Type debug descriptor.
549 bool IsStatic; // Is the global a static.
550 bool IsDefinition; // Is the global defined in context.
552 explicit GlobalDesc(unsigned T);
555 DebugInfoDesc *getContext() const { return Context; }
556 const std::string &getName() const { return Name; }
557 const std::string &getFullName() const { return FullName; }
558 const std::string &getLinkageName() const { return LinkageName; }
559 CompileUnitDesc *getFile() const {
560 return static_cast<CompileUnitDesc *>(File);
562 unsigned getLine() const { return Line; }
563 TypeDesc *getType() const {
564 return static_cast<TypeDesc *>(TyDesc);
566 bool isStatic() const { return IsStatic; }
567 bool isDefinition() const { return IsDefinition; }
568 void setContext(DebugInfoDesc *C) { Context = C; }
569 void setName(const std::string &N) { Name = N; }
570 void setFullName(const std::string &N) { FullName = N; }
571 void setLinkageName(const std::string &N) { LinkageName = N; }
572 void setFile(CompileUnitDesc *U) {
573 File = static_cast<DebugInfoDesc *>(U);
575 void setLine(unsigned L) { Line = L; }
576 void setType(TypeDesc *T) {
577 TyDesc = static_cast<DebugInfoDesc *>(T);
579 void setIsStatic(bool IS) { IsStatic = IS; }
580 void setIsDefinition(bool ID) { IsDefinition = ID; }
582 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
584 virtual void ApplyToFields(DIVisitor *Visitor);
587 //===----------------------------------------------------------------------===//
588 /// GlobalVariableDesc - This class packages debug information associated with a
590 class GlobalVariableDesc : public GlobalDesc {
591 GlobalVariable *Global; // llvm global.
593 GlobalVariableDesc();
596 GlobalVariable *getGlobalVariable() const { return Global; }
597 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
599 /// ApplyToFields - Target the visitor to the fields of the
600 /// GlobalVariableDesc.
601 virtual void ApplyToFields(DIVisitor *Visitor);
603 /// getDescString - Return a string used to compose global names and labels.
605 virtual const char *getDescString() const {
606 return "llvm.dbg.global_variable";
609 /// getTypeString - Return a string used to label this descriptor's type.
611 virtual const char *getTypeString() const {
612 return "llvm.dbg.global_variable.type";
615 /// getAnchorString - Return a string used to label this descriptor's anchor.
617 const char *getAnchorString() const {
618 return "llvm.dbg.global_variables";
625 // Implement isa/cast/dyncast.
626 static bool classof(const GlobalVariableDesc *) { return true; }
627 static bool classof(const DebugInfoDesc *D);
630 //===----------------------------------------------------------------------===//
631 /// SubprogramDesc - This class packages debug information associated with a
632 /// subprogram/function.
633 struct SubprogramDesc : public GlobalDesc {
636 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
638 virtual void ApplyToFields(DIVisitor *Visitor);
640 /// getDescString - Return a string used to compose global names and labels.
642 virtual const char *getDescString() const {
643 return "llvm.dbg.subprogram";
646 /// getTypeString - Return a string used to label this descriptor's type.
648 virtual const char *getTypeString() const {
649 return "llvm.dbg.subprogram.type";
652 /// getAnchorString - Return a string used to label this descriptor's anchor.
654 const char *getAnchorString() const {
655 return "llvm.dbg.subprograms";
662 // Implement isa/cast/dyncast.
663 static bool classof(const SubprogramDesc *) { return true; }
664 static bool classof(const DebugInfoDesc *D);
667 //===----------------------------------------------------------------------===//
668 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
670 class BlockDesc : public DebugInfoDesc {
671 DebugInfoDesc *Context; // Context debug descriptor.
676 DebugInfoDesc *getContext() const { return Context; }
677 void setContext(DebugInfoDesc *C) { Context = C; }
679 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
681 virtual void ApplyToFields(DIVisitor *Visitor);
683 /// getDescString - Return a string used to compose global names and labels.
685 virtual const char *getDescString() const {
686 return "llvm.dbg.block";
689 /// getTypeString - Return a string used to label this descriptor's type.
691 virtual const char *getTypeString() const {
692 return "llvm.dbg.block.type";
699 // Implement isa/cast/dyncast.
700 static bool classof(const BlockDesc *) { return true; }
701 static bool classof(const DebugInfoDesc *D);
704 } // End llvm namespace