summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-10-17 23:05:28 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-10-17 23:05:28 +0000
commit40f8f2ff2452c32529a10ba504ba7fbecf8731cd (patch)
tree0392a1c9839e20891d21a660b8e23ceb7d2075c8 /llvm/lib/MC
parentb522550ce579b2709b4f10f20efc01f202b23975 (diff)
downloadbcm5719-llvm-40f8f2ff2452c32529a10ba504ba7fbecf8731cd.tar.gz
bcm5719-llvm-40f8f2ff2452c32529a10ba504ba7fbecf8731cd.zip
Add support for a new extension to the .file directive:
.file filenumber "directory" "filename" This removes one join+split of the directory+filename in MC internals. Because bitcode files have independent fields for directory and filenames in debug info, this patch may change the .o files written by existing .bc files. llvm-svn: 142300
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r--llvm/lib/MC/MCAsmStreamer.cpp35
-rw-r--r--llvm/lib/MC/MCContext.cpp33
-rw-r--r--llvm/lib/MC/MCLoggingStreamer.cpp8
-rw-r--r--llvm/lib/MC/MCNullStreamer.cpp3
-rw-r--r--llvm/lib/MC/MCParser/AsmParser.cpp23
-rw-r--r--llvm/lib/MC/MCPureStreamer.cpp3
-rw-r--r--llvm/lib/MC/MCStreamer.cpp3
7 files changed, 75 insertions, 33 deletions
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 3fcbb05907b..d90f7b2ad2d 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -29,6 +29,7 @@
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/PathV2.h"
#include <cctype>
using namespace llvm;
@@ -50,6 +51,7 @@ private:
unsigned ShowInst : 1;
unsigned UseLoc : 1;
unsigned UseCFI : 1;
+ unsigned UseDwarfDirectory : 1;
enum EHSymbolFlags { EHGlobal = 1,
EHWeakDefinition = 1 << 1,
@@ -63,13 +65,15 @@ private:
public:
MCAsmStreamer(MCContext &Context, formatted_raw_ostream &os,
bool isVerboseAsm, bool useLoc, bool useCFI,
+ bool useDwarfDirectory,
MCInstPrinter *printer, MCCodeEmitter *emitter,
MCAsmBackend *asmbackend,
bool showInst)
: MCStreamer(Context), OS(os), MAI(Context.getAsmInfo()),
InstPrinter(printer), Emitter(emitter), AsmBackend(asmbackend),
CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm),
- ShowInst(showInst), UseLoc(useLoc), UseCFI(useCFI) {
+ ShowInst(showInst), UseLoc(useLoc), UseCFI(useCFI),
+ UseDwarfDirectory(useDwarfDirectory) {
if (InstPrinter && IsVerboseAsm)
InstPrinter->setCommentStream(CommentStream);
}
@@ -196,7 +200,8 @@ public:
unsigned char Value = 0);
virtual void EmitFileDirective(StringRef Filename);
- virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Filename);
+ virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
+ StringRef Filename);
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa, unsigned Discriminator,
@@ -748,13 +753,27 @@ void MCAsmStreamer::EmitFileDirective(StringRef Filename) {
EmitEOL();
}
-bool MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo, StringRef Filename){
+bool MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
+ StringRef Filename) {
+ if (!UseDwarfDirectory && !Directory.empty()) {
+ if (sys::path::is_absolute(Filename))
+ return EmitDwarfFileDirective(FileNo, "", Filename);
+
+ SmallString<128> FullPathName = Directory;
+ sys::path::append(FullPathName, Filename);
+ return EmitDwarfFileDirective(FileNo, "", FullPathName);
+ }
+
if (UseLoc) {
OS << "\t.file\t" << FileNo << ' ';
+ if (!Directory.empty()) {
+ PrintQuotedString(Directory, OS);
+ OS << ' ';
+ }
PrintQuotedString(Filename, OS);
EmitEOL();
}
- return this->MCStreamer::EmitDwarfFileDirective(FileNo, Filename);
+ return this->MCStreamer::EmitDwarfFileDirective(FileNo, Directory, Filename);
}
void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
@@ -1271,9 +1290,9 @@ void MCAsmStreamer::Finish() {
MCStreamer *llvm::createAsmStreamer(MCContext &Context,
formatted_raw_ostream &OS,
bool isVerboseAsm, bool useLoc,
- bool useCFI, MCInstPrinter *IP,
- MCCodeEmitter *CE, MCAsmBackend *MAB,
- bool ShowInst) {
+ bool useCFI, bool useDwarfDirectory,
+ MCInstPrinter *IP, MCCodeEmitter *CE,
+ MCAsmBackend *MAB, bool ShowInst) {
return new MCAsmStreamer(Context, OS, isVerboseAsm, useLoc, useCFI,
- IP, CE, MAB, ShowInst);
+ useDwarfDirectory, IP, CE, MAB, ShowInst);
}
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 82690ee3b3e..9e28b8f41c6 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -248,7 +248,8 @@ const MCSection *MCContext::getCOFFSection(StringRef Section,
/// 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) {
+unsigned MCContext::GetDwarfFile(StringRef Directory, 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.
@@ -266,19 +267,21 @@ unsigned MCContext::GetDwarfFile(StringRef FileName, unsigned FileNumber) {
// 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('/');
+ if (Directory.empty()) {
+ // Separate the directory part from the basename of the FileName.
+ std::pair<StringRef, StringRef> Slash = FileName.rsplit('/');
+ Directory = Slash.second;
+ if (!Directory.empty())
+ FileName = Slash.first;
+ }
// Find or make a entry in the MCDwarfDirs vector for this 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.
+ unsigned DirIndex;
+ if (Directory.empty()) {
+ // For FileNames with no directories a DirIndex of 0 is used.
+ DirIndex = 0;
} else {
- StringRef Directory = Slash.first;
- Name = Slash.second;
DirIndex = 0;
for (unsigned End = MCDwarfDirs.size(); DirIndex < End; DirIndex++) {
if (Directory == MCDwarfDirs[DirIndex])
@@ -291,16 +294,16 @@ unsigned MCContext::GetDwarfFile(StringRef FileName, unsigned FileNumber) {
}
// 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 .
+ // directory names are stored at MCDwarfDirs[DirIndex-1] where FileNames
+ // are stored at MCDwarfFiles[FileNumber].Name .
DirIndex++;
}
// Now make the MCDwarfFile entry and place it in the slot in the MCDwarfFiles
// vector.
- char *Buf = static_cast<char *>(Allocate(Name.size()));
- memcpy(Buf, Name.data(), Name.size());
- File = new (*this) MCDwarfFile(StringRef(Buf, Name.size()), DirIndex);
+ char *Buf = static_cast<char *>(Allocate(FileName.size()));
+ memcpy(Buf, FileName.data(), FileName.size());
+ File = new (*this) MCDwarfFile(StringRef(Buf, FileName.size()), DirIndex);
// return the allocated FileNumber.
return FileNumber;
diff --git a/llvm/lib/MC/MCLoggingStreamer.cpp b/llvm/lib/MC/MCLoggingStreamer.cpp
index 3fe8ac72c8e..a7b79476767 100644
--- a/llvm/lib/MC/MCLoggingStreamer.cpp
+++ b/llvm/lib/MC/MCLoggingStreamer.cpp
@@ -208,10 +208,12 @@ public:
return Child->EmitFileDirective(Filename);
}
- virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Filename) {
+ virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
+ StringRef Filename) {
LogCall("EmitDwarfFileDirective",
- "FileNo:" + Twine(FileNo) + " Filename:" + Filename);
- return Child->EmitDwarfFileDirective(FileNo, Filename);
+ "FileNo:" + Twine(FileNo) + " Directory:" + Directory +
+ " Filename:" + Filename);
+ return Child->EmitDwarfFileDirective(FileNo, Directory, Filename);
}
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
diff --git a/llvm/lib/MC/MCNullStreamer.cpp b/llvm/lib/MC/MCNullStreamer.cpp
index a6c0adb6793..d178b507a0f 100644
--- a/llvm/lib/MC/MCNullStreamer.cpp
+++ b/llvm/lib/MC/MCNullStreamer.cpp
@@ -83,7 +83,8 @@ namespace {
unsigned char Value = 0) {}
virtual void EmitFileDirective(StringRef Filename) {}
- virtual bool EmitDwarfFileDirective(unsigned FileNo,StringRef Filename) {
+ virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
+ StringRef Filename) {
return false;
}
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 50fa4d4d7ba..4e8e15c7d6c 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -2303,7 +2303,8 @@ bool AsmParser::ParseDirectiveEndIf(SMLoc DirectiveLoc) {
}
/// ParseDirectiveFile
-/// ::= .file [number] string
+/// ::= .file [number] filename
+/// ::= .file number directory filename
bool GenericAsmParser::ParseDirectiveFile(StringRef, SMLoc DirectiveLoc) {
// FIXME: I'm not sure what this is.
int64_t FileNumber = -1;
@@ -2319,17 +2320,31 @@ bool GenericAsmParser::ParseDirectiveFile(StringRef, SMLoc DirectiveLoc) {
if (getLexer().isNot(AsmToken::String))
return TokError("unexpected token in '.file' directive");
- StringRef Filename = getTok().getString();
- Filename = Filename.substr(1, Filename.size()-2);
+ // Usually the directory and filename together, otherwise just the directory.
+ StringRef Path = getTok().getString();
+ Path = Path.substr(1, Path.size()-2);
Lex();
+ StringRef Directory;
+ StringRef Filename;
+ if (getLexer().is(AsmToken::String)) {
+ if (FileNumber == -1)
+ return TokError("explicit path specified, but no file number");
+ Filename = getTok().getString();
+ Filename = Filename.substr(1, Filename.size()-2);
+ Directory = Path;
+ Lex();
+ } else {
+ Filename = Path;
+ }
+
if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.file' directive");
if (FileNumber == -1)
getStreamer().EmitFileDirective(Filename);
else {
- if (getStreamer().EmitDwarfFileDirective(FileNumber, Filename))
+ if (getStreamer().EmitDwarfFileDirective(FileNumber, Directory, Filename))
Error(FileNumberLoc, "file number already allocated");
}
diff --git a/llvm/lib/MC/MCPureStreamer.cpp b/llvm/lib/MC/MCPureStreamer.cpp
index 086c9229bcd..1a2a92e3293 100644
--- a/llvm/lib/MC/MCPureStreamer.cpp
+++ b/llvm/lib/MC/MCPureStreamer.cpp
@@ -93,7 +93,8 @@ public:
virtual void EmitFileDirective(StringRef Filename) {
report_fatal_error("unsupported directive in pure streamer");
}
- virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Filename) {
+ virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
+ StringRef Filename) {
report_fatal_error("unsupported directive in pure streamer");
return false;
}
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 3afa22b0d0b..2a37f82a518 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -142,8 +142,9 @@ void MCStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue,
}
bool MCStreamer::EmitDwarfFileDirective(unsigned FileNo,
+ StringRef Directory,
StringRef Filename) {
- return getContext().GetDwarfFile(Filename, FileNo) == 0;
+ return getContext().GetDwarfFile(Directory, Filename, FileNo) == 0;
}
void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
OpenPOWER on IntegriCloud