[llvm-commits] [llvm-gcc-4.2] r109522 - in /llvm-gcc-4.2/trunk/gcc: llvm-debug.cpp llvm-debug.h

Devang Patel dpatel at apple.com
Tue Jul 27 11:15:02 PDT 2010


Author: dpatel
Date: Tue Jul 27 13:15:01 2010
New Revision: 109522

URL: http://llvm.org/viewvc/llvm-project?rev=109522&view=rev
Log:
Reapply 109316.
r109521 updated tests to not rely on absolute path.

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp
    llvm-gcc-4.2/trunk/gcc/llvm-debug.h

Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp?rev=109522&r1=109521&r2=109522&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Tue Jul 27 13:15:01 2010
@@ -57,28 +57,16 @@
 #endif
 
 
-/// DirectoryAndFile - Extract the directory and file name from a path.  If no
-/// directory is specified, then use the source working directory.
+/// DirectoryAndFile - If Filename is absolute then directory name is empty.
+/// Otherwise directory name is current working directory.
 static void DirectoryAndFile(const std::string &FullPath,
                              std::string &Directory, std::string &FileName) {
-  // Look for the directory slash.
-  size_t Slash = FullPath.rfind('/');
-  
-  // If no slash
-  if (Slash == std::string::npos) {
-    // The entire path is the file name.
+  FileName = FullPath;
+
+  if (FullPath[0] != '/')
+    Directory = std::string(get_src_pwd());
+  else
     Directory = "";
-    FileName = FullPath;
-  } else {
-    // Separate the directory from the file name.
-    Directory = FullPath.substr(0, Slash);
-    FileName = FullPath.substr(Slash + 1);
-  }
-  
-  // If no directory present then use source working directory.
-  if (Directory.empty() || Directory[0] != '/') {
-    Directory = std::string(get_src_pwd()) + "/" + Directory;
-  }
 }
 
 /// NodeSizeInBits - Returns the size in bits stored in a tree node regardless
@@ -1394,10 +1382,13 @@
   }
 
   // Get source file information.
-  std::string Directory;
-  std::string FileName;
-  DirectoryAndFile(FullPath, Directory, FileName);
-  
+  llvm::StringRef Dir;
+  if (FullPath[0] != '/') {
+    if (CWD.empty())
+      CWD = std::string(get_src_pwd());
+    Dir = llvm::StringRef(CWD);
+  }
+
   // Set up Language number.
   unsigned LangTag;
   const std::string LanguageName(lang_hooks.name);
@@ -1432,8 +1423,8 @@
   unsigned ObjcRunTimeVer = 0;
   if (flag_objc_abi != 0 && flag_objc_abi != -1)
     ObjcRunTimeVer = flag_objc_abi;
-  return DebugFactory.CreateCompileUnit(LangTag, FileName.c_str(),
-                                        Directory.c_str(),
+  return DebugFactory.CreateCompileUnit(LangTag, FullPath,
+                                        Dir,
                                         version_string, isMain,
                                         optimize, Flags,
                                         ObjcRunTimeVer);
@@ -1449,10 +1440,13 @@
   }
 
   // Get source file information.
-  std::string Directory;
-  std::string FileName;
-  DirectoryAndFile(FullPath, Directory, FileName);
-  return DebugFactory.CreateFile(FileName, Directory, TheCU);
+  llvm::StringRef Dir;
+  if (FullPath[0] != '/') {
+    if (CWD.empty())
+      CWD = std::string(get_src_pwd());
+    Dir = llvm::StringRef(CWD);
+  }
+  return DebugFactory.CreateFile(FullPath, Dir, TheCU);
 }
 
 /* LLVM LOCAL end (ENTIRE FILE!)  */

Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.h?rev=109522&r1=109521&r2=109522&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-debug.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-debug.h Tue Jul 27 13:15:01 2010
@@ -63,6 +63,7 @@
   int PrevLineNo;                       // Previous location line# encountered.
   BasicBlock *PrevBB;                   // Last basic block encountered.
   DICompileUnit TheCU;                  // The compile unit.
+  std::string CWD;                      // Current working directory.
 
   // Current GCC lexical block (or enclosing FUNCTION_DECL).
   tree_node *CurrentGCCLexicalBlock;	





More information about the llvm-commits mailing list