Adding a collector name attribute to Function in the IR. These
[oota-llvm.git] / lib / AsmParser / llvmAsmParser.y
index 31fd6190827d9530ee23ae3b27e0799c16225f88..57b6f81d8fb756b34096b3bbb4a1d09b6947b865 100644 (file)
@@ -1046,7 +1046,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) {
 %token<StrVal> STRINGCONSTANT ATSTRINGCONSTANT PCTSTRINGCONSTANT
 %type <StrVal> LocalName OptLocalName OptLocalAssign
 %type <StrVal> GlobalName OptGlobalAssign GlobalAssign
-%type <StrVal> OptSection SectionString
+%type <StrVal> OptSection SectionString OptGC
 
 %type <UIntVal> OptAlign OptCAlign
 
@@ -1090,7 +1090,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) {
 
 // Function Attributes
 %token SIGNEXT ZEROEXT NORETURN INREG SRET NOUNWIND NOALIAS BYVAL NEST
-%token READNONE READONLY
+%token READNONE READONLY GC
 
 // Visibility Styles
 %token DEFAULT HIDDEN PROTECTED
@@ -1244,6 +1244,12 @@ OptFuncAttrs  : /* empty */ { $$ = ParamAttr::None; }
               }
               ;
 
+OptGC         : /* empty */ { $$ = 0; }
+              | GC STRINGCONSTANT {
+                $$ = $2;
+              }
+              ;
+
 // OptAlign/OptCAlign - An optional alignment, and an optional alignment with
 // a comma before it.
 OptAlign : /*empty*/        { $$ = 0; } |
@@ -1330,16 +1336,28 @@ Types
   | Types '(' ArgTypeListI ')' OptFuncAttrs {
     // Allow but ignore attributes on function types; this permits auto-upgrade.
     // FIXME: remove in LLVM 3.0.
+    const Type* RetTy = *$1;
+    if (!(RetTy->isFirstClassType() || RetTy == Type::VoidTy ||
+          isa<OpaqueType>(RetTy)))
+      GEN_ERROR("LLVM Functions cannot return aggregates");
+
     std::vector<const Type*> Params;
     TypeWithAttrsList::iterator I = $3->begin(), E = $3->end();
     for (; I != E; ++I ) {
       const Type *Ty = I->Ty->get();
       Params.push_back(Ty);
     }
+
     bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
     if (isVarArg) Params.pop_back();
 
-    FunctionType *FT = FunctionType::get(*$1, Params, isVarArg);
+    for (unsigned i = 0; i != Params.size(); ++i)
+      if (!(Params[i]->isFirstClassType() || isa<OpaqueType>(Params[i])))
+        GEN_ERROR("Function arguments must be value types!");
+
+    CHECK_FOR_ERROR
+
+    FunctionType *FT = FunctionType::get(RetTy, Params, isVarArg);
     delete $3;   // Delete the argument list
     delete $1;   // Delete the return type handle
     $$ = new PATypeHolder(HandleUpRefs(FT)); 
@@ -1354,9 +1372,16 @@ Types
       const Type* Ty = I->Ty->get();
       Params.push_back(Ty);
     }
+
     bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
     if (isVarArg) Params.pop_back();
 
+    for (unsigned i = 0; i != Params.size(); ++i)
+      if (!(Params[i]->isFirstClassType() || isa<OpaqueType>(Params[i])))
+        GEN_ERROR("Function arguments must be value types!");
+
+    CHECK_FOR_ERROR
+
     FunctionType *FT = FunctionType::get($1, Params, isVarArg);
     delete $3;      // Delete the argument list
     $$ = new PATypeHolder(HandleUpRefs(FT)); 
@@ -2206,7 +2231,7 @@ ArgList : ArgListH {
   };
 
 FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')' 
-                  OptFuncAttrs OptSection OptAlign {
+                  OptFuncAttrs OptSection OptAlign OptGC {
   std::string FunctionName(*$3);
   delete $3;  // Free strdup'd memory!
   
@@ -2309,6 +2334,10 @@ FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')'
     Fn->setSection(*$8);
     delete $8;
   }
+  if ($10) {
+    Fn->setCollector($10->c_str());
+    delete $10;
+  }
 
   // Add all of the arguments we parsed to the function...
   if ($5) {                     // Is null if empty...