[llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y

Chris Lattner clattner at apple.com
Sat Apr 28 21:20:29 PDT 2007


> +  switch (ID.Type) {
> +  case ValID::GlobalName:
> +  case ValID::GlobalID:
> +   const PointerType *PTy = dyn_cast<PointerType>(Ty);
> +   if (!PTy) {
> +     GenerateError("Invalid type for reference to global" );
> +     return 0;
> +   }
> +   const Type* ElTy = PTy->getElementType();
> +   if (const FunctionType *FTy = dyn_cast<FunctionType>(ElTy))
> +     V = new Function(FTy, GlobalValue::ExternalLinkage);
> +   else
> +     V = new GlobalVariable(ElTy, false,  
> GlobalValue::ExternalLinkage);
> +   break;
> +  default:
> +   V = new Argument(Ty);
> +  }

Very nice.  Please indent the code in the case statements one more  
space though :)

> @@ -1943,6 +1959,30 @@
>  // ThreadLocal
>  ThreadLocal : THREAD_LOCAL { $$ = true; } | { $$ = false; };
>
> +// AliaseeRef - Match either GlobalValue or bitcast to GlobalValue.
> +AliaseeRef : ResultTypes SymbolicValueRef {
> +    const Type* VTy = $1->get();
> +    Value *V = getVal(VTy, $2);
> +    GlobalValue* Aliasee = dyn_cast<GlobalValue>(V);
> +    if (!Aliasee)
> +      GEN_ERROR("Aliases can be created only to global values");
> +
> +    $$ = Aliasee;
> +    CHECK_FOR_ERROR
> +    delete $1;
> +   }
> +   | BITCAST '(' AliaseeRef TO Types ')' {
> +    Constant *Val = $3;
> +    const Type *DestTy = $5->get();
> +    if (!CastInst::castIsValid($1, $3, DestTy))
> +      GEN_ERROR("invalid cast opcode for cast from '" +
> +                Val->getType()->getDescription() + "' to '" +
> +                DestTy->getDescription() + "'");
> +
> +    $$ = ConstantExpr::getCast($1, $3, DestTy);
> +    CHECK_FOR_ERROR
> +    delete $5;
> +   };

I'd suggest eliminating this production and...

> @@ -2045,34 +2085,20 @@
>      CurGV = 0;
>      CHECK_FOR_ERROR
>    }
> -  | OptGlobalAssign GVVisibilityStyle ALIAS AliasLinkage ResultTypes
> -    SymbolicValueRef {
> +  | OptGlobalAssign GVVisibilityStyle ALIAS AliasLinkage AliaseeRef {

Instead of AliaseeRef, use ResolvedVal here.  Then just check  
ResolvedVal for the two acceptable forms.

-Chris



More information about the llvm-commits mailing list