[llvm] r229007 - AsmWriter/Bitcode: MDFile
Duncan P. N. Exon Smith
dexonsmith at apple.com
Thu Feb 12 17:19:14 PST 2015
Author: dexonsmith
Date: Thu Feb 12 19:19:14 2015
New Revision: 229007
URL: http://llvm.org/viewvc/llvm-project?rev=229007&view=rev
Log:
AsmWriter/Bitcode: MDFile
Added:
llvm/trunk/test/Assembler/invalid-mdfile-missing-directory.ll
llvm/trunk/test/Assembler/invalid-mdfile-missing-filename.ll
Modified:
llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/trunk/lib/IR/AsmWriter.cpp
llvm/trunk/test/Assembler/debug-info.ll
Modified: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h?rev=229007&r1=229006&r2=229007&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Thu Feb 12 19:19:14 2015
@@ -150,7 +150,8 @@ namespace bitc {
METADATA_GENERIC_DEBUG = 12, // [distinct, tag, vers, header, n x md num]
METADATA_SUBRANGE = 13, // [distinct, count, lo]
METADATA_ENUMERATOR = 14, // [distinct, value, name?]
- METADATA_BASIC_TYPE = 15 // [distinct, tag, name, size, align, enc]
+ METADATA_BASIC_TYPE = 15, // [distinct, tag, name, size, align, enc]
+ METADATA_FILE = 16 // [distinct, filename, directory]
};
// The constants block (CONSTANTS_BLOCK_ID) describes emission for each
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=229007&r1=229006&r2=229007&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Thu Feb 12 19:19:14 2015
@@ -733,16 +733,23 @@ public:
MDTuple *getFileNode() const { return cast<MDTuple>(getOperand(0)); }
StringRef getFilename() const {
- if (auto *S = cast_or_null<MDString>(getFileNode()->getOperand(0)))
+ if (auto *S = getRawFilename())
return S->getString();
return StringRef();
}
StringRef getDirectory() const {
- if (auto *S = cast_or_null<MDString>(getFileNode()->getOperand(1)))
+ if (auto *S = getRawDirectory())
return S->getString();
return StringRef();
}
+ MDString *getRawFilename() const {
+ return cast_or_null<MDString>(getFileNode()->getOperand(0));
+ }
+ MDString *getRawDirectory() const {
+ return cast_or_null<MDString>(getFileNode()->getOperand(1));
+ }
+
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDFileKind;
}
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=229007&r1=229006&r2=229007&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Feb 12 19:19:14 2015
@@ -3242,9 +3242,20 @@ bool LLParser::ParseMDCompositeType(MDNo
bool LLParser::ParseMDSubroutineType(MDNode *&Result, bool IsDistinct) {
return TokError("unimplemented parser");
}
+
+/// ParseMDFileType:
+/// ::= !MDFileType(filename: "path/to/file", directory: "/path/to/dir")
bool LLParser::ParseMDFile(MDNode *&Result, bool IsDistinct) {
- return TokError("unimplemented parser");
+#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
+ REQUIRED(filename, MDStringField, ); \
+ REQUIRED(directory, MDStringField, );
+ PARSE_MD_FIELDS();
+#undef VISIT_MD_FIELDS
+
+ Result = GET_OR_DISTINCT(MDFile, (Context, filename.Val, directory.Val));
+ return false;
}
+
bool LLParser::ParseMDCompileUnit(MDNode *&Result, bool IsDistinct) {
return TokError("unimplemented parser");
}
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=229007&r1=229006&r2=229007&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Thu Feb 12 19:19:14 2015
@@ -1382,6 +1382,16 @@ std::error_code BitcodeReader::ParseMeta
NextMDValueNo++);
break;
}
+ case bitc::METADATA_FILE: {
+ if (Record.size() != 3)
+ return Error("Invalid record");
+
+ MDValueList.AssignValue(
+ GET_OR_DISTINCT(MDFile, Record[0], (Context, getMDString(Record[1]),
+ getMDString(Record[2]))),
+ NextMDValueNo++);
+ break;
+ }
case bitc::METADATA_STRING: {
std::string String(Record.begin(), Record.end());
llvm::UpgradeMDStringConstant(String);
Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=229007&r1=229006&r2=229007&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Thu Feb 12 19:19:14 2015
@@ -868,11 +868,18 @@ static void WriteMDSubroutineType(const
SmallVectorImpl<uint64_t> &, unsigned) {
llvm_unreachable("write not implemented");
}
-static void WriteMDFile(const MDFile *, const ValueEnumerator &,
- BitstreamWriter &, SmallVectorImpl<uint64_t> &,
- unsigned) {
- llvm_unreachable("write not implemented");
+
+static void WriteMDFile(const MDFile *N, const ValueEnumerator &VE,
+ BitstreamWriter &Stream,
+ SmallVectorImpl<uint64_t> &Record, unsigned Abbrev) {
+ Record.push_back(N->isDistinct());
+ Record.push_back(VE.getMetadataOrNullID(N->getRawFilename()));
+ Record.push_back(VE.getMetadataOrNullID(N->getRawDirectory()));
+
+ Stream.EmitRecord(bitc::METADATA_FILE, Record, Abbrev);
+ Record.clear();
}
+
static void WriteMDCompileUnit(const MDCompileUnit *, const ValueEnumerator &,
BitstreamWriter &, SmallVectorImpl<uint64_t> &,
unsigned) {
Modified: llvm/trunk/lib/IR/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=229007&r1=229006&r2=229007&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Feb 12 19:19:14 2015
@@ -1401,10 +1401,16 @@ static void writeMDSubroutineType(raw_os
const Module *) {
llvm_unreachable("write not implemented");
}
-static void writeMDFile(raw_ostream &, const MDFile *, TypePrinting *,
+
+static void writeMDFile(raw_ostream &Out, const MDFile *N, TypePrinting *,
SlotTracker *, const Module *) {
- llvm_unreachable("write not implemented");
+ Out << "!MDFile(";
+ FieldSeparator FS;
+ Out << FS << "filename: \"" << N->getFilename() << "\"";
+ Out << FS << "directory: \"" << N->getDirectory() << "\"";
+ Out << ")";
}
+
static void writeMDCompileUnit(raw_ostream &, const MDCompileUnit *,
TypePrinting *, SlotTracker *, const Module *) {
llvm_unreachable("write not implemented");
Modified: llvm/trunk/test/Assembler/debug-info.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/debug-info.ll?rev=229007&r1=229006&r2=229007&view=diff
==============================================================================
--- llvm/trunk/test/Assembler/debug-info.ll (original)
+++ llvm/trunk/test/Assembler/debug-info.ll Thu Feb 12 19:19:14 2015
@@ -1,8 +1,8 @@
; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
; RUN: verify-uselistorder %s
-; CHECK: !named = !{!0, !0, !1, !2, !3, !4, !5, !6, !7, !8, !8}
-!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10}
+; CHECK: !named = !{!0, !0, !1, !2, !3, !4, !5, !6, !7, !8, !8, !9, !10, !11, !12}
+!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12, !13, !14}
; CHECK: !0 = !MDSubrange(count: 3)
; CHECK-NEXT: !1 = !MDSubrange(count: 3, lowerBound: 4)
@@ -27,3 +27,12 @@
!8 = !MDBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
!9 = !MDBasicType(tag: DW_TAG_base_type)
!10 = !MDBasicType(tag: DW_TAG_base_type, name: "", size: 0, align: 0, encoding: 0)
+
+; CHECK-NEXT: !9 = !{!"path/to/file", !"/path/to/dir"}
+; CHECK-NEXT: !10 = !MDFile(filename: "path/to/file", directory: "/path/to/dir")
+; CHECK-NEXT: !11 = !{null, null}
+; CHECK-NEXT: !12 = !MDFile(filename: "", directory: "")
+!11 = !{!"path/to/file", !"/path/to/dir"}
+!12 = !MDFile(filename: "path/to/file", directory: "/path/to/dir")
+!13 = !{null, null}
+!14 = !MDFile(filename: "", directory: "")
Added: llvm/trunk/test/Assembler/invalid-mdfile-missing-directory.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdfile-missing-directory.ll?rev=229007&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdfile-missing-directory.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdfile-missing-directory.ll Thu Feb 12 19:19:14 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: [[@LINE+1]]:30: error: missing required field 'directory'
+!0 = !MDFile(filename: "file")
Added: llvm/trunk/test/Assembler/invalid-mdfile-missing-filename.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdfile-missing-filename.ll?rev=229007&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdfile-missing-filename.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdfile-missing-filename.ll Thu Feb 12 19:19:14 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: [[@LINE+1]]:30: error: missing required field 'filename'
+!0 = !MDFile(directory: "dir")
More information about the llvm-commits
mailing list