- GEN_ERROR("Alias name cannot be empty")
- const PointerType *PFTy = 0;
- const FunctionType *Ty = 0;
- Value* V = 0;
- const Type* VTy = 0;
- if (!(PFTy = dyn_cast<PointerType>($5->get())) ||
- !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
- VTy = $5->get();
- V = getExistingVal(VTy, $6);
- } else {
- VTy = PFTy;
- V = getExistingVal(PFTy, $6);
+ GEN_ERROR("Alias name cannot be empty");
+
+ Constant* Aliasee = $5;
+ if (Aliasee == 0)
+ GEN_ERROR(std::string("Invalid aliasee for alias: ") + Name);
+
+ GlobalAlias* GA = new GlobalAlias(Aliasee->getType(), $4, Name, Aliasee,
+ CurModule.CurrentModule);
+ GA->setVisibility($2);
+ InsertValue(GA, CurModule.Values);
+
+
+ // If there was a forward reference of this alias, resolve it now.
+
+ ValID ID;
+ if (!Name.empty())
+ ID = ValID::createGlobalName(Name);
+ else
+ ID = ValID::createGlobalID(CurModule.Values.size()-1);
+
+ if (GlobalValue *FWGV =
+ CurModule.GetForwardRefForGlobal(GA->getType(), ID)) {
+ // Replace uses of the fwdref with the actual alias.
+ FWGV->replaceAllUsesWith(GA);
+ if (GlobalVariable *GV = dyn_cast<GlobalVariable>(FWGV))
+ GV->eraseFromParent();
+ else
+ cast<Function>(FWGV)->eraseFromParent();