[llvm] r203836 - MCDwarf: Sink file/directory creation down into MCDwarfFileTable form MCContext

David Blaikie dblaikie at gmail.com
Thu Mar 13 12:15:04 PDT 2014


Author: dblaikie
Date: Thu Mar 13 14:15:04 2014
New Revision: 203836

URL: http://llvm.org/viewvc/llvm-project?rev=203836&view=rev
Log:
MCDwarf: Sink file/directory creation down into MCDwarfFileTable form MCContext

Modified:
    llvm/trunk/include/llvm/MC/MCDwarf.h
    llvm/trunk/lib/MC/MCContext.cpp
    llvm/trunk/lib/MC/MCDwarf.cpp

Modified: llvm/trunk/include/llvm/MC/MCDwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=203836&r1=203835&r2=203836&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCDwarf.h (original)
+++ llvm/trunk/include/llvm/MC/MCDwarf.h Thu Mar 13 14:15:04 2014
@@ -190,6 +190,8 @@ public:
   //
   const MCSymbol *EmitCU(MCStreamer *MCOS) const;
 
+  unsigned getFile(StringRef Directory, StringRef FileName, unsigned FileNumber);
+
   const SmallVectorImpl<std::string> &getMCDwarfDirs() const {
     return MCDwarfDirs;
   }

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=203836&r1=203835&r2=203836&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Thu Mar 13 14:15:04 2014
@@ -338,56 +338,7 @@ const MCSectionCOFF *MCContext::getCOFFS
 unsigned MCContext::GetDwarfFile(StringRef Directory, StringRef FileName,
                                  unsigned FileNumber, unsigned CUID) {
   MCDwarfFileTable &Table = MCDwarfFileTablesCUMap[CUID];
-  SmallVectorImpl<MCDwarfFile>& MCDwarfFiles = Table.getMCDwarfFiles();
-  SmallVectorImpl<std::string>& MCDwarfDirs = Table.getMCDwarfDirs();
-  // Make space for this FileNumber in the MCDwarfFiles vector if needed.
-  if (FileNumber >= MCDwarfFiles.size()) {
-    MCDwarfFiles.resize(FileNumber + 1);
-  }
-
-  // Get the new MCDwarfFile slot for this FileNumber.
-  MCDwarfFile &File = MCDwarfFiles[FileNumber];
-
-  // It is an error to use see the same number more than once.
-  if (!File.Name.empty())
-    return 0;
-
-  if (Directory.empty()) {
-    // Separate the directory part from the basename of the FileName.
-    StringRef tFileName = sys::path::filename(FileName);
-    if (!tFileName.empty()) {
-      Directory = sys::path::parent_path(FileName);
-      if (!Directory.empty())
-        FileName = tFileName;
-    }
-  }
-
-  // Find or make an entry in the MCDwarfDirs vector for this Directory.
-  // Capture directory name.
-  unsigned DirIndex;
-  if (Directory.empty()) {
-    // For FileNames with no directories a DirIndex of 0 is used.
-    DirIndex = 0;
-  } else {
-    DirIndex = 0;
-    for (unsigned End = MCDwarfDirs.size(); DirIndex < End; DirIndex++) {
-      if (Directory == MCDwarfDirs[DirIndex])
-        break;
-    }
-    if (DirIndex >= MCDwarfDirs.size())
-      MCDwarfDirs.push_back(Directory);
-    // The DirIndex is one based, as DirIndex of 0 is used for FileNames with
-    // no directories.  MCDwarfDirs[] is unlike MCDwarfFiles[] in that the
-    // directory names are stored at MCDwarfDirs[DirIndex-1] where FileNames
-    // are stored at MCDwarfFiles[FileNumber].Name .
-    DirIndex++;
-  }
-
-  File.Name = FileName;
-  File.DirIndex = DirIndex;
-
-  // return the allocated FileNumber.
-  return FileNumber;
+  return Table.getFile(Directory, FileName, FileNumber);
 }
 
 /// isValidDwarfFileNumber - takes a dwarf file number and returns true if it

Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=203836&r1=203835&r2=203836&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Thu Mar 13 14:15:04 2014
@@ -325,6 +325,55 @@ const MCSymbol *MCDwarfFileTable::EmitCU
   return LineStartSym;
 }
 
+unsigned MCDwarfFileTable::getFile(StringRef Directory, StringRef FileName, unsigned FileNumber) {
+  // Make space for this FileNumber in the MCDwarfFiles vector if needed.
+  MCDwarfFiles.resize(FileNumber + 1);
+
+  // Get the new MCDwarfFile slot for this FileNumber.
+  MCDwarfFile &File = MCDwarfFiles[FileNumber];
+
+  // It is an error to use see the same number more than once.
+  if (!File.Name.empty())
+    return 0;
+
+  if (Directory.empty()) {
+    // Separate the directory part from the basename of the FileName.
+    StringRef tFileName = sys::path::filename(FileName);
+    if (!tFileName.empty()) {
+      Directory = sys::path::parent_path(FileName);
+      if (!Directory.empty())
+        FileName = tFileName;
+    }
+  }
+
+  // Find or make an entry in the MCDwarfDirs vector for this Directory.
+  // Capture directory name.
+  unsigned DirIndex;
+  if (Directory.empty()) {
+    // For FileNames with no directories a DirIndex of 0 is used.
+    DirIndex = 0;
+  } else {
+    DirIndex = 0;
+    for (unsigned End = MCDwarfDirs.size(); DirIndex < End; DirIndex++) {
+      if (Directory == MCDwarfDirs[DirIndex])
+        break;
+    }
+    if (DirIndex >= MCDwarfDirs.size())
+      MCDwarfDirs.push_back(Directory);
+    // The DirIndex is one based, as DirIndex of 0 is used for FileNames with
+    // no directories.  MCDwarfDirs[] is unlike MCDwarfFiles[] in that the
+    // directory names are stored at MCDwarfDirs[DirIndex-1] where FileNames
+    // are stored at MCDwarfFiles[FileNumber].Name .
+    DirIndex++;
+  }
+
+  File.Name = FileName;
+  File.DirIndex = DirIndex;
+
+  // return the allocated FileNumber.
+  return FileNumber;
+}
+
 /// Utility function to emit the encoding to a streamer.
 void MCDwarfLineAddr::Emit(MCStreamer *MCOS, int64_t LineDelta,
                            uint64_t AddrDelta) {





More information about the llvm-commits mailing list