From 3845e50edea58edd0f5e0f2b732e0106b53ba279 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 12 Aug 2009 23:32:33 +0000 Subject: Extend the AsmWriter to print unnamed numbered types as "%0 = type ..." and unnamed numbered global variables as "@0 = global ...". Extend the AsmParser to recognize these forms. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78859 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/LLParser.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++--- lib/AsmParser/LLParser.h | 1 + 2 files changed, 50 insertions(+), 3 deletions(-) (limited to 'lib/AsmParser') diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index b5699ff..ab686ce 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -117,8 +117,10 @@ bool LLParser::ParseTopLevelEntities() { case lltok::kw_target: if (ParseTargetDefinition()) return true; break; case lltok::kw_deplibs: if (ParseDepLibs()) return true; break; case lltok::kw_type: if (ParseUnnamedType()) return true; break; + case lltok::LocalVarID: if (ParseUnnamedType()) return true; break; case lltok::StringConstant: // FIXME: REMOVE IN LLVM 3.0 case lltok::LocalVar: if (ParseNamedType()) return true; break; + case lltok::GlobalID: if (ParseUnnamedGlobal()) 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; @@ -236,9 +238,23 @@ bool LLParser::ParseDepLibs() { return ParseToken(lltok::rsquare, "expected ']' at end of list"); } -/// toplevelentity +/// ParseUnnamedType: /// ::= 'type' type +/// ::= LocalVarID '=' 'type' type bool LLParser::ParseUnnamedType() { + unsigned TypeID = NumberedTypes.size(); + + // Handle the LocalVarID form. + if (Lex.getKind() == lltok::LocalVarID) { + if (Lex.getUIntVal() != TypeID) + return Error(Lex.getLoc(), "type expected to be numbered '%" + + utostr(TypeID) + "'"); + Lex.Lex(); // eat LocalVarID; + + if (ParseToken(lltok::equal, "expected '=' after name")) + return true; + } + assert(Lex.getKind() == lltok::kw_type); LocTy TypeLoc = Lex.getLoc(); Lex.Lex(); // eat kw_type @@ -246,8 +262,6 @@ bool LLParser::ParseUnnamedType() { PATypeHolder Ty(Type::VoidTy); if (ParseType(Ty)) return true; - unsigned TypeID = NumberedTypes.size(); - // See if this type was previously referenced. std::map >::iterator FI = ForwardRefTypeIDs.find(TypeID); @@ -348,6 +362,38 @@ bool LLParser::ParseGlobalType(bool &IsConstant) { return false; } +/// ParseUnnamedGlobal: +/// OptionalVisibility ALIAS ... +/// OptionalLinkage OptionalVisibility ... -> global variable +/// GlobalID '=' OptionalVisibility ALIAS ... +/// GlobalID '=' OptionalLinkage OptionalVisibility ... -> global variable +bool LLParser::ParseUnnamedGlobal() { + unsigned VarID = NumberedVals.size(); + std::string Name; + LocTy NameLoc = Lex.getLoc(); + + // Handle the GlobalID form. + if (Lex.getKind() == lltok::GlobalID) { + if (Lex.getUIntVal() != VarID) + return Error(Lex.getLoc(), "variable expected to be numbered '%" + + utostr(VarID) + "'"); + Lex.Lex(); // eat GlobalID; + + if (ParseToken(lltok::equal, "expected '=' after name")) + return true; + } + + bool HasLinkage; + unsigned Linkage, Visibility; + if (ParseOptionalLinkage(Linkage, HasLinkage) || + ParseOptionalVisibility(Visibility)) + return true; + + if (HasLinkage || Lex.getKind() != lltok::kw_alias) + return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility); + return ParseAlias(Name, NameLoc, Visibility); +} + /// ParseNamedGlobal: /// GlobalVar '=' OptionalVisibility ALIAS ... /// GlobalVar '=' OptionalLinkage OptionalVisibility ... -> global variable diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h index 40848cf..4bdbbfe 100644 --- a/lib/AsmParser/LLParser.h +++ b/lib/AsmParser/LLParser.h @@ -143,6 +143,7 @@ namespace llvm { bool ParseDefine(); bool ParseGlobalType(bool &IsConstant); + bool ParseUnnamedGlobal(); bool ParseNamedGlobal(); bool ParseGlobal(const std::string &Name, LocTy Loc, unsigned Linkage, bool HasLinkage, unsigned Visibility); -- cgit v1.1