summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp11
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp2
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h8
-rw-r--r--llvm/lib/MC/MCAsmStreamer.cpp86
-rw-r--r--llvm/lib/MC/MCDwarf.cpp61
-rw-r--r--llvm/lib/MC/MCParser/AsmParser.cpp6
-rw-r--r--llvm/lib/MC/MCStreamer.cpp9
7 files changed, 66 insertions, 117 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 3681556ca38..2caf9c9ed27 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -476,9 +476,8 @@ DwarfDebug::getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit) {
// explicitly describe the directory of all files, never relying on the
// compilation directory.
if (!Asm->OutStreamer->hasRawTextSupport() || SingleCU)
- Asm->OutStreamer->emitDwarfFile0Directive(
- CompilationDir, FN, NewCU.getMD5AsBytes(DIUnit->getFile()),
- DIUnit->getSource(), NewCU.getUniqueID());
+ Asm->OutStreamer->getContext().setMCLineTableCompilationDir(
+ NewCU.getUniqueID(), CompilationDir);
StringRef Producer = DIUnit->getProducer();
StringRef Flags = DIUnit->getFlags();
@@ -2111,10 +2110,8 @@ void DwarfDebug::emitDebugStrDWO() {
MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) {
if (!useSplitDwarf())
return nullptr;
- const DICompileUnit *DIUnit = CU.getCUNode();
- SplitTypeUnitFileTable.maybeSetRootFile(
- DIUnit->getDirectory(), DIUnit->getFilename(),
- CU.getMD5AsBytes(DIUnit->getFile()), DIUnit->getSource());
+ if (SingleCU)
+ SplitTypeUnitFileTable.setCompilationDir(CU.getCUNode()->getDirectory());
return &SplitTypeUnitFileTable;
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 3df2894b43b..377e557f637 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -284,7 +284,7 @@ void DwarfUnit::addSectionOffset(DIE &Die, dwarf::Attribute Attribute,
addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer);
}
-MD5::MD5Result *DwarfUnit::getMD5AsBytes(const DIFile *File) const {
+MD5::MD5Result *DwarfUnit::getMD5AsBytes(const DIFile *File) {
assert(File);
Optional<DIFile::ChecksumInfo<StringRef>> Checksum = File->getChecksum();
if (!Checksum || Checksum->Kind != DIFile::CSK_MD5)
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
index 9752a961183..5de39637f52 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -306,10 +306,6 @@ public:
const MCSymbol *Label,
const MCSymbol *Sec);
- /// If the \p File has an MD5 checksum, return it as an MD5Result
- /// allocated in the MCContext.
- MD5::MD5Result *getMD5AsBytes(const DIFile *File) const;
-
protected:
~DwarfUnit();
@@ -320,6 +316,10 @@ protected:
/// create a new ID and insert it in the line table.
virtual unsigned getOrCreateSourceID(const DIFile *File) = 0;
+ /// If the \p File has an MD5 checksum, return it as an MD5Result
+ /// allocated in the MCContext.
+ MD5::MD5Result *getMD5AsBytes(const DIFile *File);
+
/// Look in the DwarfDebug map for the MDNode that corresponds to the
/// reference.
template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 0a006ecf66d..f254cb50b60 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -218,10 +218,6 @@ public:
MD5::MD5Result *Checksum = 0,
Optional<StringRef> Source = None,
unsigned CUID = 0) override;
- void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
- MD5::MD5Result *Checksum,
- Optional<StringRef> Source,
- unsigned CUID = 0) override;
void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa, unsigned Discriminator,
@@ -1080,10 +1076,21 @@ void MCAsmStreamer::EmitFileDirective(StringRef Filename) {
EmitEOL();
}
-void printDwarfFileDirective(unsigned FileNo, StringRef Directory,
- StringRef Filename, MD5::MD5Result *Checksum,
- Optional<StringRef> Source, bool UseDwarfDirectory,
- raw_svector_ostream &OS) {
+Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(
+ unsigned FileNo, StringRef Directory, StringRef Filename,
+ MD5::MD5Result *Checksum, Optional<StringRef> Source, unsigned CUID) {
+ assert(CUID == 0);
+
+ MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
+ unsigned NumFiles = Table.getMCDwarfFiles().size();
+ Expected<unsigned> FileNoOrErr =
+ Table.tryGetFile(Directory, Filename, Checksum, Source, FileNo);
+ if (!FileNoOrErr)
+ return FileNoOrErr.takeError();
+ FileNo = FileNoOrErr.get();
+ if (NumFiles == Table.getMCDwarfFiles().size())
+ return FileNo;
+
SmallString<128> FullPathName;
if (!UseDwarfDirectory && !Directory.empty()) {
@@ -1097,68 +1104,31 @@ void printDwarfFileDirective(unsigned FileNo, StringRef Directory,
}
}
- OS << "\t.file\t" << FileNo << ' ';
+ SmallString<128> Str;
+ raw_svector_ostream OS1(Str);
+ OS1 << "\t.file\t" << FileNo << ' ';
if (!Directory.empty()) {
- PrintQuotedString(Directory, OS);
- OS << ' ';
+ PrintQuotedString(Directory, OS1);
+ OS1 << ' ';
}
- PrintQuotedString(Filename, OS);
+ PrintQuotedString(Filename, OS1);
if (Checksum) {
- OS << " md5 ";
- PrintQuotedString(Checksum->digest(), OS);
+ OS1 << " md5 ";
+ PrintQuotedString(Checksum->digest(), OS1);
}
if (Source) {
- OS << " source ";
- PrintQuotedString(*Source, OS);
+ OS1 << " source ";
+ PrintQuotedString(*Source, OS1);
}
-}
-
-Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(
- unsigned FileNo, StringRef Directory, StringRef Filename,
- MD5::MD5Result *Checksum, Optional<StringRef> Source, unsigned CUID) {
- assert(CUID == 0 && "multiple CUs not supported by MCAsmStreamer");
-
- MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
- unsigned NumFiles = Table.getMCDwarfFiles().size();
- Expected<unsigned> FileNoOrErr =
- Table.tryGetFile(Directory, Filename, Checksum, Source, FileNo);
- if (!FileNoOrErr)
- return FileNoOrErr.takeError();
- FileNo = FileNoOrErr.get();
- if (NumFiles == Table.getMCDwarfFiles().size())
- return FileNo;
-
- SmallString<128> Str;
- raw_svector_ostream OS1(Str);
- printDwarfFileDirective(FileNo, Directory, Filename, Checksum, Source,
- UseDwarfDirectory, OS1);
-
- if (MCTargetStreamer *TS = getTargetStreamer())
+ if (MCTargetStreamer *TS = getTargetStreamer()) {
TS->emitDwarfFileDirective(OS1.str());
- else
+ } else {
EmitRawText(OS1.str());
+ }
return FileNo;
}
-void MCAsmStreamer::emitDwarfFile0Directive(StringRef Directory,
- StringRef Filename,
- MD5::MD5Result *Checksum,
- Optional<StringRef> Source,
- unsigned CUID) {
- assert(CUID == 0);
-
- SmallString<128> Str;
- raw_svector_ostream OS1(Str);
- printDwarfFileDirective(0, Directory, Filename, Checksum, Source,
- UseDwarfDirectory, OS1);
-
- if (MCTargetStreamer *TS = getTargetStreamer())
- TS->emitDwarfFileDirective(OS1.str());
- else
- EmitRawText(OS1.str());
-}
-
void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa,
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index ee675acd530..685b46a606d 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -346,34 +346,6 @@ void MCDwarfLineTableHeader::emitV2FileDirTables(MCStreamer *MCOS) const {
MCOS->EmitIntValue(0, 1); // Terminate the file list.
}
-static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile,
- bool HasMD5, bool HasSource,
- Optional<MCDwarfLineStr> &LineStr) {
- assert(!DwarfFile.Name.empty());
- if (LineStr)
- LineStr->emitRef(MCOS, DwarfFile.Name);
- else {
- MCOS->EmitBytes(DwarfFile.Name); // FileName and...
- MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
- }
- MCOS->EmitULEB128IntValue(DwarfFile.DirIndex); // Directory number.
- if (HasMD5) {
- MD5::MD5Result *Cksum = DwarfFile.Checksum;
- MCOS->EmitBinaryData(
- StringRef(reinterpret_cast<const char *>(Cksum->Bytes.data()),
- Cksum->Bytes.size()));
- }
- if (HasSource) {
- if (LineStr)
- LineStr->emitRef(MCOS, DwarfFile.Source.getValueOr(StringRef()));
- else {
- MCOS->EmitBytes(
- DwarfFile.Source.getValueOr(StringRef())); // Source and...
- MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
- }
- }
-}
-
void MCDwarfLineTableHeader::emitV5FileDirTables(
MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr) const {
// The directory format, which is just a list of the directory paths. In a
@@ -422,12 +394,33 @@ void MCDwarfLineTableHeader::emitV5FileDirTables(
MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
: dwarf::DW_FORM_string);
}
- // Then the counted list of files. The root file is file #0, then emit the
- // files as provide by .file directives.
- MCOS->EmitULEB128IntValue(MCDwarfFiles.size());
- emitOneV5FileEntry(MCOS, RootFile, HasMD5, HasSource, LineStr);
- for (unsigned i = 1; i < MCDwarfFiles.size(); ++i)
- emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasMD5, HasSource, LineStr);
+ // Then the list of file names. These start at 1.
+ MCOS->EmitULEB128IntValue(MCDwarfFiles.size() - 1);
+ for (unsigned i = 1; i < MCDwarfFiles.size(); ++i) {
+ assert(!MCDwarfFiles[i].Name.empty());
+ if (LineStr)
+ LineStr->emitRef(MCOS, MCDwarfFiles[i].Name);
+ else {
+ MCOS->EmitBytes(MCDwarfFiles[i].Name); // FileName and...
+ MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
+ }
+ MCOS->EmitULEB128IntValue(MCDwarfFiles[i].DirIndex); // Directory number.
+ if (HasMD5) {
+ MD5::MD5Result *Cksum = MCDwarfFiles[i].Checksum;
+ MCOS->EmitBinaryData(
+ StringRef(reinterpret_cast<const char *>(Cksum->Bytes.data()),
+ Cksum->Bytes.size()));
+ }
+ if (HasSource) {
+ if (LineStr)
+ LineStr->emitRef(MCOS, MCDwarfFiles[i].Source.getValueOr(StringRef()));
+ else {
+ MCOS->EmitBytes(
+ MCDwarfFiles[i].Source.getValueOr(StringRef())); // Source and...
+ MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
+ }
+ }
+ }
}
std::pair<MCSymbol *, MCSymbol *>
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 062c7117b68..76eef5e3725 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3258,8 +3258,8 @@ bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
FileNumber = getTok().getIntVal();
Lex();
- if (FileNumber < 0)
- return TokError("negative file number");
+ if (FileNumber < 1)
+ return TokError("file number less than one");
}
std::string Path = getTok().getString();
@@ -3338,8 +3338,6 @@ bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
// we turn off -g option, directly use the existing debug info instead.
if (getContext().getGenDwarfForAssembly())
getContext().setGenDwarfForAssembly(false);
- else if (FileNumber == 0)
- getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem, Source);
else {
Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
FileNumber, Directory, Filename, CKMem, Source);
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index eed061dcacd..bf27a0abfda 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -199,15 +199,6 @@ MCStreamer::tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
Source, CUID);
}
-void MCStreamer::emitDwarfFile0Directive(StringRef Directory,
- StringRef Filename,
- MD5::MD5Result *Checksum,
- Optional<StringRef> Source,
- unsigned CUID) {
- getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum,
- Source);
-}
-
void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa,
OpenPOWER on IntegriCloud