From: Victor Hernandez Date: Thu, 3 Dec 2009 23:40:58 +0000 (+0000) Subject: Add ParseInlineMetadata() which can parses metadata that refers to an instruction... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1971556cc271710b683bc3ca8327c903791c910f;p=oota-llvm.git Add ParseInlineMetadata() which can parses metadata that refers to an instruction. Extend ParseParameterList() to use this new function so that calls to llvm.dbg.declare can pass inline metadata git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90497 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index a92dbf82a0b..193e8ddbc05 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -581,6 +581,37 @@ bool LLParser::ParseStandaloneMetadata() { return false; } +/// ParseInlineMetadata: +/// !{type %instr} +/// !{...} MDNode +/// !"foo" MDString +bool LLParser::ParseInlineMetadata(Value *&V, PerFunctionState &PFS) { + assert(Lex.getKind() == lltok::Metadata && "Only for Metadata"); + V = 0; + + Lex.Lex(); + if (Lex.getKind() == lltok::lbrace) { + Lex.Lex(); + if (ParseTypeAndValue(V, PFS) || + ParseToken(lltok::rbrace, "expected end of metadata node")) + return true; + + Value *Vals[] = { V }; + V = MDNode::get(Context, Vals, 1); + return false; + } + + // Standalone metadata reference + // !{ ..., !42, ... } + if (!ParseMDNode((MetadataBase *&)V)) + return false; + + // MDString: + // '!' STRINGCONSTANT + if (ParseMDString((MetadataBase *&)V)) return true; + return false; +} + /// ParseAlias: /// ::= GlobalVar '=' OptionalVisibility 'alias' OptionalLinkage Aliasee /// Aliasee @@ -1377,15 +1408,23 @@ bool LLParser::ParseParameterList(SmallVectorImpl &ArgList, // Parse the argument. LocTy ArgLoc; PATypeHolder ArgTy(Type::getVoidTy(Context)); - unsigned ArgAttrs1, ArgAttrs2; + unsigned ArgAttrs1 = Attribute::None; + unsigned ArgAttrs2 = Attribute::None; Value *V; - if (ParseType(ArgTy, ArgLoc) || - ParseOptionalAttrs(ArgAttrs1, 0) || - ParseValue(ArgTy, V, PFS) || - // FIXME: Should not allow attributes after the argument, remove this in - // LLVM 3.0. - ParseOptionalAttrs(ArgAttrs2, 3)) + if (ParseType(ArgTy, ArgLoc)) return true; + + if (Lex.getKind() == lltok::Metadata) { + if (ParseInlineMetadata(V, PFS)) + return true; + } else { + if (ParseOptionalAttrs(ArgAttrs1, 0) || + ParseValue(ArgTy, V, PFS) || + // FIXME: Should not allow attributes after the argument, remove this + // in LLVM 3.0. + ParseOptionalAttrs(ArgAttrs2, 3)) + return true; + } ArgList.push_back(ParamInfo(ArgLoc, V, ArgAttrs1|ArgAttrs2)); } diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h index 1112dc494c4..d14b1cb362d 100644 --- a/lib/AsmParser/LLParser.h +++ b/lib/AsmParser/LLParser.h @@ -279,7 +279,9 @@ namespace llvm { LocTy Loc; return ParseTypeAndBasicBlock(BB, Loc, PFS); } - + + bool ParseInlineMetadata(Value *&V, PerFunctionState &PFS); + struct ParamInfo { LocTy Loc; Value *V;