[llvm] r229006 - AsmWriter: MDBasicType: Recognize DW_ATE in 'encoding'
Duncan P. N. Exon Smith
dexonsmith at apple.com
Thu Feb 12 18:38:07 PST 2015
> On 2015-Feb-12, at 18:35, David Blaikie <dblaikie at gmail.com> wrote:
>
>
>
> On Thu, Feb 12, 2015 at 5:17 PM, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:
> Author: dexonsmith
> Date: Thu Feb 12 19:17:35 2015
> New Revision: 229006
>
> URL: http://llvm.org/viewvc/llvm-project?rev=229006&view=rev
> Log:
> AsmWriter: MDBasicType: Recognize DW_ATE in 'encoding'
>
> Modified:
> llvm/trunk/lib/AsmParser/LLLexer.cpp
> llvm/trunk/lib/AsmParser/LLParser.cpp
> llvm/trunk/lib/AsmParser/LLToken.h
> llvm/trunk/lib/IR/AsmWriter.cpp
> llvm/trunk/test/Assembler/debug-info.ll
> llvm/trunk/utils/vim/llvm.vim
>
> Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=229006&r1=229005&r2=229006&view=diff
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLLexer.cpp (original)
> +++ llvm/trunk/lib/AsmParser/LLLexer.cpp Thu Feb 12 19:17:35 2015
> @@ -738,11 +738,15 @@ lltok::Kind LLLexer::LexIdentifier() {
> INSTKEYWORD(landingpad, LandingPad);
> #undef INSTKEYWORD
>
> - if (Len >= strlen("DW_TAG_") &&
> - !memcmp(StartChar, "DW_TAG_", strlen("DW_TAG_"))) {
> - StrVal.assign(StartChar, CurPtr);
> - return lltok::DwarfTag;
> +#define DWKEYWORD(TYPE, TOKEN) \
> + if (Len >= strlen("DW_" #TYPE "_") && \
> + !memcmp(StartChar, "DW_" #TYPE "_", strlen("DW_" #TYPE "_"))) { \
>
> No chance this could be done with a StringSwitch, I guess?
>
Doesn't seem to be the style in this file... but looking at it, I'm not
sure it would be cleaner anyway.
How would you handle the `StrVal.assign()`, which only happens for some
tokens? (Happens for all of the `DWKEYWORD` tokens of course, but if
I change `DWKEYWORD` I should find something relevant for the rest of
`LexIdentifier()` probably.)
>
> + StrVal.assign(StartChar, CurPtr); \
> + return lltok::TOKEN; \
> }
> + DWKEYWORD(TAG, DwarfTag);
> + DWKEYWORD(ATE, DwarfAttEncoding);
> +#undef DWKEYWORD
>
> // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
> // the CFE to avoid forcing it to deal with 64-bit numbers.
>
> Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=229006&r1=229005&r2=229006&view=diff
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
> +++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Feb 12 19:17:35 2015
> @@ -2946,6 +2946,9 @@ struct ColumnField : public MDUnsignedFi
> struct DwarfTagField : public MDUnsignedField {
> DwarfTagField() : MDUnsignedField(0, dwarf::DW_TAG_hi_user) {}
> };
> +struct DwarfAttEncodingField : public MDUnsignedField {
> + DwarfAttEncodingField() : MDUnsignedField(0, dwarf::DW_ATE_hi_user) {}
> +};
>
> struct MDSignedField : public MDFieldImpl<int64_t> {
> int64_t Min;
> @@ -3016,6 +3019,25 @@ bool LLParser::ParseMDField(LocTy Loc, S
>
> template <>
> bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
> + DwarfAttEncodingField &Result) {
> + if (Lex.getKind() == lltok::APSInt)
> + return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
> +
> + if (Lex.getKind() != lltok::DwarfAttEncoding)
> + return TokError("expected DWARF type attribute encoding");
> +
> + unsigned Encoding = dwarf::getAttributeEncoding(Lex.getStrVal());
> + if (!Encoding)
> + return TokError("invalid DWARF type attribute encoding" + Twine(" '") +
> + Lex.getStrVal() + "'");
> + assert(Encoding <= Result.Max && "Expected valid DWARF language");
> + Result.assign(Encoding);
> + Lex.Lex();
> + return false;
> +}
> +
> +template <>
> +bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
> MDSignedField &Result) {
> if (Lex.getKind() != lltok::APSInt)
> return TokError("expected signed integer");
> @@ -3202,7 +3224,7 @@ bool LLParser::ParseMDBasicType(MDNode *
> OPTIONAL(name, MDStringField, ); \
> OPTIONAL(size, MDUnsignedField, (0, UINT32_MAX)); \
> OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
> - OPTIONAL(encoding, MDUnsignedField, (0, UINT32_MAX));
> + OPTIONAL(encoding, DwarfAttEncodingField, );
> PARSE_MD_FIELDS();
> #undef VISIT_MD_FIELDS
>
>
> Modified: llvm/trunk/lib/AsmParser/LLToken.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLToken.h?rev=229006&r1=229005&r2=229006&view=diff
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLToken.h (original)
> +++ llvm/trunk/lib/AsmParser/LLToken.h Thu Feb 12 19:17:35 2015
> @@ -199,6 +199,7 @@ namespace lltok {
> MetadataVar, // !foo
> StringConstant, // "foo"
> DwarfTag, // DW_TAG_foo (includes "DW_TAG_")
> + DwarfAttEncoding, // DW_ATE_foo (includes "DW_ATE_")
>
> // Type valued tokens (TyVal).
> Type,
>
> Modified: llvm/trunk/lib/IR/AsmWriter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=229006&r1=229005&r2=229006&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/AsmWriter.cpp (original)
> +++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Feb 12 19:17:35 2015
> @@ -1377,8 +1377,13 @@ static void writeMDBasicType(raw_ostream
> Out << FS << "size: " << N->getSizeInBits();
> if (N->getAlignInBits())
> Out << FS << "align: " << N->getAlignInBits();
> - if (N->getEncoding())
> - Out << FS << "encoding: " << N->getEncoding();
> + if (unsigned Encoding = N->getEncoding()) {
> + Out << FS << "encoding: ";
> + if (const char *S = dwarf::AttributeEncodingString(Encoding))
> + Out << S;
> + else
> + Out << Encoding;
> + }
> Out << ")";
> }
>
>
> Modified: llvm/trunk/test/Assembler/debug-info.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/debug-info.ll?rev=229006&r1=229005&r2=229006&view=diff
> ==============================================================================
> --- llvm/trunk/test/Assembler/debug-info.ll (original)
> +++ llvm/trunk/test/Assembler/debug-info.ll Thu Feb 12 19:17:35 2015
> @@ -20,10 +20,10 @@
> !5 = !MDEnumerator(value: -8, name: "negeight")
> !6 = !MDEnumerator(value: 0, name: "")
>
> -; CHECK-NEXT: !6 = !MDBasicType(tag: DW_TAG_base_type, name: "name", size: 1, align: 2, encoding: 3)
> +; CHECK-NEXT: !6 = !MDBasicType(tag: DW_TAG_base_type, name: "name", size: 1, align: 2, encoding: DW_ATE_unsigned_char)
> ; CHECK-NEXT: !7 = !MDBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
> ; CHECK-NEXT: !8 = !MDBasicType(tag: DW_TAG_base_type)
> -!7 = !MDBasicType(tag: DW_TAG_base_type, name: "name", size: 1, align: 2, encoding: 3)
> +!7 = !MDBasicType(tag: DW_TAG_base_type, name: "name", size: 1, align: 2, encoding: DW_ATE_unsigned_char)
> !8 = !MDBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
> !9 = !MDBasicType(tag: DW_TAG_base_type)
> !10 = !MDBasicType(tag: DW_TAG_base_type, name: "", size: 0, align: 0, encoding: 0)
>
> Modified: llvm/trunk/utils/vim/llvm.vim
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/vim/llvm.vim?rev=229006&r1=229005&r2=229006&view=diff
> ==============================================================================
> --- llvm/trunk/utils/vim/llvm.vim (original)
> +++ llvm/trunk/utils/vim/llvm.vim Thu Feb 12 19:17:35 2015
> @@ -78,6 +78,7 @@ syn match llvmIdentifier /![-a-zA-Z$._
> syn match llvmIdentifier /![-a-zA-Z$._][-a-zA-Z$._0-9]*\ze\s*[=!]/
> syn match llvmType /!\zs\a\+\ze\s*(/
> syn match llvmConstant /\<DW_TAG_[a-z_]\+\>/
> +syn match llvmConstant /\<DW_ATE_[a-zA-Z_]\+\>/
>
> " Syntax-highlight dejagnu test commands.
> syn match llvmSpecialComment /;\s*RUN:.*$/
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list