<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 12, 2015 at 7:12 PM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
> On 2015-Feb-12, at 18:44, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Thu, Feb 12, 2015 at 6:38 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>> wrote:<br>
><br>
> > On 2015-Feb-12, at 18:35, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
> ><br>
> ><br>
> ><br>
> > On Thu, Feb 12, 2015 at 5:17 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>> wrote:<br>
> > Author: dexonsmith<br>
> > Date: Thu Feb 12 19:17:35 2015<br>
> > New Revision: 229006<br>
> ><br>
> > URL: <a href="http://llvm.org/viewvc/llvm-project?rev=229006&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=229006&view=rev</a><br>
> > Log:<br>
> > AsmWriter: MDBasicType: Recognize DW_ATE in 'encoding'<br>
> ><br>
> > Modified:<br>
> > llvm/trunk/lib/AsmParser/LLLexer.cpp<br>
> > llvm/trunk/lib/AsmParser/LLParser.cpp<br>
> > llvm/trunk/lib/AsmParser/LLToken.h<br>
> > llvm/trunk/lib/IR/AsmWriter.cpp<br>
> > llvm/trunk/test/Assembler/debug-info.ll<br>
> > llvm/trunk/utils/vim/llvm.vim<br>
> ><br>
> > Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp<br>
> > URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=229006&r1=229005&r2=229006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=229006&r1=229005&r2=229006&view=diff</a><br>
> > ==============================================================================<br>
> > --- llvm/trunk/lib/AsmParser/LLLexer.cpp (original)<br>
> > +++ llvm/trunk/lib/AsmParser/LLLexer.cpp Thu Feb 12 19:17:35 2015<br>
> > @@ -738,11 +738,15 @@ lltok::Kind LLLexer::LexIdentifier() {<br>
> > INSTKEYWORD(landingpad, LandingPad);<br>
> > #undef INSTKEYWORD<br>
> ><br>
> > - if (Len >= strlen("DW_TAG_") &&<br>
> > - !memcmp(StartChar, "DW_TAG_", strlen("DW_TAG_"))) {<br>
> > - StrVal.assign(StartChar, CurPtr);<br>
> > - return lltok::DwarfTag;<br>
> > +#define DWKEYWORD(TYPE, TOKEN) \<br>
> > + if (Len >= strlen("DW_" #TYPE "_") && \<br>
> > + !memcmp(StartChar, "DW_" #TYPE "_", strlen("DW_" #TYPE "_"))) { \<br>
> ><br>
> > No chance this could be done with a StringSwitch, I guess?<br>
> ><br>
><br>
> Doesn't seem to be the style in this file... but looking at it, I'm not<br>
> sure it would be cleaner anyway.<br>
><br>
> How would you handle the `StrVal.assign()`, which only happens for some<br>
> tokens? (Happens for all of the `DWKEYWORD` tokens of course, but if<br>
> I change `DWKEYWORD` I should find something relevant for the rest of<br>
> `LexIdentifier()` probably.)<br>
><br>
> I was just looking at/suggesting for the DWKEYWORD case<br>
</div></div>ah<br>
<span class=""><br>
> , but if there's only the two, that might not be worth much (or did you add a bunch more for the other enums along the way?)<br>
<br>
</span>There are eventually 5.<br>
<br>
I don't think `StringSwitch` helps here, though. It doesn't handle<br>
`startswith()` cases, right?<br>
<span class=""><br>
> This code just generally seems a bit weirdly low-level... why aren't we just using StringRef::operator== for these comparisons at least, even if StringSwitch doesn't fit?<br>
<br>
</span>Yeah, it is weirdly low-level. Probably predates `StringRef`. Might<br>
be worth someone going through and updating the whole function. I'll<br>
try to circle back to that.<br>
<br>
(It's `StringRef::startswith()` that's relevant in this macro, though.)<br></blockquote><div><br>Hmm, rightio - little lost on me, clearly.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
><br>
><br>
> ><br>
> > + StrVal.assign(StartChar, CurPtr); \<br>
> > + return lltok::TOKEN; \<br>
> > }<br>
> > + DWKEYWORD(TAG, DwarfTag);<br>
> > + DWKEYWORD(ATE, DwarfAttEncoding);<br>
> > +#undef DWKEYWORD<br>
> ><br>
> > // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by<br>
> > // the CFE to avoid forcing it to deal with 64-bit numbers.<br>
> ><br>
> > Modified: llvm/trunk/lib/AsmParser/LLParser.cpp<br>
> > URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=229006&r1=229005&r2=229006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=229006&r1=229005&r2=229006&view=diff</a><br>
> > ==============================================================================<br>
> > --- llvm/trunk/lib/AsmParser/LLParser.cpp (original)<br>
> > +++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Feb 12 19:17:35 2015<br>
> > @@ -2946,6 +2946,9 @@ struct ColumnField : public MDUnsignedFi<br>
> > struct DwarfTagField : public MDUnsignedField {<br>
> > DwarfTagField() : MDUnsignedField(0, dwarf::DW_TAG_hi_user) {}<br>
> > };<br>
> > +struct DwarfAttEncodingField : public MDUnsignedField {<br>
> > + DwarfAttEncodingField() : MDUnsignedField(0, dwarf::DW_ATE_hi_user) {}<br>
> > +};<br>
> ><br>
> > struct MDSignedField : public MDFieldImpl<int64_t> {<br>
> > int64_t Min;<br>
> > @@ -3016,6 +3019,25 @@ bool LLParser::ParseMDField(LocTy Loc, S<br>
> ><br>
> > template <><br>
> > bool LLParser::ParseMDField(LocTy Loc, StringRef Name,<br>
> > + DwarfAttEncodingField &Result) {<br>
> > + if (Lex.getKind() == lltok::APSInt)<br>
> > + return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));<br>
> > +<br>
> > + if (Lex.getKind() != lltok::DwarfAttEncoding)<br>
> > + return TokError("expected DWARF type attribute encoding");<br>
> > +<br>
> > + unsigned Encoding = dwarf::getAttributeEncoding(Lex.getStrVal());<br>
> > + if (!Encoding)<br>
> > + return TokError("invalid DWARF type attribute encoding" + Twine(" '") +<br>
> > + Lex.getStrVal() + "'");<br>
> > + assert(Encoding <= Result.Max && "Expected valid DWARF language");<br>
> > + Result.assign(Encoding);<br>
> > + Lex.Lex();<br>
> > + return false;<br>
> > +}<br>
> > +<br>
> > +template <><br>
> > +bool LLParser::ParseMDField(LocTy Loc, StringRef Name,<br>
> > MDSignedField &Result) {<br>
> > if (Lex.getKind() != lltok::APSInt)<br>
> > return TokError("expected signed integer");<br>
> > @@ -3202,7 +3224,7 @@ bool LLParser::ParseMDBasicType(MDNode *<br>
> > OPTIONAL(name, MDStringField, ); \<br>
> > OPTIONAL(size, MDUnsignedField, (0, UINT32_MAX)); \<br>
> > OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \<br>
> > - OPTIONAL(encoding, MDUnsignedField, (0, UINT32_MAX));<br>
> > + OPTIONAL(encoding, DwarfAttEncodingField, );<br>
> > PARSE_MD_FIELDS();<br>
> > #undef VISIT_MD_FIELDS<br>
> ><br>
> ><br>
> > Modified: llvm/trunk/lib/AsmParser/LLToken.h<br>
> > URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLToken.h?rev=229006&r1=229005&r2=229006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLToken.h?rev=229006&r1=229005&r2=229006&view=diff</a><br>
> > ==============================================================================<br>
> > --- llvm/trunk/lib/AsmParser/LLToken.h (original)<br>
> > +++ llvm/trunk/lib/AsmParser/LLToken.h Thu Feb 12 19:17:35 2015<br>
> > @@ -199,6 +199,7 @@ namespace lltok {<br>
> > MetadataVar, // !foo<br>
> > StringConstant, // "foo"<br>
> > DwarfTag, // DW_TAG_foo (includes "DW_TAG_")<br>
> > + DwarfAttEncoding, // DW_ATE_foo (includes "DW_ATE_")<br>
> ><br>
> > // Type valued tokens (TyVal).<br>
> > Type,<br>
> ><br>
> > Modified: llvm/trunk/lib/IR/AsmWriter.cpp<br>
> > URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=229006&r1=229005&r2=229006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=229006&r1=229005&r2=229006&view=diff</a><br>
> > ==============================================================================<br>
> > --- llvm/trunk/lib/IR/AsmWriter.cpp (original)<br>
> > +++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Feb 12 19:17:35 2015<br>
> > @@ -1377,8 +1377,13 @@ static void writeMDBasicType(raw_ostream<br>
> > Out << FS << "size: " << N->getSizeInBits();<br>
> > if (N->getAlignInBits())<br>
> > Out << FS << "align: " << N->getAlignInBits();<br>
> > - if (N->getEncoding())<br>
> > - Out << FS << "encoding: " << N->getEncoding();<br>
> > + if (unsigned Encoding = N->getEncoding()) {<br>
> > + Out << FS << "encoding: ";<br>
> > + if (const char *S = dwarf::AttributeEncodingString(Encoding))<br>
> > + Out << S;<br>
> > + else<br>
> > + Out << Encoding;<br>
> > + }<br>
> > Out << ")";<br>
> > }<br>
> ><br>
> ><br>
> > Modified: llvm/trunk/test/Assembler/debug-info.ll<br>
> > URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/debug-info.ll?rev=229006&r1=229005&r2=229006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/debug-info.ll?rev=229006&r1=229005&r2=229006&view=diff</a><br>
> > ==============================================================================<br>
> > --- llvm/trunk/test/Assembler/debug-info.ll (original)<br>
> > +++ llvm/trunk/test/Assembler/debug-info.ll Thu Feb 12 19:17:35 2015<br>
> > @@ -20,10 +20,10 @@<br>
> > !5 = !MDEnumerator(value: -8, name: "negeight")<br>
> > !6 = !MDEnumerator(value: 0, name: "")<br>
> ><br>
> > -; CHECK-NEXT: !6 = !MDBasicType(tag: DW_TAG_base_type, name: "name", size: 1, align: 2, encoding: 3)<br>
> > +; CHECK-NEXT: !6 = !MDBasicType(tag: DW_TAG_base_type, name: "name", size: 1, align: 2, encoding: DW_ATE_unsigned_char)<br>
> > ; CHECK-NEXT: !7 = !MDBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")<br>
> > ; CHECK-NEXT: !8 = !MDBasicType(tag: DW_TAG_base_type)<br>
> > -!7 = !MDBasicType(tag: DW_TAG_base_type, name: "name", size: 1, align: 2, encoding: 3)<br>
> > +!7 = !MDBasicType(tag: DW_TAG_base_type, name: "name", size: 1, align: 2, encoding: DW_ATE_unsigned_char)<br>
> > !8 = !MDBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")<br>
> > !9 = !MDBasicType(tag: DW_TAG_base_type)<br>
> > !10 = !MDBasicType(tag: DW_TAG_base_type, name: "", size: 0, align: 0, encoding: 0)<br>
> ><br>
> > Modified: llvm/trunk/utils/vim/llvm.vim<br>
> > URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/vim/llvm.vim?rev=229006&r1=229005&r2=229006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/vim/llvm.vim?rev=229006&r1=229005&r2=229006&view=diff</a><br>
> > ==============================================================================<br>
> > --- llvm/trunk/utils/vim/llvm.vim (original)<br>
> > +++ llvm/trunk/utils/vim/llvm.vim Thu Feb 12 19:17:35 2015<br>
> > @@ -78,6 +78,7 @@ syn match llvmIdentifier /![-a-zA-Z$._<br>
> > syn match llvmIdentifier /![-a-zA-Z$._][-a-zA-Z$._0-9]*\ze\s*[=!]/<br>
> > syn match llvmType /!\zs\a\+\ze\s*(/<br>
> > syn match llvmConstant /\<DW_TAG_[a-z_]\+\>/<br>
> > +syn match llvmConstant /\<DW_ATE_[a-zA-Z_]\+\>/<br>
> ><br>
> > " Syntax-highlight dejagnu test commands.<br>
> > syn match llvmSpecialComment /;\s*RUN:.*$/<br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > llvm-commits mailing list<br>
> > <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br>
</div></div></blockquote></div><br></div></div>