AsmWriter/Bitcode: MDLexicalBlockFile
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 13 Feb 2015 01:30:42 +0000 (01:30 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 13 Feb 2015 01:30:42 +0000 (01:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229017 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Bitcode/LLVMBitCodes.h
lib/AsmParser/LLParser.cpp
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/IR/AsmWriter.cpp
test/Assembler/invalid-mdlexicalblockfile-missing-discriminator.ll [new file with mode: 0644]
test/Assembler/invalid-mdlexicalblockfile-missing-parent.ll [new file with mode: 0644]
test/Assembler/mdlexicalblock.ll

index b917c05..441f6d6 100644 (file)
@@ -157,7 +157,8 @@ namespace bitc {
     METADATA_SUBROUTINE_TYPE=19,  // [distinct, flags, types]
     METADATA_COMPILE_UNIT  = 20,  // [distinct, ...]
     METADATA_SUBPROGRAM    = 21,  // [distinct, ...]
-    METADATA_LEXICAL_BLOCK = 22   // [distinct, scope, file, line, column]
+    METADATA_LEXICAL_BLOCK = 22,  // [distinct, scope, file, line, column]
+    METADATA_LEXICAL_BLOCK_FILE=23// [distinct, scope, file, discriminator]
   };
 
   // The constants block (CONSTANTS_BLOCK_ID) describes emission for each
index e579b43..90a6808 100644 (file)
@@ -3482,9 +3482,21 @@ bool LLParser::ParseMDLexicalBlock(MDNode *&Result, bool IsDistinct) {
   return false;
 }
 
+/// ParseMDLexicalBlockFile:
+///   ::= !MDLexicalBlockFile(scope: !0, file: !2, discriminator: 9)
 bool LLParser::ParseMDLexicalBlockFile(MDNode *&Result, bool IsDistinct) {
-  return TokError("unimplemented parser");
+#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED)                                    \
+  REQUIRED(scope, MDField, );                                                  \
+  OPTIONAL(file, MDField, );                                                   \
+  REQUIRED(discriminator, MDUnsignedField, (0, UINT32_MAX));
+  PARSE_MD_FIELDS();
+#undef VISIT_MD_FIELDS
+
+  Result = GET_OR_DISTINCT(MDLexicalBlockFile,
+                           (Context, scope.Val, file.Val, discriminator.Val));
+  return false;
 }
+
 bool LLParser::ParseMDNamespace(MDNode *&Result, bool IsDistinct) {
   return TokError("unimplemented parser");
 }
index 22dcd2a..fa139d7 100644 (file)
@@ -1479,6 +1479,17 @@ std::error_code BitcodeReader::ParseMetadata() {
           NextMDValueNo++);
       break;
     }
+    case bitc::METADATA_LEXICAL_BLOCK_FILE: {
+      if (Record.size() != 4)
+        return Error("Invalid record");
+
+      MDValueList.AssignValue(
+          GET_OR_DISTINCT(MDLexicalBlockFile, Record[0],
+                          (Context, getMDOrNull(Record[1]),
+                           getMDOrNull(Record[2]), Record[3])),
+          NextMDValueNo++);
+      break;
+    }
     case bitc::METADATA_STRING: {
       std::string String(Record.begin(), Record.end());
       llvm::UpgradeMDStringConstant(String);
index 21dc534..4643a72 100644 (file)
@@ -993,11 +993,20 @@ static void WriteMDLexicalBlock(const MDLexicalBlock *N,
   Record.clear();
 }
 
-static void WriteMDLexicalBlockFile(const MDLexicalBlockFile *,
-                                    const ValueEnumerator &, BitstreamWriter &,
-                                    SmallVectorImpl<uint64_t> &, unsigned) {
-  llvm_unreachable("write not implemented");
+static void WriteMDLexicalBlockFile(const MDLexicalBlockFile *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->getDiscriminator());
+
+  Stream.EmitRecord(bitc::METADATA_LEXICAL_BLOCK_FILE, Record, Abbrev);
+  Record.clear();
 }
+
 static void WriteMDNamespace(const MDNamespace *, const ValueEnumerator &,
                              BitstreamWriter &, SmallVectorImpl<uint64_t> &,
                              unsigned) {
index 7baa6ed..560f71f 100644 (file)
@@ -1642,11 +1642,24 @@ static void writeMDLexicalBlock(raw_ostream &Out, const MDLexicalBlock *N,
   Out << ")";
 }
 
-static void writeMDLexicalBlockFile(raw_ostream &, const MDLexicalBlockFile *,
-                                    TypePrinting *, SlotTracker *,
-                                    const Module *) {
-  llvm_unreachable("write not implemented");
+static void writeMDLexicalBlockFile(raw_ostream &Out,
+                                    const MDLexicalBlockFile *N,
+                                    TypePrinting *TypePrinter,
+                                    SlotTracker *Machine,
+                                    const Module *Context) {
+  Out << "!MDLexicalBlockFile(";
+  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);
+  }
+  Out << FS << "discriminator: " << N->getDiscriminator();
+  Out << ")";
 }
+
 static void writeMDNamespace(raw_ostream &, const MDNamespace *, TypePrinting *,
                              SlotTracker *, const Module *) {
   llvm_unreachable("write not implemented");
diff --git a/test/Assembler/invalid-mdlexicalblockfile-missing-discriminator.ll b/test/Assembler/invalid-mdlexicalblockfile-missing-discriminator.ll
new file mode 100644 (file)
index 0000000..b71eed8
--- /dev/null
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: [[@LINE+1]]:36: error: missing required field 'discriminator'
+!0 = !MDLexicalBlockFile(scope: !{})
diff --git a/test/Assembler/invalid-mdlexicalblockfile-missing-parent.ll b/test/Assembler/invalid-mdlexicalblockfile-missing-parent.ll
new file mode 100644 (file)
index 0000000..1c901e2
--- /dev/null
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: [[@LINE+1]]:42: error: missing required field 'scope'
+!0 = !MDLexicalBlockFile(discriminator: 0)
index f41b828..78d77b4 100644 (file)
@@ -1,8 +1,8 @@
 ; 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}
+; CHECK: !named = !{!0, !1, !2, !3, !4, !4, !5, !6, !7, !7}
+!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
 
 !0 = distinct !{}
 !1 = !{!"path/to/file", !"/path/to/dir"}
 ; CHECK: !4 = !MDLexicalBlock(scope: !0)
 !4 = !MDLexicalBlock(scope: !0)
 !5 = !MDLexicalBlock(scope: !0, file: null, line: 0, column: 0)
+
+; CHECK: !5 = !MDLexicalBlockFile(scope: !3, file: !2, discriminator: 0)
+; CHECK: !6 = !MDLexicalBlockFile(scope: !3, file: !2, discriminator: 1)
+!6 = !MDLexicalBlockFile(scope: !3, file: !2, discriminator: 0)
+!7 = !MDLexicalBlockFile(scope: !3, file: !2, discriminator: 1)
+
+; CHECK: !7 = !MDLexicalBlockFile(scope: !3, discriminator: 7)
+!8 = !MDLexicalBlockFile(scope: !3, discriminator: 7)
+!9 = !MDLexicalBlockFile(scope: !3, file: null, discriminator: 7)