From: Duncan P. N. Exon Smith Date: Fri, 13 Feb 2015 01:28:16 +0000 (+0000) Subject: AsmWriter: MDSubprogram: Recognize DW_VIRTUALITY in 'virtuality' X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=4730b909f68da9853fe8a58f93f85c53dd2b1d8f AsmWriter: MDSubprogram: Recognize DW_VIRTUALITY in 'virtuality' git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229015 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index 100cb2eb1e1..63eb96324fa 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -746,6 +746,7 @@ lltok::Kind LLLexer::LexIdentifier() { } DWKEYWORD(TAG, DwarfTag); DWKEYWORD(ATE, DwarfAttEncoding); + DWKEYWORD(VIRTUALITY, DwarfVirtuality); DWKEYWORD(LANG, DwarfLang); #undef DWKEYWORD diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 9c3bb4a5836..445c7a405f7 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -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(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, ); \ diff --git a/lib/AsmParser/LLToken.h b/lib/AsmParser/LLToken.h index ae43a14201a..ff894df5db4 100644 --- a/lib/AsmParser/LLToken.h +++ b/lib/AsmParser/LLToken.h @@ -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). diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index fbc12ae7ec4..bdcf51ba49f 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -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()) diff --git a/test/Assembler/mdsubprogram.ll b/test/Assembler/mdsubprogram.ll index cbf907b6107..ba05bd21e69 100644 --- a/test/Assembler/mdsubprogram.ll +++ b/test/Assembler/mdsubprogram.ll @@ -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) diff --git a/utils/vim/llvm.vim b/utils/vim/llvm.vim index df564113185..e3e462f9a2f 100644 --- a/utils/vim/llvm.vim +++ b/utils/vim/llvm.vim @@ -80,6 +80,7 @@ syn match llvmType /!\zs\a\+\ze\s*(/ syn match llvmConstant /\/ syn match llvmConstant /\/ syn match llvmConstant /\/ +syn match llvmConstant /\/ " Syntax-highlight dejagnu test commands. syn match llvmSpecialComment /;\s*RUN:.*$/