AsmParser: Recognize DW_TAG_* constants

Recognize `DW_TAG_` constants in assembly, and output it by default for
`GenericDebugNode`.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228042 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-02-03 21:56:01 +00:00
parent 6adbfa3815
commit 1602e58745
9 changed files with 57 additions and 8 deletions

View File

@@ -738,6 +738,12 @@ 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;
}
// 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.
if ((TokStart[0] == 'u' || TokStart[0] == 's') &&

View File

@@ -24,6 +24,7 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/raw_ostream.h"
@@ -2936,6 +2937,28 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
return false;
}
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfTagField &Result) {
if (Lex.getKind() == lltok::APSInt)
return ParseMDField(Loc, Name,
static_cast<MDUnsignedField<uint32_t> &>(Result));
if (Result.Seen)
return Error(Loc,
"field '" + Name + "' cannot be specified more than once");
if (Lex.getKind() != lltok::DwarfTag)
return TokError("expected DWARF tag");
unsigned Tag = dwarf::getTag(Lex.getStrVal());
if (Tag == dwarf::DW_TAG_invalid)
return TokError("invalid DWARF tag" + Twine(" '") + Lex.getStrVal() + "'");
assert(Tag < 1u << 16 && "Expected valid DWARF tag");
Result.assign(Tag);
Lex.Lex();
return false;
}
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDField &Result) {
Metadata *MD;
if (ParseMetadata(MD, nullptr))
@@ -3056,7 +3079,7 @@ bool LLParser::ParseMDLocation(MDNode *&Result, bool IsDistinct) {
/// ::= !GenericDebugNode(tag: 15, header: "...", operands: {...})
bool LLParser::ParseGenericDebugNode(MDNode *&Result, bool IsDistinct) {
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
REQUIRED(tag, MDUnsignedField<uint32_t>, (0, ~0u >> 16)); \
REQUIRED(tag, DwarfTagField, ); \
OPTIONAL(header, MDStringField, ); \
OPTIONAL(operands, MDFieldList, );
PARSE_MD_FIELDS();

View File

@@ -102,6 +102,9 @@ namespace llvm {
NumTy Max = std::numeric_limits<NumTy>::max())
: ImplTy(Default), Max(Max) {}
};
struct DwarfTagField : public MDUnsignedField<uint32_t> {
DwarfTagField() : MDUnsignedField<uint32_t>(0, ~0u >> 16) {}
};
struct MDField : public MDFieldImpl<Metadata *> {
MDField() : ImplTy(nullptr) {}
};
@@ -427,6 +430,7 @@ namespace llvm {
bool ParseMDField(LocTy Loc, StringRef Name,
MDUnsignedField<uint32_t> &Result);
bool ParseMDField(LocTy Loc, StringRef Name, DwarfTagField &Result);
bool ParseMDField(LocTy Loc, StringRef Name, MDField &Result);
bool ParseMDField(LocTy Loc, StringRef Name, MDStringField &Result);
bool ParseMDField(LocTy Loc, StringRef Name, MDFieldList &Result);

View File

@@ -198,6 +198,7 @@ namespace lltok {
LocalVar, // %foo %"foo"
MetadataVar, // !foo
StringConstant, // "foo"
DwarfTag, // DW_TAG_foo (includes "DW_TAG_")
// Type valued tokens (TyVal).
Type,