[llvm-commits] [llvm] r77410 - in /llvm/trunk/lib/AsmParser: LLLexer.cpp LLLexer.h LLParser.cpp LLParser.h LLToken.h
Devang Patel
dpatel at apple.com
Tue Jul 28 17:34:03 PDT 2009
Author: dpatel
Date: Tue Jul 28 19:34:02 2009
New Revision: 77410
URL: http://llvm.org/viewvc/llvm-project?rev=77410&view=rev
Log:
Parse named metadata.
Modified:
llvm/trunk/lib/AsmParser/LLLexer.cpp
llvm/trunk/lib/AsmParser/LLLexer.h
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/AsmParser/LLParser.h
llvm/trunk/lib/AsmParser/LLToken.h
Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=77410&r1=77409&r2=77410&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLLexer.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLLexer.cpp Tue Jul 28 19:34:02 2009
@@ -253,7 +253,7 @@
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 @@
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]+
Modified: llvm/trunk/lib/AsmParser/LLLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.h?rev=77410&r1=77409&r2=77410&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLLexer.h (original)
+++ llvm/trunk/lib/AsmParser/LLLexer.h Tue Jul 28 19:34:02 2009
@@ -75,6 +75,7 @@
lltok::Kind LexDigitOrNegative();
lltok::Kind LexPositive();
lltok::Kind LexAt();
+ lltok::Kind LexMetadata();
lltok::Kind LexPercent();
lltok::Kind LexQuote();
lltok::Kind Lex0x();
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=77410&r1=77409&r2=77410&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Tue Jul 28 19:34:02 2009
@@ -121,6 +121,7 @@
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 @@
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() {
Modified: llvm/trunk/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=77410&r1=77409&r2=77410&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.h (original)
+++ llvm/trunk/lib/AsmParser/LLParser.h Tue Jul 28 19:34:02 2009
@@ -148,6 +148,7 @@
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);
Modified: llvm/trunk/lib/AsmParser/LLToken.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLToken.h?rev=77410&r1=77409&r2=77410&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLToken.h (original)
+++ llvm/trunk/lib/AsmParser/LLToken.h Tue Jul 28 19:34:02 2009
@@ -125,6 +125,7 @@
GlobalVar, // @foo @"foo"
LocalVar, // %foo %"foo"
StringConstant, // "foo"
+ NamedMD, // !foo
// Metadata valued tokens.
Metadata, // !"foo" !{i8 42}
More information about the llvm-commits
mailing list