Simplify some code
authorChris Lattner <sabre@nondot.org>
Tue, 16 Oct 2001 19:54:17 +0000 (19:54 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 16 Oct 2001 19:54:17 +0000 (19:54 +0000)
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
lib/AsmParser/llvmAsmParser.y

index 6abe6083f0dcc9df73b218854de90dd5fa2f997a..cc37bd9bf97100443978285b041ba338dabafeff 100644 (file)
@@ -187,7 +187,6 @@ struct MethPlaceHolderHelper : public Method {
 typedef PlaceholderValue<TypePlaceHolderHelper>  TypePlaceHolder;
 typedef PlaceholderValue<InstPlaceHolderHelper>  ValuePlaceHolder;
 typedef PlaceholderValue<BBPlaceHolderHelper>    BBPlaceHolder;
-typedef PlaceholderValue<MethPlaceHolderHelper>  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();
   }
 }
index 994c2233d2db6ca6baff360f2125f216e9426d89..b45456d609610234acfd00518de287312b575bf8 100644 (file)
@@ -28,7 +28,7 @@
 #include <algorithm>
 #include <stdio.h>            // 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<Value *> ValueList;           // Numbered defs
-static void ResolveDefinitions(vector<ValueList> &LateResolvers);
+static void ResolveDefinitions(vector<ValueList> &LateResolvers,
+                               vector<ValueList> *FutureLateResolvers = 0);
 static void ResolveTypes      (vector<PATypeHolder<Type> > &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<MethodType>(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<ValueList> *LateResolver = inMethodScope() ? 
-    &CurMeth.LateResolveValues : &CurModule.LateResolveValues;
-
-  if (isa<MethodType>(Ty))
-    ThrowException("Methods are not values and must be referenced as pointers");
-
-  if (const PointerType *PTy = dyn_cast<PointerType>(Ty))
-    if (const MethodType *MTy = dyn_cast<MethodType>(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<ValueList> &LateResolvers) {
+static void ResolveDefinitions(vector<ValueList> &LateResolvers,
+                               vector<ValueList> *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<Type>(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<ValueList> &LateResolvers) {
                         V->getType()->getDescription() + "'",
                         getLineNumFromPlaceHolder(V));
       }
-
-      assert(!isa<Type>(V) && "Types should be in LateResolveTypes!");
-
-      V->replaceAllUsesWith(TheRealValue);
-      delete V;
     }
   }
 
@@ -487,6 +487,7 @@ static void ResolveSomeTypes(vector<PATypeHolder<Type> > &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<Method>(V), Normal, Except, vector<Value*>());
+      $$ = new InvokeInst(V, Normal, Except, vector<Value*>());
     } 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<Method>(V), Normal, Except,
+      $$ = new InvokeInst(V, Normal, Except,
                          vector<Value*>($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<Method>(V), vector<Value*>());
+      $$ = new CallInst(V, vector<Value*>());
     } else {                                     // Has arguments?
       // Loop through MethodType's arguments and ensure they are specified
       // correctly!