[llvm-commits] [llvm] r47407 - /llvm/trunk/lib/AsmParser/llvmAsmParser.y

Chris Lattner clattner at apple.com
Thu Feb 21 22:02:09 PST 2008


> Author: dpatel
> Log:
> Parse
> 	ret i32 1, i8 2
> another step towards multiple return value support.

>
> @@ -1459,7 +1460,7 @@
>   : Types {
>     if (!UpRefs.empty())
>       GEN_ERROR("Invalid upreference in type: " + (*$1)- 
> >getDescription());
> -    if (!(*$1)->isFirstClassType())
> +    if (!(*$1)->isFirstClassType() && (*$1)->getTypeID() !=  
> Type::StructTyID)

This should use isa<StructType>()

> +ReturnedVal : ResolvedVal {
> +    $$ = new std::vector<Value *>();
> +    $$->push_back($1);
> +    CHECK_FOR_ERROR
> +  }
> +  | ReturnedVal ',' ConstVal {

Why ConstVal here?  Any value can be returned, it seems that this  
should be ResolvedVal.

> @@ -2565,8 +2576,31 @@
>
>   };
>
> -BBTerminatorInst : RET ResolvedVal {              // Return with a  
> result...
> -    $$ = new ReturnInst($2);
> +BBTerminatorInst :
> +  RET ReturnedVal  { // Return with a result...
> +    if($2->size() == 1)
> +      $$ = new ReturnInst($2->back());
> +    else {
> +
> +      std::vector<const Type*> Elements;
> +      std::vector<Constant*> Vals;
> +      for (std::vector<Value *>::iterator I = $2->begin(),
> +             E = $2->end(); I != E; ++I) {
> +        Value *V = *I;
> +        Constant *C = cast<Constant>(V);
> +        Elements.push_back(V->getType());
> +        Vals.push_back(C);
> +      }
> +
> +      const StructType *STy = StructType::get(Elements);
> +      PATypeHolder *PTy =
> +        new PATypeHolder(HandleUpRefs(StructType::get(Elements)));
> +
> +      Constant *CS = ConstantStruct::get(STy, Vals); // *$2);
> +      $$ = new ReturnInst(CS);
> +      delete PTy;
> +    }
> +    delete $2;

This isn't going to work for returning non-constants.  Return should  
take multiple operands when multiple things are returned, it shouldn't  
force them together into a constantstruct.

-Chris




More information about the llvm-commits mailing list