[llvm] r229018 - AsmWriter/Bitcode: MDNamespace
Duncan P. N. Exon Smith
dexonsmith at apple.com
Thu Feb 12 17:32:09 PST 2015
Author: dexonsmith
Date: Thu Feb 12 19:32:09 2015
New Revision: 229018
URL: http://llvm.org/viewvc/llvm-project?rev=229018&view=rev
Log:
AsmWriter/Bitcode: MDNamespace
Added:
llvm/trunk/test/Assembler/invalid-mdnamespace-missing-namespace.ll
llvm/trunk/test/Assembler/mdnamespace.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
Modified: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h?rev=229018&r1=229017&r2=229018&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Thu Feb 12 19:32:09 2015
@@ -158,7 +158,8 @@ namespace bitc {
METADATA_COMPILE_UNIT = 20, // [distinct, ...]
METADATA_SUBPROGRAM = 21, // [distinct, ...]
METADATA_LEXICAL_BLOCK = 22, // [distinct, scope, file, line, column]
- METADATA_LEXICAL_BLOCK_FILE=23// [distinct, scope, file, discriminator]
+ METADATA_LEXICAL_BLOCK_FILE=23,//[distinct, scope, file, discriminator]
+ METADATA_NAMESPACE = 24 // [distinct, scope, file, name, line]
};
// 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=229018&r1=229017&r2=229018&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Thu Feb 12 19:32:09 2015
@@ -1104,6 +1104,8 @@ public:
Metadata *getScope() const { return getOperand(1); }
StringRef getName() const { return getStringOperand(2); }
+ MDString *getRawName() const { return getOperandAs<MDString>(2); }
+
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDNamespaceKind;
}
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=229018&r1=229017&r2=229018&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Feb 12 19:32:09 2015
@@ -3497,9 +3497,22 @@ bool LLParser::ParseMDLexicalBlockFile(M
return false;
}
+/// ParseMDNamespace:
+/// ::= !MDNamespace(scope: !0, file: !2, name: "SomeNamespace", line: 9)
bool LLParser::ParseMDNamespace(MDNode *&Result, bool IsDistinct) {
- return TokError("unimplemented parser");
+#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
+ REQUIRED(scope, MDField, ); \
+ OPTIONAL(file, MDField, ); \
+ OPTIONAL(name, MDStringField, ); \
+ OPTIONAL(line, LineField, );
+ PARSE_MD_FIELDS();
+#undef VISIT_MD_FIELDS
+
+ Result = GET_OR_DISTINCT(MDNamespace,
+ (Context, scope.Val, file.Val, name.Val, line.Val));
+ return false;
}
+
bool LLParser::ParseMDTemplateTypeParameter(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=229018&r1=229017&r2=229018&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Thu Feb 12 19:32:09 2015
@@ -1490,6 +1490,18 @@ std::error_code BitcodeReader::ParseMeta
NextMDValueNo++);
break;
}
+ case bitc::METADATA_NAMESPACE: {
+ if (Record.size() != 5)
+ return Error("Invalid record");
+
+ MDValueList.AssignValue(
+ GET_OR_DISTINCT(MDNamespace, Record[0],
+ (Context, getMDOrNull(Record[1]),
+ getMDOrNull(Record[2]), getMDString(Record[3]),
+ Record[4])),
+ 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=229018&r1=229017&r2=229018&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Thu Feb 12 19:32:09 2015
@@ -1007,11 +1007,20 @@ static void WriteMDLexicalBlockFile(cons
Record.clear();
}
-static void WriteMDNamespace(const MDNamespace *, const ValueEnumerator &,
- BitstreamWriter &, SmallVectorImpl<uint64_t> &,
- unsigned) {
- llvm_unreachable("write not implemented");
+static void WriteMDNamespace(const MDNamespace *N, const ValueEnumerator &VE,
+ BitstreamWriter &Stream,
+ SmallVectorImpl<uint64_t> &Record,
+ unsigned Abbrev) {
+ Record.push_back(N->isDistinct());
+ Record.push_back(VE.getMetadataOrNullID(N->getScope()));
+ Record.push_back(VE.getMetadataOrNullID(N->getFile()));
+ Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
+ Record.push_back(N->getLine());
+
+ Stream.EmitRecord(bitc::METADATA_NAMESPACE, Record, Abbrev);
+ Record.clear();
}
+
static void WriteMDTemplateTypeParameter(const MDTemplateTypeParameter *,
const ValueEnumerator &,
BitstreamWriter &,
Modified: llvm/trunk/lib/IR/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=229018&r1=229017&r2=229018&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Feb 12 19:32:09 2015
@@ -1660,10 +1660,24 @@ static void writeMDLexicalBlockFile(raw_
Out << ")";
}
-static void writeMDNamespace(raw_ostream &, const MDNamespace *, TypePrinting *,
- SlotTracker *, const Module *) {
- llvm_unreachable("write not implemented");
+static void writeMDNamespace(raw_ostream &Out, const MDNamespace *N,
+ TypePrinting *TypePrinter, SlotTracker *Machine,
+ const Module *Context) {
+ Out << "!MDNamespace(";
+ FieldSeparator FS;
+ Out << FS << "scope: ";
+ writeMetadataAsOperand(Out, N->getScope(), TypePrinter, Machine, Context);
+ if (N->getFile()) {
+ Out << FS << "file: ";
+ writeMetadataAsOperand(Out, N->getFile(), TypePrinter, Machine, Context);
+ }
+ if (!N->getName().empty())
+ Out << FS << "name: \"" << N->getName() << "\"";
+ if (N->getLine())
+ Out << FS << "line: " << N->getLine();
+ Out << ")";
}
+
static void writeMDTemplateTypeParameter(raw_ostream &,
const MDTemplateTypeParameter *,
TypePrinting *, SlotTracker *,
Added: llvm/trunk/test/Assembler/invalid-mdnamespace-missing-namespace.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdnamespace-missing-namespace.ll?rev=229018&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdnamespace-missing-namespace.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdnamespace-missing-namespace.ll Thu Feb 12 19:32:09 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: [[@LINE+1]]:36: error: missing required field 'scope'
+!0 = !MDNamespace(name: "Namespace")
Added: llvm/trunk/test/Assembler/mdnamespace.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/mdnamespace.ll?rev=229018&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/mdnamespace.ll (added)
+++ llvm/trunk/test/Assembler/mdnamespace.ll Thu Feb 12 19:32:09 2015
@@ -0,0 +1,16 @@
+; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
+; RUN: verify-uselistorder %s
+
+; CHECK: !named = !{!0, !1, !2, !3, !4, !4}
+!named = !{!0, !1, !2, !3, !4, !5}
+
+!0 = distinct !{}
+!1 = !{!"path/to/file", !"/path/to/dir"}
+!2 = !MDFile(filename: "path/to/file", directory: "/path/to/dir")
+
+; CHECK: !3 = !MDNamespace(scope: !0, file: !2, name: "Namespace", line: 7)
+!3 = !MDNamespace(scope: !0, file: !2, name: "Namespace", line: 7)
+
+; CHECK: !4 = !MDNamespace(scope: !0)
+!4 = !MDNamespace(scope: !0, file: null, name: "", line: 0)
+!5 = !MDNamespace(scope: !0)
More information about the llvm-commits
mailing list