X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAsmParser%2FLLParser.cpp;h=9de1cafb5e07b205a4a8fcbb65adeab13968e00f;hb=42991eeb64ee178bd12ac243b0cfa7b3bde97f49;hp=0333eedac4d979d026c957707de9d8b47afe73c3;hpb=211a14e476abc9b864ab6a5d5e0bbb86d288b650;p=oota-llvm.git diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 0333eedac4d..9de1cafb5e0 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -18,8 +18,6 @@ #include "llvm/DerivedTypes.h" #include "llvm/InlineAsm.h" #include "llvm/Instructions.h" -#include "llvm/LLVMContext.h" -#include "llvm/Metadata.h" #include "llvm/Module.h" #include "llvm/Operator.h" #include "llvm/ValueSymbolTable.h" @@ -465,42 +463,43 @@ bool LLParser::ParseNamedGlobal() { // MDString: // ::= '!' STRINGCONSTANT -bool LLParser::ParseMDString(MetadataBase *&MDS) { +bool LLParser::ParseMDString(MDString *&Result) { std::string Str; if (ParseStringConstant(Str)) return true; - MDS = MDString::get(Context, Str); + Result = MDString::get(Context, Str); return false; } // MDNode: // ::= '!' MDNodeNumber -bool LLParser::ParseMDNode(MetadataBase *&Node) { +bool LLParser::ParseMDNode(MDNode *&Result) { // !{ ..., !42, ... } unsigned MID = 0; - if (ParseUInt32(MID)) return true; + if (ParseUInt32(MID)) return true; // Check existing MDNode. - std::map::iterator I = MetadataCache.find(MID); + std::map >::iterator I = MetadataCache.find(MID); if (I != MetadataCache.end()) { - Node = cast(I->second); + Result = I->second; return false; } // Check known forward references. - std::map >::iterator + std::map, LocTy> >::iterator FI = ForwardRefMDNodes.find(MID); if (FI != ForwardRefMDNodes.end()) { - Node = cast(FI->second.first); + Result = FI->second.first; return false; } - // Create MDNode forward reference - SmallVector Elts; + // Create MDNode forward reference. + + // FIXME: This is not unique enough! std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID); - Elts.push_back(MDString::get(Context, FwdRefName)); - MDNode *FwdNode = MDNode::get(Context, Elts.data(), Elts.size()); + Value *V = MDString::get(Context, FwdRefName)); + MDNode *FwdNode = MDNode::get(Context, &V, 1); ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc()); - Node = FwdNode; + Result = FwdNode; return false; } @@ -523,10 +522,12 @@ bool LLParser::ParseNamedMetadata() { Lex.Lex(); SmallVector Elts; do { - if (Lex.getKind() != lltok::Metadata) - return TokError("Expected '!' here"); + if (ParseToken(lltok::Metadata, "Expected '!' here")) + return true; Lex.Lex(); - MetadataBase *N = 0; + + // FIXME: This rejects MDStrings. Are they legal in an named MDNode or not? + MDNode *N = 0; if (ParseMDNode(N)) return true; Elts.push_back(N); } while (EatIfPresent(lltok::comma)); @@ -546,7 +547,7 @@ bool LLParser::ParseStandaloneMetadata() { unsigned MetadataID = 0; if (ParseUInt32(MetadataID)) return true; - if (MetadataCache.find(MetadataID) != MetadataCache.end()) + if (MetadataCache.count(MetadataID)) return TokError("Metadata id is already used"); if (ParseToken(lltok::equal, "expected '=' here")) return true; @@ -563,6 +564,7 @@ bool LLParser::ParseStandaloneMetadata() { if (Lex.getKind() != lltok::lbrace) return TokError("Expected '{' here"); + // FIXME: This doesn't make sense here. SmallVector Elts; if (ParseMDNodeVector(Elts) || ParseToken(lltok::rbrace, "expected end of metadata node")) @@ -570,11 +572,10 @@ bool LLParser::ParseStandaloneMetadata() { MDNode *Init = MDNode::get(Context, Elts.data(), Elts.size()); MetadataCache[MetadataID] = Init; - std::map >::iterator + std::map, LocTy> >::iterator FI = ForwardRefMDNodes.find(MetadataID); if (FI != ForwardRefMDNodes.end()) { - MDNode *FwdNode = cast(FI->second.first); - FwdNode->replaceAllUsesWith(Init); + FI->second.first->replaceAllUsesWith(Init); ForwardRefMDNodes.erase(FI); } @@ -601,14 +602,16 @@ bool LLParser::ParseInlineMetadata(Value *&V, PerFunctionState &PFS) { return false; } + // FIXME: This can't possibly work at all. r90497 + // Standalone metadata reference // !{ ..., !42, ... } - if (!ParseMDNode((MetadataBase *&)V)) + if (!ParseMDNode((MDNode *&)V)) return false; // MDString: // '!' STRINGCONSTANT - if (ParseMDString((MetadataBase *&)V)) return true; + if (ParseMDString((MDString *&)V)) return true; return false; } @@ -1107,28 +1110,33 @@ bool LLParser::ParseOptionalCallingConv(CallingConv::ID &CC) { /// ParseOptionalCustomMetadata /// ::= /* empty */ -/// ::= !dbg !42 +/// ::= !dbg !42 (',' !dbg !57)* bool LLParser::ParseOptionalCustomMetadata() { if (Lex.getKind() != lltok::NamedOrCustomMD) return false; - std::string Name = Lex.getStrVal(); - Lex.Lex(); + while (1) { + std::string Name = Lex.getStrVal(); + Lex.Lex(); - if (Lex.getKind() != lltok::Metadata) - return TokError("Expected '!' here"); - Lex.Lex(); + if (Lex.getKind() != lltok::Metadata) + return TokError("expected '!' here"); + Lex.Lex(); - MetadataBase *Node; - if (ParseMDNode(Node)) return true; + MDNode *Node; + if (ParseMDNode(Node)) return true; - MetadataContext &TheMetadata = M->getContext().getMetadata(); - unsigned MDK = TheMetadata.getMDKind(Name.c_str()); - if (!MDK) - MDK = TheMetadata.registerMDKind(Name.c_str()); - MDsOnInst.push_back(std::make_pair(MDK, cast(Node))); + unsigned MDK = M->getMDKindID(Name.c_str()); + MDsOnInst.push_back(std::make_pair(MDK, Node)); - return false; + // If this is the end of the list, we're done. + if (!EatIfPresent(lltok::comma)) + return false; + + // The next value must be a custom metadata id. + if (Lex.getKind() != lltok::NamedOrCustomMD) + return TokError("expected more custom metadata ids"); + } } /// ParseOptionalAlignment @@ -1213,7 +1221,7 @@ PATypeHolder LLParser::HandleUpRefs(const Type *ty) { PATypeHolder Ty(ty); #if 0 - errs() << "Type '" << Ty->getDescription() + dbgs() << "Type '" << Ty->getDescription() << "' newly formed. Resolving upreferences.\n" << UpRefs.size() << " upreferences active!\n"; #endif @@ -1231,7 +1239,7 @@ PATypeHolder LLParser::HandleUpRefs(const Type *ty) { UpRefs[i].LastContainedTy) != Ty->subtype_end(); #if 0 - errs() << " UR#" << i << " - TypeContains(" << Ty->getDescription() << ", " + dbgs() << " UR#" << i << " - TypeContains(" << Ty->getDescription() << ", " << UpRefs[i].LastContainedTy->getDescription() << ") = " << (ContainsType ? "true" : "false") << " level=" << UpRefs[i].NestingLevel << "\n"; @@ -1248,7 +1256,7 @@ PATypeHolder LLParser::HandleUpRefs(const Type *ty) { continue; #if 0 - errs() << " * Resolving upreference for " << UpRefs[i].UpRefTy << "\n"; + dbgs() << " * Resolving upreference for " << UpRefs[i].UpRefTy << "\n"; #endif if (!TypeToResolve) TypeToResolve = UpRefs[i].UpRefTy; @@ -1934,6 +1942,8 @@ bool LLParser::ParseValID(ValID &ID) { case lltok::Metadata: { // !{...} MDNode, !"foo" MDString ID.Kind = ValID::t_Metadata; Lex.Lex(); + + // FIXME: This doesn't belong here. if (Lex.getKind() == lltok::lbrace) { SmallVector Elts; if (ParseMDNodeVector(Elts) || @@ -1946,12 +1956,13 @@ bool LLParser::ParseValID(ValID &ID) { // Standalone metadata reference // !{ ..., !42, ... } - if (!ParseMDNode(ID.MetadataVal)) + // FIXME: Split MetadataVal into one for MDNode and one for MDString. + if (!ParseMDNode((MDNode*&)ID.MetadataVal)) return false; // MDString: // ::= '!' STRINGCONSTANT - if (ParseMDString(ID.MetadataVal)) return true; + if (ParseMDString((MDString*&)ID.MetadataVal)) return true; ID.Kind = ValID::t_Metadata; return false; } @@ -2829,10 +2840,9 @@ bool LLParser::ParseBasicBlock(PerFunctionState &PFS) { ParseOptionalCustomMetadata(); // Set metadata attached with this instruction. - MetadataContext &TheMetadata = M->getContext().getMetadata(); for (SmallVector, 2>::iterator MDI = MDsOnInst.begin(), MDE = MDsOnInst.end(); MDI != MDE; ++MDI) - TheMetadata.addMD(MDI->first, MDI->second, Inst); + Inst->setMetadata(MDI->first, MDI->second); MDsOnInst.clear(); BB->getInstList().push_back(Inst); @@ -3015,9 +3025,9 @@ bool LLParser::ParseCmpPredicate(unsigned &P, unsigned Opc) { //===----------------------------------------------------------------------===// /// ParseRet - Parse a return instruction. -/// ::= 'ret' void (',' !dbg, !1) -/// ::= 'ret' TypeAndValue (',' !dbg, !1) -/// ::= 'ret' TypeAndValue (',' TypeAndValue)+ (',' !dbg, !1) +/// ::= 'ret' void (',' !dbg, !1)* +/// ::= 'ret' TypeAndValue (',' !dbg, !1)* +/// ::= 'ret' TypeAndValue (',' TypeAndValue)+ (',' !dbg, !1)* /// [[obsolete: LLVM 3.0]] bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS) { @@ -3038,8 +3048,8 @@ bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB, if (ParseOptionalCustomMetadata()) return true; } else { // The normal case is one return value. - // FIXME: LLVM 3.0 remove MRV support for 'ret i32 1, i32 2', requiring use - // of 'ret {i32,i32} {i32 1, i32 2}' + // FIXME: LLVM 3.0 remove MRV support for 'ret i32 1, i32 2', requiring + // use of 'ret {i32,i32} {i32 1, i32 2}' SmallVector RVs; RVs.push_back(RV); @@ -3840,6 +3850,7 @@ bool LLParser::ParseMDNodeVector(SmallVectorImpl &Elts) { Lex.Lex(); do { Value *V = 0; + // FIXME: REWRITE. if (Lex.getKind() == lltok::kw_null) { Lex.Lex(); V = 0; @@ -3848,11 +3859,11 @@ bool LLParser::ParseMDNodeVector(SmallVectorImpl &Elts) { if (ParseType(Ty)) return true; if (Lex.getKind() == lltok::Metadata) { Lex.Lex(); - MetadataBase *Node = 0; + MDNode *Node = 0; if (!ParseMDNode(Node)) V = Node; else { - MetadataBase *MDS = 0; + MDString *MDS = 0; if (ParseMDString(MDS)) return true; V = MDS; }