AsmWriter: MDSubprogram: Recognize DW_VIRTUALITY in 'virtuality'
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 13 Feb 2015 01:28:16 +0000 (01:28 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 13 Feb 2015 01:28:16 +0000 (01:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229015 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/LLLexer.cpp
lib/AsmParser/LLParser.cpp
lib/AsmParser/LLToken.h
lib/IR/AsmWriter.cpp
test/Assembler/mdsubprogram.ll
utils/vim/llvm.vim

index 100cb2eb1e109510fd120d6e4aaf598611cc67f4..63eb96324faaa413587f12f1974a0aba3f90ea1e 100644 (file)
@@ -746,6 +746,7 @@ lltok::Kind LLLexer::LexIdentifier() {
   }
   DWKEYWORD(TAG, DwarfTag);
   DWKEYWORD(ATE, DwarfAttEncoding);
+  DWKEYWORD(VIRTUALITY, DwarfVirtuality);
   DWKEYWORD(LANG, DwarfLang);
 #undef DWKEYWORD
 
index 9c3bb4a58364d5560ef6d29f3ccd956134d5859b..445c7a405f7752bd4ecb3d24d59fe33facb98afe 100644 (file)
@@ -2949,6 +2949,9 @@ struct DwarfTagField : public MDUnsignedField {
 struct DwarfAttEncodingField : public MDUnsignedField {
   DwarfAttEncodingField() : MDUnsignedField(0, dwarf::DW_ATE_hi_user) {}
 };
+struct DwarfVirtualityField : public MDUnsignedField {
+  DwarfVirtualityField() : MDUnsignedField(0, dwarf::DW_VIRTUALITY_max) {}
+};
 struct DwarfLangField : public MDUnsignedField {
   DwarfLangField() : MDUnsignedField(0, dwarf::DW_LANG_hi_user) {}
 };
@@ -3026,6 +3029,25 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfTagField &Result) {
   return false;
 }
 
+template <>
+bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
+                            DwarfVirtualityField &Result) {
+  if (Lex.getKind() == lltok::APSInt)
+    return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
+
+  if (Lex.getKind() != lltok::DwarfVirtuality)
+    return TokError("expected DWARF virtuality code");
+
+  unsigned Virtuality = dwarf::getVirtuality(Lex.getStrVal());
+  if (!Virtuality)
+    return TokError("invalid DWARF virtuality code" + Twine(" '") +
+                    Lex.getStrVal() + "'");
+  assert(Virtuality <= Result.Max && "Expected valid DWARF virtuality code");
+  Result.assign(Virtuality);
+  Lex.Lex();
+  return false;
+}
+
 template <>
 bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfLangField &Result) {
   if (Lex.getKind() == lltok::APSInt)
@@ -3408,7 +3430,8 @@ bool LLParser::ParseMDCompileUnit(MDNode *&Result, bool IsDistinct) {
 ///   ::= !MDSubprogram(scope: !0, name: "foo", linkageName: "_Zfoo",
 ///                     file: !1, line: 7, type: !2, isLocal: false,
 ///                     isDefinition: true, scopeLine: 8, containingType: !3,
-///                     virtuality: 2, virtualIndex: 10, flags: 11,
+///                     virtuality: DW_VIRTUALTIY_pure_virtual,
+///                     virtualIndex: 10, flags: 11,
 ///                     isOptimized: false, function: void ()* @_Z3foov,
 ///                     templateParams: !4, declaration: !5, variables: !6)
 bool LLParser::ParseMDSubprogram(MDNode *&Result, bool IsDistinct) {
@@ -3423,7 +3446,7 @@ bool LLParser::ParseMDSubprogram(MDNode *&Result, bool IsDistinct) {
   OPTIONAL(isDefinition, MDBoolField, (true));                                 \
   OPTIONAL(scopeLine, LineField, );                                            \
   OPTIONAL(containingType, MDField, );                                         \
-  OPTIONAL(virtuality, MDUnsignedField, (0, dwarf::DW_VIRTUALITY_max));        \
+  OPTIONAL(virtuality, DwarfVirtualityField, );                                \
   OPTIONAL(virtualIndex, MDUnsignedField, (0, UINT32_MAX));                    \
   OPTIONAL(flags, MDUnsignedField, (0, UINT32_MAX));                           \
   OPTIONAL(isOptimized, MDBoolField, );                                        \
index ae43a14201ac7868fe3422be463d40b564f0aaf1..ff894df5db4f7d48f19a98defe3a733f7411b6dd 100644 (file)
@@ -200,6 +200,7 @@ namespace lltok {
     StringConstant,    // "foo"
     DwarfTag,          // DW_TAG_foo (includes "DW_TAG_")
     DwarfAttEncoding,  // DW_ATE_foo (includes "DW_ATE_")
+    DwarfVirtuality,   // DW_VIRTUALITY_foo (includes "DW_VIRTUALITY_")
     DwarfLang,         // DW_LANG_foo (includes "DW_LANG_")
 
     // Type valued tokens (TyVal).
index fbc12ae7ec4e1c59c96e2d0d51cc49390b218104..bdcf51ba49ff7a9c34d70b5622e6ba73b63c8d99 100644 (file)
@@ -1588,8 +1588,13 @@ static void writeMDSubprogram(raw_ostream &Out, const MDSubprogram *N,
     writeMetadataAsOperand(Out, N->getContainingType(), TypePrinter, Machine,
                            Context);
   }
-  if (N->getVirtuality())
-    Out << FS << "virtuality: " << N->getVirtuality();
+  if (unsigned V = N->getVirtuality()) {
+    Out << FS << "virtuality: ";
+    if (const char *S = dwarf::VirtualityString(V))
+      Out << S;
+    else
+      Out << V;
+  }
   if (N->getVirtualIndex())
     Out << FS << "virtualIndex: " << N->getVirtualIndex();
   if (N->getFlags())
index cbf907b61077797ad8a1b54ccc20e7da7b35bb2f..ba05bd21e699d268b88a1a86e83d54bcd0ea558e 100644 (file)
@@ -15,12 +15,12 @@ declare void @_Z3foov()
 !6 = distinct !{}
 !7 = distinct !{}
 
-; CHECK: !8 = !MDSubprogram(scope: !0, name: "foo", linkageName: "_Zfoov", file: !2, line: 7, type: !3, isLocal: true, isDefinition: false, scopeLine: 8, containingType: !4, virtuality: 2, virtualIndex: 10, flags: 11, isOptimized: true, function: void ()* @_Z3foov, templateParams: !5, declaration: !6, variables: !7)
+; CHECK: !8 = !MDSubprogram(scope: !0, name: "foo", linkageName: "_Zfoov", file: !2, line: 7, type: !3, isLocal: true, isDefinition: false, scopeLine: 8, containingType: !4, virtuality: DW_VIRTUALITY_pure_virtual, virtualIndex: 10, flags: 11, isOptimized: true, function: void ()* @_Z3foov, templateParams: !5, declaration: !6, variables: !7)
 !8 = !MDSubprogram(scope: !0, name: "foo", linkageName: "_Zfoov",
                    file: !2, line: 7, type: !3, isLocal: true,
                    isDefinition: false, scopeLine: 8, containingType: !4,
-                   virtuality: 2, virtualIndex: 10, flags: 11,
-                   isOptimized: true, function: void ()* @_Z3foov,
+                   virtuality: DW_VIRTUALITY_pure_virtual, virtualIndex: 10,
+                   flags: 11, isOptimized: true, function: void ()* @_Z3foov,
                    templateParams: !5, declaration: !6, variables: !7)
 
 ; CHECK: !9 = !MDSubprogram(scope: null, name: "bar", isLocal: false, isDefinition: true, isOptimized: false)
index df564113185e318c38f1a3d0516e2b0bbdb88062..e3e462f9a2f5bc6d6a3b61ddef8d808264a387c3 100644 (file)
@@ -80,6 +80,7 @@ syn match   llvmType /!\zs\a\+\ze\s*(/
 syn match   llvmConstant /\<DW_TAG_[a-z_]\+\>/
 syn match   llvmConstant /\<DW_ATE_[a-zA-Z_]\+\>/
 syn match   llvmConstant /\<DW_LANG_[a-zA-Z0-9_]\+\>/
+syn match   llvmConstant /\<DW_VIRTUALITY_[a-z_]\+\>/
 
 " Syntax-highlight dejagnu test commands.
 syn match  llvmSpecialComment /;\s*RUN:.*$/