diff options
author | Devang Patel <dpatel@apple.com> | 2009-07-29 00:34:02 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2009-07-29 00:34:02 +0000 |
commit | eff2ab61b5d411fe64ba601d402b7c549644b590 (patch) | |
tree | 9ae0776e9d9fe6b7bb3aed32ed6ab3104d00e5c5 /lib/AsmParser | |
parent | f457d1316dec017cf204b54524878310c356bf64 (diff) | |
download | llvm-eff2ab61b5d411fe64ba601d402b7c549644b590.tar.gz llvm-eff2ab61b5d411fe64ba601d402b7c549644b590.tar.bz2 llvm-eff2ab61b5d411fe64ba601d402b7c549644b590.tar.xz |
Parse named metadata.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77410 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser')
-rw-r--r-- | lib/AsmParser/LLLexer.cpp | 18 | ||||
-rw-r--r-- | lib/AsmParser/LLLexer.h | 1 | ||||
-rw-r--r-- | lib/AsmParser/LLParser.cpp | 36 | ||||
-rw-r--r-- | lib/AsmParser/LLParser.h | 1 | ||||
-rw-r--r-- | lib/AsmParser/LLToken.h | 1 |
5 files changed, 56 insertions, 1 deletions
diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index c9b2821243..4a7e123093 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -253,7 +253,7 @@ lltok::Kind LLLexer::LexToken() { case ';': SkipLineComment(); return LexToken(); - case '!': return lltok::Metadata; + case '!': return LexMetadata(); case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '-': @@ -421,7 +421,23 @@ static bool JustWhitespaceNewLine(const char *&Ptr) { return false; } +/// LexMetadata: +/// !{...} +/// !42 +/// !foo +lltok::Kind LLLexer::LexMetadata() { + if (isalpha(CurPtr[0])) { + ++CurPtr; + while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' || + CurPtr[0] == '.' || CurPtr[0] == '_') + ++CurPtr; + StrVal.assign(TokStart+1, CurPtr); // Skip ! + return lltok::NamedMD; + } + return lltok::Metadata; +} + /// LexIdentifier: Handle several related productions: /// Label [-a-zA-Z$._0-9]+: /// IntegerType i[0-9]+ diff --git a/lib/AsmParser/LLLexer.h b/lib/AsmParser/LLLexer.h index 4e05463941..de39272f45 100644 --- a/lib/AsmParser/LLLexer.h +++ b/lib/AsmParser/LLLexer.h @@ -75,6 +75,7 @@ namespace llvm { lltok::Kind LexDigitOrNegative(); lltok::Kind LexPositive(); lltok::Kind LexAt(); + lltok::Kind LexMetadata(); lltok::Kind LexPercent(); lltok::Kind LexQuote(); lltok::Kind Lex0x(); diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index b2d2b51b6c..36f714b38e 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -121,6 +121,7 @@ bool LLParser::ParseTopLevelEntities() { case lltok::LocalVar: if (ParseNamedType()) return true; break; case lltok::GlobalVar: if (ParseNamedGlobal()) return true; break; case lltok::Metadata: if (ParseStandaloneMetadata()) return true; break; + case lltok::NamedMD: if (ParseNamedMetadata()) return true; break; // The Global variable production with no name can have many different // optional leading prefixes, the production is: @@ -409,6 +410,41 @@ bool LLParser::ParseMDNode(MetadataBase *&Node) { return false; } +///ParseNamedMetadata: +/// !foo = !{ !1, !2 } +bool LLParser::ParseNamedMetadata() { + assert(Lex.getKind() == lltok::NamedMD); + Lex.Lex(); + std::string Name = Lex.getStrVal(); + + if (ParseToken(lltok::equal, "expected '=' here")) + return true; + + if (Lex.getKind() != lltok::Metadata) + return TokError("Expected '!' here"); + Lex.Lex(); + + if (Lex.getKind() != lltok::lbrace) + return TokError("Expected '{' here"); + Lex.Lex(); + SmallVector<MetadataBase *, 8> Elts; + do { + if (Lex.getKind() != lltok::Metadata) + return TokError("Expected '!' here"); + Lex.Lex(); + MetadataBase *N = 0; + if (ParseMDNode(N)) return true; + Elts.push_back(N); + } while (EatIfPresent(lltok::comma)); + + if (ParseToken(lltok::rbrace, "expected end of metadata node")) + return true; + + NamedMDNode::Create(Name.c_str(), Name.length(), + Elts.data(), Elts.size(), M); + return false; +} + /// ParseStandaloneMetadata: /// !42 = !{...} bool LLParser::ParseStandaloneMetadata() { diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h index c77ef9d6d1..40848cfe77 100644 --- a/lib/AsmParser/LLParser.h +++ b/lib/AsmParser/LLParser.h @@ -148,6 +148,7 @@ namespace llvm { bool HasLinkage, unsigned Visibility); bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility); bool ParseStandaloneMetadata(); + bool ParseNamedMetadata(); bool ParseMDString(MetadataBase *&S); bool ParseMDNode(MetadataBase *&N); diff --git a/lib/AsmParser/LLToken.h b/lib/AsmParser/LLToken.h index 75cc1db8ad..a49d05442b 100644 --- a/lib/AsmParser/LLToken.h +++ b/lib/AsmParser/LLToken.h @@ -125,6 +125,7 @@ namespace lltok { GlobalVar, // @foo @"foo" LocalVar, // %foo %"foo" StringConstant, // "foo" + NamedMD, // !foo // Metadata valued tokens. Metadata, // !"foo" !{i8 42} |