summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-03-13 19:15:04 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-03-13 19:15:04 +0000
commitb60d2ba5c499041e39b2f37c4c0cf11f3824c15f (patch)
treeca7fd741eb32f6a8dae7bc9faa8753d321f5d321 /lib
parentac01874f19fb2551f39d339fe023dca4cc58b2ea (diff)
downloadllvm-b60d2ba5c499041e39b2f37c4c0cf11f3824c15f.tar.gz
llvm-b60d2ba5c499041e39b2f37c4c0cf11f3824c15f.tar.bz2
llvm-b60d2ba5c499041e39b2f37c4c0cf11f3824c15f.tar.xz
MCDwarf: Sink file/directory creation down into MCDwarfFileTable form MCContext
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203836 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/MC/MCContext.cpp51
-rw-r--r--lib/MC/MCDwarf.cpp49
2 files changed, 50 insertions, 50 deletions
diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp
index 48cb5aae1f..6ffe25982d 100644
--- a/lib/MC/MCContext.cpp
+++ b/lib/MC/MCContext.cpp
@@ -338,56 +338,7 @@ const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) {
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
diff --git a/lib/MC/MCDwarf.cpp b/lib/MC/MCDwarf.cpp
index b0a75d5de2..5b633ebf8d 100644
--- a/lib/MC/MCDwarf.cpp
+++ b/lib/MC/MCDwarf.cpp
@@ -325,6 +325,55 @@ const MCSymbol *MCDwarfFileTable::EmitCU(MCStreamer *MCOS) const {
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) {