From 386a3b7b953a9de769824a7f3516d9dd3021d3e2 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 16 Oct 2001 19:54:17 +0000 Subject: [PATCH] Simplify some code Remove Method special case Fix bug exposed by this testcase: implementation void "PtrFunc2"() begin bb1: %reg = add int(int)* null, null add int (int)* %reg, null ret void end git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@852 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/ParserInternals.h | 3 -- lib/AsmParser/llvmAsmParser.y | 53 +++++++++++++++++---------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/lib/AsmParser/ParserInternals.h b/lib/AsmParser/ParserInternals.h index 6abe6083f0d..cc37bd9bf97 100644 --- a/lib/AsmParser/ParserInternals.h +++ b/lib/AsmParser/ParserInternals.h @@ -187,7 +187,6 @@ struct MethPlaceHolderHelper : public Method { typedef PlaceholderValue TypePlaceHolder; typedef PlaceholderValue ValuePlaceHolder; typedef PlaceholderValue BBPlaceHolder; -typedef PlaceholderValue MethPlaceHolder; static inline ValID &getValIDFromPlaceHolder(const Value *Val) { const Type *Ty = Val->getType(); @@ -198,7 +197,6 @@ static inline ValID &getValIDFromPlaceHolder(const Value *Val) { switch (Ty->getPrimitiveID()) { case Type::TypeTyID: return ((TypePlaceHolder*)Val)->getDef(); case Type::LabelTyID: return ((BBPlaceHolder*)Val)->getDef(); - case Type::MethodTyID: return ((MethPlaceHolder*)Val)->getDef(); default: return ((ValuePlaceHolder*)Val)->getDef(); } } @@ -212,7 +210,6 @@ static inline int getLineNumFromPlaceHolder(const Value *Val) { switch (Ty->getPrimitiveID()) { case Type::TypeTyID: return ((TypePlaceHolder*)Val)->getLineNum(); case Type::LabelTyID: return ((BBPlaceHolder*)Val)->getLineNum(); - case Type::MethodTyID: return ((MethPlaceHolder*)Val)->getLineNum(); default: return ((ValuePlaceHolder*)Val)->getLineNum(); } } diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 994c2233d2d..b45456d6096 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -28,7 +28,7 @@ #include #include // This embarasment is due to our flex lexer... -int yyerror(const char *ErrorMsg); // Forward declarations to prevent "implicit +int yyerror(const char *ErrorMsg); // Forward declarations to prevent "implicit int yylex(); // declaration" of xxx warnings. int yyparse(); @@ -49,7 +49,8 @@ string CurFilename; // when the method is completed. // typedef vector ValueList; // Numbered defs -static void ResolveDefinitions(vector &LateResolvers); +static void ResolveDefinitions(vector &LateResolvers, + vector *FutureLateResolvers = 0); static void ResolveTypes (vector > &LateResolveTypes); static struct PerModuleInfo { @@ -147,7 +148,7 @@ static struct PerMethodInfo { void MethodDone() { // If we could not resolve some blocks at parsing time (forward branches) // resolve the branches now... - ResolveDefinitions(LateResolveValues); + ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues); Values.clear(); // Clear out method local definitions Types.clear(); @@ -254,6 +255,9 @@ static Value *lookupInSymbolTable(const Type *Ty, const string &Name) { // it. Otherwise return null. // static Value *getValNonImprovising(const Type *Ty, const ValID &D) { + if (isa(Ty)) + ThrowException("Methods are not values and must be referenced as pointers"); + switch (D.Type) { case ValID::NumberVal: { // Is it a numbered definition? unsigned type = Ty->getUniqueID(); @@ -351,25 +355,16 @@ static Value *getVal(const Type *Ty, const ValID &D) { // forward, so just create an entry to be resolved later and get to it... // Value *d = 0; - vector *LateResolver = inMethodScope() ? - &CurMeth.LateResolveValues : &CurModule.LateResolveValues; - - if (isa(Ty)) - ThrowException("Methods are not values and must be referenced as pointers"); - - if (const PointerType *PTy = dyn_cast(Ty)) - if (const MethodType *MTy = dyn_cast(PTy->getValueType())) - Ty = MTy; // Convert pointer to method to method type - switch (Ty->getPrimitiveID()) { case Type::LabelTyID: d = new BBPlaceHolder(Ty, D); break; - case Type::MethodTyID: d = new MethPlaceHolder(Ty, D); - LateResolver = &CurModule.LateResolveValues; break; default: d = new ValuePlaceHolder(Ty, D); break; } assert(d != 0 && "How did we not make something?"); - InsertValue(d, *LateResolver); + if (inMethodScope()) + InsertValue(d, CurMeth.LateResolveValues); + else + InsertValue(d, CurModule.LateResolveValues); return d; } @@ -390,16 +385,26 @@ static Value *getVal(const Type *Ty, const ValID &D) { // time (forward branches, phi functions for loops, etc...) resolve the // defs now... // -static void ResolveDefinitions(vector &LateResolvers) { +static void ResolveDefinitions(vector &LateResolvers, + vector *FutureLateResolvers = 0) { // Loop over LateResolveDefs fixing up stuff that couldn't be resolved for (unsigned ty = 0; ty < LateResolvers.size(); ty++) { while (!LateResolvers[ty].empty()) { Value *V = LateResolvers[ty].back(); + assert(!isa(V) && "Types should be in LateResolveTypes!"); + LateResolvers[ty].pop_back(); ValID &DID = getValIDFromPlaceHolder(V); Value *TheRealValue = getValNonImprovising(Type::getUniqueIDType(ty),DID); - if (TheRealValue == 0) { + if (TheRealValue) { + V->replaceAllUsesWith(TheRealValue); + delete V; + } else if (FutureLateResolvers) { + // Methods have their unresolved items forwarded to the module late + // resolver table + InsertValue(V, *FutureLateResolvers); + } else { if (DID.Type == 1) ThrowException("Reference to an invalid definition: '" +DID.getName()+ "' of type '" + V->getType()->getDescription() + "'", @@ -410,11 +415,6 @@ static void ResolveDefinitions(vector &LateResolvers) { V->getType()->getDescription() + "'", getLineNumFromPlaceHolder(V)); } - - assert(!isa(V) && "Types should be in LateResolveTypes!"); - - V->replaceAllUsesWith(TheRealValue); - delete V; } } @@ -487,6 +487,7 @@ static void ResolveSomeTypes(vector > &LateResolveTypes) { // static bool setValueName(Value *V, char *NameStr) { if (NameStr == 0) return false; + string Name(NameStr); // Copy string free(NameStr); // Free old string @@ -1365,7 +1366,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... // Create the call node... if (!$5) { // Has no arguments? - $$ = new InvokeInst(cast(V), Normal, Except, vector()); + $$ = new InvokeInst(V, Normal, Except, vector()); } else { // Has arguments? // Loop through MethodType's arguments and ensure they are specified // correctly! @@ -1382,7 +1383,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... if (I != E || (ArgI != ArgE && !Ty->isVarArg())) ThrowException("Invalid number of parameters detected!"); - $$ = new InvokeInst(cast(V), Normal, Except, + $$ = new InvokeInst(V, Normal, Except, vector($5->begin(), $5->end())); } delete $5; @@ -1496,7 +1497,7 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef { // Create the call node... if (!$5) { // Has no arguments? - $$ = new CallInst(cast(V), vector()); + $$ = new CallInst(V, vector()); } else { // Has arguments? // Loop through MethodType's arguments and ensure they are specified // correctly!