[llvm] r229016 - AsmWriter/Bitcode: MDLexicalBlock
Duncan P. N. Exon Smith
dexonsmith at apple.com
Thu Feb 12 17:29:29 PST 2015
Author: dexonsmith
Date: Thu Feb 12 19:29:28 2015
New Revision: 229016
URL: http://llvm.org/viewvc/llvm-project?rev=229016&view=rev
Log:
AsmWriter/Bitcode: MDLexicalBlock
Added:
llvm/trunk/test/Assembler/invalid-mdlexicalblock-missing-parent.ll
llvm/trunk/test/Assembler/mdlexicalblock.ll
Modified:
llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.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=229016&r1=229015&r2=229016&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Thu Feb 12 19:29:28 2015
@@ -156,7 +156,8 @@ namespace bitc {
METADATA_COMPOSITE_TYPE= 18, // [distinct, ...]
METADATA_SUBROUTINE_TYPE=19, // [distinct, flags, types]
METADATA_COMPILE_UNIT = 20, // [distinct, ...]
- METADATA_SUBPROGRAM = 21 // [distinct, ...]
+ METADATA_SUBPROGRAM = 21, // [distinct, ...]
+ METADATA_LEXICAL_BLOCK = 22 // [distinct, scope, file, line, column]
};
// The constants block (CONSTANTS_BLOCK_ID) describes emission for each
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=229016&r1=229015&r2=229016&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Feb 12 19:29:28 2015
@@ -3466,9 +3466,22 @@ bool LLParser::ParseMDSubprogram(MDNode
return false;
}
+/// ParseMDLexicalBlock:
+/// ::= !MDLexicalBlock(scope: !0, file: !2, line: 7, column: 9)
bool LLParser::ParseMDLexicalBlock(MDNode *&Result, bool IsDistinct) {
- return TokError("unimplemented parser");
+#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
+ REQUIRED(scope, MDField, ); \
+ OPTIONAL(file, MDField, ); \
+ OPTIONAL(line, LineField, ); \
+ OPTIONAL(column, ColumnField, );
+ PARSE_MD_FIELDS();
+#undef VISIT_MD_FIELDS
+
+ Result = GET_OR_DISTINCT(
+ MDLexicalBlock, (Context, scope.Val, file.Val, line.Val, column.Val));
+ return false;
}
+
bool LLParser::ParseMDLexicalBlockFile(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=229016&r1=229015&r2=229016&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Thu Feb 12 19:29:28 2015
@@ -1468,6 +1468,17 @@ std::error_code BitcodeReader::ParseMeta
NextMDValueNo++);
break;
}
+ case bitc::METADATA_LEXICAL_BLOCK: {
+ if (Record.size() != 5)
+ return Error("Invalid record");
+
+ MDValueList.AssignValue(
+ GET_OR_DISTINCT(MDLexicalBlock, Record[0],
+ (Context, getMDOrNull(Record[1]),
+ getMDOrNull(Record[2]), 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=229016&r1=229015&r2=229016&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Thu Feb 12 19:29:28 2015
@@ -978,11 +978,21 @@ static void WriteMDSubprogram(const MDSu
Record.clear();
}
-static void WriteMDLexicalBlock(const MDLexicalBlock *, const ValueEnumerator &,
- BitstreamWriter &, SmallVectorImpl<uint64_t> &,
- unsigned) {
- llvm_unreachable("write not implemented");
+static void WriteMDLexicalBlock(const MDLexicalBlock *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(N->getLine());
+ Record.push_back(N->getColumn());
+
+ Stream.EmitRecord(bitc::METADATA_LEXICAL_BLOCK, Record, Abbrev);
+ Record.clear();
}
+
static void WriteMDLexicalBlockFile(const MDLexicalBlockFile *,
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=229016&r1=229015&r2=229016&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Feb 12 19:29:28 2015
@@ -1623,10 +1623,25 @@ static void writeMDSubprogram(raw_ostrea
Out << ")";
}
-static void writeMDLexicalBlock(raw_ostream &, const MDLexicalBlock *,
- TypePrinting *, SlotTracker *, const Module *) {
- llvm_unreachable("write not implemented");
+static void writeMDLexicalBlock(raw_ostream &Out, const MDLexicalBlock *N,
+ TypePrinting *TypePrinter, SlotTracker *Machine,
+ const Module *Context) {
+ Out << "!MDLexicalBlock(";
+ 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->getLine())
+ Out << FS << "line: " << N->getLine();
+ if (N->getColumn())
+ Out << FS << "column: " << N->getColumn();
+ Out << ")";
}
+
static void writeMDLexicalBlockFile(raw_ostream &, const MDLexicalBlockFile *,
TypePrinting *, SlotTracker *,
const Module *) {
Added: llvm/trunk/test/Assembler/invalid-mdlexicalblock-missing-parent.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdlexicalblock-missing-parent.ll?rev=229016&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdlexicalblock-missing-parent.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdlexicalblock-missing-parent.ll Thu Feb 12 19:29:28 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: [[@LINE+1]]:29: error: missing required field 'scope'
+!0 = !MDLexicalBlock(line: 7)
Added: llvm/trunk/test/Assembler/mdlexicalblock.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/mdlexicalblock.ll?rev=229016&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/mdlexicalblock.ll (added)
+++ llvm/trunk/test/Assembler/mdlexicalblock.ll Thu Feb 12 19:29:28 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 = !MDLexicalBlock(scope: !0, file: !2, line: 7, column: 35)
+!3 = !MDLexicalBlock(scope: !0, file: !2, line: 7, column: 35)
+
+; CHECK: !4 = !MDLexicalBlock(scope: !0)
+!4 = !MDLexicalBlock(scope: !0)
+!5 = !MDLexicalBlock(scope: !0, file: null, line: 0, column: 0)
More information about the llvm-commits
mailing list