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
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;
}
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");
}
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);
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) {
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");
; 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)
!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: "")
--- /dev/null
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: [[@LINE+1]]:30: error: missing required field 'directory'
+!0 = !MDFile(filename: "file")
--- /dev/null
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: [[@LINE+1]]:30: error: missing required field 'filename'
+!0 = !MDFile(directory: "dir")