[llvm-commits] [dragonegg] r92702 - in /dragonegg/trunk: llvm-debug.cpp llvm-debug.h

Duncan Sands baldrick at free.fr
Mon Jan 4 23:10:36 PST 2010


Author: baldrick
Date: Tue Jan  5 01:10:36 2010
New Revision: 92702

URL: http://llvm.org/viewvc/llvm-project?rev=92702&view=rev
Log:
Port commit 91441 (dpatel) from llvm-gcc:
Emit debug info for C++ namespaces.

Modified:
    dragonegg/trunk/llvm-debug.cpp
    dragonegg/trunk/llvm-debug.h

Modified: dragonegg/trunk/llvm-debug.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-debug.cpp?rev=92702&r1=92701&r2=92702&view=diff

==============================================================================
--- dragonegg/trunk/llvm-debug.cpp (original)
+++ dragonegg/trunk/llvm-debug.cpp Tue Jan  5 01:10:36 2010
@@ -256,10 +256,20 @@
     Virtuality = dwarf::DW_VIRTUALITY_virtual;
     ContainingType = getOrCreateType(DECL_CONTEXT (FnDecl));
   }
+  bool UseModuleContext = false;
+  // If this artificial function has abstract origin then put this function
+  // at module scope. The abstract copy will be placed in appropriate region.
+  if (DECL_ABSTRACT_ORIGIN (FnDecl) != FnDecl
+      && DECL_ARTIFICIAL(FnDecl))
+    UseModuleContext = true;
+  
+  const char *FnName = lang_hooks.dwarf_name(FnDecl, 0);
   DISubprogram SP = 
-    DebugFactory.CreateSubprogram(findRegion(DECL_CONTEXT(FnDecl)),
-                                  lang_hooks.dwarf_name(FnDecl, 0),
-                                  lang_hooks.dwarf_name(FnDecl, 0),
+    DebugFactory.CreateSubprogram((UseModuleContext ?
+                                   getOrCreateCompileUnit(main_input_filename) :
+                                   findRegion(DECL_CONTEXT(FnDecl))),
+                                  (UseModuleContext ? FnName : StringRef()), 
+                                  (UseModuleContext ? FnName : StringRef()), 
                                   LinkageName,
                                   getOrCreateCompileUnit(Loc.file), CurLineNo,
                                   FNType,
@@ -275,7 +285,23 @@
   RegionMap[FnDecl] = WeakVH(SP.getNode());
 }
 
-  /// findRegion - Find tree_node N's region.
+/// getOrCreateNameSpace - Get name space descriptor for the tree node.
+DINameSpace DebugInfo::getOrCreateNameSpace(tree Node, DIDescriptor Context) {
+  std::map<tree_node *, WeakVH >::iterator I = 
+    NameSpaceCache.find(Node);
+  if (I != NameSpaceCache.end())
+    return DINameSpace(cast<MDNode>(I->second));
+
+  expanded_location Loc = GetNodeLocation(Node, false);
+  DINameSpace DNS =
+    DebugFactory.CreateNameSpace(Context, GetNodeName(Node),
+                                 getOrCreateCompileUnit(Loc.file), Loc.line);
+
+  NameSpaceCache[Node] = WeakVH(DNS.getNode());
+  return DNS;
+}
+
+/// findRegion - Find tree_node N's region.
 DIDescriptor DebugInfo::findRegion(tree Node) {
   if (Node == NULL_TREE)
     return getOrCreateCompileUnit(main_input_filename);
@@ -288,8 +314,14 @@
   if (TYPE_P (Node)) {
     DIType Ty = getOrCreateType(Node);
     return DIDescriptor(Ty.getNode());
-  } else if (DECL_P (Node))
+  } else if (DECL_P (Node)) {
+    if (TREE_CODE (Node) == NAMESPACE_DECL) {
+      DIDescriptor NSContext = findRegion(DECL_CONTEXT(Node));
+      DINameSpace NS = getOrCreateNameSpace(Node, NSContext);
+      return DIDescriptor(NS.getNode());
+    }
     return findRegion (DECL_CONTEXT (Node));
+  }
 
   // Otherwise main compile unit covers everything.
   return getOrCreateCompileUnit(main_input_filename);

Modified: dragonegg/trunk/llvm-debug.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-debug.h?rev=92702&r1=92701&r2=92702&view=diff

==============================================================================
--- dragonegg/trunk/llvm-debug.h (original)
+++ dragonegg/trunk/llvm-debug.h Tue Jan  5 01:10:36 2010
@@ -64,6 +64,9 @@
   std::map<tree_node *, WeakVH > SPCache;
                                         // Cache of previously constructed 
                                         // Subprograms.
+  std::map<tree_node *, WeakVH> NameSpaceCache;
+                                        // Cache of previously constructed name 
+                                        // spaces.
   SmallVector<WeakVH, 4> RegionStack;
                                         // Stack to track declarative scopes.
   
@@ -132,6 +135,9 @@
 
   /// findRegion - Find tree_node N's region.
   DIDescriptor findRegion(tree_node *n);
+  
+  /// getOrCreateNameSpace - Get name space descriptor for the tree node.
+  DINameSpace getOrCreateNameSpace(tree_node *Node, DIDescriptor Context);
 };
 
 } // end namespace llvm





More information about the llvm-commits mailing list