AsmWriter: MDBasicType: Recognize DW_ATE in 'encoding'
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 13 Feb 2015 01:17:35 +0000 (01:17 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 13 Feb 2015 01:17:35 +0000 (01:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229006 91177308-0d34-0410-b5e6-96231b3b80d8

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

index eb16608..64a67c0 100644 (file)
@@ -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 "_"))) {          \
+    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.
index 8024213..992ad10 100644 (file)
@@ -2946,6 +2946,9 @@ struct ColumnField : public MDUnsignedField {
 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;
@@ -3014,6 +3017,25 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfTagField &Result) {
   return false;
 }
 
+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) {
@@ -3202,7 +3224,7 @@ bool LLParser::ParseMDBasicType(MDNode *&Result, bool IsDistinct) {
   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
 
index 4e5af1e..65c59b5 100644 (file)
@@ -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,
index f7ed216..c2d2514 100644 (file)
@@ -1377,8 +1377,13 @@ static void writeMDBasicType(raw_ostream &Out, const MDBasicType *N,
     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 << ")";
 }
 
index 267e785..d376fea 100644 (file)
 !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)
index 57c7133..6f32864 100644 (file)
@@ -78,6 +78,7 @@ syn match   llvmIdentifier /![-a-zA-Z$._][-a-zA-Z$._0-9]*\ze\s*$/
 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:.*$/