diff options
author | Kevin Enderby <enderby@apple.com> | 2010-07-28 20:55:35 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2010-07-28 20:55:35 +0000 |
commit | 7cbf73a73f296167b6e978dbd919ed249e88eeb5 (patch) | |
tree | e9e874037081d251472bdc3a8e21c6876d9d2623 /lib/MC/MCContext.cpp | |
parent | 329878f4ddd72c6f2d2d6acfa48d7e1447ed88c0 (diff) |
Added first bit of support for the dwarf .file directive. This patch collects
the info from the .file directive and makes file and directory tables that
will eventually be put out as part of the dwarf info in the output file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109651 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCContext.cpp')
-rw-r--r-- | lib/MC/MCContext.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 1137064253..7470e8d003 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -14,6 +14,7 @@ #include "llvm/MC/MCSectionCOFF.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCLabel.h" +#include "llvm/MC/MCDwarf.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/Twine.h" using namespace llvm; @@ -181,3 +182,63 @@ const MCSection *MCContext::getCOFFSection(StringRef Section, Entry.setValue(Result); return Result; } + +//===----------------------------------------------------------------------===// +// Dwarf Management +//===----------------------------------------------------------------------===// + +/// GetDwarfFile - takes a file name an number to place in the dwarf file and +/// directory tables. If the file number has already been allocated it is an +/// error and zero is returned and the client reports the error, else the +/// allocated file number is returned. The file numbers may be in any order. +unsigned MCContext::GetDwarfFile(StringRef FileName, unsigned FileNumber) { + // TODO: a FileNumber of zero says to use the next available file number. + // Note: in GenericAsmParser::ParseDirectiveFile() FileNumber was checked + // to not be less than one. This needs to be change to be not less than zero. + + // Make space for this FileNumber in the MCDwarfFiles vector if needed. + if (FileNumber >= MCDwarfFiles.size()) { + MCDwarfFiles.resize(FileNumber + 1); + } else { + MCDwarfFile *&ExistingFile = MCDwarfFiles[FileNumber]; + if (ExistingFile) + // It is an error to use see the same number more than once. + return 0; + } + + // Get the new MCDwarfFile slot for this FileNumber. + MCDwarfFile *&File = MCDwarfFiles[FileNumber]; + + // Separate the directory part from the basename of the FileName. + std::pair<StringRef, StringRef> Slash = FileName.rsplit('/'); + + // Find or make a entry in the MCDwarfDirs vector for this Directory. + StringRef Directory; + StringRef Name; + unsigned DirIndex; + // Capture directory name. + if (Slash.second.empty()) { + Name = Slash.first; + DirIndex = 0; // For FileNames with no directories a DirIndex of 0 is used. + } else { + Directory = Slash.first; + Name = Slash.second; + for (DirIndex = 1; DirIndex < MCDwarfDirs.size(); DirIndex++) { + std::string *&Dir = MCDwarfDirs[DirIndex]; + if (Directory == *Dir) + break; + } + if (DirIndex >= MCDwarfDirs.size()) { + MCDwarfDirs.resize(DirIndex + 1); + std::string *&NewDir = MCDwarfDirs[DirIndex]; + NewDir = new (*this) std::string(Directory); + } + } + + // Now make the MCDwarfFile entry and place it in the slot in the MCDwarfFiles + // vector. + File = new (*this) MCDwarfFile(Name, DirIndex); + + // return the allocated FileNumber. + return FileNumber; +} |