From bc721ed100e5b662790ddfc014a1bb497386a947 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 13 Jul 2004 08:28:21 +0000 Subject: [PATCH] Eliminate some mega-cruft here. There is no reason to DERIVE FROM IR CLASSES just to keep track of some per-object state! Gaah! Whoever wrote this stuff... oh wait, that would be me. Never mind. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14790 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/ParserInternals.h | 54 --------------------------------- lib/AsmParser/llvmAsmParser.y | 39 ++++++++++++++++-------- 2 files changed, 26 insertions(+), 67 deletions(-) diff --git a/lib/AsmParser/ParserInternals.h b/lib/AsmParser/ParserInternals.h index 56852ab1f38..c8d5d13c37b 100644 --- a/lib/AsmParser/ParserInternals.h +++ b/lib/AsmParser/ParserInternals.h @@ -158,60 +158,6 @@ struct ValID { } }; - - -template -class PlaceholderValue : public SuperType { - ValID D; - int LineNum; -public: - PlaceholderValue(const Type *Ty, const ValID &d) : SuperType(Ty), D(d) { - LineNum = llvmAsmlineno; - } - ValID &getDef() { return D; } - int getLineNum() const { return LineNum; } -}; - -struct InstPlaceHolderHelper : public Instruction { - InstPlaceHolderHelper(const Type *Ty) : Instruction(Ty, UserOp1, "") {} - - virtual Instruction *clone() const { abort(); return 0; } - virtual const char *getOpcodeName() const { return "placeholder"; } -}; - -struct BBPlaceHolderHelper : public BasicBlock { - BBPlaceHolderHelper(const Type *Ty) : BasicBlock() { - assert(Ty == Type::LabelTy); - } -}; - -typedef PlaceholderValue ValuePlaceHolder; -typedef PlaceholderValue BBPlaceHolder; - -static inline ValID &getValIDFromPlaceHolder(const Value *Val) { - const Type *Ty = Val->getType(); - if (isa(Ty) && - isa(cast(Ty)->getElementType())) - Ty = cast(Ty)->getElementType(); - - switch (Ty->getTypeID()) { - case Type::LabelTyID: return ((BBPlaceHolder*)Val)->getDef(); - default: return ((ValuePlaceHolder*)Val)->getDef(); - } -} - -static inline int getLineNumFromPlaceHolder(const Value *Val) { - const Type *Ty = Val->getType(); - if (isa(Ty) && - isa(cast(Ty)->getElementType())) - Ty = cast(Ty)->getElementType(); - - switch (Ty->getTypeID()) { - case Type::LabelTyID: return ((BBPlaceHolder*)Val)->getLineNum(); - default: return ((ValuePlaceHolder*)Val)->getLineNum(); - } -} - } // End llvm namespace #endif diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 9c13bcf0a67..65ba280fd53 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -69,6 +69,11 @@ static struct PerModuleInfo { std::vector Types; std::map LateResolveTypes; + /// PlaceHolderInfo - When temporary placeholder objects are created, remember + /// how they were referenced and one which line of the input they came from so + /// that we can resolve them alter and print error messages as appropriate. + std::map > PlaceHolderInfo; + // GlobalRefs - This maintains a mapping between 's and forward // references to global values. Global values may be referenced before they // are defined, and if so, the temporary object that they represent is held @@ -356,7 +361,6 @@ static Value *getValNonImprovising(const Type *Ty, const ValID &D) { return 0; } - // getVal - This function is identical to getValNonImprovising, except that if a // value is not already defined, it "improvises" by creating a placeholder var // that looks and acts just like the requested variable. When the value is @@ -373,18 +377,21 @@ static Value *getVal(const Type *Ty, const ValID &D) { // or an id number that hasn't been read yet. We may be referencing something // forward, so just create an entry to be resolved later and get to it... // - Value *d = 0; - switch (Ty->getTypeID()) { - case Type::LabelTyID: d = new BBPlaceHolder(Ty, D); break; - default: d = new ValuePlaceHolder(Ty, D); break; - } + if (Ty == Type::LabelTy) + V = new BasicBlock(); + else + V = new Argument(Ty); + + // Remember where this forward reference came from. FIXME, shouldn't we try + // to recycle these things?? + CurModule.PlaceHolderInfo.insert(std::make_pair(V, std::make_pair(D, + llvmAsmlineno))); - assert(d != 0 && "How did we not make something?"); if (inFunctionScope()) - InsertValue(d, CurFun.LateResolveValues); + InsertValue(V, CurFun.LateResolveValues); else - InsertValue(d, CurModule.LateResolveValues); - return d; + InsertValue(V, CurModule.LateResolveValues); + return V; } @@ -413,12 +420,18 @@ static void ResolveDefinitions(std::map &LateResolvers, while (!List.empty()) { Value *V = List.back(); List.pop_back(); - ValID &DID = getValIDFromPlaceHolder(V); + + std::map >::iterator PHI = + CurModule.PlaceHolderInfo.find(V); + assert(PHI != CurModule.PlaceHolderInfo.end() && "Placeholder error!"); + + ValID &DID = PHI->second.first; Value *TheRealValue = getValNonImprovising(LRI->first, DID); if (TheRealValue) { V->replaceAllUsesWith(TheRealValue); delete V; + CurModule.PlaceHolderInfo.erase(PHI); } else if (FutureLateResolvers) { // Functions have their unresolved items forwarded to the module late // resolver table @@ -427,12 +440,12 @@ static void ResolveDefinitions(std::map &LateResolvers, if (DID.Type == ValID::NameVal) ThrowException("Reference to an invalid definition: '" +DID.getName()+ "' of type '" + V->getType()->getDescription() + "'", - getLineNumFromPlaceHolder(V)); + PHI->second.second); else ThrowException("Reference to an invalid definition: #" + itostr(DID.Num) + " of type '" + V->getType()->getDescription() + "'", - getLineNumFromPlaceHolder(V)); + PHI->second.second); } } } -- 2.34.1