Introduce DILocation.
[oota-llvm.git] / include / llvm / Analysis / DebugInfo.h
index 314873a384b8fba1194f4a175f7bb2f6416fee00..7c6b421ca35c878408d7d536cf9f60155843b354 100644 (file)
@@ -95,6 +95,8 @@ namespace llvm {
     bool isSubprogram() const;
     bool isGlobalVariable() const;
     bool isScope() const;
+    bool isCompileUnit() const;
+    bool isLexicalBlock() const;
   };
 
   /// DISubrange - This is used to represent ranges, for array bounds.
@@ -126,13 +128,24 @@ namespace llvm {
       if (DbgNode && !isScope())
         DbgNode = 0;
     }
+
+    virtual const std::string &getFilename(std::string &F) const {
+      return F;
+    }
+
+    virtual const std::string &getDirectory(std::string &D) const {
+      return D;
+    }
   };
 
   /// DICompileUnit - A wrapper for a compile unit.
-  class DICompileUnit : public DIDescriptor {
+  class DICompileUnit : public DIScope {
   public:
-    explicit DICompileUnit(MDNode *N = 0)
-      : DIDescriptor(N, dwarf::DW_TAG_compile_unit) {}
+    explicit DICompileUnit(MDNode *N = 0) {
+      DbgNode = N;
+      if (DbgNode && !isCompileUnit())
+       DbgNode = 0;
+    }
 
     unsigned getLanguage() const     { return getUnsignedField(2); }
     const std::string &getFilename(std::string &F) const {
@@ -337,11 +350,26 @@ namespace llvm {
   };
 
   /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
-  class DISubprogram : public DIGlobal {
+  class DISubprogram : public DIScope {
   public:
-    explicit DISubprogram(MDNode *N = 0)
-      : DIGlobal(N, dwarf::DW_TAG_subprogram) {}
+    explicit DISubprogram(MDNode *N = 0) {
+      DbgNode = N;
+      if (DbgNode && !isSubprogram())
+       DbgNode = 0;
+    }
 
+    DIDescriptor getContext() const     { return getDescriptorField(2); }
+    const std::string &getName(std::string &F) const {
+      return getStringField(3, F);
+    }
+    const std::string &getDisplayName(std::string &F) const {
+      return getStringField(4, F);
+    }
+    const std::string &getLinkageName(std::string &F) const {
+      return getStringField(5, F);
+    }
+    DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
+    unsigned getLineNumber() const      { return getUnsignedField(7); }
     DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
 
     /// getReturnTypeName - Subprogram return types are encoded either as
@@ -357,6 +385,18 @@ namespace llvm {
       return T.getName(F);
     }
 
+    /// isLocalToUnit - Return true if this subprogram is local to the current
+    /// compile unit, like 'static' in C.
+    unsigned isLocalToUnit() const      { return getUnsignedField(9); }
+    unsigned isDefinition() const       { return getUnsignedField(10); }
+
+    const std::string &getFilename(std::string &F) const {
+      return getCompileUnit().getFilename(F);
+    }
+    const std::string &getDirectory(std::string &F) const {
+      return getCompileUnit().getDirectory(F);
+    }
+
     /// Verify - Verify that a subprogram descriptor is well formed.
     bool Verify() const;
 
@@ -415,13 +455,40 @@ namespace llvm {
     void dump() const;
   };
 
-  /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc).
-  class DIBlock : public DIDescriptor {
+  /// DILexicalBlock - This is a wrapper for a lexical block.
+  class DILexicalBlock : public DIScope {
   public:
-    explicit DIBlock(MDNode *N = 0)
-      : DIDescriptor(N, dwarf::DW_TAG_lexical_block) {}
+    explicit DILexicalBlock(MDNode *N = 0) {
+      DbgNode = N;
+      if (DbgNode && !isLexicalBlock()) 
+       DbgNode = 0;
+    }
+    DIScope getContext() const { return getFieldAs<DIScope>(1); }
 
-    DIDescriptor getContext() const { return getDescriptorField(1); }
+    const std::string &getFilename(std::string &F) const {
+      return getContext().getFilename(F);
+    }
+    const std::string &getDirectory(std::string &D) const {
+      return getContext().getDirectory(D);
+    }
+  };
+
+  /// DILocation - This object holds location information. This object
+  /// is not associated with any DWARF tag.
+  class DILocation : public DIDescriptor {
+  public:
+    explicit DILocation(MDNode *L) { DbgNode = L; }
+
+    unsigned getLineNumber() const     { return getUnsignedField(0); }
+    unsigned getColumnNumber() const   { return getUnsignedField(1); }
+    DIScope  getScope() const          { return getFieldAs<DIScope>(3); }
+    DILocation getOrigLocation() const { return getFieldAs<DILocation>(4); }
+    std::string getFilename(std::string &F) const  { 
+      return getScope().getFilename(F); 
+    }
+    std::string getDirectory(std::string &D) const { 
+      return getScope().getDirectory(D); 
+    }
   };
 
   /// DIFactory - This object assists with the construction of the various
@@ -520,9 +587,13 @@ namespace llvm {
                               DICompileUnit CompileUnit, unsigned LineNo,
                               DIType Type);
 
-    /// CreateBlock - This creates a descriptor for a lexical block with the
-    /// specified parent context.
-    DIBlock CreateBlock(DIDescriptor Context);
+    /// CreateLexicalBlock - This creates a descriptor for a lexical block 
+    /// with the specified parent context.
+    DILexicalBlock CreateLexicalBlock(DIDescriptor Context);
+
+    /// CreateLocation - Creates a debug info location.
+    DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo, 
+                             DIScope S, DILocation OrigLoc);
 
     /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
     /// inserting it at the end of the specified basic block.